PgAdmin is an open-source administration tool for Postgres databases. It has a graphical user interface written with the Qt application framework and uses libpq as its backend driver to communicate with the database server.

It can be used to manage local or remote PostgreSQL servers, create new databases, execute SQL queries and scripts against those databases using an interactive query editor that provides syntax highlighting and intelligent autocomplete, among other things, import data from various sources into the database or generate reports from within the program about available space in tablespaces or indexes as well as many other things.

The main reason Linux user choose PgAdmin 4 is that its UI looks very simple and modern, similar to other web apps like Google Drive. In contrast, other administration tools for PostgreSQL tend to look complex and outdated in comparison, which can be discouraging for new developers who want to learn more about databases.

Prerequisites

  • You’ll need root privileges throughout this tutorial, so run everything as root with either sudo or su.
  • A server running Debian 11 or Debian 10 (Buster) with a minimum of 2GB of RAM and 15 GB of free space.
  • This tutorial was tested on Debian but should work on all previous versions or other Debian-based distributions like Ubuntu and Linux Mint.

Step1: Updating the System

First, log in to your Debian server via SSH as the root user, update the system and install some necessary packages:

sudo apt update && sudo apt upgrade

This command will update the repositories and install new software packages.

Once the update is completed, we need to install some required dependencies. Such as: ca-certificates, gnupg

sudo apt-get install curl ca-certificates gnupg gnupg2 -y

These dependencies will help us compile and run PgAdmin 4. Type Y and hit Enter when prompted. The installation may take a minute or two.

<img alt="Install prerequisites" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-1.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="386" src="data:image/svg xml,” width=”659″>

Step 2: Install PostgreSQL

Because PgAdmin 4 requires the PostgreSQL server to run. So before we install pgAdmin4, we must install the PostgreSQL server first.

sudo apt-get install postgresql -y

Once the installation is complete, start the PostgreSQL service and enable it to launch automatically at system boots:

sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service

Check the status of the PostgreSQL server with:

sudo systemctl status postgresql.service

If you see an output saying “active (running)”, everything is OK.

<img alt="Start Postgres service" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-2.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="190" loading="lazy" src="data:image/svg xml,” width=”656″>

The PostgreSQL server listens to requests on TCP port 5432 by default. Run the following command to check if PostgreSQL is listening on port 5432.

ss -antpl | grep 5432

It should display an output similar to the following one.

<img alt="Check postgres port" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-3.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="87" loading="lazy" src="data:image/svg xml,” width=”660″>

Step 3: Installing pgAdmin 4 on Debian

The pgAdmin 3 package is shipped with Debian 10, while the pgAdmin 4 package is not. To install pgAdmin 4, we need to add the official package repository of PostgreSQL on Debian 10.

First, add the GPG key to the system using the curl command.

curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add

You should get an OK output if the key has been added successfully.

<img alt="Add repo key" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-4.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="113" loading="lazy" src="data:image/svg xml,” width=”668″>

Once the key is added, add the official PostgreSQL package repository to your sources.list file in /etc/apt/sources.list using the echo command.

sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'

You are now ready to install pgAdmin 4 on Debian. To install pgAdmin 4, run the following command.

sudo apt-get update
sudo apt-get install pgadmin4 -y

Once the installation is done, you must run a web setup script that shipped with pgAdmin 4. This setup script lets you run pgAdmin 4 in web interface/web mode.

Run the following command to run the script.

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

For the pgadmin4 initial user account, you will be prompted to provide an email address and a password. Enter any username, a secure password and email address for this initial user. Once you fill in all the details, hit Enter to continue the installation.

After that, you will be asked a series of questions, type Y and hit ENTER to accept the default.

<img alt="Start setup script" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-5.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="353" loading="lazy" src="data:image/svg xml,” width=”670″>

Step 4: Configuring the Firewall

If you installed pgadmin4 on a server behind a firewall or router that has a firewall enabled, you will need to open TCP Ports 80 and 443 on your firewall.

You can do this with the ufw command.

sudo ufw allow http
sudo ufw allow https

<img alt="Configure the firewall" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-6.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="96" loading="lazy" src="data:image/svg xml,” width=”1056″>

Reload the firewall with the following command to all the changes take effect.

sudo ufw reload

To check the status of the firewall and your rules, run:

sudo ufw status

You should see something like this.

<img alt="Check Firewall status" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-7.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="189" loading="lazy" src="data:image/svg xml,” width=”647″>

Step 5: Accessing the pgAdmin 4 Web Interface

Now that you have completed the installations, you can access pgAdmin 4 on your server’s IP address. To get started, open a web browser and type the URL below in the address bar.

https:///pgadmin4

Where: is the actual IP address of your PostgreSQL server.

For example, to access pgAdmin 4 on 192.168.1.103, type:

https://192.168.1.103/pgadmin4

If all goes well, you should see a log in page as shown below. Enter the username and password you created during installation, then click Login.

<img alt="Login to pgAdmin 4" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-8.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="670" loading="lazy" src="data:image/svg xml,” width=”1359″>

Once you are authorized, you will be taken to the pgadmin4 dashboard. From there, you can use pgAdmin 4 to manage your PostgreSQL servers and databases.

<img alt="Pgadmin" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19788-9.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="574" loading="lazy" src="data:image/svg xml,” width=”1602″>

That’s it! You have successfully installed pgAdmin 4 on a Debian 10 system. For more information about pgAdmin, please visit the official pgAdmin documentation page.

Conclusion

In this guide, we have shown you how to install pgAdmin 4 on a Debian system. You can now use the pgAdmin graphical tool to manage your database servers from a web interface. Happy data management.