How To Install PostgreSQL 16.3 On CentOS Stream 9

Howt to install PosrgreSQL

In the vast landscape of database management systems (DBMS), PostgreSQL stands tall as a stalwart, revered for its robustness, extensibility, and adherence to SQL standards. PostgreSQL, often referred to as Postgres, is an open-source relational database management system renowned for its reliability, flexibility, and feature-rich capabilities. Let’s delve into the intricacies of this powerful engine, understanding what makes it a preferred choice for businesses, developers, and data professionals worldwide.

Installing PostgreSQL 16.3 on CentOS Stream 9

In this short article we will show you how to install PostgreSQL version 16.3 on CentOS Stream 9 operating system. We will through several step to install PostgreSQL as listed below :

  1. System Repository Update
  2. Enabling PostgreSQL DNF Repository
  3. Installing PostgreSQL 16.3 on CentOS Stream 9
  4. Testing PostgreSQL 16.3

Prerequisites

There are several prerequisites to install PostgreSQL database engine on CentOS Steram 9, namely :

  • A system running CentOS Stream 9
  • A user with sudo privileges
  • Sufficient space and good internet connectivity

1. System Repository Update

It is a recommended way, to be always updating system update before we are installing a new software or adding new packages to the system. For this purpose we will submit following command line :

$ sudo dnf update

2. Enabling PostgreSQL DNF Repository

To be able to access the newest PostgreSQL repository in CentOS Stream 9 is by enabling PostgreSQL repository. For this purpose we will submit command line :

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

Output :

[ramansah@bckinfo ~]$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
PostgreSQL 16 for RHEL / Rocky / AlmaLinux 9 - 109 B/s | 659 B 00:06
PostgreSQL 16 for RHEL / Rocky / AlmaLinux 9 - 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
PostgreSQL 16 for RHEL / Rocky / AlmaLinux 9 - 11 kB/s | 304 kB 00:26
PostgreSQL 15 for RHEL / Rocky / AlmaLinux 9 - 227 B/s | 659 B 00:02
PostgreSQL 15 for RHEL / Rocky / AlmaLinux 9 - 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
PostgreSQL 15 for RHEL / Rocky / AlmaLinux 9 - 17 kB/s | 498 kB 00:29
PostgreSQL 14 for RHEL / Rocky / AlmaLinux 9 - 230 B/s | 659 B 00:02
PostgreSQL 14 for RHEL / Rocky / AlmaLinux 9 - 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
PostgreSQL 14 for RHEL / Rocky / AlmaLinux 9 - 98 kB/s | 794 kB 00:08
PostgreSQL 13 for RHEL / Rocky / AlmaLinux 9 - 249 B/s | 659 B 00:02
PostgreSQL 13 for RHEL / Rocky / AlmaLinux 9 - 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
PostgreSQL 13 for RHEL / Rocky / AlmaLinux 9 - 31 kB/s | 750 kB 00:24
PostgreSQL 12 for RHEL / Rocky / AlmaLinux 9 - 163 B/s | 659 B 00:04
PostgreSQL 12 for RHEL / Rocky / AlmaLinux 9 - 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
PostgreSQL 12 for RHEL / Rocky / AlmaLinux 9 - 9.3 kB/s | 689 kB 01:14
pgdg-redhat-repo-latest.noarch.rpm 8.2 kB/s | 15 kB 00:01
Package pgdg-redhat-repo-42.0-43PGDG.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

Then we will list the PostgreSQL database repository

$ sudo dnf module list postgresql

Output :

3. Installing PostgreSQL 16.3 On CentOS Stream 9

We will list the PostgreSQL repository which is ready to installed by submitting command line :

$ sudo dnf module list postgresql

Output :

[ramansah@bckinfo ~]$ sudo dnf module list postgresql
Last metadata expiration check: 0:00:37 ago on Fri 10 May 2024 11:39:31 AM WIB.
CentOS Stream 9 - AppStream
Name Stream Profiles Summary
postgresql 15 client, server [d] PostgreSQL server and client module
postgresql 16 client, server [d] PostgreSQL server and client module

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

The PostgreSQL version 16.3 has been exist on the system, then we will install it by submitting command line :

$ sudo dnf -y install postgresql16-server

Output :

[ramansah@bckinfo ~]$ sudo dnf -y install postgresql16-server
Last metadata expiration check: 0:04:00 ago on Fri 10 May 2024 11:39:31 AM WIB.
Dependencies resolved.
=========================================================================================
Package Architecture Version Repository Size
=========================================================================================
Installing:
postgresql16-server x86_64 16.3-1PGDG.rhel9 pgdg16 6.7 M
Installing dependencies:
lz4 x86_64 1.9.3-5.el9 baseos 59 k
postgresql16 x86_64 16.3-1PGDG.rhel9 pgdg16 1.7 M
postgresql16-libs x86_64 16.3-1PGDG.rhel9 pgdg16 333 k

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

