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.
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
sudo dnf update -y
Now install PostgreSQL 14 with the following command
sudo dnf install postgresql14 postgresql14-server
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
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
listen_addresses = 'localhost'
listen_addresses = '*'
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.
Learning how to install PostgreSQL is an important step in learning how to use it on a server system.