home / blog

Postgresql hello world

1. Download and build it.

wget http://ftp.postgresql.org/pub/source/v9.1.3/postgresql-9.1.3.tar.bz2
tar xjf postgresql-9.1.3.tar.bz2
cd postgresql-9.1.3
sudo apt-get install libreadline-dev zlib1g-dev
./configure --prefix=$(pwd)/local
make install

2. Initialize and run. Setup a database, with a root user, prompt for password.

export PATH=local/bin:$PATH
initdb -U root -W datadir
postgres -D datadir

3. Create a regular user and a database.

createuser -U root horse -W
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
createdb horsedb -U root -O horse

4. Connect as regular user, create a table and insert some data, then select it.

psql horsedb -U horse
CREATE TABLE horses (name VARCHAR(255), size INT);
INSERT INTO horses (name, size) VALUES('glue factory', 123);
INSERT INTO horses (name, size) VALUES('Mr Ed', 456);
SELECT * FROM horses;
     name     | size 
 glue factory |  123
 Mr Ed        |  456
This entry was posted in geek. Bookmark the permalink.

Leave a Reply

Your email address will not be published.