Since Red Hat switched to systemd on RHEL 7, there are some changes in the packaging as compared to RHEL 5 and RHEL 6. So, how do you install and configura PostgreSQL on RHEL 7? Here is a quick guide

Package installatin

First, as usual, you need to install the repository package. If you have mirrored postgres 94 repo to your local repository, then just run

yum install  postgresql94-libs  postgresql94-server postgresql94-contrib postgresql94

Please visit the repo RPMs page, download packages then install them.

Here is the link

PostgreSQL DB initialization

The next step is initializing the cluster. Run this command as root.

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

By default, the postgres data directory is located at /var/lib/pgsql/9.4/data, if you want move it to a dedicated disk area, do so by running

mv /var/lib/pgsql/9.4 <postgresql directory>  ; ln -s <postgresql directory> /var/lib/pgsql/9.4

If there is no error message, then move to the next step.

PostgreSQL configuration files

There are two main configuration files for postgres, they are:


Change the configuration values according to you application's needs. See Postgresql mostly tuned parameters for details.

Start the PostgreSQL service

This is done by systemd:

systemctl start postgresql-9.4.servics

The postmasters should start, if there is no port conflict, etc.

Run the command below to see error log

systemctl status postgresql-9.4.servics

In order to start PostgreSQL on boot, you need to enable the unit file:

systemctl enable postgresql-9.4.service

To restart or reload the instance, you can use the following commands:

systemctl restart postgresql-9.4.service
systemctl reload postgresql-9.4.service

To stop PostgreSQL service

systemctl stop