Tuesday, April 27, 2010

Setting up a Postgres server on RHEL/CentOS 5

The procedure for installing and setting up an account in MySQL is widely documented in various places (such as the document for setting up a MySQL account for Wordpress); however, I haven’t found an online guide for installing and configuring Postgres for RHEL/CentOS Linux.

That in mind, here is my guide
  • Install Postgres:
    yum install postgresql-server
  • Choose language of Postgres UI:
    cd /var/lib/pgsql ; vi data/postgresql.conf
  • Set up a "www" account and make a database for said account:
    su postgres
    # Answer No for all three questions when doing:
    createuser www
    createdb -O www www
    # No, no, and no (no special privileges)
  • Make the database password protected:
    vi /var/lib/pgsql/data/pg_hba.conf
    Make all authentication over the network 'password' instead of 'ident'

  • Apply the changes:
    /etc/init.d/postgresql restart
  • Let’s give the “www” user a password:
    su postgres
    psql
    And at the prompt...
    ALTER ROLE www WITH LOGIN;
    ALTER ROLE www WITH PASSWORD 'foo';
    \q
    The semicolon is important.