Kapten
All guides

Data

Postgres in production: the checklist

Where to run it, how to back it up, how to prove the backup works, how to connect to it, and what to watch once real users depend on it.

Cover illustration for Postgres in production: the checklist, intermediate levelDataIntermediate · ff55
On this page11 sections
  1. 01The one thing you cannot redeploy
  2. 02Managed or in-cluster?
  3. 03Backups
  4. 04The restore test
  5. 05Connections and pooling
  6. 06Migrations
  7. 07Sizing
  8. 08Private networking
  9. 09Users and permissions
  10. 10What to monitor
  11. 11Before launch

The one thing you cannot redeploy

Every other part of your application can be rebuilt from the repository. The database cannot. That single fact should shape every decision in this guide: when in doubt, choose the option that makes data loss less likely and recovery more boring.

Managed or in-cluster?

You can run Postgres yourself on Kubernetes, or use your provider’s managed service (Amazon RDS or Aurora, Cloud SQL, Azure Database for PostgreSQL).

Choose managed for almost every production workload at a small or medium company. You get automated backups, point-in-time recovery, minor version patching, failover options and storage that grows: all things you would otherwise have to build and operate.

Consider in-cluster for development, previews and test environments, where cost and speed matter more than durability, or when you have specific requirements and the people to operate them.

Managed or in-cluster?
Managed and in-cluster Postgres at a glance. Qualitative assessment, not measurements.
DimensionManaged serviceIn-clusterEdge
Backups and point-in-time recovery built inHighLowManaged service
Patching and failover handled for youHighLowManaged service
Operational load on your team (lower is better)LowHighManaged service
Cost of a short-lived environment (lower is better)MediumLowIn-cluster
Speed to create and throw awayMediumHighIn-cluster
Figure 1. The trade-off above, as levels. Managed wins everything that protects the data; in-cluster wins cost and speed for environments you can throw away.Illustrative · qualitative, not measurements

Kapten offers both when you add a database: Managed provisions your cloud provider’s database service, In cluster runs it on the environment’s cluster. Pick managed for production; in-cluster is a reasonable choice for development and preview environments.

Backups

Turn on automated backups on day one and decide:

  • Retention. How far back can you restore? A week is a floor for most products; longer if you have compliance or contractual requirements.
  • Point-in-time recovery (PITR). Restore to any moment within the retention window, not just to last night. This is what saves you from the bad DELETE at 14:32.
  • Copies outside the primary region or account, if losing the region or the account is a risk you need to cover.

The restore test

A backup you have never restored is a hope, not a backup. Schedule a restore test:

  1. Restore the latest backup, or a point in time, into a separate instance.
  2. Run a few queries your application depends on.
  3. Record how long it took, end to end.
  4. Delete the test instance.
  1. Restore
    Latest backup or a point in time, into a new instance.
  2. Query
    Reads the application depends on.
    Gate: Results match
  3. Record
    End-to-end time, written down.
  4. Delete
    Remove the test instance.
Figure 2. A restore test is four steps. The clock runs from the first to the third: that is your real recovery time.

Do it before launch and then regularly. The time it takes is your real recovery time, and it is usually longer than people expect.

Connections and pooling

Postgres handles each connection with a dedicated process, and the number it can hold is finite. Applications that scale horizontally (more replicas, serverless functions, background workers) can exhaust it quickly.

  • Size each service’s pool deliberately. Total connections across all replicas must stay below the database’s limit, with room left for migrations and administration.
  • Use a connection pooler (PgBouncer or your provider’s proxy) when you have many replicas or short-lived processes.
  • Set statement and idle timeouts so a stuck client cannot hold connections forever.
PointConnections in use (conns)Event
06:0042
07:0045
08:0048
09:0052
10:0050
11:0088Deploy: workers ×3
12:0096Alert: near limit
13:0094
14:0061Event: pooler on
15:0040
16:0038
17:0041
Threshold: Limit minus headroom at 90 conns.
Figure 3. Connections in use over a sample day. Scaling the workers out nearly exhausts the database; a pooler brings usage back down.Illustrative · sample data

