Skip to content

How to Set Up pgAdmin on a Linux Server – Manage PostgreSQL Databases in Your Browser

Set up pgAdmin 4 on your Linux server as a One-Click App with HTTPS or manually using Docker Compose. Securely connect PostgreSQL, run queries, and create backups.

30 November 202612 min read2 Views0 helpful

Introduction

pgAdmin is the best-known web interface for PostgreSQL. In your browser, you can create databases, users, and tables, write SQL queries in the Query Tool, view your database server's load, and create backups with pg_dump without having to type the commands yourself. pgAdmin 4 is open source and runs in server mode as a web application with its own login.

In this guide, we'll show you two ways to get started: the easy way, as a One-Click App that makes pgAdmin available over HTTPS in just a few minutes, and a manual installation using Docker Compose via the console. After that, you'll learn how to connect a PostgreSQL database on the same VPS or on another server without exposing the database port to the internet, and how to create, query, and back up databases.

When pgAdmin Makes Sense on a VPS

pgAdmin is not a database; it's an interface for PostgreSQL servers that are already running. This could be the PostgreSQL One-Click App on the same VPS, a database used by another app, or a PostgreSQL server elsewhere. pgAdmin is a good fit if:

  • You'd rather manage PostgreSQL in a browser than with psql, for example, the database for a web app, a Discord bot, or a game server plugin.
  • You want to see multiple PostgreSQL servers in one place, such as a test and a live database.
  • Multiple people need to manage databases but shouldn't have SSH access to the server. pgAdmin has its own user accounts.
  • You want to develop queries or inspect tables, with a results table, query history, and an explanation of the execution plan.
  • You occasionally need to back up or restore an individual database without having to memorize the pg_dump options.

pgAdmin is less suitable for MySQL and MariaDB; phpMyAdmin is designed for those. For very large databases and automatic nightly backups, using the console with pg_dump and a cron job is more reliable than using a browser interface.

The Easy Way: pgAdmin as a One-Click App

With your VPS's One-Click Apps, pgAdmin runs over HTTPS without you having to set up Docker, a reverse proxy, or a certificate yourself. The app doesn't include its own database: after logging in, you add the PostgreSQL servers you want pgAdmin to manage.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. For instructions, see VPS: One-Click Apps.
  • A PostgreSQL server for pgAdmin to manage, for example, the PostgreSQL One-Click App on the same VPS.
  • pgAdmin itself uses few resources. The image is just over 600 MB, and a small VPS is enough for pgAdmin alone. If PostgreSQL runs on the same VPS, allocate additional storage for the database.

Install

  1. Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
  2. Search for “pgAdmin” in the App catalog and click Install app next to pgAdmin.
  3. Use a custom subdomain or zap.cloud is already selected, with a randomly generated name. Leave the option enabled or enter your own name, such as pgadmin. With a domain, pgAdmin is accessible over HTTPS, so your database passwords are encrypted in transit.
  4. Two fields are required under App configuration: enter an email address in PGADMIN_DEFAULT_EMAIL; this will be your pgAdmin username. Set a long, secure password in PGADMIN_DEFAULT_PASSWORD. Neither value is generated automatically.
  5. Click Queue installation.

On its first launch, pgAdmin sets up its internal database. This takes about one to two minutes, after which the app's status changes to Online.

Info: You don't need to use a real email address

pgAdmin only checks whether the value looks like an email address. The app won't send emails unless you configure its email settings. So don't rely on the “Forgotten your password?” link on the login page; keep your password somewhere safe, such as in a password manager.

First Login

  1. Open pgAdmin using the Access link on the app card.
  2. Sign in with the email address and password you entered in the installation form. You can also find both later under the gear icon on the app card > App environment > App configuration.
  3. On the login page, you can choose the interface language, including German. The terms in this guide are from the English interface.

After logging in, you'll see the Object Explorer on the left, with the empty Servers entry, and the Dashboard on the right, with the Add New Server link.

