cancel
Showing results for 
Search instead for 
Did you mean: 

How to install PostgreSQL 11 on CentOS 7

This is a quick and simple guide to installing community PostgreSQL 11 on CentOS 7, utilizingyum, the package tool that comes as part of CentOS 7. Although this guide is listed as a CentOS 7 guide, it is compatible with Red Hat Enterprise Linux 7 (RHEL 7) as well.

 

  1.  Add the PostgreSQL RPM repo:
    [root@d9d091127ce3 /]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    
    Please note that in the command above, you will need to press "Y"  during some of the prompts in the command line. If you want to use this in a script, or just don't like waiting for the prompts, you can add the -yflag, seen here:
    [root@d9d091127ce3 /]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    
  2. Use YUM to pull and install the PostgreSQL 11 server (which also comes with the client). Just like with the command above, you will also need to press "Y" at the prompts, 
    [root@d9d091127ce3 /]# yum install postgresql11-server
    
    Just like in step 1, you will need to press "Y" at some of the prompts for the installation to complete, so you can use the-yflag here as well if you want to use this in a script.
    [root@d9d091127ce3 /]# yum install -y postgresql11-server
    
  3. Now that PostgreSQL 11 is installed, we need to initialize the database cluster using the following command:
    [root@d9d091127ce3 /]# /usr/pgsql-11/bin/postgresql-11-setup initdb
    
  4. Finally, we need to start the PostgreSQL 11 Service.
    [root@d9d091127ce3 /]# systemctl start postgresql-11.service
    
    If you would like PostgreSQL 11 to start up automatically upon booting up your CentOS 7 device, you can enable it with the following command:
    [root@d9d091127ce3 /]# systemctl enable postgresql-11.service
    
  5. At this point, you're all set! You can begin using your PostgreSQL 11 database with the following command:
    [root@d9d091127ce3 /]# su - postgres -c "psql"
    

 

I omitted the output of the commands above to keep the steps clear and concise, but if you are interested in seeing the output, here is the full output of the steps above from my terminal.

 

[root@d9d091127ce3 /]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Loaded plugins: fastestmirror, ovl
pgdg-redhat-repo-latest.noarch.rpm | 5.6 kB 00:00:00
Examining /var/tmp/yum-root-ej0z0F/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-4.noarch
Marking /var/tmp/yum-root-ej0z0F/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-4 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================
Package Arch Version Repository Size
====================================================================================
Installing:
pgdg-redhat-repo noarch 42.0-4 /pgdg-redhat-repo-latest.noarch 6.8 k

Transaction Summary
====================================================================================
Install 1 Package

Total size: 6.8 k
Installed size: 6.8 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-redhat-repo-42.0-4.noarch 1/1
Verifying : pgdg-redhat-repo-42.0-4.noarch 1/1

Installed:
pgdg-redhat-repo.noarch 0:42.0-4

Complete!


