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.
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_dumpoptions.
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.
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.
- 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.
- Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
- Search for “pgAdmin” in the App catalog and click Install app next to pgAdmin.
- 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. - 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 inPGADMIN_DEFAULT_PASSWORD. Neither value is generated automatically. - 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.
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.
- Open pgAdmin using the Access link on the app card.
- 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.
- 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.
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.
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.
- 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.
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.
| Minimum | Recommended | |
|---|---|---|
| CPU | 1 vCPU core | 2 vCPU cores |
| RAM | 1 GB | 2 GB if PostgreSQL runs on the same server |
| Storage | 2 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.
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:
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.
Create a directory and add a compose.yaml file to it:
sudo mkdir -p /opt/pgadmin
cd /opt/pgadmin
sudo nano compose.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:
imagesets the version. 9.19.0 is also the version used by the One-Click App. Find new versions on Docker Hub.network_mode: hostlets pgAdmin run directly on the server's network. This allows it to reach a PostgreSQL server that only listens on127.0.0.1on the server, using that exact address.PGADMIN_LISTEN_ADDRESSandPGADMIN_LISTEN_PORTmake pgAdmin listen only locally on port 5050. Without these lines, it would use port 80.PGADMIN_DEFAULT_EMAILandPGADMIN_DEFAULT_PASSWORDare the credentials for the first account. ReplaceCHANGE_MEwith a secure password. As with the One-Click App, these values only apply on the first launch.- The
pgadmin-datavolume contains the server list, settings, and Storage Manager.
Start pgAdmin and check the logs:
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.
Until a reverse proxy is running, access pgAdmin through an SSH tunnel. Run this on your PC:
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.
For permanent access, put nginx in front of pgAdmin. Create a /etc/nginx/sites-available/pgadmin file:
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:
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.
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:
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.
Set the new version for image in compose.yaml and restart the container:
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.
These steps are the same for the One-Click App and the manual installation.
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.
- Click Add New Server on the Dashboard.
- Under Name on the General tab, enter a name, for example, “PostgreSQL.”
- Enter the following on the Connection tab:
| Field | What to enter |
|---|---|
| Host name/address | Your VPS's IP address |
| Port | 5432 or the value of POSTGRES_PORT |
| Maintenance database | postgres |
| Username | The value of SERVICE_USER_POSTGRES |
| Password | The value of SERVICE_PASSWORD_POSTGRES |
- 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.
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.
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.
- 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.
- Click Add New Server and enter a name.
- On the SSH Tunnel tab: turn on Use SSH tunneling, enter the other server's IP address under Tunnel host,
22under Tunnel port, and the SSH user under Username. Under Authentication, select Identity file and then the file you uploaded. Alternatively, use Password. - On the Connection tab, enter
127.0.0.1as 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. - Click Save.
By default, pgAdmin doesn't save the SSH password, so you'll be prompted for it each time you connect.
It's best to create a separate user and database for each application:
- Expand your server in the Object Explorer, right-click Login/Group Roles, and select Create > Login/Group Role.
- 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. - 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:
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.
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.
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;.
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:
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.
- 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.
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.”