Warning: You can only change your password in pgAdmin

PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD only apply on the very first launch. If you change them later under App environment, the old password will remain valid. To set a new password, use Change Password in your user menu at the top right of pgAdmin.

Login Lockout After Three Failed Attempts

pgAdmin locks an account after three incorrect password attempts. This protects against password guessing, but it can also lock you out if you mistype your password. Only another administrator account can unlock a locked account. So, after your first login, use Users in your user menu at the top right to create a second account with the Administrator role, and store its login details separately.

Updates and backups

  • Install updates in the app settings (gear icon) > App update: click Check for updates, then, if a new version is available, click Apply update. Your databases won't be affected; they aren't stored in pgAdmin.
  • pgAdmin itself only stores your server list, saved passwords, settings, and files from the Storage Manager, such as backups. This data is stored in the app's volume on your VPS, and a VPS backup in the Backups tab will include it.
  • If you only need pgAdmin occasionally, stop the app from its card afterward and start it again when needed. Anyone who knows the address can access the login page.

Manual Installation

The rest of this guide covers the manual installation of pgAdmin using Docker Compose via the console, for example, on a server without One-Click Apps or alongside a PostgreSQL server you've installed yourself. The commands are written for Debian and Ubuntu.

Requirements

MinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM1 GB2 GB if PostgreSQL runs on the same server
Storage2 GB free (image just over 600 MB)10 GB if you store backups in pgAdmin

These are guidelines; pgAdmin doesn't specify official minimum requirements. You'll also need Docker with the Compose plugin, as described in How to Set Up Docker on a Linux Server, and SSH access; see VPS: First Access via SSH.

Prepare the Firewall

In this guide, pgAdmin only listens on 127.0.0.1; it's only accessible from outside through the reverse proxy over HTTPS. So, only open SSH and the web ports:

Code
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Don't open PostgreSQL port 5432. pgAdmin connects locally on the server, and you can access remote databases through an SSH tunnel; see below. For more on the firewall, see VPS: Open Ports and Manage the Firewall on Linux.

Install with Docker Compose

Create a directory and add a compose.yaml file to it:

Code
sudo mkdir -p /opt/pgadmin
cd /opt/pgadmin
sudo nano compose.yaml
yaml
services:
  pgadmin:
    image: dpage/pgadmin4:9.19.0
    container_name: pgadmin
    restart: unless-stopped
    network_mode: host
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@example.com
      PGADMIN_DEFAULT_PASSWORD: CHANGE_ME
      PGADMIN_LISTEN_ADDRESS: 127.0.0.1
      PGADMIN_LISTEN_PORT: 5050
    volumes:
      - pgadmin-data:/var/lib/pgadmin

volumes:
  pgadmin-data:

The important lines:

  • image sets the version. 9.19.0 is also the version used by the One-Click App. Find new versions on Docker Hub.
  • network_mode: host lets pgAdmin run directly on the server's network. This allows it to reach a PostgreSQL server that only listens on 127.0.0.1 on the server, using that exact address.
  • PGADMIN_LISTEN_ADDRESS and PGADMIN_LISTEN_PORT make pgAdmin listen only locally on port 5050. Without these lines, it would use port 80.
  • PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD are the credentials for the first account. Replace CHANGE_ME with a secure password. As with the One-Click App, these values only apply on the first launch.
  • The pgadmin-data volume contains the server list, settings, and Storage Manager.

Start pgAdmin and check the logs:

Code
sudo docker compose up -d
sudo docker compose logs -f pgadmin

Once Listening at: http://127.0.0.1:5050 appears, pgAdmin is ready. Press Ctrl + C to exit the log view.

First Access

Until a reverse proxy is running, access pgAdmin through an SSH tunnel. Run this on your PC:

Code
ssh -L 5050:127.0.0.1:5050 root@SERVER_IP

