Restored Cloud SQL instance shows read‑inconsistency after backup
0 reputation · 17 Mar 2024, 13:54 UTC
0 reputation · 17 Mar 2024, 13:54 UTC
Goal: confirm that a Cloud SQL instance restored from a backup returns data that matches the backup point immediately after the restore operation, without relying on manual waiting.
Constraint: the Backup and DR service reports success based on API completion and does not surface replica lag as an error; the window of possible read‑inconsistency varies with instance size, region, and ongoing workload, and no built‑in flag indicates when the instance has caught up to the backup snapshot.
Questions: What is the maximum observable lag window after a Cloud SQL backup restore? Is there a metric or flag that signals when the instance has reached consistency with the backup point? Can a post‑restore readiness check be configured to block reads until consistency is guaranteed?
32275 reputation · 17 Mar 2024, 20:58 UTC
After a Cloud SQL backup restore, the instance is reported as RUNNING as soon as the restore API finishes, but internal crash‑recovery or redo‑log application may still be running. This creates a window where reads can return data that is older than the backup point. The length of this window is not fixed; it depends on instance size, storage throughput, and the write load at the time of the backup, typically ranging from a few seconds up to several minutes.
pg_last_xact_replay_timestamp() returns NULL when recovery is complete.SHOW ENGINE INNODB STATUS shows no active recovery threads and the LSN has advanced past the backup LSN when recovery finishes.cloudsql.googleapis.com/database/replication_lag on a read replica drop to zero once the replica has applied all changes from the primary, providing an external signal that roughly matches internal consistency.RUNNING state via the Cloud SQL API or Console.SELECT pg_last_xact_replay_timestamp(); repeat until the result is NULL.SHOW ENGINE INNODB STATUS; verify that there are no active recovery threads and that the LSN shown is greater than the LSN recorded at backup time.SELECT MAX(updated_at) FROM heartbeat WHERE source='backup') and compare the result to the backup timestamp; resume reads only when the returned timestamp is ≥ the backup timestamp.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.