PostgreSQL is a powerful, open-source object-relational database system known for its robustness, scalability, and compliance with SQL standards. pgAdmin4, on the other hand, is a popular open-source and feature-rich web-based interface for managing PostgreSQL databases. This article will guide you through the Steps of installing PostgreSQL and pgAdmin4 on a CentOS/RHEL 9 system using the official PostgreSQL DNF repositories.

Advertisement

Prerequisites”

  • A system running CentOS/RHEL 9.
  • Sudo privileges.
  • Internet connectivity.

Step 1: System Update

Before installing new packages, it’s always a good idea to update your system. Open a terminal and run:

sudo dnf update -y 

Step 2: Enable PostgreSQL DNF Repository

First, you need to enable the PostgreSQL DNF repository to access the latest PostgreSQL packages. Run the following command to do so:

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

Step 3: Install PostgreSQL

Now, install PostgreSQL. For this guide, we’ll assume you are installing PostgreSQL 16, but you can replace 16 with any other available version.

sudo dnf -y install postgresql16-server 

After installation, initialize the database server:

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

Enable and start the PostgreSQL service:

sudo systemctl enable postgresql-16 
sudo systemctl start postgresql-16 

Step 4: Secure PostgreSQL

Switch to the PostgreSQL user:

sudo su - postgres 

Access the PostgreSQL prompt:

psql 

At the PostgreSQL prompt, set a password for the PostgreSQL user:

\password 

Type the desired password and exit:

\q 

Return to your regular user account:

exit 

Step 5: Install pgAdmin4

Enable the EPEL repository which is required for pgAdmin4:

sudo dnf -y install epel-release 

Install pgAdmin4:

sudo dnf -y install pgadmin4 

Step 6: Configure pgAdmin4

You need to configure pgAdmin4 by running the setup script:

sudo /usr/pgadmin4/bin/setup-web.sh 

Follow the on-screen instructions to set up an admin email and password.

Step 7: Access pgAdmin4

Once the setup is complete, you can access pgAdmin4 through your web browser. Navigate to:

  • http://your_server_ip/pgadmin4
  • Log in using the admin email and password you set during configuration.

    Step 8: Add PostgreSQL Server in pgAdmin4

    1. Log into pgAdmin4.
    2. Right-click on ‘Servers’ in the left pane and select ‘Create’ &gt>> ‘Server’.
    3. In the ‘General’ tab, give a name to your server.
    4. In the ‘Connection’ tab, enter the hostname (localhost if on the same machine), the username (postgres), and the password set earlier.
    5. Click ‘Save’.

    Conclusion

    You have successfully installed PostgreSQL and pgAdmin4 on your CentOS/RHEL 9 system. You can now manage your PostgreSQL databases through the pgAdmin4 web interface, taking advantage of its many features for efficient database administration and development.

    Remember to regularly update your system and PostgreSQL to maintain security and stability.

    Share.

    1 Comment

    Exit mobile version