How to Install PostgreSQL and pgAdmin in RHEL 8

Pgadmin4 is an opensource web-based management tool for managing PostgreSQL databases. It’s a Python-based web-application developed using the flask framework at the backend and HTML5, CSS3, and Bootstrap on the frontend. Pgadmin4 is a rewrite of Pgadmin 3 which is written in C++ and ships with the following notable features:

Pgadmin4 Features

  • Sleek and revamped web interface with polished icons and panels.
  • Fully responsive web layout with dashboards for real-time monitoring.
  • Live SQL query tool/editor with syntax highlighting.
  • Powerful management dialogs and tools for common tasks.
  • Useful hints to get you started.
  • And so much more.

In this article, you will learn how to install PostgreSQL with pagAdmin4 in server mode running behind the Apache webserver using the WSGI module on RHEL 8.

Install PostgreSQL on RHEL 8

The first step in installing PgAdmin4 is to install the PostgreSQL database server. PostgreSQL is available in the Appstream repository in different versions. You can make your selection by enabling your preferred package using the dnf package manager.

To list the available modules for PostgreSQL, run the command:

# dnf module list postgresql
List Modules for Postgresql
List Modules for Postgresql

The output indicates that there are 3 versions available for download from the AppStream repository: version 9.6, 10, and 12. We can also see that the default version is Postgresql 10 as indicated by the [d] tag. This is what you would install by running the command below.

# dnf install postgresql-server

However, we want to install the latest version, which is PostgreSQL 12. Therefore, we will enable that module and override the default module stream. To do so, run the command:

# dnf module enable postgresql:12
Enable Module for PostgreSQL
Enable Module for PostgreSQL

Once you have enabled the module for Postgresql 12, proceed and install Postgresql 12 alongside its dependencies as shown.

# dnf install postgresql-server
Install PostgreSQL in RHEL 8
Install PostgreSQL in RHEL 8

Before anything else, you need to create a database cluster. A cluster comprises a collection of databases that are managed by a server instance. To create a database cluster, invoke the command:

# postgresql-setup --initdb

If everything went well, you should get the output below.

Initialize PostgreSQL Database
Initialize PostgreSQL Database

Once the cluster is created, you can now start and enable your PostgreSQL instance as shown:

# systemctl start postgresql
# systemctl enable postgresql

To confirm that Postgresql is up and running, execute:

# systemctl status postgresql
Verify PostgreSQL Status
Verify PostgreSQL Status

Installing Pgadmin4 in RHEL 8

To install Pgadmin4, first, add the external repository shown below.

# rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm

Next, run the command below to install pgadmin4 in server mode.

# dnf install pgadmin4-web  
Install Pgadmin4 in RHEL 8
Install Pgadmin4 in RHEL 8

Next, install the policycoreutils packages which provide the core utilities needed by SELinux.

$ sudo dnf install policycoreutils-python-utils
Install Python Policycoreutils in RHEL 8
Install Python Policycoreutils in RHEL 8

Once installed, run the Pgadmin4 setup script as shown. This is going to create a pgadmin user account, storage and log directories, configure SELinux and spin up the Apache webserver on which pgAdmin4 will run on.

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

When prompted, provide the required information and hit 'Y' to start the Apache webserver.

Run Pgadmin Setup Script
Run Pgadmin Setup Script

If you have a firewall running, open port 80 to allow web service traffic.

# firewall-cmd --add-port=80/tcp --permanent
# firewall-cmd --reload

Next, configure SELinux as shown:

# setsebool -P httpd_can_network_connect 1

To access pgadmin4, launch your browser and browse the URL shown.

http://server-ip/pgadmin4

Be sure to log in using the email address and the password that you provided when running the setup script.

pgadmin4 Login
pgadmin4 Login

This ushers you to the Pgadmin4 dashboard as shown below.

pgadmin4 Dashboard
pgadmin4 Dashboard

And that’s how you install Pgadmin4 in server mode. You can now create and manage PostgreSQL databases using the SQL editor and monitor their performance using the dashboards provided. This brings us to the end of this guide.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

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

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply
  1. The following information is out of date and produces a 404 error:

    rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm
    

    It should be updated to:

    rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
    
    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.