---
title: "Too many Cloud SQL connections during a Cloud Run traffic split | Proofline"
description: "During a gradual rollout, both revisions keep instances, and every instance keeps its pool."
url: https://proofline.sh/learn/cloud-run-traffic-split-cloud-sql-connections/
---

[Learning center](/learn/)

# Too many Cloud SQL connections during a Cloud Run traffic split

During a gradual rollout, both revisions keep instances, and every instance keeps its pool. Count sessions per revision across the minutes around the traffic step: if the old and new revisions' sessions together filled the table while each alone fits, the split caused the error; if the new revision opens more per instance, the release did.

Capacity overruns The Proofline team November 23, 2026 7 min read

## How the split shows up in the connection table

A Cloud Run service shifting traffic with `gcloud run services update-traffic SERVICE --to-revisions REVISION=PERCENTAGE` runs two revisions side by side. The new one starts instances for its share, and the old one does not drop its instances at the moment its share falls. Requests leave it, but Cloud Run may keep instances idle for up to 15 minutes after they finish handling requests, and an idle instance can keep resources such as open database connections. [Gradual rollouts](https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration) · [Idle instances](https://cloud.google.com/run/docs/about-instance-autoscaling)

The database sees the sum. PostgreSQL then refuses new sessions with SQLSTATE `53300`, which reaches the revision that is opening connections: usually the new one, since its instances are the ones starting. That makes the new revision look broken when the table filled because two revisions shared it. This is the admission stage of [the four stages](/learn/cloud-run-cloud-sql-connection-errors/#stage).

Three settings change how many instances can coexist:

-   A service-level maximum is divided among the revisions that receive traffic, in proportion to their share, so a revision can hit its effective maximum while the service has not. A revision-level maximum applies to each revision on its own, so the service total can exceed it during a split. [Maximum instances and traffic splits](https://cloud.google.com/run/docs/configuring/max-instances)
-   When a deploy sends 100% of traffic to a new revision at once, Cloud Run starts enough instances of the new revision before directing traffic to it, so the overlap happens there too. [Deployments](https://cloud.google.com/run/docs/about-instance-autoscaling)
-   Revision-level minimum instances start whenever the revision is referenced in a traffic split or has a tag, and stay up with no requests. A tagged old revision with a revision-level minimum holds its pools indefinitely. [Minimum instances and tags](https://cloud.google.com/run/docs/configuring/min-instances)

A split set once stays in place: later deploys keep that traffic pattern until all traffic goes to the latest revision. [Lifecycle of traffic splits](https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration)

## Check 1: line up the traffic steps with the first refusal

Cloud Run logs each instance start in `varlog/system`, with the reason `DEPLOYMENT_ROLLOUT` for instances started by traffic shifting between revisions, a split adjustment or a deployment health check. Read those starts beside the first database refusals: [Instance scaling logs](https://cloud.google.com/run/docs/logging)

```
gcloud logging read \
  'resource.type="cloud_run_revision"
   AND resource.labels.service_name="SERVICE"
   AND timestamp>="START_TIME"
   AND (textPayload:"Starting new instance" OR textPayload:"53300" OR jsonPayload.message:"53300")' \
  --project PROJECT --order=asc --limit=300 \
  --format='value(timestamp, resource.labels.revision_name, labels.instanceId, textPayload, jsonPayload.message)'
```

Whether the SQLSTATE appears in the text depends on the driver and on how the application logs errors; search for the driver's wording if the code is missing. Then read the configured split:

```
gcloud run services describe SERVICE \
  --project PROJECT --region REGION \
  --format='yaml(metadata.annotations, status.traffic)'
```

`status.traffic` lists each revision with its percentage and tag; `run.googleapis.com/maxScale` among the service's annotations is the service-level maximum. [Service status](https://cloud.google.com/run/docs/reference/rest/v1/namespaces.services) · [Annotations](https://cloud.google.com/run/docs/reference/rest/v1/ObjectMeta)

If the first refusal follows a traffic step within minutes and the two revisions' `DEPLOYMENT_ROLLOUT` starts cluster around it, continue. If the refusals began before the step, read [the budget for a single revision](/learn/cloud-run-cloud-sql-connection-budget/).

## Check 2: count instances and sessions per revision

Chart Cloud Run's `container/instance_count` for the window, grouped by `revision_name` and `state`. The metric splits instances into `active` and `idle`, so you can see how many old instances stayed up idle after the step. Beside it, chart Cloud SQL's `database/postgresql/num_backends_by_application`, which counts connections grouped by application, sampled every 60 seconds. Both keep history, so they work after the incident. [Cloud Run metrics](https://cloud.google.com/monitoring/api/metrics_gcp_p_z) · [Cloud SQL metrics](https://cloud.google.com/monitoring/api/metrics_gcp_c)

Grouping by application tells revisions apart only if each revision names its connections. [Which revision holds the connections](/learn/which-cloud-run-revision-holds-cloud-sql-connections/) shows how to set `application_name` from `K_REVISION` and how to count without it.

Divide each revision's sessions by its instance count, then read the result:

| At the first refusal | Sessions per instance | Reading |
| --- | --- | --- |
| Old and new sessions together reach the usable slots; each revision alone fits | About equal in both revisions | The split's overlap filled the table. The old revision's instances, many idle, still held their pools |
| Same | Clearly higher in the new revision | The release changed how many connections an instance opens: pool size, workers per instance, or a connection opened per request. It fails at full traffic too |
| Neither revision's sessions rose at the step | Unchanged | Not the split. Look at the other clients' sessions in the same minutes |

## What to do with each reading

For the overlap, plan each step against the sum: old revision's instances, including idle ones, plus the new revision's instances at its share, times the per-instance limit, plus other clients. Smaller steps add fewer new instances at once. A service-level maximum caps the two revisions together, since it is divided between them. A smaller pool per instance leaves room for both. The old revision's idle instances go away within 15 minutes of their last request unless a minimum keeps them, so the overlap is temporary; a tag with a revision-level minimum makes it permanent.

For a release that opens more per instance, routing traffic back to the old revision removes the cause. Fix the pool or worker change before the next attempt, and recompute the full-traffic budget.

## A worked fixture: one error at a split, two causes

The fixture is illustrative. `orders-api` connects to `orders-db`, which has 397 usable slots; `orders-worker` and analysts hold 22. Each instance of `orders-api` runs one pool of 10 connections and names its connections from `K_REVISION`. Each revision carries `autoscaling.knative.dev/maxScale: '30'`, and the service sets no service-level maximum. `orders-api-00017` serves all traffic with 24 instances and 240 sessions.

**Split A, 2026-11-18.** At 10:00:00 UTC the team runs `update-traffic --to-revisions orders-api-00018=50`. By 10:01, `varlog/system` shows 15 `DEPLOYMENT_ROLLOUT` starts for `orders-api-00018`. `orders-api-00017` still has 24 instances, 12 of them idle.

| Time (UTC) | `orders-api-00017` sessions | `orders-api-00018` sessions | Other | Total |
| --- | --- | --- | --- | --- |
| 09:59 | 240 | 0 | 22 | 262 |
| 10:01:30 | 240 | 135 | 22 | 397 |
| 10:16 | 130 | 150 | 22 | 302 |

At 10:01:42 the first `53300` appears on a new `orders-api-00018` instance. Per instance, `orders-api-00017` holds 240 / 24 = 10 and `orders-api-00018` holds 135 / 15 = 9: the same pool, and its newest instances not yet full. By 10:16 the old revision is down to 13 instances and the total has room. The split caused the error. The next step goes to 100% only after the old revision's idle instances have drained, with a service-level maximum of 30, which holds the revisions taking traffic near 300 pooled connections. Idle old instances and Cloud Run's brief excess above the maximum come on top of that. [Maximum instances](https://cloud.google.com/run/docs/configuring/max-instances) · [Instance autoscaling](https://cloud.google.com/run/docs/about-instance-autoscaling)

**Split B, 2026-11-20.** At 15:00:00 UTC, `orders-api-00019` gets 10%. At 15:02:10, `53300` errors begin on `orders-api-00019`.

| Time (UTC) | `orders-api-00017` sessions | `orders-api-00019` sessions | Other | Total |
| --- | --- | --- | --- | --- |
| 15:02 | 220 (22 instances) | 155 (4 instances) | 22 | 397 |

The old revision holds 10 per instance; the new one holds nearly 39, and its fourth instance was still being refused when the table filled. The release raised the web server's workers from one to four, each with its own pool of 10: 40 per instance. At full traffic, 22 instances would want 880. Route traffic back to `orders-api-00017`, then fix the pool before rolling forward.

## Where the checks mislead

`num_backends_by_application` is only as precise as the names the clients set. Connections with no `application_name` fall into one group, and a revision that names its connections after the service instead of the revision merges both revisions into one line.

The minute samples can hide the moment the table was full. A pool that grows during a burst and shrinks again within the minute leaves the refusals in the application's logs and a total below the limit on the chart.

The old revision's idle instances can be shut down at any time, and the 15 minutes is an upper bound. Do not plan a rollout around them staying; plan the budget as if they stay the full 15 minutes.

For errors at a traffic step that are not about the database, such as instances that never started or requests aborted for lack of an instance, see [errors after shifting traffic](/learn/cloud-run-errors-after-traffic-shift/).

## Questions

### Why do I get too many connections only during a Cloud Run gradual rollout?

Both revisions run instances during the split, and the old revision's instances can stay idle for up to 15 minutes while still holding their pools. The two revisions together can need more slots than either needs alone.

### Does the service-level maximum instances setting limit both revisions during a split?

Yes. Cloud Run divides the service-level maximum among the revisions that receive traffic, in proportion to their share. Revision-level maximums apply to each revision separately, so with only those set, the service total can exceed any one of them.

### How do I tell whether the new revision or the split caused too many connections?

Compare sessions per instance in each revision. If they are about equal and the sum filled the table, the overlap did it. If the new revision holds clearly more per instance, the release changed the connection count and will fail at full traffic too.

## 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 429, 500 and 503 errors after shifting traffic to a new revision](/learn/cloud-run-errors-after-traffic-shift/)
    
    Capacity overruns The Proofline team November 20, 2026 9 min read
    
-   ### [Which Cloud Run revision holds these Cloud SQL connections?](/learn/which-cloud-run-revision-holds-cloud-sql-connections/)
    
    Broken dependencies The Proofline team November 23, 2026 6 min read
