Interview Prep/Real-World Interview/Data loss and corruption

An engineer ran `DELETE FROM orders;` on the production Postgres (forgot the `WHERE`) at 14:32.

BeginnerTroubleshootingData loss and corruption
Answer

Likely causes → A manual write against production with no guardrails: direct psql access, autocommit on, no peer review.

Diagnose → Pin the exact time of the statement from the DB logs (log_statement = 'mod') or CloudTrail/pgaudit, and work out which tables were touched and what writes happened after it.

Fix → Don't restore over the live database. Restore a copy to just before the mistake and copy the missing rows back:

flowchart LR
    A["Find exact time of DELETE"] --> B["PITR restore to new instance at 14:31:59"]
    B --> C["Export deleted rows"]
    C --> D["Insert into prod, skip conflicts"]
    D --> E["Reconcile counts and totals"]
aws rds restore-db-instance-to-point-in-time --source-db-instance-identifier prod \
  --target-db-instance-identifier prod-pitr-1431 --restore-time 2026-11-09T14:31:59Z
pg_dump -h prod-pitr-1431... -t orders --data-only -Fc -f orders.dump

Prevent → No routine human write access to production. Use reviewed migration or runbook scripts, BEGIN; before any manual change, and test PITR restores regularly.

All Real-World Interview questions Roadmap: Interview readiness

More on Data loss and corruption