PostgreSQL – useful stuff

(Everything below has been done on FreeBSD 10.1 with PostgreSQL 9.3)

How to connect to the PostgreSQL database:

su – psql

pgsql -U pgsql -d template1

How to list the PostgreSQL databases

\l #(that is a lowercase L not an i)

How to add a user and grant permissions to a certain PostgreSQL database:

psql -U pgsql -d template1

CREATE USER username WITH PASSWORD ‘password’;

CREATE DATABASE dbname;

GRANT ALL PRIVILEGES ON DATABASE dbname to username;

Remove database and user:

DROP DATABASE dbname;

DROP USER username;

Backup/Dump | Restore a PostgreSQL database:

dump -> pg_dump -U username dbname -f dump.sql

restore -> psql -U username -d dbname -f dump.sql

CentOS wifi howto setup

Hi,

So here are the instructions for getting the wifi rolling:
——————————————
yum -y install wireless-tools wpa_supplicant dbus
——————————————
ifconfig wlan0 up
iwlist wlan0 scan

record the channel number
ifconfig wlan0 down
——————————————
create /etc/sysconfig/network-scripts/ifcfg-wlan0 with the contents below and the instructions mentioned below:

DEVICE=wlan0
HWADDR=<your-mac-address>
TYPE=Wireless
UUID=<an-optional-uuid> #generate one with uuidgen
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
PEERDNS=yes
USERCTL=yes
NETWORKING_IPV6=no
ESSID=<your-ssid> # you should either know this or take it from the iwlist wlan0 scan
CHANNEL=<ssid-channel> #the channel you got from when you ran iwlist wlan0 scan
MODE=Managed
RATE=Auto
——————————————
chkconfig NetworkManager off
——————————————
edit /etc/sysconfig/wpa_supplicant and add the wlan name: INTERFACES=”-iwlan0″
——————————————
load the encrypted passphrase in the supplicant
wpa_passphrase <ssid> <passphrase> >> /etc/wpa_supplicant/wpa_supplicant.conf
——————————————
chkconfig messagebus on
chkconfig wpa_supplicant on
——————————————
If the wireless is the only active option, edit /etc/sysconfig/network-scripts – the configs for ifcfg-eth0 and 1 and set onboot to no, so that the route goes over wifi.
——————————————
reboot

Everything should be good to go.

RVM style multiple Python versions on the same server – Centos5

Hi, so i need to setup some services that use Python 2.7.6, however, since i am using the same Centos5.10 machines that i can’t reload, and i don’t really need to reload them since they are working fine (don’t fix what’s not broken), and on Centos5 you have 2.4.3, and if you decide to upgrade it, you will most likely screw a lot of things in the process, here’s a nice tutorial on how to work things out, using a similar approach to Ruby’s Version Manager or RVM:

1 – Create a user of your choosing, and login as said user.

2 – git clone git://github.com/yyuu/pyenv.git .pyenv

3 – Add env variables to your bash profile (i assume you should be using the bash shell, if you’re using another shell not sure how that goes):

echo ‘export PYENV_ROOT=”$HOME/.pyenv”‘ >> ~/.bash_profile
echo ‘export PATH=”$PYENV_ROOT/bin:$PATH”‘ >> ~/.bash_profile
echo ‘eval “$(pyenv init -)”‘ >> ~/.bash_profile

4 – Logout and relog, or restart shell. I find relog to be the choice for me as i usually have consoles opened for long periods of time, so i might forget and control+D and then miss my settings and wonder why.

5 – Install the Python version you need!

pyenv install 2.7.6

6 – Setup your new installed version as default:

pyenv local 2.7.6

7 – Enjoy your new Python installation!