Why a flag change looks like a bad deploy#
Cloud SQL applies database flags to PostgreSQL through the Admin API. When you set, remove or modify a flag, the database might be restarted, and if the instance is the source of a replica, the replica restarts too. Cloud SQL's flag table has a column that says, flag by flag, whether a restart is required. Configure database flags
A restart ends every session. From Cloud Run it looks like any other admission failure at stage 4 of the hub's stage table: connections reset, new ones refused while the server starts, then recovery. Flag changes often ship in the same change window as application deploys, sometimes from the same Terraform apply, so the two land minutes apart and the deploy is the obvious suspect.
Two features of the flags API make surprise restarts more likely:
- A
PATCHwithdatabaseFlags, andgcloud sql instances patch --database-flags, replace the whole list. A change that sets one new flag without repeating the existing ones removes those, and removing a restart-required flag restarts the instance. Set a database flag ·gcloud sql instances patch --clear-database-flagsand a change of--tierboth carry the warning that the instance will be restarted.gcloud sql instances patch
Check 1: find the update and who sent it#
A flag change returns an operation of type UPDATE, the type Cloud SQL uses for any change to the instance's settings. List the operations around the errors:
gcloud sql operations list --instance INSTANCE --project PROJECT --limit=20 \
--format='table(operationType, status, startTime, endTime, user)'
The user field is the email address of whoever started the operation. The operation's start and end bound the window in which the restart can fall. Operation resource · Response to a flag change
The UPDATE type does not say which setting changed. The Admin Activity audit log records each call to cloudsql.instances.update with the caller's identity; as a long-running operation it usually writes one entry when the operation starts and another when it ends. Cloud SQL audit logging
gcloud logging read '
logName="projects/PROJECT/logs/cloudaudit.googleapis.com%2Factivity"
AND protoPayload.serviceName="cloudsql.googleapis.com"
AND protoPayload.methodName="cloudsql.instances.update"
AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
--project PROJECT --order=asc --format=json
Audit entries can carry the request the caller sent in protoPayload.request. If the entry has one, it shows the settings in the call; if it does not, compare the current flags with the values in your infrastructure code or a copy of the instance description from before the change. Audit log entry structure
gcloud sql instances describe INSTANCE --project PROJECT \
--format='yaml(settings.databaseFlags, settings.tier)'
Check 2: does the changed flag restart the instance?#
Look up each flag that changed in the "Restart Required?" column of Cloud SQL's flag table. A sample for PostgreSQL:
| Flag | Restart required | Note from the flag table |
|---|---|---|
max_connections | Yes | Default depends on the instance's memory |
shared_buffers | Yes | Default is one third of the instance's memory |
max_locks_per_transaction | Yes | Changes on the primary can restart replicas |
cloudsql.enable_pgaudit | Yes | |
work_mem | No | |
log_min_duration_statement | No | |
cloudsql.iam_authentication | No |
UPDATE overlaps the errors | Changed flag requires a restart | All revisions failed together | Reading |
|---|---|---|---|
| Yes | Yes | Yes | The flag change restarted the database. The deploy is not involved |
| Yes | No | Yes | The update did not restart PostgreSQL through that flag. Check whether the same call changed the tier or cleared flags; otherwise look at the other operations in the window |
| Yes or no | Either | No, only the new revision | The deploy. Compare the revisions as the hub describes |
A worked fixture: same window, two changes#
The fixture is illustrative. orders-api runs orders-api-00017 at 100%. At 14:02:30 UTC a pipeline shifts 50% of traffic to orders-api-00018. Both connect to orders-db through Cloud Run's built-in connection.
Change A. The operations list:
| operationType | status | startTime | endTime | user |
|---|---|---|---|---|
UPDATE | DONE | 14:03:10 | 14:04:25 | infra-deployer@shop-prod.iam.gserviceaccount.com |
Errors run from 14:03:31 to 14:04:12 on both revisions, in proportion to their traffic. The audit entry for cloudsql.instances.update at 14:03:10 has the same principal, and its request lists one flag, max_connections=400. The instance description from the morning listed max_connections=200 and log_min_duration_statement=500; it now lists only max_connections=400. Raising max_connections requires a restart, and the replacement also dropped log_min_duration_statement. The Terraform change that raised the limit caused the outage; the deploy was in the same window by chance. Put the missing flag back in the same change, and schedule future restart-required changes as a planned restart.
Change B. Same window, different update:
| operationType | status | startTime | endTime | user |
|---|---|---|---|---|
UPDATE | DONE | 14:03:10 | 14:03:42 | infra-deployer@shop-prod.iam.gserviceaccount.com |
The request sets work_mem and repeats the existing flags. work_mem does not require a restart. The errors come only from orders-api-00018, start at 14:02:41 and continue after 14:04; orders-api-00017 serves its half without errors throughout. The flag change is not involved. Move traffic back to orders-api-00017 and read the new revision's error stage.
Where the checks mislead#
"Restart required" in the table describes the flag, not what happened on the instance. The operation's start and end are the outer bounds; a client sees the restart as a shorter gap inside them. Read the PostgreSQL log, cloudsql.googleapis.com/postgres.log, for the shutdown and startup lines that place it to the second. View Cloud SQL logs
A flag that needs no restart can still change behavior right away. Lowering work_mem, for example, changes query plans and latency without an outage. That is a different symptom: slower requests, not dropped connections. Is the latency in Cloud SQL or in the Cloud Run instance?
The operations log records what was done through the console, the gcloud CLI or the Admin API. Actions taken through a database client such as psql do not appear there. Instance operations log
Raising max_connections because the service ran out of connections is a common trigger for this incident. Before changing it, compare the service's connection budget with the limit; Cloud Run allows up to 100 connections per container instance to a Cloud SQL database, so the total grows with instance count. Connection limits · Connection budgets during rolling deployments
To plan a restart you need, such as turning on logical decoding, see what the restart costs the service.
Questions#
Which Cloud SQL flags restart the instance?
Cloud SQL's flag table has a "Restart Required?" column for every supported flag. For PostgreSQL, max_connections, shared_buffers and max_locks_per_transaction are among those that require a restart; work_mem and log_min_duration_statement are among those that do not.
How do I find who changed a Cloud SQL database flag?
The UPDATE operation's user field names the caller, and the Admin Activity audit log records cloudsql.instances.update with the principal and, when present, the request.
Can setting one flag remove the others?
Yes. A patch with a list of flags replaces the existing list, so a change that does not repeat the current flags removes them, and removing a restart-required flag restarts the instance.