Install and Use pgAdmin 4 on Rocky Linux 8|AlmaLinux 8

PgAdmin is an open-source and widely used frontend management tool for the PostgreSQL database system developed in Python language. It allows one to manage the PostgreSQL database from the web interface by providing all the required features.

This release version PgAdmin 4 replaces the previous version PgAdmin 3 which was written in C++ language with support for PostgreSQL up to version 9.2. pgAdmin 4 comes with the following amazing features:

  • A live SQL Query Tool with direct data editing
  • A syntax-highlighting SQL editor
  • Supportive error messages
  • Helpful hints
  • Has support for administrative queries
  • A redesigned graphical interface
  • Online help and information about using pgAdmin dialogs and tools.
  • Responsive, context-sensitive behavior
  • Auto-detection and support for objects discovered at run-time

How To Install pgAdmin on Rocky Linux 8 | AlmaLinux 8

In this guide, we will systematically walk through how to install and use pgAdmin 4 on Rocky Linux 8 | AlmaLinux 8.

Before we proceed, you will require to have PostgreSQL installed on your Rocky Linux 8 | AlmaLinux 8 with the aid of this guide

You will also need a superuser account created. Login to the PostgreSQL shell.

sudo -u postgres psql

Now create a superuser to be used to connect and manage other users and databases.

postgres-# CREATE ROLE admin WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'Passw0rd';
postgres-# \q

Now with PostgreSQL installed, proceed and install PgAdmin 4 using the steps below.

Step 1 – Add the PgAdmin Repository

We first need to add the pgAdmin YUM repository to our system to be able to install this latest pgAdmin version.

Install the required package

sudo dnf install yum-utils

Then disable the PostgreSQL common repositories to allow us to grab the latest PgAdmin 4 packages from the PgAdmin repositories.

sudo yum-config-manager --disable pgdg-common

Now add the pgAdmin 4 repositories to our Rocky Linux| AlmaLinux 8 with the command:

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

Update your package index.

sudo dnf update

Step 2 – Install PgAdmin 4 on Rocky Linux |AlmaLinux 8

Now with the repositories added, installing pgAdmin 4 is as easy as robbing a child’s bank. Simply use the command below to install PgAdmin 4 on Rocky Linux |AlmaLinux 8.

sudo dnf install pgadmin4

Dependency Tree:

....             
Transaction Summary
================================================================================
Install  15 Packages

Total download size: 182 M
Installed size: 558 M
Is this ok [y/N]: y

Step 3 – Start Apache webserver

To access the pgAdmin web UI, we need a web server, Apache has been installed automatically when installing pgAdmin. We, therefore, need to ensure that the Apache webserver is running on our system.

sudo systemctl start httpd

Enable Apache to run automatically on boot.

sudo systemctl enable httpd

Check the status of the service.

$ sudo systemctl status httpd
 httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-11-04 04:01:12 EDT; 8s ago
     Docs: man:httpd.service(8)
 Main PID: 48450 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 241 (limit: 23532)
   Memory: 64.3M
   CGroup: /system.slice/httpd.service
           ├─48450 /usr/sbin/httpd -DFOREGROUND
           ├─48451 /usr/sbin/httpd -DFOREGROUND
           ├─48452 /usr/sbin/httpd -DFOREGROUND
           ├─48453 /usr/sbin/httpd -DFOREGROUND
           ├─48454 /usr/sbin/httpd -DFOREGROUND
           └─48455 /usr/sbin/httpd -DFOREGROUND

Nov 04 04:01:12 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Nov 04 04:01:12 localhost.localdomain httpd[48450]: [Thu Nov 04 04:01:12.380306 2021] [so:warn] [pid 48450:tid 140690349939008] AH01574: module wsgi_>
Nov 04 04:01:12 localhost.localdomain httpd[48450]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using loca>
Nov 04 04:01:12 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Nov 04 04:01:12 localhost.localdomain httpd[48450]: Server configured, listening on: port 80

Step 4 – Configure PgAdmin 4 Web Service

PgAdmin has a script that creates a new user, sets up the PgAdmin web UI, and also manages the Apache webserver. The script is located at /usr/pgadmin4/bin/setup-web.sh and is executed as below:

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

Now you will be prompted to provide details that will, later on, be used to login to the pgAdmin 4 web UI. Proceed as below.

Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

Email address: admin@techviewleo.com
Password: Enter Password here
Retype password: Re-enter Password here
pgAdmin 4 - Application Initialisation
======================================

Creating storage and log directories...
Configuring SELinux...
The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? y
Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4

Set SELinux in permissive mode as below.

sudo setenforce permissive

You also need to modify your firewall rules to allow HTTP traffic.

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

Step 5 – How to use PgAdmin

Now everything is set up, we can proceed to access the pgAdmin Web UI so that we can manage our PostgreSQL instance. Access the web interface using the URL http://server-ip/pgadmin4

Related posts

Perform Manual Failover & Switchover with repmgr in PostgreSQL

Configure automatic failover with repmgrd in PostgreSQL

Monitor Streaming Replication trong PostgreSQL