PostgreSQL 11 Released. It is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 11 on CentOS/RHEL 7/6 system.
This article has been tested on CentOS Linux release 7.5
Step 1 – Configure Yum Repository
Firstly you need to configure the PostgreSQL repository in your system. Use one of the below commands as per your operating system version.
sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
For more details visit PostgreSQL repositories link page where you can get repository package rpm for various operating systems.
Step 2 – Installing PostgreSQL on CentOS 7
After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 11 on your system with yum package manager.
yum install postgresql11-server
This will also install some additional required packages on your system. Enter y to confirm and complete the installation process.
Step 3 – Initialize PGDATA
After that, you need to initialize the PostgreSQL instance. In other words, this will create a data directory and other configuration files on your system. To initialize the database use the below command.
/usr/pgsql-11/bin/postgresql-11-setup initdb
The above command will take some time to initialize PostgreSQL first time. PGDATA environment variable contains the path of data directory.
PostgreSQL 11 default data directory location is /var/lib/pgsql/11/data
Setp 4 – Start PostgreSQL Server
To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.
systemctl enable postgresql-11.service systemctl start postgresql-11.service
Step 5 – Verify PostgreSQL Installation
After completing the above all steps. Your PostgreSQL 11 server is ready to use. Log in to your server to verify the connection.
su - postgres -c "psql" psql (11.0) Type "help" for help. postgres=#
You may create a password for user postgres for security purposes.
postgres=# \password postgres
In conclusion, You have successfully installed the PostgreSQL database server on CentOS/RHEL 7 system.
9 Comments
Installed perfectly. But pg_dump version mismatch. i found pg_dump version 9.2 installed on my server.
How can I upgrade pg_dump version to 11.6
Thanks,
Hi Rahul!
I’ve been traying several ways to chance the data directory in postgresql-11 and I still can’t!, could you tell me how to do that?
Thanks in advance!
Hi Guys,
It does not work for me… when I try to do:
/usr/pgsql-11/bin/postgresql-11-setup initdb
I’m getting the following:
/usr/pgsql-11/bin/postgresql-11-setup: No such file or directory
it looks that I don’t have this postgresql-11-setup file.
List of files in /usr/pgsql-11/bin/ is:
ls -l /usr/pgsql-11/bin/
total 9760
-rwxr-xr-x. 1 root root 53328 May 8 10:19 clusterdb
-rwxr-xr-x. 1 root root 53136 May 8 10:19 createdb
-rwxr-xr-x. 1 root root 57464 May 8 10:19 createuser
-rwxr-xr-x. 1 root root 48944 May 8 10:19 dropdb
-rwxr-xr-x. 1 root root 48944 May 8 10:19 dropuser
-rwxr-xr-x. 1 root root 119440 May 8 10:19 initdb
-rwxr-xr-x. 1 root root 23552 May 8 10:19 pg_archivecleanup
-rwxr-xr-x. 1 root root 108296 May 8 10:19 pg_basebackup
-rwxr-xr-x. 1 root root 140152 May 8 10:19 pgbench
-rwxr-xr-x. 1 root root 27528 May 8 10:19 pg_config
-rwxr-xr-x. 1 root root 37528 May 8 10:19 pg_controldata
-rwxr-xr-x. 1 root root 52800 May 8 10:19 pg_ctl
-rwxr-xr-x. 1 root root 392896 May 8 10:19 pg_dump
-rwxr-xr-x. 1 root root 84984 May 8 10:19 pg_dumpall
-rwxr-xr-x. 1 root root 49400 May 8 10:19 pg_isready
-rwxr-xr-x. 1 root root 67520 May 8 10:19 pg_receivewal
-rwxr-xr-x. 1 root root 48680 May 8 10:19 pg_resetwal
-rwxr-xr-x. 1 root root 155472 May 8 10:19 pg_restore
-rwxr-xr-x. 1 root root 79360 May 8 10:19 pg_rewind
-rwxr-xr-x. 1 root root 27824 May 8 10:19 pg_test_fsync
-rwxr-xr-x. 1 root root 21616 May 8 10:19 pg_test_timing
-rwxr-xr-x. 1 root root 122880 May 8 10:19 pg_upgrade
-rwxr-xr-x. 1 root root 35968 May 8 10:19 pg_verify_checksums
-rwxr-xr-x. 1 root root 77600 May 8 10:19 pg_waldump
-rwxr-xr-x. 1 root root 7290872 May 8 10:19 postgres
lrwxrwxrwx. 1 root root 8 Jun 7 10:05 postmaster -> postgres
-rwxr-xr-x. 1 root root 608784 May 8 10:19 psql
-rwxr-xr-x. 1 root root 57104 May 8 10:19 reindexdb
-rwxr-xr-x. 1 root root 61392 May 8 10:19 vacuumdb
If “/usr/pgsql-11/bin/postgresql-11-setup initdb” – /usr/pgsql-11/bin/postgresql-11-setup: No such file or directory
Then use “service postgresql-11 initdb” to initialize the cluster first.
On centos6 works for me.
Hi Rahul,
This are the perfect steps to install in Redhat Linux 7.
As I am new to postgres, I have question regarding installation location of postgres. Can we change/install it some user manage path in some filesystem or it is default install in /var/lib/… ?
Thank you Rahul
Wrong link
https://yum.postgresql.org/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
404 – Not Found
Thanks for providing this Rahul.
As the extension, for RedHat 7 systems connected to subscription-manager, it might be useful to exclude PostgreSQL packages from other repositories just to prevent accidental installation of older version dependencies. You can check which packages are available with the following command:
yum list postgresql*
and exclude them from listed repositories with:
subscription-manager repo-override –repo=rhel-7-server-rpms –repo=rhel-7-server-optional-rpms –add=exclude:’postgresql*’
For manually added repository it is enough to add “exclude=postgresql*” to /etc/yum.repos.d/XYZ.repo file.
This worked flawlessly. I’ve been using pgsql for years but getting 11.x installed on Linux has proven…difficult. Thanks Rahul.