How to Install PostgreSQL 16 on RHEL-Based Distributions

PostgreSQL is a powerful, highly scalable, open source, and cross-platform object-relational database system that runs on Unix-like operating systems including Linux and Windows OS. It is an enterprise-level database system that is highly reliable and offers data integrity and correctness to users.

In this article, we will explain how to install the latest version of PostgreSQL 16 on RHEL and RHEL-based distributions such as Rocky Linux, AlmaLinux, Oracle Linux, and Fedora using the official PostgreSQL Yum repository.
[ez-toc]

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.

1. Update Software Package

Before initiating the PostgreSQL installation process, make sure to update your Linux system software packages by running the following dnf command.

sudo dnf update
Update System Packages
Update System Packages

2. Enabling PostgreSQL Repository

While PostgreSQL is available in the default system repositories, it’s advisable to enable the official PostgreSQL repository for access to the latest version.

On RHEL, Rocky, AlmaLinux, and Oracle Linux 9:

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

On RHEL, Rocky, AlmaLinux, and Oracle Linux 8:

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

On Fedora 39:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-39-x86_64/pgdg-fedora-repo-latest.noarch.rpm

On Fedora 38:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-38-x86_64/pgdg-fedora-repo-latest.noarch.rpm

3. Installing PostgreSQL 16 Server

After adding the PostgreSQL repository in your respective Linux distribution, use the following command to install the PostgreSQL server and client packages.

sudo dnf install -y postgresql16-server postgresql16
Install PostgreSQL Server
Install PostgreSQL Server

Important: PostgreSQL data directory /var/lib/pgsql/16/data/ contains all of the data files for the database.

4. Initializing PostgreSQL Database

Because of certain policies applicable to Red Hat-based distributions, the PostgreSQL installation will not automatically start or have the database initialized as part of the automatic startup process.

To complete your database installation, you need to initialize your database before using it for the first time.

sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
Initializing PostgreSQL Database
Initializing PostgreSQL Database

5. Configuring PostgreSQL for Remote Access

To enable remote connections, you need to modify the configuration file postgresql.conf using a text editor.

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

Update the listen_addresses parameter to allow connections from all hosts on your local network.

listen_addresses = '*'
Enable PostgreSQL Remote Access
Enable PostgreSQL Remote Access

After making the changes to the configuration file, you need to restart the PostgreSQL service to apply the new settings and enable automatic start.

sudo systemctl restart postgresql-16
sudo systemctl enable postgresql-16

6. Setting PostgreSQL User Password

Set the password for the default PostgreSQL user (postgres).

sudo passwd postgres
Set PostgreSQL User Password
Set PostgreSQL User Password

7. Accessing PostgreSQL Database

After setting the user password, you can access the PostgreSQL database server using the psql command.

sudo -i -u postgres
psql
Connecting to PostgreSQL
Connecting to PostgreSQL

Finally, read through these related articles about the PostgreSQL database management system:

Conclusion

Congratulations! You’ve successfully installed PostgreSQL 16 on RedHat-based distributions (the latest version available at the time). Remember to consult the official PostgreSQL documentation for any version-specific details or changes.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

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

5 Comments

Leave a Reply
  1. CentOS 6.9:

    Instead of this:

    # /usr/pgsql-10/bin/postgresql-10-setup initdb
    

    You need to run this:

    # service postgresql-10 initdb
    
    Reply

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.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.