How to Install PostgreSQL on AlmaLinux

Posted on by Joseph Molloy | Updated:
Reading Time: 4 minutes

PostgreSQL, previously Postgres, is an advanced open-source relational database. It is also one of the most popular database solutions used today. In fact, many companies use PostgreSQL as their primary data store for various mobile and web applications.

That shouldn’t come as a surprise because this software has been continually developed by its expert, open-source community since 1996. Fast forward to today, and PostgreSQL has already reached version 15.2, which was released on February 9th, 2023.

PostgreSQL is highly versatile and expandable due to its powerful extension support. Furthermore, it can run on any popular operating system, such as Linux, macOS, and Windows.

In this article, you will learn how to install PostgreSQL on AlmaLinux. So, read on to learn more.

Requirements

If you want to be able to follow this guide and learn how to install PostgreSQL on AlmaLinux, you should first make sure that you meet the following requirements:

  • You have a computer or server that is running AlmaLinux 9.
  • You have root or sudo privileges on your AlmaLinux machine.
  • You have access to an internet connection to download PostgreSQL for Linux.

Once you ensure the above requirements are met, feel free to proceed with the following guide.

Install PostgreSQL on AlmaLinux

If you have never installed PostgreSQL on Linux before, or this is your first time using AlmaLinux, don’t worry. Just follow our easy five-step guide to get PostgreSQL running in no time.

Step #1: Update AlmaLinux

Before you install PostgreSQL on Linux, you should first make sure that your distribution has the latest packages installed. To do this, you need to use the dnf command, which will automatically update any outdated packages.

dnf update -y

Here is the output.

Step #2: Install PostgreSQL

The latest version of PostgreSQL is not available in the AlmaLinux default repository. That’s why, in order to install the latest version of PostgreSQL, you will need to manually download PostgreSQL for Linux from its official repository. Use the following command to achieve this.

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

Here is the output.

Note:
For users on AlmaLinux 8, please be aware that postgresql15 and postgresql15-server are not accessible by default. To enable their availability, it is necessary to first disable the built-in module of PostgreSQL. Execute the following command to achieve this: dnf -qy module disable postgresql.

Now install the PostgreSQL 15 client and server with the following command.

dnf install -y postgresql15 postgresql15-server

Here is the output.

Once the installation is complete, you can initialize the PostgreSQL database. Use the following command to achieve this.

/usr/pgsql-15/bin/postgresql-15-setup initdb

Here is the output.

Finally, you should start and enable the PostgreSQL service with the following command. This command will run PostgreSQL and set it to load at boot.

systemctl enable postgresql-15 && systemctl start postgresql-15

Here is the output. Note that successfully running the command gives the message Created symlink along with the file paths.

Step #3: Set a Password

You can now set a password for the default postgres user. For maximum security, make sure to use a long string of uppercase letters, lowercase letters, numbers, and symbols. Securing the database server is critical for your application’s or website’s overall security.

Use the command below to set the password. You will be asked to retype it one more time.

passwd postgres

Here is the output.

After you have set the password for the Postgres user, you will have to use it every time you need to access PostgreSQL.

Step #4: Enable Remote Access

Since you will likely be using PostgreSQL as a server, you will need to enable remote access for it. This is because it is set to localhost by default. To enable remote access, follow these next steps.

First, open the /var/lib/pgsql/15/data/postgresql.conf file and replace listen_addresses = 'localhost' with listen_addresses = '*'.

Here you see the unchanged file.

Then, open the /var/lib/pgsql/15/data/pg_hba.conf file and add the following entry to the end of it.

host	all	 all	0.0.0.0/0	md5

Again, here is the unchanged file you will add this line to.

Finally, restart the postgreSQL service to apply the changes. Use the following command to achieve this.

systemctl restart postgresql-15

Step #5: Open the Console

To open the PostgreSQL console, use the following command.

sudo -u postgres psql

Here is the output.

You managed to install PostgreSQL on AlmaLinux.

Final Thoughts

Installing PostgreSQL on AlmaLinux does not have to be difficult. This guide walks through the installation requirements as well as installing and running PostgreSQL on Almalinux.

Liquid Web Can Meet All of Your Hosting Needs

Are you ready to host your websites and apps with AlmaLinux? Liquid Web offers you the AlmaLinux OS with VPS Hosting, Dedicated Servers, and Cloud Dedicated Servers. You can also take advantage of our fully managed images with the cPanel and Plesk control panels. Contact the sales team to get started today.

Avatar for Joseph Molloy

About the Author: Joseph Molloy

Liquid Web Security Operations tech Joseph spends his days cleaning up malware and doing his part to keep the Internet safe. He is interested in all things Linux and always looking for something new to learn. In addition, he enjoys cooking and playing guitar, is an avid horror and sci-fi reader, and is a fan of black metal music.

Latest Articles

Controlling PHP settings with a custom php.ini file

Read Article

How to install Puppet Server on Linux (AlmaLinux)

Read Article

Email security best practices for using SPF, DKIM, and DMARC

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article