Sikau

PostgreSQL · Day 15 · about 20 min

Running PostgreSQL

Backups, migrations, pooling, replicas and managed hosting.

Keeping data safe for years

A database is only as good as its last backup. Production PostgreSQL also needs schema changes without downtime, connection limits handled, and a plan for when a server dies.

The essentials

  • Backups: pg_dump for logical backups (restore with pg_restore); continuous WAL archiving for point-in-time recovery. Test restores regularly.
  • Migrations: schema changes live in versioned files (Prisma Migrate, Drizzle, Flyway). Add columns as nullable first, backfill, then add constraints — avoid long table locks.
  • Connection pooling: each connection costs memory; serverless apps need a pooler like PgBouncer.
  • Replication: streaming replicas for high availability and read scaling.
  • Monitoring: slow query logs, pg_stat_statements, disk and connection alerts.
  • Managed services (Neon, Supabase, RDS, Cloud SQL) handle much of this for you.
pg_dump --format=custom --file=cafe.dump "$DATABASE_URL"
pg_restore --clean --dbname="$STAGING_URL" cafe.dump

The rest of this lesson

  • A zero-downtime column changeexplain
  • Backups you can trustexplain
  • Safe migration order?predict
  • Expand and contractorder
  • Operations vocabularymatch
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 16 lessons of PostgreSQL