How to install PostgreSQL on Rocky Linux 9 / Alma Linux 9

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to install PostgreSQL on Rocky Linux 9 / Alma Linux 9

As we all know, PostgreSQL is one of the most important relational database managers we can find. It is the basis of many large projects that require the advanced features of PostgreSQL.

Another aspect is that Rocky Linux 9 / Alma Linux 9 are recent versions of very server-focused operating systems, so it can be quickly interesting to learn about PostgreSQL in these environments.

Let’s get started.

Install PostgreSQL on Rocky Linux 9 / Alma Linux 9

Although PostgreSQL is present in the Rocky Linux / Alma Linux repositories, it is a good idea to learn how to get a recent version.

First, update the whole system

sudo dnf update

Next, add the PostgreSQL 14 repository

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

Then refresh dnf

sudo dnf update -y

Now install PostgreSQL 14 with the following command

sudo dnf install postgresql14 postgresql14-server
Install PostgreSQL on Rocky Linux 9 / Alma Linux 9
Install PostgreSQL on Rocky Linux 9 / Alma Linux 9

When the installation is finished, it is convenient to start the default PostgreSQL database to start working with the

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

Verify the PostgreSQL version

psql -V
psql (PostgreSQL) 14.5

Then start the PostgreSQL service to use it. It is also convenient to enable it to start with the system.

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

First steps with PostgreSQL

Next, define a more secure password for the PostgreSQL user

passwd postgres

Define the secure password.

If you are going to connect to PostgreSQL remotely, you have to enable it. To do so, edit the configuration file.

sudo vi /var/lib/pgsql/14/data/postgresql.conf

And replace

listen_addresses = 'localhost'

With

listen_addresses = '*'
Configuring PostgreSQL on Rocky Linux 9
Configuring PostgreSQL

Save the changes and close the editor.

Now edit this other file

sudo vi /var/lib/pgsql/14/data/pg_hba.conf

And at the end of the file, enter:

host all all all 0.0.0.0.0/0 md5

In the same way, save the changes and close the editor.

To apply all changes, restart the service

sudo systemctl restart postgresql-14

And now you will be able to access the console

sudo -u postgres psql

Enter the password and we are ready.

Conclusion

Learning how to install PostgreSQL is an important step in learning how to use it on a server system.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook