Installing and configuring PostgreSQL 9.3 and 9.4 on RHEL 7
Red Hat Enterprise Linux 7 was released recently. The day after the release, we announced PostgreSQL 9.4 RPMs for RHEL 7, and last week we pushed PostgreSQL 9.3 RPMs for RHEL 7.
Since Red Hat switched to systemd as of 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?
Since Red Hat switched to systemd as of 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?
First, as usual, you need to install the repository package. Please visit the repo RPMs page. You will see a link to the repo package links, like for 9.4 and 9.3.
So, to install 9.4 repo RPMs for RHEL 7, run:
to install 9.3 repo RPMs for RHEL 7, run:
Next step is installing RPMs. You can either install the individual RPMs, or use groupinstall feature that install -libs, -server, -contrib along with the client package.
To install PostgreSQL 9.4 on RHEL 7, please run
To install PostgreSQL 9.3 on RHEL 7, please run
The next step is initializing the cluster. This is done using a command line tool, which is designed for the RPMs. Please run this command as root.
For 9.4:
For 9.3:
If there is no error message, you are ready to start the cluster. This is done using the unit files:
For 9.4:
For 9.3:
The postmasters should start, if there is no port conflict, etc.
As of RHEL 7, as done in the Fedora packages for two years, the unit files are located under /lib/systemd/system/ directory. Please do not edit these files directly. Instead, if you want to make any changes, create a copy of them under /etc/systemd/system/ , and edit those files. Run
Also, as of RHEL 7, we got rid of the PGPORT variable in unit files. This will fix the issues caused by changing the port number both in init script / unit file and postgresql.conf. The port can now only be changed in postgresql.conf.
In order to start PostgreSQL on boot, you need to enable the unit file:
For 9.4:
For 9.3:
To restart or reload the instance, you can use the following commands:
For 9.4:
For 9.3:
So, to install 9.4 repo RPMs for RHEL 7, run:
yum install http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-redhat94-9.4-1.noarch.rpm
to install 9.3 repo RPMs for RHEL 7, run:
yum install http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
Next step is installing RPMs. You can either install the individual RPMs, or use groupinstall feature that install -libs, -server, -contrib along with the client package.
To install PostgreSQL 9.4 on RHEL 7, please run
yum groupinstall "PostgreSQL Database Server 9.4 PGDG"
To install PostgreSQL 9.3 on RHEL 7, please run
yum groupinstall "PostgreSQL Database Server 9.3 PGDG"
The next step is initializing the cluster. This is done using a command line tool, which is designed for the RPMs. Please run this command as root.
For 9.4:
/usr/pgsql-9.4/bin/postgresql94-setup initdb
For 9.3:
/usr/pgsql-9.3/bin/postgresql93-setup initdb
If there is no error message, you are ready to start the cluster. This is done using the unit files:
For 9.4:
systemctl start postgresql-9.4.service
For 9.3:
systemctl start postgresql-9.3.service
The postmasters should start, if there is no port conflict, etc.
As of RHEL 7, as done in the Fedora packages for two years, the unit files are located under /lib/systemd/system/ directory. Please do not edit these files directly. Instead, if you want to make any changes, create a copy of them under /etc/systemd/system/ , and edit those files. Run
systemctl daemon-reloadafter adding a custom unit file.
Also, as of RHEL 7, we got rid of the PGPORT variable in unit files. This will fix the issues caused by changing the port number both in init script / unit file and postgresql.conf. The port can now only be changed in postgresql.conf.
In order to start PostgreSQL on boot, you need to enable the unit file:
For 9.4:
systemctl enable postgresql-9.4.service
For 9.3:
systemctl enable postgresql-9.3.service
To restart or reload the instance, you can use the following commands:
For 9.4:
systemctl restart postgresql-9.4.service
systemctl reload postgresql-9.4.service
For 9.3:
systemctl restart postgresql-9.3.service
systemctl reload postgresql-9.3.service
Please let us know if you see any packaging issues.
Comments
Display comments as Linear | Threaded
Martin Gudmundsson on :
Very clear and easy to follow instructions.
And happy to see the PORT variable removed. That has caused some confusion, at least for me.
It would be nice with a follow up article on how to manage several postgres instances on the same EL7 OS.
Any chance of seeing that?
//Martin
Devrim Gündüz on :
Sure. I can write it in a few days.
Regards, Devrim
Denis Subbotin on :
Devrim Gündüz on :
No. There are missing dependencies that should come from EPEL. I am waiting for EPEL 7 to recover from beta.
Regards, Devrim