Tuesday 10 July 2012

Set up Postgresql on Ubuntu 12.04

irst install postgresql. For some extensions like citext and adminpack to work we also need to have postgresql-contrib installed. We'll also install pgadmin to manage our databases.
sudo apt-get install postgresql postgresql-contrib pgadmin3
Now we'll set up some of the postgresql configurations.
First off we'll allow connections from other computers. Edit /etc/postgresql/9.1/main/postgresql.conf. To edit run the fallowing command
sudo nano /etc/postgresql/*/main/postgresql.conf
And modify the fallowing line
#listen_addresses = 'localhost'
to look like this
listen_addresses = '*'

Also edit the following file
sudo nano /etc/postgresql/*/main/pg_hba.conf
and add the following line(s) to the file. Notice replace 192.168.0.1/24 with the network that you are on. The other thing that would probably work is replace 192.168.0.1/24 with all, but anybody in the world would be able to connect to your database and not just people on your network.
# allow local connections
host all all 192.168.0.1/24 md5


Now we need to create a password yet for user postgresql. you only need to type the highlighted part. The rest is what the expected results should be.

Create a passowrd for user posgtres

$ sudo su postgres -c psql template1
psql (9.1.4)
Type "help" for help.


postgres=# ALTER USER postgres WITH PASSWORD 'password';
ALTER ROLE
postgres=# \q
$

For all of these settings to take affect we need to restart postgresql.
sudo service postgresql restart


We are now ready to connect with pgadmin

No comments:

Post a Comment