If you have a Linux server of the RedHat family (inclusing CentOS and Fedora), you might envy the way Debian/Ubuntu distributions handle PostgreSQL clusters management.
Although it is not easy to install different PostgreSQL versions on the same RedHat Linux server using RPMs, it is much simpler to install several instances of PostgreSQL (servers) and, at the same time, take advantage of the services infrastructure.
Once you have setup the RPM installation, by following the instructions that you find at the PostgreSQL YUM Repository, you will notice that the process will create two files among the others:
/etc/init.d/postgresql
: init script for the PostgreSQL server/etc/sysconfig/pgsql/postgresql
: system configuration for the postgresql service
By default, PostgreSQL data directory (PGDATA
) points to the /var/lib/pgsql/data
directory. It is possible to change it by modifying the /etc/sysconfig/pgsql/postgresql
file.
Let’s suppose we want to install two PostgreSQL servers on the same RedHat Linux, by adding a second server to the default one which will be used for development purposes. We will call this postgresql-devel
. It will be installed in the /var/lib/pgsql/data-devel
directory and will run on the 5433 port.
We create a symbolic link to the main postgresql
init script, and call it postgresql-devel
:
cd /etc/init.d/
ln -s postgresql postgresql-devel
Then we start filling the postgresql-devel
configuration file in the /etc/sysconfig/pgsql
directory. It is important to note that the init script and the system configuration file have the same name.
cat < /etc/sysconfig/pgsql/postgresql-devel
PGDATA=/var/lib/pgsql/data-devel
PGPORT=5433
PGLOG=/var/lib/pgsql/pgstartup.\${PGPORT}.log
EOF
Once this is done, you can initialise the data directory by running: /etc/init.d/postgresql-devel initdb
or simply service postgresql-devel initdb
.
Similarly you can control the startup and the shutdown of the service, by running – respectively:
service postgresql-devel start
service postgresql-devel stop
You can add/remove the script from the startup and the shutdown of the system by using chkconfig
the same way you would with other services.
The PostgreSQL wiki contains a detailed page about this topic, and I suggest that you read it along with this one. However, this simple article shows you how to easiliy integrate multiple PostgreSQL instances on the same Linux server, and manage them using the standard RedHat services infrastructure (thanks to the great job done by Devrim Gunduz).