Then open http://localhost:5050 in your browser and sign in with the email address and password from compose.yaml.

Access over HTTPS Through a Reverse Proxy

For permanent access, put nginx in front of pgAdmin. Create a /etc/nginx/sites-available/pgadmin file:

Code
server {
    listen 80;
    server_name pgadmin.example.com;

    location / {
        proxy_pass http://127.0.0.1:5050;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
        client_max_body_size 512M;
    }
}

client_max_body_size allows larger uploads in the Storage Manager, such as backup files for a restore. Enable the site and get a certificate:

Code
sudo ln -s /etc/nginx/sites-available/pgadmin /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d pgadmin.example.com

For details on nginx and certificates, see VPS: Set Up a Reverse Proxy with nginx on Linux and VPS: Create an SSL Certificate.

Back Up Your Data

Your databases are the most important thing to back up; use pg_dump (see “Backup and Restore” below). Back up the pgAdmin volume if you want to keep your server list and Storage Manager:

Code
sudo docker run --rm -v pgadmin_pgadmin-data:/data -v /root:/backup alpine tar czf /backup/pgadmin-data-$(date +%F).tar.gz -C /data .

The volume name is made up of the directory name and the name in compose.yaml. Use sudo docker volume ls to find it.

Update pgAdmin

Set the new version for image in compose.yaml and restart the container:

Code
cd /opt/pgadmin
sudo docker compose pull
sudo docker compose up -d

pgAdmin updates its internal database automatically on startup. Before upgrading across major versions, read the Release Notes.

Manage PostgreSQL with pgAdmin

These steps are the same for the One-Click App and the manual installation.

Connect a Database on the Same VPS

The PostgreSQL One-Click App opens port 5432 on your VPS. This means pgAdmin can reach it using your VPS's IP address. The connection stays on the VPS.

  1. Click Add New Server on the Dashboard.
  2. Under Name on the General tab, enter a name, for example, “PostgreSQL.”
  3. Enter the following on the Connection tab:
FieldWhat to enter
Host name/addressYour VPS's IP address
Port5432 or the value of POSTGRES_PORT
Maintenance databasepostgres
UsernameThe value of SERVICE_USER_POSTGRES
PasswordThe value of SERVICE_PASSWORD_POSTGRES
  1. Turn on Save password? if you don't want pgAdmin to ask every time you connect, then click Save.

You can find the PostgreSQL app's username and password in its settings (gear icon) under App environment > Automatically generated values. If you've manually installed PostgreSQL directly on the server, enter 127.0.0.1 as the host.

Warning: Don't open port 5432 to everyone

Port 5432 doesn't need to be accessible from the internet for pgAdmin to work. If you need to open it for other servers, restrict access to their IP addresses in your VPS's Network firewall tab and use strong passwords. For instructions, see VPS: Open Ports and Manage the Firewall on Linux.

Connect to an External Database Through an SSH Tunnel

If PostgreSQL is on another server, pgAdmin routes the connection through an SSH tunnel. The database port stays closed on the other server, and PostgreSQL can continue listening only on 127.0.0.1.

  1. To connect with a key, first upload your private SSH key: Tools > Storage Manager. For instructions on creating a key, see VPS: Create and Use SSH Keys for Linux Servers. It's best to use a dedicated key just for pgAdmin and a user without root privileges.
  2. Click Add New Server and enter a name.
  3. On the SSH Tunnel tab: turn on Use SSH tunneling, enter the other server's IP address under Tunnel host, 22 under Tunnel port, and the SSH user under Username. Under Authentication, select Identity file and then the file you uploaded. Alternatively, use Password.
  4. On the Connection tab, enter 127.0.0.1 as the Host name/address, which is the address the database can be reached at from the other server, as well as the database port, username, and password.
  5. Click Save.

By default, pgAdmin doesn't save the SSH password, so you'll be prompted for it each time you connect.

