Install PostgreSQL on Linux

Redhat Linux

  • Download a PostgreSQL distribution from http://www.postgresql.org/ftp/binary/
    • postgresql-libs-8.3.0-1PGDG.f7.i686.rpm (libraries)
    • postgresql-server-8.3.0-1PGDG.f7.i686.rpm (server)
    • postgresql-8.3.0-1PGDG.f7.i686.rpm (client)
  • To run postgres, use:
service postgresql [status|stop|start|restart]
  • The first time you run "service postgresql start", it asks you to initialize a database, run:
service postgresql initdb
  • Configuration files can be found at this path /var/lib/pgsql/data


Ubuntu Linux

sudo apt-get install postgresql-8.3
sudo apt-get install pgadmin3

(pgAdmin III is a handy GUI for PostgreSQL)

  • To run postgres, use:
/etc/init.d/postgresql [status|stop|start|restart]
  • Configuration files can be found at this path /etc/postgres/<version>/main/


PostgreSQL Configurations

  • Change postgres user password
sudo -u postgres psql template1
template1=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'postgres';
template1=# \q
  • Update pg_hba.conf with something like:

Change this line:

host all all 127.0.0.1/32 ident sameuser

to:

host all all 127.0.0.1/32 md5
  • Update postgresql.conf with (if you want to connect from a remote machine):

Change this line:

#listen_addresses = 'localhost'

to

listen_addresses = '*'

Change this line:

#password_encryption = on

to

password_encryption = on