Friday, 17 October 2014

Set Up PostgreSql On Ubuntu

sudo apt-get install postgresql postgresql-contrib

sudo apt-get install libpq-dev

sudo -u postgres createuser --superuser tarun

sudo -u postgres psql

postgres=# \password tarun

password: tarun

enter again password: tarun


Client programs, by default, connect to the local host using your Ubuntu login name and expect to find a database with that name too. So to make things REALLY easy, use your new superuser privileges granted above to create a database with the same name as your login name:

 sudo -u postgres createdb tarun

Connecting to your own database to try out some SQL should now be as easy as:


Creating additional database is just as easy, so for example, after running this:

 create database mmagap;

 If you get the below error after restart the server

psql: FATAL: Peer authentication failed for user "postgres"

Switch to postgres user

$ sudo su - postgres   #it will ask for password and by default password is also postgres

After switch the user to postgres, open psql console

$ psql

so check the version of postgres if multiple versions are available

psql=# select VERSION();

PostgreSQL 9.1.13 on x86_64-unk....         # so version is 9.1

Now Open From postgres user

vim /etc/postgresql/9.1/main/pg_hba.conf   #  9.1 is version return form upper command

and replace

local   all             postgres                                peer


local   all             postgres                                md5