Learning center

Every Cloud Run connection fails: is the Cloud SQL instance stopped or suspended?

When every revision fails to reach Cloud SQL at once, read the instance's state and settings.activationPolicy before anything else. A stopped instance reads RUNNABLE with policy NEVER; a suspended one reads SUSPENDED and says why.

Two ways an instance stops serving on purpose#

A Cloud SQL instance can be up as a resource and still refuse every connection. Two states produce that, and neither is a fault in the service:

  • Stopped. Someone or something set the activation policy to NEVER. A stopped instance stays stopped and does not respond to application connections until it is started again. Stopping suspends instance charges, which is why some teams stop idle instances on a schedule. Cloud SQL also stops an instance that is nearly out of storage, to prevent the loss of information. Start, stop and restart instances
  • Suspended. Google Cloud made the instance unavailable, for example because of a billing problem. The instance's suspensionReason says which. Instance resource

From Cloud Run, both look like a database that has vanished: every request that needs the database fails, from every revision, including instances that were connected a minute earlier. On the hub's stage table the errors can look like stage 1 or stage 4 depending on the driver. Rolling back changes nothing.

Check 1: read the state#

gcloud sql instances describe INSTANCE --project PROJECT \
  --format='yaml(state, suspensionReason, settings.activationPolicy, outOfDiskReport)'

state is the instance's serving state. Its values that matter here: SqlInstanceState · activationPolicy

stateactivationPolicyMeaning
RUNNABLEALWAYSRunning. The instance is not stopped; look elsewhere
RUNNABLENEVERStopped by its owner. RUNNABLE covers both running and stopped-by-owner
SUSPENDEDanyNot available; suspensionReason says why
MAINTENANCEanyDown for maintenance; see maintenance or deploy
FAILEDanyCreation failed or a fatal error occurred during maintenance

suspensionReason takes one of these values: BILLING_ISSUE, LEGAL_ISSUE, OPERATIONAL_ISSUE (the instance was causing operational problems, such as crashing the database), or KMS_KEY_ISSUE (the customer-managed encryption key was revoked or access to it was denied). SqlSuspensionReason

outOfDiskReport.sqlOutOfDiskState reads SOFT_SHUTDOWN when the data disk was almost used up and Cloud SQL shut the instance down to prevent data corruption. That case is a storage problem first; the storage guide covers it. SqlOutOfDiskState

The database/up metric in Cloud Monitoring reads 0 while the server is down, and database/instance_state reports which state is current, one data point per state. Their history gives the moment the instance stopped serving. Cloud SQL metrics

Check 2: who or what stopped it#

There is no separate operation type for stopping an instance. A stop sets activationPolicy to NEVER through a settings change, which the API returns as an UPDATE operation; a start is an UPDATE back to ALWAYS. Stop an instance · Operation types

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

gcloud logging read '
  logName="projects/PROJECT/logs/cloudaudit.googleapis.com%2Factivity"
  AND protoPayload.methodName="cloudsql.instances.update"
  AND timestamp>="START_TIME"' \
  --project PROJECT --order=asc \
  --format='table(timestamp, protoPayload.authenticationInfo.principalEmail, protoPayload.request)'

The user field and the audit entry's principal name the caller. When the request is recorded, it shows settings.activationPolicy. An UPDATE from a scheduler's service account at the moment database/up dropped points to a stop job. Cloud SQL audit logging · Audit log entry structure

state and policyUPDATE by a user or service account at the dropReading
RUNNABLE, NEVERYesA deliberate stop. Ask the owner of that identity before starting it, since a stop job will repeat
AnyNo, and outOfDiskReport shows SOFT_SHUTDOWNCloud SQL stopped it for storage. Starting it without more space leads back to the same stop
SUSPENDEDNot needed: suspensionReason names the causeA billing, legal, operational or key problem. The fix lies with whoever owns that account, contract or key
RUNNABLE, ALWAYSAnyNot stopped. Return to the stage table

A worked fixture: two outages at two in the morning#

The fixture is illustrative. orders-api serves from orders-api-00018; at 01:58 UTC every request that touches the database starts failing, from every instance.

Outage A. The description:

settings:
  activationPolicy: NEVER
state: RUNNABLE

The operations list shows an UPDATE from 01:58:02 to 01:58:40 by cost-scheduler@shop-prod.iam.gserviceaccount.com. Its audit entry carries a request with activationPolicy: NEVER. database/up reads 0 from 01:59. The scheduler stops instances labelled env=staging each night; orders-db was cloned from the staging instance last week, and the label came with it. Starting the instance changes it (it sets the activation policy to ALWAYS), so it is a step for someone with that authority:

gcloud sql instances patch orders-db --project shop-prod --activation-policy=always

The label needs to go too, or the job will stop it again the next night. Start an instance

Outage B. The description:

settings:
  activationPolicy: ALWAYS
state: SUSPENDED
suspensionReason:
- KMS_KEY_ISSUE

No UPDATE appears in the operations list. The instance uses a customer-managed encryption key, and the key's audit log shows its primary version disabled at 01:57. Nothing in Cloud Run or Cloud SQL's settings changed; the owner of the key has to restore access.

Where the checks mislead#

state is current, not historical. An instance that someone has already started reads RUNNABLE with ALWAYS, and the outage leaves traces only in the operations list, the audit log and the database/up history. Read those for the window, not only the description. A wider view of everything the instance went through is in the operations timeline guide.

Stopping suspends instance charges, but storage and IP address charges continue, so a stopped instance still appears in billing. Its data is unaffected. Stop an instance

Read replicas cannot be stopped and do not accept the NEVER policy. A replica that stops serving is a different problem from the primary being stopped. Start, stop and restart instances

Questions#

How do I tell whether a Cloud SQL instance is stopped?

Run gcloud sql instances describe and read state and settings.activationPolicy. A stopped instance reads RUNNABLE with activation policy NEVER; RUNNABLE alone does not mean it is running.

Why is my Cloud SQL instance suspended?

suspensionReason names the cause: BILLING_ISSUE, LEGAL_ISSUE, OPERATIONAL_ISSUE or KMS_KEY_ISSUE. Each needs action from the owner of the billing account, the content, the workload or the encryption key.

Who stopped my Cloud SQL instance?

Stopping is a settings update. The UPDATE operation's user field and the Admin Activity audit entry for cloudsql.instances.update name the caller.

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