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

--------------- Rocky & AlmaLinux 8 ---------------
$ sudo dnf install -y

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

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.