PostgreSQL is a robust default for most applications: strong consistency, rich SQL, JSON support and a large extension ecosystem. Running it well in production is mostly about operations: access control, backups you can restore to any point in time, replication, connection management and upgrades. This guide covers those; for configuration tuning, see our MySQL and PostgreSQL tuning guide.
Install from the Official Repository
Distribution packages lag behind; the PostgreSQL Global Development Group (PGDG) repository provides every supported major version for Ubuntu and Debian:
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install -y postgresql-17
sudo -u postgres psql -c "SELECT version();"
Choose a major version that is still supported (each is supported for five years) and that your application and extensions support.
Secure Access
listen_addresses = 'localhost'when the app runs on the same server; otherwise the private IP only.password_encryption = scram-sha-256andscram-sha-256entries inpg_hba.conf, nevertrustfor network connections.- Allow port 5432 in the firewall only from application servers.
- Enable TLS (
ssl = onwith certificates) for connections over any network you do not control, and usehostssllines inpg_hba.conf. - Create one role per application with only the privileges it needs; do not use the
postgressuperuser in applications.
CREATE ROLE app LOGIN PASSWORD 'long-random-password';
CREATE DATABASE app OWNER app;
# pg_hba.conf
hostssl app app 10.0.0.11/32 scram-sha-256
Size Memory and Connections
| Setting | Starting point (dedicated 32 GB server) |
|---|---|
shared_buffers | 8GB (about 25% of RAM) |
effective_cache_size | 22GB |
work_mem | 16–32MB (per operation, per connection) |
maintenance_work_mem | 1GB |
max_connections | 100–200, with pooling in front |
random_page_cost | 1.1 on NVMe |
Backups with Point-in-Time Recovery
Nightly pg_dump is simple and portable but can lose up to a day of data. Production systems should combine periodic base backups with continuous WAL archiving, which allows restoring to any moment, for example just before an accidental DELETE. pgBackRest (or Barman, or WAL-G) automates this:
# postgresql.conf
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'
wal_level = replica
# full backup weekly, incremental daily (cron or systemd timers)
pgbackrest --stanza=main --type=full backup
pgbackrest --stanza=main --type=incr backup
Store the repository off the database server (object storage or another server), encrypt it, keep several full backups, and regularly restore to a test server to prove it works. Keep a logical pg_dump as well for portability.
Streaming Replication
A standby server receiving WAL in real time shortens recovery from a server failure from hours (restore from backup) to minutes (promote the standby):
# on the primary
CREATE ROLE replicator REPLICATION LOGIN PASSWORD '...';
# pg_hba.conf: hostssl replication replicator STANDBY_IP/32 scram-sha-256
# on the standby (empty data directory)
pg_basebackup -h PRIMARY_IP -U replicator -D /var/lib/postgresql/17/main -R -X stream -P
-R writes the standby configuration. Monitor replication lag (pg_stat_replication on the primary), and rehearse promotion with pg_ctl promote or SELECT pg_promote();. A replica is not a backup: mistakes replicate instantly, so keep PITR backups too. Tools such as Patroni automate failover for teams that need it.
Connection Pooling with PgBouncer
PostgreSQL uses a process per connection, so hundreds of idle connections waste memory. PgBouncer in transaction pooling mode lets many application connections share a small number of server connections:
# /etc/pgbouncer/pgbouncer.ini
[databases]
app = host=127.0.0.1 port=5432 dbname=app
[pgbouncer]
listen_addr = 127.0.0.1
listen_port = 6432
auth_type = scram-sha-256
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 30
Transaction pooling is incompatible with session-level features such as session advisory locks and some prepared-statement usage; check your driver's documentation.
Useful Extensions
pg_stat_statements: query statistics; essential for performance work.pgcryptoanduuid-ossp(or built-ingen_random_uuid()): cryptography and UUIDs.pg_trgm: fast fuzzy text search with trigram indexes.PostGIS: geospatial data.pgvector: vector similarity search for embeddings.
Routine Maintenance
- Keep autovacuum on and check it keeps up on large, busy tables (
pg_stat_user_tables). - Watch table and index bloat;
REINDEX CONCURRENTLYrebuilds bloated indexes without blocking writes. - Apply minor version updates promptly; they are bug and security fixes and need only a restart.
- Review slow queries weekly with
pg_stat_statements.
Major Version Upgrades
| Method | Downtime | Notes |
|---|---|---|
pg_dump / restore | Proportional to database size | Simplest; fine for small databases |
pg_upgrade --link | Minutes | Fast in-place upgrade; take a backup first |
| Logical replication to a new server | Seconds to minutes at cut-over | Most work; best for large, busy databases |
Test the upgrade on a copy first and check your extensions are available for the new version.
Monitoring
Track connections, transaction rate, cache hit ratio (pg_stat_database), replication lag, long-running transactions, locks, disk space and WAL archive failures. The Prometheus PostgreSQL exporter and a dashboard cover most of these (see our monitoring guide). Alert on failed archiving: it silently breaks your point-in-time recovery.
Schema Changes Without Downtime
Some ALTER TABLE operations rewrite or lock the whole table. On large, busy tables, prefer changes that PostgreSQL can apply quickly: adding a nullable column or a column with a constant default is fast in modern versions; build indexes with CREATE INDEX CONCURRENTLY; add constraints as NOT VALID and validate them separately. Set a short lock_timeout in migration sessions so a blocked migration fails fast instead of queuing every other query behind it.
Roles and Least Privilege
Separate roles for the application (read and write on its tables), migrations (schema changes), read-only reporting and backups. Grant on schemas rather than individual tables where possible, and set default privileges so new tables inherit the right grants.
Production Checklist
- Listening only on localhost or a private interface, SCRAM authentication, TLS for remote clients.
- WAL archiving and scheduled base backups stored off the server.
- A point-in-time restore rehearsed on a test server.
- Streaming replica with lag monitoring, if recovery time matters.
- PgBouncer in front of busy applications.
SkyRainCloud Plans for This Workload
PostgreSQL benefits most from RAM and fast storage: a dedicated database on 8 vCores / 32 GB keeps a large working set cached on NVMe-backed storage. Small apps can share 2–4 vCore servers with their database.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.