How to Install pgAdmin 4 on Ubuntu 22.04 (Step-by-Step)

Install pgAdmin 4 web mode on Ubuntu 22.04 LTS. Add the pgAdmin APT repository, install pgadmin4-web, run setup-web.sh to create an admin user, and access the web interface via Apache.

pgAdmin 4 is a web-based GUI for managing PostgreSQL databases. It supports PostgreSQL 9.2+ and runs on Linux, macOS, and Windows. You can use it to create databases, manage users, run queries, view performance metrics, and more. In this guide you install pgAdmin 4 in web mode on Ubuntu 22.04 LTS, configure it with Apache, and connect to a PostgreSQL server.

In this guide you’ll:

  • Add the pgAdmin APT repository and install pgadmin4-web
  • Run the setup script to create an admin user and configure Apache
  • Access the web interface and add a PostgreSQL server connection

Prerequisites:

Related: Postgres user and database permissions · Postgres 14 on Debian 11 · Postgres 14 with Ansible · Postgres 14 on FreeBSD 13 · PostgreSQL 14 with Docker · Postgres 14 on Rocky Linux/CentOS 8 · Postgres 14 on Ubuntu 20.04 · Postgres 14 on Fedora 34 · Postgres 14 on OpenSUSE Leap 15.3

Table of contents

  1. Update the system
  2. Set up the pgAdmin repository
  3. Install pgAdmin 4
  4. Configure pgAdmin 4 web mode
  5. Access pgAdmin 4 and add a server

1. Update the system

Update package lists and upgrade:

1
2
sudo apt update
sudo apt upgrade -y

2. Set up the pgAdmin repository

pgAdmin 4 is not in the default Ubuntu repos. Add the official repository:

1
2
3
sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
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'
sudo apt update

Note: apt-key add is deprecated. For newer Ubuntu versions, consider using signed-by in the sources.list entry instead. The pgAdmin repository setup script may be updated in the future.

3. Install pgAdmin 4

Choose one:

  • Web mode only (recommended for servers): pgadmin4-web
  • Desktop mode only: pgadmin4-desktop
  • Both: pgadmin4

For a server, install web mode:

1
sudo apt install -y pgadmin4-web

4. Configure pgAdmin 4 web mode

Run the setup script to create an admin user and configure Apache:

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

You’ll be prompted for:

  • Email address for the initial admin account
  • Password (twice)
  • Whether to configure Apache (answer y)
  • Whether to restart Apache (answer y)

Example output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Setting up pgAdmin 4 in web mode on a Debian 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: [email protected]
Password:
Retype password:
...
Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4

pgAdmin 4 is available at http://127.0.0.1/pgadmin4 or http://your-server-ip/pgadmin4.

5. Access pgAdmin 4 and add a server

  1. Open http://your-server-ip/pgadmin4 in a browser.
  2. Log in with the email and password you set during setup.
  3. Click Add New Server.
  4. On the General tab, enter a name (e.g. “Production PostgreSQL”).
  5. On the Connection tab, enter:
    • Host name/address: localhost (or your PostgreSQL server IP)
    • Port: 5432 (default PostgreSQL port)
    • Maintenance database: postgres (or another database)
    • Username: your PostgreSQL user
    • Password: your PostgreSQL password
  6. Click Save.

The server appears under Servers in the left sidebar. Expand it to see databases, roles, and tablespaces. Click a database to view its dashboard and performance metrics.


Frequently Asked Questions (FAQ)

What is pgAdmin 4?

pgAdmin 4 is a web-based administration tool for PostgreSQL. It provides a GUI for creating databases, managing users, running SQL queries, viewing performance metrics, and more. It supports PostgreSQL 9.2+ and can connect to local or remote servers.

What is the difference between pgAdmin desktop and web mode?

Desktop mode (pgadmin4-desktop) runs as a standalone desktop application. Web mode (pgadmin4-web) runs via Apache and is accessible from any browser. For servers, use web mode; for local development on a desktop, either works.

Where is pgAdmin 4 installed?

The web interface is served by Apache at /pgadmin4. Config files are typically in /etc/pgadmin/ and logs in /var/log/pgadmin/. The setup script configures Apache automatically.

How do I access pgAdmin 4 from another machine?

If Apache is listening on all interfaces, use http://your-server-ip/pgadmin4. For production, set up NGINX as a reverse proxy with TLS (Let’s Encrypt) and restrict access (e.g. VPN or firewall rules).


Conclusion

You installed pgAdmin 4 in web mode on Ubuntu 22.04: added the pgAdmin APT repository, installed pgadmin4-web, ran the setup script to create an admin user and configure Apache, and added a PostgreSQL server connection. The web interface is available at http://your-server-ip/pgadmin4. For PostgreSQL installation guides, see Postgres 14 on Ubuntu 22.04 or other PostgreSQL guides linked above.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy