Install PostgreSQL on Rocky Linux 8

|
Last Updated:
|
|

In this tutorial, you will learn how to install PostgreSQL on Rocky Linux 8.

 PostgreSQL is a fully featured object-relational database management system. It supports a large part of the SQL standard and is designed to be extensible by users in many aspects.

Some of the features are: ACID transactions, foreign keys, views, sequences, subqueries, triggers, user-defined types and functions, outer joins, multiversion concurrency control. Graphical user interfaces and bindings for many programming languages are available as well.

PostgreSQL is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads.

Installing PostgreSQL on Rocky Linux 8

Rocky Linux ships with AppStream repository modules for various versions of PostgreSQL.

dnf module list postgresql
Rocky Linux 8 - AppStream
Name                                Stream                          Profiles                                    Summary                                                     
postgresql                          9.6                             client, server [d]                          PostgreSQL server and client module                         
postgresql                          10 [d]                          client, server [d]                          PostgreSQL server and client module                         
postgresql                          12                              client, server [d]                          PostgreSQL server and client module                         
postgresql                          13                              client, server [d]                          PostgreSQL server and client module                         

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

From the output above, you can can we that there are streams of various versions of PostgreSQL including v9.6, 10, 12, 13.

The AppStream modules for PostgreSQL is enabled by default.

For various reasons, you might want to install various versions of PostgreSQL on your Rocky Linux 8 box.

Install PostgreSQL 13 on Rocky Linux 8

As of this writing, PostgreSQL 13 is the current stable release.

By default, the AppStream modules for PostgreSQL 10 are enabled by default.

To install PostgreSQL 13 on Rocky Linux 8;

  • Enable PostgreSQL 13 AppStream module
dnf -qy module enable postgresql:13

Confirm;

dnf info postgresql-server
Available Packages
Name         : postgresql-server
Version      : 13.3
Release      : 1.module+el8.4.0+546+3620623e
Architecture : x86_64
Size         : 5.6 M
Source       : postgresql-13.3-1.module+el8.4.0+546+3620623e.src.rpm
Repository   : appstream
Summary      : The programs needed to create and run a PostgreSQL server
URL          : http://www.postgresql.org/
License      : PostgreSQL

Hence, you can now run the command below to install PostgreSQL 13 on Rocky Linux 8.

dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        13.3-1.module+el8.4.0+546+3620623e                           appstream                        5.6 M
Installing dependencies:
 libicu                                   x86_64                        60.3-2.el8_1                                                 baseos                           8.8 M
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        13.3-1.module+el8.4.0+546+3620623e                           appstream                        1.5 M

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 59 M
Is this ok [y/N]: y

Check the version PostgreSQL installed;

postgres -V
postgres (PostgreSQL) 13.3

Initialize the database;

postgresql-setup --initdb

Start and enable PostgreSQL to run on system boot;

systemctl enable --now postgresql

Checking the status;

systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-09-07 09:42:14 EAT; 47s ago
  Process: 15684 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
 Main PID: 15686 (postmaster)
    Tasks: 8 (limit: 4938)
   Memory: 16.8M
   CGroup: /system.slice/postgresql.service
           ├─15686 /usr/bin/postmaster -D /var/lib/pgsql/data
           ├─15688 postgres: logger   
           ├─15690 postgres: checkpointer   
           ├─15691 postgres: background writer   
           ├─15692 postgres: walwriter   
           ├─15693 postgres: autovacuum launcher   
           ├─15694 postgres: stats collector   
           └─15695 postgres: logical replication launcher   

Sep 07 09:42:13 rocky8 systemd[1]: Starting PostgreSQL database server...
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.544 EAT [15686] LOG:  starting PostgreSQL 12.7 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.4.1 202009>
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.545 EAT [15686] LOG:  listening on IPv6 address "::1", port 5432
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.545 EAT [15686] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.687 EAT [15686] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.962 EAT [15686] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 07 09:42:14 rocky8 postmaster[15686]: 2021-09-07 09:42:14.130 EAT [15686] LOG:  redirecting log output to logging collector process
Sep 07 09:42:14 rocky8 postmaster[15686]: 2021-09-07 09:42:14.130 EAT [15686] HINT:  Future log output will appear in directory "log".
Sep 07 09:42:14 rocky8 systemd[1]: Started PostgreSQL database server.

Install PostgreSQL 12 on Rocky Linux 8

To install PostgreSQL 12 on Rocky Linux, run the commands below;

dnf -qy module enable postgresql:12
dnf install postgresql-server

Otherwise, if you had other versions modules enabled, then reset the modules and install PostgreSQL as follows;

