HomeDATABASEHow To Install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9

How To Install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9

This guide will teach you how to install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9. A well-liked open-source relational database management system(RDBMS) is PostgreSQL. Numerous web, mobile, geospatial, and analytics apps frequently use it as their main data store. PostgreSQL is a database that can store both structured and unstructured data. PostgreSQL is also open-source software, which means it can be freely used, modified, and distributed.

Numerous web, mobile, geospatial, and analytics apps frequently use it as their main data store. A database that can store both structured and unstructured data is PostgreSQL. Additionally open-source, PostgreSQL is available for use, modification, and distribution without restriction.

Features of PostgreSQL 14

The following are the feature of the PostgreSQL 14 database.

  • The following are some of the cool features that have changed with PostgreSQL 14:
  • Prepared transaction decoding
  • Logical replication of ongoing transactions is supported.
  • Logical replication can now transfer binary data.
  • Enhancements to the performance of DDL-containing transaction logical decoding.
  • Multiple transactions are now permitted during logical replication table synchronization.
  • It is now easier to add/remove publications with the addition of the ADD PUBLICATION and DROP PUBLICATION options to the ALTER SUBSCRIPTION statement.
  • OUT parameters can be used in procedures.
  • The CREATE FUNCTION and CREATE PROCEDURE statements now support the SQL language.
  • TRUNCATE has the ability to operate on foreign tables via the Postgres fdw module.
  • Multirange data types are now supported.
  • The pg amcheck command-line utility was added to make it easier to run contrib/amcheck operations on many relations easier.

Install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9

The following steps will guide you on how to install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9 successfully.

#1. Update the system

Before you start installing PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9, make the following system updates:

sudo dnf update
sudo dnf install dnf-utils

Next, reboot the system.

sudo reboot

#2. Add PostgreSQL Repository on Rocky Linux 9|AlmaLinux 9

PostgreSQL is not installed by default in the Rocky Linux 9|AlmaLinux 9 base repository.
To add the PostgreSQL stable repository to your system, run the following command:

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

Dependency tree;

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

Total size: 12 k
Installed size: 14 k
Is this ok [y/N]: y
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                  1/1 
  Installing       : pgdg-redhat-repo-42.0-28.noarch                                                                  1/1 
  Verifying        : pgdg-redhat-repo-42.0-28.noarch                                                                  1/1 

Installed:
  pgdg-redhat-repo-42.0-28.noarch                                                                                         

Complete!

#3. Install PostgreSQL 14 on Rocky Linux 9|AlmaLinux 9

Once the repository has been added, disable the default PostgreSQL module:

sudo dnf -qy module disable postgresql

Install PostgreSQL using the below command.

sudo dnf check-update
sudo dnf install postgresql14-server postgresql14-docs

Sample output:

Transaction Summary
==========================================================================================================================
Install  5 Packages

Total download size: 19 M
Installed size: 71 M
Is this ok [y/N]: y
Running scriptlet: postgresql14-docs-14.6-1PGDG.rhel9.x86_64                                                        5/5 
  Verifying        : postgresql14-14.6-1PGDG.rhel9.x86_64                                                             1/5 
  Verifying        : postgresql14-docs-14.6-1PGDG.rhel9.x86_64                                                        2/5 
  Verifying        : postgresql14-libs-14.6-1PGDG.rhel9.x86_64                                                        3/5 
  Verifying        : postgresql14-server-14.6-1PGDG.rhel9.x86_64                                                      4/5 
  Verifying        : lz4-1.9.3-5.el9.x86_64                                                                           5/5 

Installed:
  lz4-1.9.3-5.el9.x86_64                                       postgresql14-14.6-1PGDG.rhel9.x86_64                      
  postgresql14-docs-14.6-1PGDG.rhel9.x86_64                    postgresql14-libs-14.6-1PGDG.rhel9.x86_64                 
  postgresql14-server-14.6-1PGDG.rhel9.x86_64                 

Complete!

In addition, you can install the following modules, binaries, and libraries in PostgreSQL:

sudo dnf install postgresql14-libs postgresql14-plperl postgresql14-plpython3 postgresql14-pltcl postgresql14-tcl postgresql14-contrib postgresql14-llvmjit

#4. Initialize and Start PostgreSQL 14 Database Service

After installing PostgreSQL 14, you must first initialize the database instance before running the service:

$ sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Initializing database ... OK

The database service PostgreSQL 14 is enabled and started as follows:

sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14

Now check its status, it should be active and running:

systemctl status postgresql-14

Output:

postgresql-14.service - PostgreSQL 14 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2022-11-29 09:53:36 EAT; 17s ago
       Docs: https://www.postgresql.org/docs/14/static/
    Process: 5482 ExecStartPre=/usr/pgsql-14/bin/postgresql-14-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 5487 (postmaster)
      Tasks: 8 (limit: 23450)
     Memory: 16.5M
        CPU: 101ms
     CGroup: /system.slice/postgresql-14.service
             ├─5487 /usr/pgsql-14/bin/postmaster -D /var/lib/pgsql/14/data/
             ├─5488 "postgres: logger "
             ├─5492 "postgres: checkpointer "
             ├─5493 "postgres: background writer "
             ├─5494 "postgres: walwriter "
             ├─5495 "postgres: autovacuum launcher "
             ├─5496 "postgres: stats collector "
             └─5497 "postgres: logical replication launcher "

#5. Accessing the PostgreSQL Command Prompt

When you install the PostgreSQL database server, it creates a user ‘postgres‘ with the role ‘postgres‘ by default. It also creates a system account called ‘postgres‘.
So, to connect to the Postgres server, log in as a Postgres user and connect to the database:

$ sudo -u postgres psql
psql (14.6)
Type "help" for help.

postgres=#

After that, secure PostgreSQL by entering a password.

\password postgres

Enter new password for user "postgres": <ENTER PASSWORD>
Enter it again: <RE-ENTER PASSWORD>

#6. Set up a PostgreSQL 14 Database

To create a user with a password, use the following command.

CREATE USER tutornix WITH PASSWORD 'YourStrongPassword';

After you’ve created the user, run the command below to create the database.

CREATE DATABASE nixdb OWNER tutornix;

List databases on your PostgreSQL.

\l

Sample output;

                                 List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 nixdb     | tutornix | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

Use the command below to exit the PostgreSQL shell.

\q

Conclusion

Congratulations! PostgreSQL has been successfully installed. Thank you for following along with this tutorial on how to install PostgreSQL 14 on your Rocky Linux 9|AmaLinux 9 system.

Check PostgreSQL documentation to know more. Cheers!

Check out these tutorials:

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here