How to Install PostgreSQL 15 on Rocky Linux and AlmaLinux

PostgreSQL is an immensely popular open-source relational database management system (RDBMS) that has been around for over 30 years. It provides SQL language support which is used for managing databases and performing CRUD operations (Create Read Update Delete).

[ You might also like: 10 Useful Websites for Learning PostgreSQL Database System]

PostgreSQL has earned itself a solid reputation for its robustness, flexibility, and performance. It’s the primary data store for numerous web and analytical applications. Global giants that rely on PostgreSQL include Spotify, Instagram, Trivago, Uber, and Netflix.

At the time of writing this guide, the latest version is PostgreSQL 15 and in this article, we demonstrate how to install PostgreSQL on Rocky Linux and AlmaLinux.

Step 1: Add the PostgreSQL Repository

The default version of PostgreSQL on Appstream repositories is PostgreSQL 10.

$ sudo dnf module list postgresql
List PostgreSQL Module
List PostgreSQL Module

From the output, we can clearly see that the default PostgreSQL stream – marked with [ d ] is PostgreSQL 10.

To install the latest PostgreSQL version, we need to, first, install the PostgreSQL YUM repository on our system as shown.

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

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

Step 2: Install PostgreSQL 15 on Rocky/Alma Linux

With the PostgreSQL YUM repository in place, the next step is to update repositories. Simply run the following command to achieve this:

$ sudo dnf update -y

Next, disable the default module which, as we saw earlier, is PostgreSQL 10.

$ sudo dnf -qy module disable postgresql

Once the default module is disabled, proceed and install PostgreSQL 15 client and server as shown.

$ sudo dnf install -y postgresql15-server

Type 'Y' and hit ENTER every time you are prompted to import the GPG key.

Install PostgreSQL 15 in Rocky Linux
Install PostgreSQL 15 in Rocky Linux

The command installs the PostgreSQL server and client alongside other dependencies. At the very end of the installation, you should have the output displayed which indicates that all the packages were successfully installed.

PostgreSQL 15 Installation Completed
PostgreSQL 15 Installation Completed

You can confirm the version of PostgreSQL installed using the command:

$ psql -V

psql (PostgreSQL) 15.0

Step 3: Initialize the PostgreSQL Database

Before proceeding further, we need to initialize the initdb database which is responsible for creating a new PostgreSQL cluster. A cluster is a group or collection of several databases that are managed by a cluster.

So, to initialize the database, run the command:

$ sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
Initialize PostgreSQL Database
Initialize PostgreSQL Database

Step 4: Start and Enable PostgreSQL Service

Once PostgreSQL is installed and initialized, the next step is to start the service and ensure the database server is running. But before that, enable PostgreSQL to start on boot time.

$ sudo systemctl enable postgresql-15

Thereafter, start the PostgreSQL database server.

$ sudo systemctl start postgresql-15

To confirm that PostgreSQL is up and running, execute:

$ sudo systemctl status postgresql-15
Check PostgreSQL Status
Check PostgreSQL Status

From the output, it’s clear that our database server is running as we would expect.

Step 5: Connect to PostgreSQL Database

When PostgreSQL is installed, a default database user called postgres is created. It does not require any authentication and a password is therefore not required to log in. In the next step, we shall create a password for the postgres user for security reasons.

For now, we are going to log in to the PostgreSQL shell by first switching to the postgres user.

$ sudo su - postgres

Once you have switched to the postgresql user, access the database prompt using the command:

$ psql
Connect PostgreSQL Database Shell
Connect PostgreSQL Database Shell

Step 6: Set Password for Postgres User

Finally, we are going to secure the postgres user with a password for security reasons. As a sudo user, run the command:

$ sudo passwd postgres

Provide a new password and confirm. Now log in again as a Postgres user.

$ su - postgres
Set Postgres User Password
Set Postgres User Password

And run the command shown.

psql -c "ALTER USER postgres WITH PASSWORD 'your-password';"
Alter Postgres User Role
Alter Postgres User Role

The next time you try logging in using the postgres user, you will be required to authenticate.

$ su - postgres
Login to PostgreSQL Database
Login to PostgreSQL Database

[ You might also like: How to Backup and Restore a PostgreSQL Database ]

And that’s just about it. We have walked you through the installation of PostgreSQL on Rocky Linux and AlmaLinux

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.