Investigation & Containment

Investigation

Four questions, in this order: are the backups really there, is every change being archived, can a restore cluster reach what it needs, and what proves a restore. Every command names the cluster with --context (Chapter 01).

  1. Which backups exist? The base backups CloudNativePG took, newest last:

    kubectl --context kind-sre-control-plane -n develop get backups
    

    One completed line per night (app-postgres-daily-...). A base backup is a full copy of the database files - the starting point of every restore.

  2. Is every change archived? The cluster’s own conditions, then the database’s archiver statistics:

    kubectl --context kind-sre-control-plane -n develop get cluster app-postgres \
      -o jsonpath='{range .status.conditions[*]}{.type}={.status}{"\n"}{end}'
    kubectl --context kind-sre-control-plane -n develop exec app-postgres-1 -c postgres -- \
      psql -tAc "SELECT archived_count, failed_count, last_archived_wal FROM pg_stat_archiver"
    

    ContinuousArchiving=True, and failed_count 0 - the archiver is healthy. That is not yet proof that the archive reaches the moment you need: the newest changes sit in the current WAL segment until it fills up or archive_timeout (5 minutes) closes it. The WAL archive is what turns “last night” into “one minute before the damage”: the base backup is replayed forward with every archived change, and the replay can stop at any moment.

  3. Can a restore cluster get out? The namespace is default-deny (Chapter 06). The policies that let Postgres reach the backup store, the API server and the operator select pods by their cluster’s name:

    kubectl --context kind-sre-control-plane -n develop get networkpolicy allow-postgres-egress-apiserver \
      -o jsonpath='{.spec.podSelector}{"\n"}'
    

    On the platform since this chapter: app-postgres and app-postgres-restore. In the story, only app-postgres - a restore under any other name had no path out, and the dropped connections looked like a slow, broken restore.

  4. What proves a restore? Not Ready - it says Postgres started. Not pg_isready - it says the port answers. Only the data: the rows you expect, read and written with the application’s own user and password.

The root cause is not the backups. It is a restore path that was never walked: a network rule that blocked it, a missing target time that replayed the damage, and no proof defined in advance.

Containment

  1. Stop the damage - stop the agent or the job that is still writing (in the story: the AI agent’s session).
  2. Do not touch production’s database - it is the evidence, and the source of the WAL to replay.
  3. Restore next to it - a new cluster, app-postgres-restore, to the moment before the damage.
  4. Prove it with data - the expected rows, with the application’s user.
  5. Then decide how to come back. Users kept writing after the damage, and those writes are not in the restore. Either freeze the application’s writes, reconcile what was written after the target with the restore, and switch to it - or, when that cannot be reconciled, copy only the lost rows back into the original.
  6. Practise it - a restore drill on a schedule, with the time it takes written down.

A backup is only as good as the last restore you proved. Restore next to production, to the moment before the damage, and prove it with data.


Pause and Predict: You restore to 14:19. How do you choose that moment - and what happens if you choose a moment the archive does not reach?