Hello,
In this week’s feature highlight, we look at How to Install PostgreSQL in Rocky Linux 8

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.
List the PostgreSQL Module
List the PostgreSQL module by using the following command:
dnf module list postgresqlOutput:
[root@server ~]# dnf module list postgresql
Last metadata expiration check: 2:22:31 ago on Fri 14 May 2021 01:53:51 PM EDT.
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
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalledEnable the PostgreSQL Module
Enable the latest version of PostgreSQL module i.e. version 12 by using the following command,
dnf module enable postgresql:12Output:
[root@server ~]# dnf module enable postgresql:12
Last metadata expiration check: 2:22:51 ago on Fri 14 May 2021 01:53:51 PM EDT.
Dependencies resolved.
================================================================================
 Package           Architecture     Version             Repository         Size
================================================================================
Enabling module streams:
 postgresql                         12
Transaction Summary
================================================================================
Is this ok [y/N]: y
Complete!Install the PostgreSQL Server
After the version 12 module has been enabled, install the postgresql-server by using the following command:
dnf install postgresql-serverOutput:
[root@server ~]# dnf install postgresql-server
Last metadata expiration check: 2:23:17 ago on Fri 14 May 2021 01:53:51 PM EDT.
Dependencies resolved.
================================================================================
 Package           Arch   Version                               Repo       Size
================================================================================
Installing:
 postgresql-server x86_64 12.5-1.module+el8.3.0+109+eaf75cf7    appstream 5.6 M
Installing dependencies:
 libpq             x86_64 12.5-1.el8_2                          appstream 194 k
 postgresql        x86_64 12.5-1.module+el8.3.0+109+eaf75cf7    appstream 1.5 MCreating a New PostgreSQL Database Cluster
Initialize a database storage area on disk by using the following command:
postgresql-setup --initdbOutput:
[root@server ~]# postgresql-setup --initdb
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.logStart the PostgreSQL service:
systemctl start postgresqlEnable the PostgreSQL service:
systemctl enable postgresqlOutput:
[root@server ~]# systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.Verify the PostgreSQL service:
systemctl status postgresqlOutput:
[root@server ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor >
   Active: active (running) since Fri 2021-05-14 16:18:20 EDT; 19s ago
 Main PID: 11270 (postmaster)
    Tasks: 8 (limit: 4835)
   Memory: 19.7M
   CGroup: /system.slice/postgresql.service
           ├─11270 /usr/bin/postmaster -D /var/lib/pgsql/data
           ├─11272 postgres: logger
           ├─11274 postgres: checkpointer
           ├─11275 postgres: background writer
           ├─11276 postgres: walwriterPostgreSQL Roles
We’ll switch to postgres account for this.
sudo -i -u postgresyou can access a postgresql prompt using the psql utility.
psqlOutput:
[postgres@server ~]$ psql
psql (12.5)
Type "help" for help.
postgres=#To exit out of the postgresql shell type.
\qChange to your original account by using the following command:
exitTo create postgresql Role:
createuser --interactiveOutput:
[postgres@vps ~]$ createuser --interactive
Enter name of role to add: jones
Shall the new role be a superuser? (y/n) yPostgreSQL Database
Create a Database by using the following command:
createdb db_nameEnter the Database name something like:
[postgres@vps ~]$ createdb jonesOpening a PostgreSQL Prompt with the New Role
Add new user by using the following command:
sudo adduser jonesTo switch over and connect to the database:
sudo -i -u jones
psqlOutput:
[jones@vps ~]$ psql
psql (12.5)
Type "help" for help.Once you logged in as jones and check your current connection information.
\conninfoOutput:
jones=# \conninfo
You are connected to database "jones" as user "jones" via socket in "/var/run/postgresql" at port "5432".
jones=#