[root@d9d091127ce3 /]# yum install postgresql11-server Loaded plugins: fastestmirror, ovl base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 pgdg10 | 4.1 kB 00:00:00 pgdg11 | 4.1 kB 00:00:00 pgdg94 | 4.1 kB 00:00:00 pgdg95 | 4.1 kB 00:00:00 pgdg96 | 4.1 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/14): base/7/x86_64/group_gz | 166 kB 00:00:00 (2/14): extras/7/x86_64/primary_db | 200 kB 00:00:01 (3/14): base/7/x86_64/primary_db | 6.0 MB 00:00:02 (4/14): pgdg10/7/x86_64/group_gz | 245 B 00:00:02 (5/14): pgdg11/7/x86_64/group_gz | 245 B 00:00:02 (6/14): pgdg95/7/x86_64/group_gz | 249 B 00:00:00 (7/14): pgdg10/7/x86_64/primary_db | 225 kB 00:00:03 (8/14): pgdg94/7/x86_64/group_gz | 247 B 00:00:01 (9/14): pgdg96/7/x86_64/group_gz | 249 B 00:00:00 (10/14): pgdg94/7/x86_64/primary_db | 249 kB 00:00:01 (11/14): pgdg95/7/x86_64/primary_db | 240 kB 00:00:01 (12/14): pgdg11/7/x86_64/primary_db | 179 kB 00:00:02 (13/14): updates/7/x86_64/primary_db | 5.0 MB 00:00:00 (14/14): pgdg96/7/x86_64/primary_db | 243 kB 00:00:01 Determining fastest mirrors * base: centos.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Resolving Dependencies --> Running transaction check ---> Package postgresql11-server.x86_64 0:11.3-1PGDG.rhel7 will be installed --> Processing Dependency: postgresql11-libs(x86-64) = 11.3-1PGDG.rhel7 for package: postgresql11-server-11.3-1PGDG.rhel7.x86_64 --> Processing Dependency: postgresql11(x86-64) = 11.3-1PGDG.rhel7 for package: postgresql11-server-11.3-1PGDG.rhel7.x86_64 --> Processing Dependency: libpq.so.5()(64bit) for package: postgresql11-server-11.3-1PGDG.rhel7.x86_64 --> Processing Dependency: libicuuc.so.50()(64bit) for package: postgresql11-server-11.3-1PGDG.rhel7.x86_64 --> Processing Dependency: libicui18n.so.50()(64bit) for package: postgresql11-server-11.3-1PGDG.rhel7.x86_64 --> Running transaction check ---> Package libicu.x86_64 0:50.1.2-17.el7 will be installed ---> Package postgresql11.x86_64 0:11.3-1PGDG.rhel7 will be installed --> Processing Dependency: systemd-sysv for package: postgresql11-11.3-1PGDG.rhel7.x86_64 ---> Package postgresql11-libs.x86_64 0:11.3-1PGDG.rhel7 will be installed --> Running transaction check ---> Package systemd-sysv.x86_64 0:219-62.el7_6.6 will be installed --> Processing Dependency: systemd = 219-62.el7_6.6 for package: systemd-sysv-219-62.el7_6.6.x86_64 --> Running transaction check ---> Package systemd.x86_64 0:219-42.el7_4.10 will be updated ---> Package systemd.x86_64 0:219-62.el7_6.6 will be an update --> Processing Dependency: systemd-libs = 219-62.el7_6.6 for package: systemd-219-62.el7_6.6.x86_64 --> Processing Dependency: libcryptsetup.so.12(CRYPTSETUP_2.0)(64bit) for package: systemd-219-62.el7_6.6.x86_64 --> Processing Dependency: liblz4.so.1()(64bit) for package: systemd-219-62.el7_6.6.x86_64 --> Processing Dependency: libcryptsetup.so.12()(64bit) for package: systemd-219-62.el7_6.6.x86_64 --> Running transaction check ---> Package cryptsetup-libs.x86_64 0:1.7.4-3.el7_4.1 will be updated ---> Package cryptsetup-libs.x86_64 0:2.0.3-3.el7 will be an update --> Processing Dependency: libjson-c.so.2()(64bit) for package: cryptsetup-libs-2.0.3-3.el7.x86_64 ---> Package lz4.x86_64 0:1.7.5-2.el7 will be installed ---> Package systemd-libs.x86_64 0:219-42.el7_4.10 will be updated ---> Package systemd-libs.x86_64 0:219-62.el7_6.6 will be an update --> Running transaction check ---> Package json-c.x86_64 0:0.11-4.el7_0 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================== Package Arch Version Repository Size ==================================================================================== Installing: postgresql11-server x86_64 11.3-1PGDG.rhel7 pgdg11 4.7 M Installing for dependencies: json-c x86_64 0.11-4.el7_0 base 31 k libicu x86_64 50.1.2-17.el7 base 6.9 M lz4 x86_64 1.7.5-2.el7 base 98 k postgresql11 x86_64 11.3-1PGDG.rhel7 pgdg11 1.7 M postgresql11-libs x86_64 11.3-1PGDG.rhel7 pgdg11 360 k systemd-sysv x86_64 219-62.el7_6.6 updates 84 k Updating for dependencies: cryptsetup-libs x86_64 2.0.3-3.el7 base 338 k systemd x86_64 219-62.el7_6.6 updates 5.1 M systemd-libs x86_64 219-62.el7_6.6 updates 407 k Transaction Summary ==================================================================================== Install 1 Package (+6 Dependent packages) Upgrade ( 3 Dependent packages) Total download size: 20 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. warning: /var/cache/yum/x86_64/7/base/packages/json-c-0.11-4.el7_0.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for json-c-0.11-4.el7_0.x86_64.rpm is not installed (1/10): json-c-0.11-4.el7_0.x86_64.rpm | 31 kB 00:00:00 (2/10): cryptsetup-libs-2.0.3-3.el7.x86_64.rpm | 338 kB 00:00:00 (3/10): lz4-1.7.5-2.el7.x86_64.rpm | 98 kB 00:00:00 (4/10): libicu-50.1.2-17.el7.x86_64.rpm | 6.9 MB 00:00:01 warning: /var/cache/yum/x86_64/7/pgdg11/packages/postgresql11-libs-11.3-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY Public key for postgresql11-libs-11.3-1PGDG.rhel7.x86_64.rpm is not installed (5/10): postgresql11-libs-11.3-1PGDG.rhel7.x86_64.rpm | 360 kB 00:00:03 Public key for systemd-libs-219-62.el7_6.6.x86_64.rpm is not installed 00:00:10 ETA (6/10): systemd-libs-219-62.el7_6.6.x86_64.rpm | 407 kB 00:00:00 (7/10): systemd-sysv-219-62.el7_6.6.x86_64.rpm | 84 kB 00:00:00 (8/10): systemd-219-62.el7_6.6.x86_64.rpm | 5.1 MB 00:00:01 (9/10): postgresql11-11.3-1PGDG.rhel7.x86_64.rpm | 1.7 MB 00:00:05 (10/10): postgresql11-server-11.3-1PGDG.rhel7.x86_64.rpm | 4.7 MB 00:00:05 ------------------------------------------------------------------------------------ Total 2.1 MB/s | 20 MB 00:09 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-4.1708.el7.centos.x86_64 (@CentOS) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Is this ok [y/N]: y Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Importing GPG key 0x442DF0F8: Userid : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>" Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8 Package : pgdg-redhat-repo-42.0-4.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : lz4-1.7.5-2.el7.x86_64 1/13 Updating : systemd-libs-219-62.el7_6.6.x86_64 2/13 Installing : postgresql11-libs-11.3-1PGDG.rhel7.x86_64 3/13 Installing : libicu-50.1.2-17.el7.x86_64 4/13 Installing : json-c-0.11-4.el7_0.x86_64 5/13 Updating : cryptsetup-libs-2.0.3-3.el7.x86_64 6/13 Updating : systemd-219-62.el7_6.6.x86_64 7/13 Installing : systemd-sysv-219-62.el7_6.6.x86_64 8/13 Installing : postgresql11-11.3-1PGDG.rhel7.x86_64 9/13 Installing : postgresql11-server-11.3-1PGDG.rhel7.x86_64 10/13 Cleanup : systemd-219-42.el7_4.10.x86_64 11/13 Cleanup : cryptsetup-libs-1.7.4-3.el7_4.1.x86_64 12/13 Cleanup : systemd-libs-219-42.el7_4.10.x86_64 13/13 Verifying : cryptsetup-libs-2.0.3-3.el7.x86_64 1/13 Verifying : postgresql11-11.3-1PGDG.rhel7.x86_64 2/13 Verifying : postgresql11-server-11.3-1PGDG.rhel7.x86_64 3/13 Verifying : systemd-sysv-219-62.el7_6.6.x86_64 4/13 Verifying : libicu-50.1.2-17.el7.x86_64 5/13 Verifying : postgresql11-libs-11.3-1PGDG.rhel7.x86_64 6/13 Verifying : lz4-1.7.5-2.el7.x86_64 7/13 Verifying : systemd-libs-219-62.el7_6.6.x86_64 8/13 Verifying : systemd-219-62.el7_6.6.x86_64 9/13 Verifying : json-c-0.11-4.el7_0.x86_64 10/13 Verifying : systemd-219-42.el7_4.10.x86_64 11/13 Verifying : cryptsetup-libs-1.7.4-3.el7_4.1.x86_64 12/13 Verifying : systemd-libs-219-42.el7_4.10.x86_64 13/13 Installed: postgresql11-server.x86_64 0:11.3-1PGDG.rhel7 Dependency Installed: json-c.x86_64 0:0.11-4.el7_0 libicu.x86_64 0:50.1.2-17.el7 lz4.x86_64 0:1.7.5-2.el7 postgresql11.x86_64 0:11.3-1PGDG.rhel7 postgresql11-libs.x86_64 0:11.3-1PGDG.rhel7 systemd-sysv.x86_64 0:219-62.el7_6.6 Dependency Updated: cryptsetup-libs.x86_64 0:2.0.3-3.el7 systemd.x86_64 0:219-62.el7_6.6 systemd-libs.x86_64 0:219-62.el7_6.6 Complete!


[root@d9d091127ce3 /]# /usr/pgsql-11/bin/postgresql-11-setup initdb Initializing database ... OK [root@d9d091127ce3 /]# systemctl start postgresql-11.service

[root@d9d091127ce3 /]# systemctl enable postgresql-11.service Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.
[root@d9d091127ce3 /]# su - postgres -c "psql" psql (11.3) Type "help" for help. postgres=#

 

Version history
Revision #:
1 of 1
Last update:
‎05-24-2019 06:29 AM
Updated by:
 
Contributors