Migrations

  • Run migrations as an explicit step before a release, not when the app starts.
  • Keep each migration compatible with the version of the code currently running, so rollbacks stay possible. The rollbacks guide covers the expand/contract pattern.
  • Run migrations as their own step. In Kapten, a pipeline can run a migration job before the API deploys.
  • Be careful with operations that lock large tables: adding an index without CONCURRENTLY, adding a column with a volatile default, changing a column type. Test them on a copy with realistic data.
  • Rehearse risky migrations on a restored copy of production. See rollbacks and migrations for how.

Sizing

Start smaller than you think, and watch:

  • CPU sustained high usually means a missing index or an expensive query, not a need for a bigger instance.
  • Memory determines how much of your working set stays cached. Falling cache hit rates are an early warning.
  • Storage grows with data, indexes, and write-ahead logs. Enable automatic storage growth and alert well before the limit.
  • IOPS limits on some storage classes can cap performance long before CPU does.

Resize based on evidence. In Kapten, a database’s CPU, memory and disk are settings of the component, so a resize is a reviewed change like any other.

Private networking

Your database should not have a public address.

  • Put it in private subnets, reachable only from the application’s network.
  • Restrict access with security groups or firewall rules to the services that need it.
  • Require TLS for connections.
  • For administration, use a bastion, a VPN or your provider’s session manager rather than opening the database to the internet “for a moment”.
Web and worker services connect to a connection pooler, which connects to a managed Postgres primary in private subnets. Administrators reach the database only through a session manager. Backups are copied to separate storage.Application networkPoolingPrivate subnetsBackupsWebWorkerSession manageradmin accessPoolerPgBouncer or proxyPostgresmanaged, TLS onlySnapshots + WALPITR windowapp usertlsautomated
  • Web connects to Pooler (app user).
  • Worker connects to Pooler.
  • Pooler connects to Postgres (tls).
  • Postgres connects to Snapshots + WAL (automated).
Figure 4. No public address: the application reaches Postgres through a pooler inside private subnets; people come in through a session manager.

In Kapten, a database is Private by default, reachable only from inside the cluster. Choose Public only if something outside the cluster must connect to it.

Users and permissions

  • The application connects with a dedicated user that can read and write its tables, and nothing else.
  • Migrations run with a separate, more privileged user.
  • People get read-only access by default; write access to production data is the exception, and is logged.
  • Never use the master user in application configuration.

What to monitor

Start with a small set of signals:

  • Connections in use versus the limit.
  • CPU, memory, free storage, and IOPS.
  • Replication lag, if you have replicas.
  • Slow queries: enable the slow query log or pg_stat_statements.
  • Backup success and the age of the latest restorable point.

Alert on free storage, connection saturation and failed backups first. Those are the three that turn into outages. The observability starter kit covers the application side.

Before launch

  • Managed instance in private subnets, TLS required.
  • Automated backups and PITR enabled, retention agreed with the data owner.
  • One successful restore test, with the time recorded.
  • Application user with least privilege; separate migration user.
  • Connection pool sized; pooler in place if needed.
  • Alerts on storage, connections and backups.
  • A written plan for restoring after a bad migration or deletion.

In Kapten, backups, disk encryption and high availability are options you turn on when you create the database, and its credentials are added to the environment as secrets such as KAPTEN_DATABASE_MAIN_CONNECTION_STRING. The restore test, the pooler and the alerts stay on your list. See the production-readiness guide to check an existing environment against it, and Add a database in the docs for the steps.

Build with Kapten

Start with one service.
Build from there.

Tell us what you want to deploy. We review each request and follow up about fit and onboarding on your preferred cloud.

Free during early access. No card required. Cloud usage billed separately.