Create a Database and User

It's best to create a separate user and database for each application:

  1. Expand your server in the Object Explorer, right-click Login/Group Roles, and select Create > Login/Group Role.
  2. Enter a name on the General tab, for example, shop_app, set a password on the Definition tab, and turn on Can login? on the Privileges tab. Click Save.
  3. Right-click Databases and select Create > Database. Enter a name, for example, shop, select the new user as the Owner, and click Save.

You can also do the same in the Query Tool with SQL:

sql
CREATE ROLE shop_app LOGIN PASSWORD 'CHANGE_ME';
CREATE DATABASE shop OWNER shop_app;

Your application can then connect to the shop database as the shop_app user. It has all privileges there, but no access to other databases.

Run Queries in the Query Tool

Select a database on the left and open Tools > Query Tool. Write your query in the editor and run it with F5 or the play icon. The result appears under Data Output at the bottom; messages and errors appear under Messages.

Tip: Take care when making changes

The Query Tool runs commands immediately and commits them directly. Test UPDATE and DELETE first with a SELECT using the same WHERE condition, or start a block with BEGIN;, check the result, and finish it with COMMIT; or ROLLBACK;.

Back Up and Restore with pg_dump

pgAdmin includes pg_dump and pg_restore for PostgreSQL versions 13 to 18 and automatically selects the appropriate version.

Backup: Right-click the database and select Backup.... Enter a name under Filename, for example, shop.backup, leave Format set to Custom, and click Backup. pgAdmin saves the file in your Storage Manager area. Download it to your PC using Tools > Storage Manager.

Restore: Create an empty database, right-click it, and select Restore.... Under Filename, select the backup file from the Storage Manager. Upload a file from your PC to the Storage Manager first. Then click Restore.

For regular backups, a cron job on the server is more reliable than clicking in pgAdmin. If PostgreSQL runs as a One-Click App, use the pg_dump in the database container. You can find the container name (it starts with postgresql-) using sudo docker ps:

Code
sudo mkdir -p /root/backups
sudo docker exec CONTAINER_NAME pg_dump -U DB_USER -Fc DB_NAME > /root/backups/DB_NAME-$(date +%F).dump

If PostgreSQL is installed directly on the server, leave out sudo docker exec CONTAINER_NAME and run pg_dump -h 127.0.0.1 -U DB_USER -Fc DB_NAME directly.

Download backups from the server regularly, for example, using SFTP.

Limitations

  • PostgreSQL only: Manage MySQL and MariaDB with phpMyAdmin.
  • No built-in database: pgAdmin needs a running PostgreSQL server and can only do what the logged-in database user is allowed to do.
  • Older PostgreSQL versions: Backup and restore only work with the included tools for versions 13 to 18.
  • Large databases: Backups and restores involving many gigabytes are more reliable via the console than through a browser.

Conclusion

You've set up pgAdmin on your Linux server, connected to a PostgreSQL database on the same VPS and to one on another server through an SSH tunnel, and learned how to create, query, and back up databases. If you also manage MySQL or MariaDB, see the guide How to Set Up phpMyAdmin on a Linux Server.

Prefer to avoid the console? Use the easy way as a One-Click App, as described above under “The Easy Way: pgAdmin as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the faster option: pgAdmin is available over HTTPS within minutes, you can install updates with a click under App Update, and there's no need to set up a reverse proxy or certificate. Manual installation with Docker Compose makes sense if your server doesn't use One-Click Apps or pgAdmin needs to reach a PostgreSQL server that only listens on 127.0.0.1.
You set the email address and password during installation. You can find them afterward in the app settings (gear icon) under App Environment > App Configuration, in PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD. If you've changed the password in pgAdmin since then, use the new password, not the value in App Environment.
pgAdmin locks an account after three incorrect passwords. Only another administrator account can unlock it in pgAdmin under Users. Create a second administrator account right after your first login.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.