How to Deploy pgAdmin on a VPS
Updated Nov 2026
verified on Ubuntu 26.04 · Nov 2026Self-host pgAdmin 4 on a VPS with Docker Compose and Caddy HTTPS: set a strong first login, back up and restore its settings volume, and upgrade a pinned image.
- A VPS with 1 GB+ RAM
- A fresh Ubuntu 26.04 server with root/sudo SSH access
- A domain or subdomain you can point at the server
What pgAdmin is
pgAdmin is the long-standing open-source administration tool for PostgreSQL, run here as a web app: browse objects, run queries, read explain plans, and manage roles. It is released under the PostgreSQL License.
pgAdmin is a door into your databases. Give it a strong password, serve it only over HTTPS, and never open PostgreSQL's port to the internet just so pgAdmin can reach it.
Server sizing
On the catalog's test box an idle pgAdmin container used about 227 MB of RAM and 761 MB of disk. Large query results and many open tabs need more.
Prepare the server
Update the system, install the tools this guide uses, and open only SSH and the two web ports:
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install -y curl openssl ufw dnsutils jq
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
If you're logged in as root, create a non-root sudo user and continue as that user:
adduser deploy
usermod -aG sudo deploy
A published container port goes around ufw on a Docker host, so only what
should be public gets published below.
Paid link — we earn a commission if you shop through it.
Install Docker
The convenience script installs Docker Engine and the Compose plugin (the Docker and Compose on Ubuntu guide covers the details):
command -v docker >/dev/null || curl -fsSL https://get.docker.com | sudo sh
sudo docker compose version
Install pgAdmin
The file below pins pgAdmin 9.19, which fixes a series of security flaws in earlier releases, so do not pin anything older.
Set your hostname and your own email address (pgAdmin uses it as the login). The
password is generated once and kept in .env:
mkdir -p ~/pgadmin && cd ~/pgadmin
if [ ! -f .env ]; then
( umask 077
printf 'DOMAIN=pgadmin.example.com\nPGADMIN_EMAIL=you@example.com\nPGADMIN_PASSWORD=%s\n' "$(openssl rand -hex 16)" > .env )
fi
cat > compose.yaml <<'EOF'
services:
pgadmin:
image: dpage/pgadmin4:9.19
restart: unless-stopped
ports: ["127.0.0.1:5050:80"]
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
PGADMIN_DISABLE_POSTFIX: "1"
volumes: ["pgadmin_data:/var/lib/pgadmin"]
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
environment:
DOMAIN: ${DOMAIN}
volumes: ["./Caddyfile:/etc/caddy/Caddyfile:ro", "caddy_data:/data"]
volumes:
pgadmin_data:
name: pgadmin_data
caddy_data:
EOF
cat > Caddyfile <<'EOF'
{$DOMAIN} {
reverse_proxy pgadmin:80 {
header_up X-Scheme {scheme}
}
}
EOF
sudo docker compose up -d
PGADMIN_DISABLE_POSTFIX skips the bundled mail server. Password reset emails
need your own SMTP settings instead.
HTTPS + domain
Create an A record for your hostname pointing at the server's public IP and confirm it resolves, because Caddy needs that to get a certificate (see Automatic HTTPS with Caddy):
dig +short pgadmin.example.com
. ~/pgadmin/.env
curl -s -o /dev/null -f --retry 40 --retry-delay 5 --retry-all-errors \
-w '%{http_code} verify=%{ssl_verify_result}\n' "https://$DOMAIN/misc/ping"
Secure first login
The account is created from the two environment variables on the first start
only; changing .env later does not change the password. Confirm it exists:
cd ~/pgadmin
sudo docker compose exec -T pgadmin /venv/bin/python3 /pgadmin4/setup.py get-users
Print the password with grep PGADMIN_PASSWORD ~/pgadmin/.env, sign in at
https://pgadmin.example.com, then:
- Turn on multi-factor authentication from the user menu.
- Change the password and keep it in a password manager.
- Register your servers. For a PostgreSQL container, put it on the same Docker network and use its service name as the host; do not publish port 5432. For a database on another machine, use the SSH tunnel tab of the server dialog.
Backups
This backs up pgAdmin itself (users, server list, preferences, saved files),
not your PostgreSQL databases; back those up with pg_dump. All of it is in the
pgadmin_data volume. Stop the container so the settings database is quiet:
cd ~/pgadmin
sudo docker compose stop pgadmin
( umask 077
sudo docker run --rm -v pgadmin_data:/d:ro alpine:3 tar czf - -C /d . > ~/pgadmin-data.tar.gz
tar czf ~/pgadmin-config.tar.gz compose.yaml Caddyfile .env )
sudo docker compose start pgadmin
tar tzf ~/pgadmin-data.tar.gz | grep pgadmin4.db
The archive can contain saved database passwords (encrypted), so protect it and copy it off the server.
To restore, empty the volume and unpack the archive. This replaces pgAdmin's
current settings. The files keep their owner, UID 5050, which the container
needs. On a new server, run sudo docker compose up --no-start first.
cd ~/pgadmin
tar tzf ~/pgadmin-data.tar.gz >/dev/null &&
sudo docker compose stop pgadmin &&
sudo docker run --rm -v pgadmin_data:/d alpine:3 find /d -mindepth 1 -delete &&
sudo docker run --rm -i -v pgadmin_data:/d alpine:3 tar xzf - -C /d < ~/pgadmin-data.tar.gz &&
sudo docker compose start pgadmin &&
. ./.env &&
curl -s -f --retry 40 --retry-delay 3 --retry-all-errors "https://$DOMAIN/misc/ping" && echo &&
sudo docker compose exec -T pgadmin /venv/bin/python3 /pgadmin4/setup.py get-users
Upgrades
Back up first: a new pgAdmin migrates its settings database on start. Read the
release notes,
change the tag in compose.yaml (this guide pins 9.19), then:
cd ~/pgadmin && . ./.env
sudo docker compose pull pgadmin &&
sudo docker compose up -d &&
curl -s -f --retry 40 --retry-delay 5 --retry-all-errors "https://$DOMAIN/misc/ping" && echo &&
sudo docker compose exec -T pgadmin /venv/bin/python3 /pgadmin4/setup.py get-users
To go back, restore the volume archive taken before the upgrade along with the old tag; do not just downgrade the image.
Troubleshooting
Container restarts with a permission error. The volume must be writable by
UID 5050; for a bind mount, sudo chown -R 5050:0 the directory.
The email address is rejected on first start. Use a normal domain; read
sudo docker compose logs pgadmin.
Cannot connect to a database. Inside the container, localhost is pgAdmin
itself. Use the database's service name or address.
Verification + next steps
This guide's run checked the HTTPS login and a restore that brought back a deleted server entry. A version change and connecting to a real database were not tested.
You're done when you sign in over HTTPS, a registered server opens, and you have restored the volume once. See the pgAdmin entry for catalog details and Best VPS for self-hosting for server picks.
Next steps
Common questions
How long does it take to follow "How to Deploy pgAdmin on a VPS"?
We estimate about 20 minutes of hands-on time for "How to Deploy pgAdmin on a VPS"; this is an editorial estimate, not a measurement.
Was the "How to Deploy pgAdmin on a VPS" guide tested?
The "How to Deploy pgAdmin on a VPS" guide was verified end-to-end on Ubuntu 26.04 (Nov 2026).