Sunday 2 March 2014

Postgresql on Ubuntu server

Install
To install use the command line and type:


 sudo apt-get install postgresql postgresql-contrib
 
This will install the latest version available in your Ubuntu release and the commonly used add-ons for it.
We then need to change the password for the postgres database user; as postgres we execute the psql command

sudo -u postgres psql postgres
 
and give the user a password

\password postgres
 
type a password and quit psql with Ctrl+D or \quit
to set a *nix password for the user use the

sudo passwd postgres
 
and type the new *nix password for the user

User access
Then to give users access amend the

/etc/postgresql/current/main/pg_hba.conf 
 
and add something like below (granting all users on subnet 10.0.0.0 255.255.255.0 access to all databases with username / password method)

typedatabaseuserip addressmethod
hostallall10.0.0.0/24md5


And make sure postgresql listen on the correct interface / ip address in

/etc/postgresql/current/main/postgresql.conf 
 
by configuring the listen_addresses. Default only listen on localhost.

This can then be tested with the following from a host on the 10.0.0.0/24 subnet:

psql -h 10.0.0.1 -U postgres -d postgres

Add a database and spesific user for it

To create a database with a user that have full rights on the database, use the following command:
sudo -u postgres createuser -D -A -P myuser
sudo -u postgres createdb -O myuser mydb
 
Else install pgadmin to manage the database.


No comments:

Post a Comment