pgAdmin 4 is the enhanced version and is a complete rewrite of pgAdmin. This includes a desktop version written in NWjs as well as a web application that can be directly deployed on a web server. The desktop version helps you to access it from the local machine, while the web server enables you to access it from a remote system. In this tutorial, you will learn to install pgAdmin 4 on Ubuntu systems. Also, include the steps to add the PostgreSQL server to pgAdmin.
Prerequisites
A running Ubuntu 20.04 LTS system. Assuming you have a pre-installed PostgreSQL server on your system. Otherwise refer to other tutorial which covers both installation of PostgreSQL and pgAdmin on Ubuntu system.
Step 1 – Install pgAdmin4 on Ubuntu
An official PPA is available for pgAdmin4 to install the latest version on Ubuntu systems. First, import the repository signing GPG key and add the pgAdmin4 PPA to your system using the following commands. After adding the PPA, update the Apt cache and install the pgAdmin4 package on your system. The pgadmin4 package contains both pgadmin4-web and pgadmin4-desktop versions, Here:
pgadmin4-web – Provides the web interface accessible in a web browser pgadmin4-desktop – Provides desktop application for Ubuntu system, which required Ubuntu Desktop system. To install on a remote server (or no desktop available) use the “pgadmin4-web” package only. For local systems with Desktop installed, can use both versions.Step 2 – Configure pgAdmin4-WebThe user has installed pgadmin4-web or both editions, and needs, to run the below command to configure it. This will add a login screen to the pgAdmin4 web dashboard.
The above script will prompt you to create a user to access the web interface. Input an email address and password when prompted. Say “y” for other confirmation asked by the script.
Step 2 – Configure pgAdmin4-Web
The user has installed pgadmin4-web or both editions, and needs, to run the below command to configure it. This will add a login screen to the pgAdmin4 web dashboard.
Once the script is finished, you are good to access the pgAdmin web dashboard. It will be available below address:
Step 3 – Access pgAdmin4 Dashboard
The above commands will also configure pgAdmin4 with the Apache web server. You can access pgAdmin4 in a web browser with the following URL: http://server_ip/pgadmin4 Make sure to change server_ip with localhost, domain name pointed to the system or system IP address.
In any case, the above page is not loading, restart the Apache server using “sudo systemctl restart apache2“. Again reload the web dashboard. Now login with the email address and password configured with /usr/pgadmin4/bin/setup-web.sh script. After successful login to pgAdmin4, you will get the dashboard.
Step 4 – Add PostgreSQL Server to pgAdmin4
After successful login to the pgAdmin4 web interface. Let’s start adding the PostgreSQL instances to pgAdmin4. You can add multiple database servers running on the local machines as well as on remote host. To add a new server, click on “Add New Server” button.
This will open a popup, Enter a friendly name here:
Switch to the connection tab. Enter the hostname of the PostgreSQL server. Use “localhost” for running the database on the same instance. Then input the authentication details.
Click “Save” to complete the connection. On successful authentication, you will see the databases in the sidebar as shown below screenshot.
All done. You have successfully added the Postgres database server to pgAdmin4. You can also add more database instances to a single pgAdmin4 server.
Conclusion
This tutorial helped you to install and configure pgAdmin4 on a Ubuntu 20.04 Linux system. Also added a database server running on the same host. Next, you can learn about backup and restore Postgres databases via command line.