How to Install PostgreSQL 16 on RHEL 9 Step by Step

Learn to install PostgreSQL 16 on RHEL 9 with this detailed guide, ensuring a robust and efficient database setup.

PostgreSQL is a powerful, open-source relational database management system known for its robustness, performance, and flexibility. The latest version, PostgreSQL 16, brings several enhancements and new features. This guide provides a comprehensive, step-by-step process to install PostgreSQL 16 on RHEL 9, ensuring a smooth and secure setup.

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Step 1: Update Your System
  4. Step 2: Add the PostgreSQL Repository
  5. Step 3: Install PostgreSQL 16
  6. Step 4: Initialize the PostgreSQL Database
  7. Step 5: Start and Enable PostgreSQL Service
  8. Step 6: Secure PostgreSQL Installation
  9. Step 7: Verify PostgreSQL Installation
  10. Step 8: Basic PostgreSQL Configuration
  11. Conclusion
  12. References

Introduction

PostgreSQL 16 offers new features, performance improvements, and security enhancements. Installing it on RHEL 9 ensures you leverage the latest advancements in database technology. This guide will walk you through each step of the installation and configuration process, helping you set up PostgreSQL 16 efficiently and securely.

Prerequisites

Before you begin, ensure you have the following:

  • A system running RHEL 9.
  • A user account with sudo privileges.
  • Internet access to download necessary packages.

Step 1: Update Your System

Start by updating your system to ensure all existing packages are up-to-date. Open your terminal and run the following commands:

sudo dnf update -y sudo dnf upgrade -y

This ensures that your system is ready for new installations.

Step 2: Add the PostgreSQL Repository

PostgreSQL is not included in the default RHEL 9 repositories, so you need to add the PostgreSQL YUM repository.

  1. Download the PostgreSQL repository RPM package:

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

  2. Disable the default PostgreSQL module to avoid conflicts:

    sudo dnf -qy module disable postgresql

Step 3: Install PostgreSQL 16

Now that the repository is added, you can install PostgreSQL 16.

  1. Install PostgreSQL 16 server and client:

    sudo dnf install -y postgresql16-server postgresql16

  2. Verify the installation:

    psql --version

    This command should return the version of PostgreSQL installed on your system.

Step 4: Initialize the PostgreSQL Database

Before starting the PostgreSQL service, you need to initialize the database.

  1. Initialize the database:

    sudo /usr/pgsql-16/bin/postgresql-16-setup initdb

Step 5: Start and Enable PostgreSQL Service

To start using PostgreSQL, start the service and enable it to start on boot.

  1. Start the PostgreSQL service:

    sudo systemctl start postgresql-16

  2. Enable the PostgreSQL service to start on boot:

    sudo systemctl enable postgresql-16

  3. Check the status of the PostgreSQL service:

    sudo systemctl status postgresql-16

    This command should show that the PostgreSQL service is active and running.

Step 6: Secure PostgreSQL Installation

Securing your PostgreSQL installation involves setting a password for the postgres user and configuring access controls.

  1. Switch to the postgres user:

    sudo -i -u postgres

  2. Set a password for the postgres user:

    psql -c "ALTER USER postgres WITH PASSWORD 'your_secure_password';"

  3. Exit the postgres user shell:

    exit

Step 7: Verify PostgreSQL Installation

To verify the installation and check that PostgreSQL is working correctly, log in to the PostgreSQL server as the postgres user.

  1. Log in to PostgreSQL:

    sudo -i -u postgres psql

  2. Check connection info:

    \conninfo

    You should see information about the current connection, indicating that PostgreSQL is running correctly.

  3. Exit the PostgreSQL shell:

    \q

Step 8: Basic PostgreSQL Configuration

Configure PostgreSQL for your specific needs by editing the postgresql.conf and pg_hba.conf files.

  1. Edit the postgresql.conf file:

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

    Adjust settings such as listen_addresses, port, and logging options as needed.

  2. Edit the pg_hba.conf file for access control:

    sudo nano /var/lib/pgsql/16/data/pg_hba.conf

    Configure the authentication methods for different connections (local, host, etc.).

  3. Restart PostgreSQL to apply changes:

    sudo systemctl restart postgresql-16

Conclusion

Installing PostgreSQL 16 on RHEL 9 involves several steps to ensure a secure and optimized setup. By following this guide, you have successfully installed PostgreSQL, initialized the database, configured the service, and secured your installation. You are now ready to use PostgreSQL 16 for your database needs.

Compelling Summary: Learn to install PostgreSQL 16 on RHEL 9 with this detailed guide, ensuring a robust and efficient database setup.

References

By following these steps, you will have a fully functional PostgreSQL 16 database server on RHEL 9, ready to handle your data needs efficiently and securely.