Deployment guide

PostgreSQL on a VPS: a reliable and controlled database

Deploy on a VPS Cloud →

Databases8 min read

PostgreSQL on a VPS: a reliable and controlled database

PostgreSQL is often the trusted database of business applications, APIs and analytics tools. On a ServOrbit VPS, you control the version, the storage, the backups and the access instead of paying for a managed database by the GB. The guide focuses on the decisions that matter: persistence, users, network and restoration.

Why self-host PostgreSQL on a VPS

Managed databases (RDS, Cloud SQL) bill per GB stored, per IOPS and per connection, and often limit the available extensions. By deploying PostgreSQL on your own VPS, you enable pg_stat_statements, PostGIS, pgvector or TimescaleDB without restriction, you choose your exact version (15, 16, 17) and you keep your data in a jurisdiction you control. A VPS with an NVMe SSD disk and a dedicated CPU offers very low I/O latencies, ideal for the transactional workloads of a production application. You pay a fixed and predictable flat rate, and you alone decide on your strategy for replication, encryption and backup retention.

The concrete benefits of a self-hosted PostgreSQL

  • Fixed and predictable cost: no billing per GB, per IOPS or per number of active connections.
  • Free extensions: pgvector for AI, PostGIS for geospatial, TimescaleDB for time series.
  • Full control of backups: scheduled pg_dump, pg_basebackup or physical replication to a second VPS.
  • Fine tuning of postgresql.conf (shared_buffers, work_mem, WAL) impossible with most managed offerings.
  • Data sovereignty: your data stays on an infrastructure you choose.
  • Real superuser access to audit, profile and optimize without a support ticket.

Hardware and software prerequisites

For a development PostgreSQL instance or a small production project, plan for a VPS with 2 vCPU, 4 GB of RAM and 40 GB of NVMe SSD: PostgreSQL likes memory for its page cache. For a heavier load (several hundred connections or datasets of several tens of GB), aim for 4 vCPU and 8 GB of RAM. On the software side: Ubuntu 22.04 or 24.04 LTS, Docker Engine and the Docker Compose v2 plugin, a domain name pointing to the VPS (e.g. db.mydomain.com) if you expose remote access, and a ufw firewall configured to let through only the strict minimum. Also reserve a dedicated Docker volume for PGDATA to decouple the data from the container.

Deploy PostgreSQL with Docker in production

01

Prepare the VPS and the firewall

Connect via SSH, update the system with apt update && apt upgrade -y, install Docker via curl -fsSL https://get.docker.com | sh. Block port 5432 from the outside with ufw deny 5432: the database must never be directly exposed to the Internet.

02

Write the docker-compose.yml

Create a postgres:17 service, mount a named volume on /var/lib/postgresql/data, and define POSTGRES_PASSWORD, POSTGRES_DB and POSTGRES_USER via a .env file that is never committed. Add shm_size: 256mb for large sorts and a healthcheck with pg_isready.

03

Launch and initialize the database

Start with docker compose up -d, check the logs via docker compose logs -f postgres, then connect with docker compose exec postgres psql -U app -d mabase. Create your application roles with minimal privileges rather than using the superuser.

04

Expose access via a tunnel or a TLS proxy

For secure remote access, never open 5432 in the clear: use an SSH tunnel (ssh -L 5432:localhost:5432) or place pgbouncer behind a reverse proxy. Enable SSL on the PostgreSQL side with a Let's Encrypt certificate mounted in the container (ssl = on in postgresql.conf).

05

Tune the configuration

Adjust shared_buffers to about 25% of the RAM, effective_cache_size to 50-75%, and work_mem according to your queries. Enable pg_stat_statements to identify slow queries. Use the PGTune tool as a starting point.

06

Automate the backups

Schedule a daily pg_dump via a cron task on the host, compress into custom .dump format, and copy the archives to external storage. Regularly test restoration with pg_restore: an untested backup does not exist.

For high availability, deploy a second VPS in physical streaming replication (primary_conninfo + replication slot). You get a warm standby ready to fail over, and you can offload your heavy read queries to it (hot_standby = on) to relieve the primary. Combined with pgBackRest for differential incremental backups, you reach an RPO of a few minutes without depending on a managed service.

The official documentation

For advanced configuration, tool-specific options and version changes, refer to the official PostgreSQL documentation. This guide covers going live on a ServOrbit VPS; the vendor documentation remains the reference for fine tuning.

Deploy your PostgreSQL in minutes

Launch a ServOrbit Cloud VPS with a preconfigured Docker template, NVMe SSD and dedicated CPU: the ideal environment to host PostgreSQL without per-GB billing.

Need help?

Browse our help center and FAQ, or write to our team — support in French, English and Arabic.