Monday, August 1, 2011

Installation and Configuration of PostgreSQL to a Headless CentOS Server Step-By-Step


This procedure walks you through step-by-step installation and configuration of 64-bit PostgreSQL server 8.4.8 onto a headless 64-bit CentOS 5.5 server.  The procedure involves four basic steps: 1) install PostgreSQL, 2) initialize the database, 3) start the PostgreSQL service, 4) create a symlink, 5) ensure ownership, and 6) ensure external client access.  You will install the server only; you will not install any GUI interfaces (such as pgAdmin).  All references used in this walkthrough are provided in the References section.  Good luck!


Step 1: Install PostgreSQL

This step will install the PostgreSQL package group that comes with 64-bit CentOS.  This group includes the following packages:
  • postgresql-libs-8.4.8-1PGDG.rhel5.x86_64.rpm
  • postgresql-8.4.8-1PGDG.rhel5.x86_64.rpm
  • postgresql-server-8.4.8-1PGDG.rhel5.x86_64.rpm
Open a terminal on the target server.  Login to the root account.

Install the PostgreSQL server package and its dependencies using YUM.  Be sure to disable gpg signature checking, in order to avoid annoying warnings:
[root]# yum install postgresql-server --nogpgcheck
Installation of this package group will create the following subdirectories:
  • /var/log/pgsql
  • /var/lib/pgsql
  • /usr/share/pgsql
  • /usr/lib64/pgsql
  • /etc/sysconfig/pgsq
Step 2: Initialize the Database

Note that database initialization on RHEL (and thus also CentOS) will be somewhat different than other Linux flavors.

Execute the following command:
[root]# service postgresql initdb –D /var/lib/pgsql/data
Or, you may need to initialize the database using this approach:
[root]# /etc/init.d/postgresql start
Step 3: Start the Service

Execute the following command:
[root]# /etc/rc.d/init.d/postgresql start
Step 4: Create the Symlink

The default location on RHEL (and thus also CentOS) systems is /var/lib/pgsql.  However, applications such as bash will expect the location to be /usr/local/pgsql.  This can be fixed via soft symlink:
[root]# ln –s /var/lib/pgsql   /usr/local/pgsql
Step 5: Ensure Ownership

Check to make sure that the postgres account owns the pgsql directory and subdirectories:
[root]# ls –l /var/lib
If not, you will need to change ownership.  When changing ownership, do so recursively.  Test the account by logging into it and then performing stop and start commands:
[root]# su – postgres 
-bash-3.2$ pg_ctl –stop 
-bash-3.2$ pg_ctrl start
Step 6: Enable External Client Access

Stop the PostgreSQL instance so that you can edit configuration settings files:
[root]# service postgresql stop
Save a copy of the original configuration file:
[root]# cp /var/lib/pgsql/data/postgresql.conf /var/lib/pgsql/data/postgresql.conf.ORIGINAL
Update the PostgreSQL configuration file to enable it to listen in on the server IP address at the default port:
[root]# vi /var/lib/pgsql/data/postgresql.conf
Uncomment the line “listen_addresses” and set it equal to ‘*’.  Uncomment the “port” and leave it set to the default port (5432). Save a copy of the original security access file:
[root]# cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.ORIGINAL
Update the PostgreSQL security access file to enable client access to this PostgreSQL instance from within the subnet
[root]# vi /var/lib/pgsql/data/pg_hba.conf
Identify the mask appropriate to your network.  For example, if it is, you would add this line:
host all all  md5
Additionally, if you want to be able to use a GUI to interact with this postgresql instance over a VPN, you’ll need to identify the IP address that is received by the PostgreSQL instance and add this to the list of hosts allowed to connect.  For example, if your VPN IP address was, then to allow only your IP address to be able to connect you would add the following:
host all all  md5
Startup the postgressql service back up:
[root]# service postgresql start
This completes this PostgreSQL installation procedure.
In this step-by-step walkthrough, you installed the 64-bit version of PostgreSQL server 8.4.8 onto a headless 64-bit CentOS server.  Congratulations!
  1. PostgreSQL Home Page:
  2. PostgreSQL 8.4.8 Documentation:
  • TBD

No comments: