Skip to content

How to Install PostgreSQL and pgAdmin4 on CentOS/RHEL 9

Installing PostgreSQL 9.1 on CentOS 5/6 and RHEL 5/6. PostgreSQL is open source object-relational, highly scalable, SQL compliant database management system

Steps
8
Category
Databases
Covers
CentOS, PostgreSQL, RHEL
On this page 8 steps

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.

Prerequisites”

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

Step 1 of 8System 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 of 8Enable 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 of 8Install 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 of 8Secure 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 of 8Install 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 of 8Configure 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 of 8Access 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 of 8Add 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. This tutorial helped you to install and configure PostgreSQL database server as well as pgAdmin4. You can now manage your PostgreSQL databases through the pgAdmin4 web interface, taking advantage of its many features for efficient database administration and development.

    Rahul

    Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

    1 Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *


    Back to top