On this page
Schema Migrations & Reliability
Prev: Scaling, Partitioning & Sharding | Up: design_patterns | Next: nosql
Rel: DDL & Constraints, Transactions, ACID & Isolation Levels
Ref: PostgreSQL — Backup and Restore
Tags: #public #databases #design-patterns #migrations #reliability
Contents
- > Zero-Downtime Expand-and-Contract Migrations
- > Idempotency Keys & Transactional Outbox
- > Backups & Point-in-Time Recovery (PITR)
Zero-Downtime Expand-and-Contract Migrations
Never rename or drop a live column in one step while old app instances are still running:
- Expand: Add the new nullable column or table; deploy app code that dual-writes both old and new columns.
- Backfill: Populate historical rows in small batches to avoid lock contention and WAL spikes.
- Switch reads: Deploy app code reading from the new column, add
NOT NULL/ constraints (NOT VALID->VALIDATE CONSTRAINTin PostgreSQL). - Contract: Remove writes to the old column, then drop it in a later release.
Idempotency Keys & Transactional Outbox
- Idempotency key: Store a unique client-generated key per mutation so retried HTTP requests never double-charge or duplicate rows.
- Transactional outbox: Write domain state and an
outbox_eventsrow in the same DB transaction; a background worker relays outbox rows to queues/webhooks with at-least-once delivery.
Backups & Point-in-Time Recovery (PITR)
A backup is only real once you have tested restoring it. Combine periodic base backups with continuous WAL archiving for Point-in-Time Recovery to any second before an accidental DELETE.
Linked from
Related notes
- tuts/databases/design_patterns Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/scaling_partitioning_and_sharding Linked here; links to this page; shared tags: #databases
- tuts/databases/sql/ddl_and_constraints Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/transactions_acid_and_isolation Linked here; shared tags: #databases
- tuts/databases/nosql Linked here; shared tags: #databases
- tuts/databases/postgresql/mvcc_vacuum_and_wal links to this page; shared tags: #databases
- tuts/databases shared tags: #databases
- tuts/databases/design_patterns/indexing_and_storage_engines shared tags: #databases
- tuts/databases/design_patterns/normalization_and_data_modeling shared tags: #databases
- tuts/databases/mongodb shared tags: #databases