---
title: "Did a Cloud SQL failover cause these Cloud Run errors? | Proofline"
description: "A Cloud SQL failover closes every connection and leaves the instance unavailable for about sixty seconds."
url: https://proofline.sh/learn/cloud-sql-ha-failover-cloud-run-errors/
---

[Learning center](/learn/)

# Did a Cloud SQL failover cause these Cloud Run errors?

A Cloud SQL failover closes every connection and leaves the instance unavailable for about sixty seconds. It explains errors that hit all revisions at one moment and stop within minutes. Errors that outlast that window belong to how the service's connection pools recover, or to something else.

Broken dependencies The Proofline team November 23, 2026 6 min read

## What a failover looks like from the service

An instance configured for high availability has a primary and a standby in two zones of one region. When the primary or its zone fails, the standby becomes the primary, and Cloud SQL reroutes clients to it through the same IP address. Any existing connections to the primary are closed, and reconnecting takes approximately 60 seconds. The application reconnects with the same connection string, so no configuration changes. [High availability](https://cloud.google.com/sql/docs/postgres/high-availability)

From Cloud Run, that reads as a burst of broken connections on every instance of every revision at once, followed by connection attempts that fail or wait, and then recovery. Requests that were mid-transaction fail even if the pool reconnects cleanly. Cloud SQL's connection guidance says retries only make sense when first connecting or first taking a connection from the pool; an error in the middle of a transaction must be retried by the application from the start of the transaction. [Exponential backoff](https://cloud.google.com/sql/docs/postgres/manage-connections#backoff)

Cloud SQL sometimes restarts the instance instead of failing over. An HA instance can also restart itself to recover, which the API records as `AUTO_RESTART`. Either way the effect on clients is close to a failover: every session ends. On the hub's [stage table](/learn/cloud-run-cloud-sql-connection-errors/#stage), all three land at stage 4, admission and use. [Operation types](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/operations)

## Check 1: did the instance fail over or restart?

Three records answer this, and each covers a gap in the others.

The operations list records `FAILOVER`, `AUTO_RESTART` and `RESTART` with their start and end:

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

The audit logs say who or what started it. A failover that a user or service account starts writes an Admin Activity entry with the method `cloudsql.instances.failover` and that identity. A failover Cloud SQL starts on its own writes a System Event entry with the method `cloudsql.instances.autoFailover`. A user-initiated restart writes `cloudsql.instances.restart`. Cloud SQL always writes these two log types; you don't need to enable anything. [Failover overview](https://cloud.google.com/sql/docs/postgres/high-availability#failover-overview) · [Cloud SQL audit logging](https://cloud.google.com/sql/docs/postgres/audit-logging) · [Audit log names](https://cloud.google.com/logging/docs/audit)

```
gcloud logging read '
  protoPayload.serviceName="cloudsql.googleapis.com"
  AND protoPayload.methodName=("cloudsql.instances.failover" OR "cloudsql.instances.autoFailover" OR "cloudsql.instances.restart")
  AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
  --project PROJECT --order=asc \
  --format='table(timestamp, logName, protoPayload.methodName, protoPayload.authenticationInfo.principalEmail)'
```

The instance itself shows where it serves from now. `gceZone` is the zone the instance currently serves from, and it differs from the zone chosen at creation after a failover. Read it with `settings.availabilityType`, which is `REGIONAL` for an HA instance. [Instance resource](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances)

```
gcloud sql instances describe INSTANCE --project PROJECT \
  --format='yaml(settings.availabilityType, gceZone, secondaryGceZone)'
```

If Cloud SQL restarted the instance because of a crash or resource exhaustion, such as running out of memory, the database error log in Cloud Logging holds the crash and recovery details. [High availability](https://cloud.google.com/sql/docs/postgres/high-availability) · [View Cloud SQL logs](https://cloud.google.com/sql/docs/postgres/logging)

## Check 2: do the errors fit the failover window?

Group the service's errors by minute and revision from the operation's start onward, using the error query from the hub's [first check](/learn/cloud-run-cloud-sql-connection-errors/#stage). Three shapes are common.

| Errors begin | Errors end | Revisions affected | Reading |
| --- | --- | --- | --- |
| Within seconds of the operation's start | A minute or two after it | All that served | The failover or restart. Nothing in the service needs to change |
| Within seconds of the operation's start | Long after, on some instances only | All, then a subset | The failover started it; those instances' pools are handing out closed connections. Fix pool validation and retry, not the deploy |
| Before the operation, or with no operation at all | Any time | One revision | Not a failover. The failover guide does not apply; go back to the stage table |

The second row is the one that gets misread as a bad deploy, because the errors that remain cluster on particular instances and look unrelated to the database. Cloud Run's default request-based billing throttles an idle instance's CPU, which pauses the background threads a pool uses to validate connections and close expired ones. When a request wakes the instance, the pool can hand out a connection the server closed during the idle period. Cloud SQL recommends instance-based billing for services that keep pools. [Connect from Cloud Run](https://cloud.google.com/sql/docs/postgres/connect-run) · [Billing settings](https://cloud.google.com/run/docs/configuring/billing-settings)

## A worked fixture: one failover, two tails

The fixture is illustrative. `orders-db` is an HA PostgreSQL instance in `europe-west1`, primary in zone `europe-west1-b`. Service `orders-api` runs `orders-api-00018` (90% of traffic) and `orders-api-00017` (10%, kept for a slow rollout), with request-based billing and a connection pool that validates connections only in a background thread.

The System Event log:

| Time (UTC) | Log | Method |
| --- | --- | --- |
| 03:41:12 | `system_event` | `cloudsql.instances.autoFailover` |

The operations list shows a `FAILOVER` from 03:41:12 to 03:42:20, and `gceZone` now reads `europe-west1-c`.

**Tail A.** Errors per minute, by revision:

| Minute (UTC) | `orders-api-00018` | `orders-api-00017` |
| --- | --- | --- |
| 03:40 | 0 | 0 |
| 03:41 | 212 | 23 |
| 03:42 | 61 | 7 |
| 03:43 | 0 | 0 |

Both revisions fail together from the operation's start and stop within a minute of its end. This is the failover and nothing more. A rollback would have moved traffic to instances that failed in the same seconds.

**Tail B.** Same failover, but the errors do not stop:

| Minute (UTC) | `orders-api-00018` | `orders-api-00017` |
| --- | --- | --- |
| 03:41 | 212 | 23 |
| 03:42 | 61 | 7 |
| 03:43 to 03:55 | 4 to 9 a minute | 1 to 2 a minute |

The remaining errors come from five instance IDs, each of which had served no requests between 03:40 and its first error. Each one fails a request or two, then succeeds. Both revisions behave alike, so the deploy is not involved: idle instances kept connections the failover closed and handed them out on wake. The fix is in the pool: validate a connection before use or retry once on a closed connection, and consider instance-based billing.

## Where the checks mislead

Sixty seconds is the documented expectation, and the HA page notes that the duration can differ by environment. Use the operation's actual start and end, not the figure. [Failover process](https://cloud.google.com/sql/docs/postgres/high-availability#failover-process)

A failover needs a healthy standby, and the primary must not be stopped, in maintenance or running a long operation such as a backup. If both primary and standby are unresponsive, Cloud SQL does not fail over, and the outage lasts as long as the fault. Long errors with no `FAILOVER` in the list can be that case; the instance's `database/up` metric reports 0 during unplanned downtime even while its state still reads as running. [Failover requirements](https://cloud.google.com/sql/docs/postgres/high-availability#failover-requirements) · [Cloud SQL metrics](https://cloud.google.com/monitoring/api/metrics_gcp_c)

Maintenance affects HA primaries the same way it affects other instances, so a brief drop on an HA instance may be `MAINTENANCE`, not `FAILOVER`. The [maintenance guide](/learn/cloud-sql-maintenance-or-deploy/) covers that reading. [Maintenance downtime](https://cloud.google.com/sql/docs/postgres/high-availability#maintenance_downtime)

After a failover the new primary serves from another zone of the same region, and it stays there until a failback. If query latency differs after the event, compare it with `gceZone` before blaming the code that shipped next. [Failover and failback](https://cloud.google.com/sql/docs/postgres/high-availability)

## Questions

### How long does a Cloud SQL failover take?

Cloud SQL's documentation says to expect the instance to be unavailable for about sixty seconds, and that reconnecting takes approximately 60 seconds. Read the `FAILOVER` operation's start and end for the actual window on your instance.

### Do I need to change my Cloud Run service after a Cloud SQL failover?

No configuration change is needed: the standby takes over the same IP address and the connection name stays the same. What can need changing is the pool: if errors continue on some instances after the failover, the pool is handing out connections the failover closed.

### How do I know whether someone started the failover?

A user- or service-account-initiated failover writes an Admin Activity audit entry with the method `cloudsql.instances.failover` and the caller's identity. An automatic one writes a System Event entry with `cloudsql.instances.autoFailover`.

## 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](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Cloud Run cannot reach Cloud SQL: revision, identity or connection?](/learn/cloud-run-cloud-sql-connection-errors/)
    
    Broken dependencies The Proofline team November 23, 2026 10 min read
    
-   ### [Errors right after a Cloud Run deploy: Cloud SQL maintenance or the new revision?](/learn/cloud-sql-maintenance-or-deploy/)
    
    Broken dependencies The Proofline team November 23, 2026 6 min read