Total download size: 8.9 M
Installed size: 40 M
Downloading Packages:
(1/4): lz4-1.9.3-5.el9.x86_64.rpm 174 kB/s | 59 kB 00:00
(2/4): postgresql16-server-16.3-1PGDG.rhel9.x86_64.rpm 420 kB/s | 6.7 MB 00:16
(3/4): postgresql16-libs-16.3-1PGDG.rhel9.x86_64.rpm 7.2 kB/s | 333 kB 00:45
(4/4): postgresql16-16.3-1PGDG.rhel9.x86_64.rpm 18 kB/s | 1.7 MB 01:41
-----------------------------------------------------------------------------------------
Total 87 kB/s | 8.9 MB 01:44
PostgreSQL 16 for RHEL / Rocky / AlmaLinux 9 - x86_64 2.4 MB/s | 2.4 kB 00:00
Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : postgresql16-libs-16.3-1PGDG.rhel9.x86_64 1/4
Running scriptlet: postgresql16-libs-16.3-1PGDG.rhel9.x86_64 1/4
Installing : lz4-1.9.3-5.el9.x86_64 2/4
Installing : postgresql16-16.3-1PGDG.rhel9.x86_64 3/4
Running scriptlet: postgresql16-16.3-1PGDG.rhel9.x86_64 3/4
Running scriptlet: postgresql16-server-16.3-1PGDG.rhel9.x86_64 4/4
Installing : postgresql16-server-16.3-1PGDG.rhel9.x86_64 4/4
Running scriptlet: postgresql16-server-16.3-1PGDG.rhel9.x86_64 4/4
Verifying : lz4-1.9.3-5.el9.x86_64 1/4
Verifying : postgresql16-16.3-1PGDG.rhel9.x86_64 2/4
Verifying : postgresql16-libs-16.3-1PGDG.rhel9.x86_64 3/4
Verifying : postgresql16-server-16.3-1PGDG.rhel9.x86_64 4/4

Installed:
lz4-1.9.3-5.el9.x86_64 postgresql16-16.3-1PGDG.rhel9.x86_64
postgresql16-libs-16.3-1PGDG.rhel9.x86_64 postgresql16-server-16.3-1PGDG.rhel9.x86_64

Complete!

Then we initializes the PostgreSQL 16.3 database by submitting command line :

[ramansah@bckinfo ~]$ sudo /usr/pgsql-16/bin/postgresql-16-setup initdb 
Initializing database ... OK

Then we will enable and start PostgreSQL service by submitting command lines :

$ sudo systemctl start postgresql-16
$ sudo systemctl enable postgresql-16
$ sudo systemctl status postgresql-16

Output :

[ramansah@bckinfo ~]$ sudo systemctl start postgresql-16 
[ramansah@bckinfo ~]$ sudo systemctl enable postgresql-16
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-16.service → /usr/lib/systemd/system/postgresql-16.service.
[ramansah@bckinfo ~]$ sudo systemctl status postgresql-16
● postgresql-16.service - PostgreSQL 16 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-16.service; enabled; preset: disabled)
Active: active (running) since Fri 2024-05-10 15:01:04 WIB; 12s ago
Docs: https://www.postgresql.org/docs/16/static/
Main PID: 3655 (postgres)
Tasks: 7 (limit: 22828)
Memory: 23.6M
CPU: 74ms
CGroup: /system.slice/postgresql-16.service
├─3655 /usr/pgsql-16/bin/postgres -D /var/lib/pgsql/16/data/
├─3656 "postgres: logger "
├─3657 "postgres: checkpointer "
├─3658 "postgres: background writer "
├─3660 "postgres: walwriter "
├─3661 "postgres: autovacuum launcher "
└─3662 "postgres: logical replication launcher "

May 10 15:01:04 bckinfo systemd[1]: Starting PostgreSQL 16 database server...
May 10 15:01:04 bckinfo postgres[3655]: 2024-05-10 15:01:04.636 WIB [3655] LOG: redirecting lo>
May 10 15:01:04 bckinfo postgres[3655]: 2024-05-10 15:01:04.636 WIB [3655] HINT: Future log ou>
May 10 15:01:04 bckinfo systemd[1]: Started PostgreSQL 16 database server.

4. Testing PostgreSQL 16.3

At this stage, we will connect to database and querying its version. By default, from localhost we are able to connect to PostgreSQL Server.

$ sudo su - postgres
[ramansah@bckinfo ~]$ sudo su - postgres
[postgres@bckinfo ~]$ psql
psql (16.3)
Type "help" for help.

postgres=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3), 64-bit
(1 row)

After we are already logged in to PostgreSQL database system, we could do anything, such line : display all databases which was alredy exist on the system.

 postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Acce
ss privileges
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-------
----------------
postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
template0 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/pos
tgres +
| | | | | | | | postgr
es=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/pos
tgres +
| | | | | | | | postgr

After installation was completed done, then we will use it suitable with our needs.

Conclusion

The postgreSQL 16.3 installation on CentOS Steram 9 steps can be summarized :

$ sudo dnf update
$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
$ sudo dnf module list PostgreSQL
$ sudo dnf -y install postgresql16-server
## login to database PostgreSQL in localhost
$ sudo su - postgres
$ psql

PostgreSQL’s journey from a research project to a cornerstone of modern data infrastructure exemplifies the power of open-source collaboration and innovation. Its robustness, extensibility, and adherence to standards have earned it a place of prominence in the realm of database management systems.

(Visited 21 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *