Last updated November 16, 2026
Is self-hosted PostgreSQL free?
Yes, completely. PostgreSQL is released under the PostgreSQL License, a liberal open-source license similar to BSD or MIT. You can use, modify and distribute it for any purpose, commercial use included, without paying and without signing anything. The only condition is keeping the copyright notice in copies you distribute.
There is no paid edition and nothing held back for an enterprise tier. The PostgreSQL Global Development Group says it has no plans to change the license. Companies sell support and managed hosting around Postgres, but the database you self-host is the full product.
Self-hosted Postgres vs Supabase, Neon and managed Postgres: what it costs
Prices checked on 2026-11-16. Hetzner prices exclude VAT; the managed plans are billed in US dollars, monthly or by usage.
| Option | Per month | Per year | Memory |
|---|---|---|---|
| Self-hosted on a Hetzner VPS (CPX12) | €9.99–11.99 | €120–144 | 2 GB |
| Self-hosted on a Hetzner VPS (CPX22) | €16.99–19.99 | €204–240 | 4 GB |
| DigitalOcean Managed PostgreSQL, smallest | $15.15 | $182 | 1 GiB |
| Supabase Pro with Micro compute | $25 | $300 | 1 GB |
| Neon Launch, "low load" estimate | about $22 | about $264 | scales |
| DigitalOcean Managed PostgreSQL, 4 GiB | $60.90 | $731 | 4 GiB |
| Supabase Pro with Medium compute | $75 | $900 | 4 GB |
For the same 4 GB of memory, a VPS costs about €200 a year against $731 for DigitalOcean's managed plan and $900 for Supabase. The VPS can also run your app next to the database. What you give up is someone else watching it: on a VPS, backups, updates and failover are your job. Supabase also bundles auth, storage and an API, and Neon bills by compute hours with scale to zero, so a quiet side project can cost less there.
With SSH Workbench, add $199 once or $9 a month. That one license covers every database and app on all your servers.
PostgreSQL VPS requirements
- A Linux VPS. The PostgreSQL docs do not set a minimum server size. A small app database runs comfortably on 1 to 2 GB of RAM. Give it more if your working data set is large, since Postgres is fastest when the hot data fits in memory.
- Disk space for the data, plus room for at least a few backup files.
- A domain or subdomain, only if apps outside the server connect, for example
db.example.com. It is used for the TLS certificate. - Docker or Podman on the server.
Self-host PostgreSQL in one click with SSH Workbench
- Connect your server in SSH Workbench, open Apps, then Deploy app, and pick PostgreSQL.
- Under Who needs to connect to this database?, choose Just apps on this server (recommended). The port is bound to 127.0.0.1, and you reach it from your laptop over an SSH tunnel.
- Or choose External services (Vercel, AWS, my other servers) and enter a domain whose A record points at the server. You get an encrypted connection string that ends in
sslmode=require, with a Let's Encrypt certificate that is renewed and reloaded without dropping connections. If the domain is on Cloudflare, set the record to DNS only, since the proxy does not carry database traffic. - Set Backups to Daily or Hourly. Scheduled backups are kept for 7 days.
- Leave Performance on Tuned for a production database. It sizes memory settings such as
shared_buffersandwork_memto the server's RAM. Pick Conservative when several databases share the server. - Under Advanced, choose the version (18, 17, 16 or 15), set Max connections if you do not use a connection pool, and an optional CPU limit.
The username and database both default to postgres. A 24-character password is generated for you and shown once after the deploy, together with the SSH tunnel command or the connection string, so save it then.
Self-host PostgreSQL with docker compose
To set it up by hand, this compose file runs Postgres 18 with the port closed to the internet and the data in a named volume. Replace the password before the first start.
services:
db:
image: postgres:18
restart: unless-stopped
shm_size: 128mb
ports:
- "127.0.0.1:5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: change-me-to-a-long-random-password
POSTGRES_DB: app
volumes:
- pgdata:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d app"]
interval: 10s
timeout: 5s
retries: 5
volumes:
pgdata:Start it with docker compose up -d. From version 18 the official image stores data under /var/lib/postgresql/18/docker, so the volume mounts at /var/lib/postgresql. For Postgres 17 and older, mount it at /var/lib/postgresql/data instead.
The POSTGRES_* variables only take effect on the first start, when the data folder is empty. Changing them later does nothing to an existing database.
Connecting to self-hosted Postgres
Apps on the same server connect to 127.0.0.1:5432:
postgresql://postgres:[email protected]:5432/appServices in the same compose file use the service name as the host, db in the example above.
From your laptop, open an SSH tunnel and connect to the local end, with psql or a GUI client:
ssh -N -L 15432:127.0.0.1:5432 root@your-server-ip
psql "postgresql://postgres:YOUR_PASSWORD@localhost:15432/app"Port 15432 avoids a clash with a Postgres running on your own machine. Keep the database port closed in your firewall unless you deliberately expose it with TLS, as the External services option does.
Self-hosted Postgres backup
Back up with a logical dump, not by copying the data folder while Postgres runs. pg_dumpall captures every database plus the roles:
docker compose exec -T db pg_dumpall -U postgres | gzip > backup-$(date +%F).sql.gzTo restore into a fresh, empty instance:
gunzip -c backup-2026-11-16.sql.gz | docker compose exec -T db psql -U postgres -d postgresCopy the files off the server too. A backup on the same disk does not help if the VPS is lost.
SSH Workbench's backups run pg_dumpall the same way and gzip the result. They leave out role passwords, so after a restore you set those again. A restore is refused if the target already holds user databases, because a dump restored on top would mix old and new data.
Updating PostgreSQL
Minor releases (18.1 to 18.2) need no dump. Pull the image and recreate the container:
docker compose pull
docker compose up -dPostgreSQL ships minor releases at least every three months and recommends always running the latest one for your major version. Each major version is supported for 5 years; 14 reaches end of life in November 2026.
Major versions (17 to 18) change the data format, so a new image cannot read the old folder. Either dump and restore, or use pg_upgrade. With Docker, the dump route is simplest: run pg_dumpall on the old version, stop it, start the new version on a new volume, and restore the dump. Keep the old volume until the new one checks out.
Postgres for n8n and other self-hosted apps
Many self-hosted apps want Postgres underneath: n8n recommends it over SQLite for production, and Sentry and GitLab use it too. One Postgres server can hold a database for each app. Create a separate user and database per app so one app's credentials cannot read another's data:
CREATE USER n8n WITH PASSWORD 'another-long-password';
CREATE DATABASE n8n OWNER n8n;Then point the app at 127.0.0.1:5432 with those credentials, or at the service name if both run in one compose file.
Troubleshooting
password authentication failed for user "postgres". You changed POSTGRES_PASSWORD after the first start, and the image ignores it once the data exists. Use the original password, or change it inside the database with ALTER USER postgres WITH PASSWORD '...'.
connection refused from another container. Inside a container, 127.0.0.1 means that container, not the server. Use the compose service name as the host, or put both containers on a shared Docker network.
role "root" does not exist. psql defaults to your system username. Pass the user explicitly: psql -U postgres.
Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster". You started the 18 image on a volume mounted at the old /var/lib/postgresql/data path, or on data from an older major. Mount the volume at /var/lib/postgresql, and move old data across with a dump and restore. If the container keeps restarting for another reason, see Docker container keeps restarting.
Self-hosting PostgreSQL: questions
What is the best way to self host Postgres?
For one app or a handful, run the official postgres Docker image on a VPS with the port bound to 127.0.0.1, a named volume and a nightly dump copied off the server. Installing from your distribution's packages works just as well if you prefer systemd to containers. Kubernetes operators such as CloudNativePG only pay off once you already run Kubernetes.
Should I use Supabase, Neon or self-hosted Postgres?
Pick Supabase if you want auth, file storage and an instant API on top of the database, and Neon if you need branching or a database that scales to zero between requests. Self-host when you want plain Postgres with fixed costs and full superuser access, and you are fine owning backups and updates. Moving later is a pg_dump and restore in either direction.
Which GUI can I use to manage self-hosted Postgres?
pgAdmin, DBeaver and TablePlus all connect to a self-hosted server. Open an SSH tunnel first, then point the client at localhost and the tunnel port; DBeaver and TablePlus can also open the tunnel for you from their connection settings. Running pgAdmin as a container on the server works too, but keep its port on 127.0.0.1 like the database.
How do I make docker compose wait for Postgres to be ready?
Give the Postgres service a healthcheck that runs pg_isready, as in the compose file above, and add depends_on with condition: service_healthy to the app service. A plain depends_on only waits for the container to start, and Postgres needs a few seconds more before it accepts connections, especially on first boot while it creates the database.
How do I run a self-hosted Postgres cluster?
Postgres has built-in streaming replication: a primary ships its write-ahead log to one or more standbys that can take over if it fails. Failover is not automatic on its own, so most teams add Patroni or, on Kubernetes, CloudNativePG to promote a standby. For a single app, one server with tested backups is usually enough, and much simpler to run.
Related guides
PostgreSQL is a trademark of the PostgreSQL Community Association of Canada. SSH Workbench is not affiliated with or endorsed by the PostgreSQL Community Association of Canada.