dnf -qy module reset postgresql
dnf -qy module enable postgresql:12
dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        12.7-1.module+el8.4.0+587+d46efd10                           appstream                        5.6 M
Installing dependencies:
 libicu                                   x86_64                        60.3-2.el8_1                                                 baseos                           8.8 M
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        12.7-1.module+el8.4.0+587+d46efd10                           appstream                        1.5 M

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 59 M
Is this ok [y/N]: y

After install, you can verify the version;

postgres -V
postgres (PostgreSQL) 12.7

Initialize the database;

postgresql-setup --initdb

Start and enable PostgreSQL to run on system boot;

systemctl enable --now postgresql

Install PostgreSQL 10 on Rocky Linux 8

By default, you would simply run the commands below to install PostgreSQL 10 on Rocky Linux 8.

dnf install postgresql-server

However, if you have other versions AppStream modules enabled, then you have to reset the modules.

dnf -qy module reset postgresql
dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        10.17-1.module+el8.4.0+548+9eccbe3f                          appstream                        5.1 M
Installing dependencies:
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        10.17-1.module+el8.4.0+548+9eccbe3f                          appstream                        1.5 M
Enabling module streams:
 postgresql                                                             10                                                                                                 

Transaction Summary
============================================================================================================================================================================
Install  3 Packages

Total download size: 6.8 M
Installed size: 26 M
Is this ok [y/N]: y

After install, you can verify the version;

postgres -V
postgres (PostgreSQL) 10.17

Initialize the database;

postgresql-setup --initdb

Start and enable PostgreSQL to run on system boot;

systemctl enable --now postgresql

Similarly, to install PostgreSQL 9.x, then enable the module and run the installation command.

Install PostgreSQL 11 on Rocky Linux 8

Rocky Linux do not provide repositories for installing PostgreSQL 11.

Thus, if you want to install PostgreSQL 11 on Rocky Linux 8, then you need to install the repository RPM:

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Disable the built-in PostgreSQL module:

dnf -qy module disable postgresql

Install PostgreSQL 11 on Rocky Linux 8

dnf install postgresql11-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                         Architecture                       Version                                        Repository                          Size
============================================================================================================================================================================
Installing:
 postgresql11-server                             x86_64                             11.13-1PGDG.rhel8                              pgdg11                             4.9 M
Installing dependencies:
 libicu                                          x86_64                             60.3-2.el8_1                                   baseos                             8.8 M
 postgresql11                                    x86_64                             11.13-1PGDG.rhel8                              pgdg11                             1.7 M
 postgresql11-libs                               x86_64                             11.13-1PGDG.rhel8                              pgdg11                             394 k

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 60 M
Is this ok [y/N]: y

Initialize the database;

postgresql-11-setup initdb

Start and enable PostgreSQL to run on system boot;

systemctl enable --now postgresql-11

Checking the status;

systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-09-07 09:19:07 EAT; 44s ago
     Docs: https://www.postgresql.org/docs/11/static/
  Process: 11990 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 11995 (postmaster)
    Tasks: 8 (limit: 4938)
   Memory: 16.4M
   CGroup: /system.slice/postgresql-11.service
           ├─11995 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─12001 postgres: logger   
           ├─12003 postgres: checkpointer   
           ├─12004 postgres: background writer   
           ├─12005 postgres: walwriter   
           ├─12006 postgres: autovacuum launcher   
           ├─12007 postgres: stats collector   
           └─12008 postgres: logical replication launcher   

Sep 07 09:19:05 rocky8 systemd[1]: Starting PostgreSQL 11 database server...
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.387 EAT [11995] LOG:  listening on IPv6 address "::1", port 5432
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.387 EAT [11995] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.541 EAT [11995] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.848 EAT [11995] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 07 09:19:07 rocky8 postmaster[11995]: 2021-09-07 09:19:07.005 EAT [11995] LOG:  redirecting log output to logging collector process
Sep 07 09:19:07 rocky8 postmaster[11995]: 2021-09-07 09:19:07.005 EAT [11995] HINT:  Future log output will appear in directory "log".
Sep 07 09:19:07 rocky8 systemd[1]: Started PostgreSQL 11 database server.

Read More on PostgreSQL Tutorials.

Other Tutorials

Install LAMP Stack on Debian 11

Enable MSSQL Server and Database Level Auditing

Install PostgreSQL 13 on Debian 11

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
gen_too
Co-founder of Kifarunix.com, Linux Tips and Tutorials. Linux/Unix admin and author at Kifarunix.com.

Leave a Comment