Learning center

Build a timeline of what happened to the Cloud SQL instance during an incident

Merge four records into one UTC timeline: Cloud SQL operations, Cloud SQL audit logs, the PostgreSQL log, and Cloud Run's audit, system and request logs. The timeline shows what the provider and the control plane recorded; changes made inside the database usually leave no trace in it.

Why one list is not enough#

The hub points to gcloud sql operations list for the window, and for a single maintenance event or failover that is enough (where the checks mislead). In a longer incident, several things happen to the instance and the service, and each record holds a different part:

RecordHoldsMisses
Operations listEach Admin API operation: type, insertTime, startTime, endTime, status, user, errorActions taken through a database client such as psql
Admin Activity audit logSettings changes, restarts, failovers, CA rotations, with the principalData-level calls, and anything Google Cloud does on its own
System Event audit logWhat Cloud SQL did on its own: automatic failovers, automated backups, automatic storage increasesAnything a person started
Data Access audit logUser and login calls, such as cloudsql.users.update and cloudsql.instances.loginEverything, unless enabled: Data Access logs are off by default
PostgreSQL logShutdowns, startups, errors, and statements if statement logging is onThe control plane's view

Operation resource · Cloud SQL audit logging · Data Access logs off by default · Instance operations log

Step 1: the instance's operations#

gcloud sql operations list --instance INSTANCE --project PROJECT --limit=50 \
  --format='table(operationType, status, insertTime, startTime, endTime, user)'

The three times differ in meaning: insertTime is when the operation was queued, startTime when it began and endTime when it finished, all in UTC. An operation can start later than it was queued, so put startTime on the timeline. The console's operations pane shows completion time in your local time zone; convert it before merging. Operation fields · Instance operations log

Most incident-relevant types are MAINTENANCE, FAILOVER, AUTO_RESTART, RESTART, UPDATE and UPDATE_USER. UPDATE covers any settings change, including stopping the instance, flag changes and SSL settings. The type does not say which setting changed.

Step 2: both services' audit logs in one stream#

One query reads Cloud SQL's and Cloud Run's Admin Activity and System Event entries in time order. Long-running Cloud SQL methods usually write two entries, one when the operation starts and one when it ends. Audit log names · Long-running operations · Cloud Run audit logging

gcloud logging read '
  logName=("projects/PROJECT/logs/cloudaudit.googleapis.com%2Factivity"
        OR "projects/PROJECT/logs/cloudaudit.googleapis.com%2Fsystem_event")
  AND protoPayload.serviceName=("cloudsql.googleapis.com" OR "run.googleapis.com")
  AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
  --project PROJECT --order=asc \
  --format='table(timestamp, protoPayload.serviceName, protoPayload.methodName, protoPayload.authenticationInfo.principalEmail, protoPayload.resourceName)'

Admin Activity and System Event logs land in the _Required bucket, which keeps them for 400 days. Both are always written. Logging retention · High availability

Step 3: the database's own log#

The PostgreSQL log places a restart to the second, which the operation's span cannot do:

gcloud logging read '
  resource.type="cloudsql_database"
  AND logName="projects/PROJECT/logs/cloudsql.googleapis.com%2Fpostgres.log"
  AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
  --project PROJECT --order=asc --format='value(timestamp, severity, textPayload)'

View Cloud SQL logs

Statements appear only if the instance logs them. The log_statement flag set to ddl records DDL, including role changes, and mod adds data-modifying statements; its default is none. log_statement

Step 4: the Cloud Run side#

Add three events for each revision: when the service update that created it or moved traffic was made (Step 2's ReplaceService or UpdateService entries), when its instances started (the system log, varlog/system, records each start as Starting new instance with a reason), and when it served its first request. The : operator matches part of the log name, and a bare string searches every field. Cloud Run logs · Logging query language · When did the rollout start serving?

gcloud run revisions list --service SERVICE --project PROJECT --region REGION \
  --format='table(metadata.name, metadata.creationTimestamp)'

gcloud logging read '
  resource.type="cloud_run_revision"
  AND resource.labels.service_name="SERVICE"
  AND logName:"varlog"
  AND "Starting new instance"
  AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
  --project PROJECT --order=asc \
  --format='value(timestamp, resource.labels.revision_name, textPayload)'

Instance starts matter because a new instance opens new connections. Many database-side changes, such as a password, an SSL mode or a CA, affect only new connections, so they first show up at the next instance start, whatever caused it.

A worked fixture: one timeline, one gap#

The fixture is illustrative. orders-api connects to orders-db through the built-in connection. Errors begin at 14:03 UTC.

Incident A. The merged timeline:

Time (UTC)SourceEvent
14:02:30Admin Activity, Cloud RunReplaceService by deployer@shop-prod.iam.gserviceaccount.com; orders-api-00018 takes 100%
14:02:41Cloud Run varlog/systemNew orders-api-00018 instances start
14:03:05Admin Activity, Cloud SQLcloudsql.instances.restart by oncall-b@example.com
14:03:05 to 14:03:58Operations listRESTART, DONE
14:03:09PostgreSQL logShutdown
14:03:12 to 14:03:44Cloud Run errorsBoth revisions' connections reset or refused
14:03:47PostgreSQL logReady to accept connections
after 14:03:48Cloud RunNo errors

The errors sit inside the restart, start after the shutdown, and end with the startup. The deploy came 35 seconds before and is not involved. The engineer restarted the database while investigating an unrelated alert.

Incident B. Same deploy at 14:02:30. From 14:02:52 every new orders-api-00018 instance fails with FATAL: password authentication failed for user "orders_app", and a fresh orders-api-00017 instance started through its tag fails the same way. The operations list shows no UPDATE_USER that day; the audit stream shows only the Cloud Run update; Data Access logs are off; log_statement is none.

The timeline is silent where the cause sits. The failure is at the login stage and shared by both revisions, which places it in the database, and no control-plane record shows a password change. That points to a change made from a database client, such as ALTER ROLE ... PASSWORD, which the operations list does not record. Ask who holds a privileged database login and compare the password in the secret with the one the user now has. Turning on statement logging to catch the next change has a cost: an ALTER ROLE with a plaintext password would be written to the log. A password changed through the Admin API would have appeared as UPDATE_USER; the hub's third incident shows that case.

What the timeline cannot show#

It cannot show changes made inside PostgreSQL unless statement logging or pgAudit records them, and it cannot show who logged in unless Data Access logs for Cloud SQL are enabled. Silence in these records is not evidence that nothing changed. Instance operations log · Data Access audit logs

It cannot show the network between the service and the instance. A path that drops packets leaves no Cloud SQL operation and no audit entry.

It cannot show events outside the project, such as a provider incident in the region. A cloud provider incident during a rollout covers that check.

Scheduled maintenance appears in the operations list as MAINTENANCE; read the list as well as the audit logs before concluding that nothing happened to the instance. Maintenance or deploy?

Questions#

How do I see what happened to a Cloud SQL instance at a given time?

List its operations with gcloud sql operations list --instance INSTANCE, read Cloud SQL's Admin Activity and System Event audit logs for the window, and read the PostgreSQL log for shutdowns and startups. Put the three on one UTC timeline.

Does the Cloud SQL operations list show password changes?

It shows UPDATE_USER for changes made through the console, the gcloud CLI or the Admin API. A password changed with a SQL command from a database client does not appear there.

How long are Cloud SQL audit logs kept?

Admin Activity and System Event audit logs go to the _Required bucket, which keeps them for 400 days. Data Access logs are written only if you enable them.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading