Skip to content

Running more than one 9.4 /9.3 instance in parallel on RHEL 7

In the 3rd post of "PostgreSQL on RHEL7 series, I will mention about running more than one 9.4 instance on RHEL 7. This article is also valid for 9.3.
In previous versions of RHEL, a good way to start multiple instance is/was using sysconfig files. As of RHEL 7, this is pretty much simplified.

First, you will need to create a new unit file for the new cluster. You can give any name in here. To distinguish the cluster, I added port value to the unit file name:

cp /lib/systemd/system/postgresql-9.4.service /etc/systemd/system/postgresql-9.4-5434.service

Ok, now please edit this file, and change PGDATA. Please note that you can give any directory name in here that postgres can access. You don't have to create this directory now, it will be created in the next step:


Let's move forward with initdb:

/usr/pgsql-9.4/bin/postgresql94-setup initdb postgresql-9.4-5434

As you probably noticed, we passed a string to setup script, as a second parameter. This one must match the name of the unit file you created in the previous step. This script will run initdb in the specifled location.

Final step before starting the cluster is changing the port number:

sed -i "s/#port = 5432/port = 5434/g" /var/lib/pgsql/9.4/data-5434/postgresql.conf

Now, you can start the cluster:

systemctl start postgresql-9.4-5434.service

Please don't forget to set this instance to start on boot:

systemctl enable postgresql-9.4-5434.service

You can check the status of the cluster with the following command:

systemctl status postgresql-9.4-5434.service
postgresql-9.4-5434.service - PostgreSQL 9.4 database server
Loaded: loaded (/etc/systemd/system/postgresql-9.4-5434.service; enabled)
Active: active (running) since Thu 2014-07-03 16:07:49 EEST; 7min ago
Process: 17245 ExecStart=/usr/pgsql-9.4/bin/pg_ctl start -D ${PGDATA} -s -w -t 300 (code=exited, status=0/SUCCESS)
Process: 17240 ExecStartPre=/usr/pgsql-9.4/bin/postgresql94-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 17250 (postgres)
CGroup: /system.slice/postgresql-9.4-5434.service
├─17250 /usr/pgsql-9.4/bin/postgres -D /var/lib/pgsql/9.4/data-5434
├─17251 postgres: logger process
├─17253 postgres: checkpointer process
├─17254 postgres: writer process
├─17255 postgres: wal writer process
├─17256 postgres: autovacuum launcher process
└─17257 postgres: stats collector process

Jul 03 16:07:48 rhel-7-x86-64 pg_ctl[17245]: < 2014-07-03 16:07:48.490 EEST >LOG: redirecting log output to logging collector process
Jul 03 16:07:48 rhel-7-x86-64 pg_ctl[17245]: < 2014-07-03 16:07:48.490 EEST >HINT: Future log output will appear in directory "pg_log".
Jul 03 16:07:49 rhel-7-x86-64 systemd[1]: Started PostgreSQL 9.4 database server.
Jul 03 16:15:13 rhel-7-x86-64 systemd[1]: Started PostgreSQL 9.4 database server.


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options