---
title: "A schema change during a Cloud Run traffic split: which revision must accept it? | Proofline"
description: "While a Cloud Run service splits traffic, every revision in the split, and every tagged revision, queries the same Cloud SQL schema."
url: https://proofline.sh/learn/cloud-run-traffic-split-schema-change/
---

[Learning center](/learn/)

# A schema change during a Cloud Run traffic split: which revision must accept it?

While a Cloud Run service splits traffic, every revision in the split, and every tagged revision, queries the same Cloud SQL schema. A migration that lands during the split must work for the oldest of them. A change that removes something the old revision uses waits until that revision holds no sessions and you have given it up as a rollback target. Read the service's traffic block for who can receive requests, and pg\_stat\_activity for who still holds connections.

Schema conflicts The Proofline team November 23, 2026 6 min read

## How the mismatch shows up

A traffic split makes two releases serve at once, for as long as the split lasts. A schema change applied in that window meets both. The errors come from whichever revision the change did not plan for:

-   **The old revision fails after the migration.** A dropped or renamed column gives SQLSTATE `42703` (`undefined_column`) on the old revision's queries. An added column can fail it too: a connection that prepared `SELECT *` before the migration gets `cached plan must not change result type` until the statement is prepared again. [PostgreSQL error codes](https://www.postgresql.org/docs/current/errcodes-appendix.html) · [The cached-plan error after adding a column](/learn/postgres-cached-plan-result-type/)
-   **The new revision fails before the migration.** If the new revision takes its share of traffic before its migration has run, its queries name a column that does not exist yet.

Errors from one revision only, starting at a migration's timestamp, point to this mismatch rather than to the release's logic. The [four stages](/learn/cloud-run-cloud-sql-connection-errors/#stage) of a connection all succeed here; the failure is in the queries.

## Which revision meets which schema

Each change in a schema migration is either additive, meaning the old revision can ignore it, or it removes or changes something the old revision reads or writes. The order of the deploy and the migration decides which revision has to tolerate what:

| Order | The old revision meets | The new revision meets | Requirement |
| --- | --- | --- | --- |
| Migration, then deploy and split | The new schema | The new schema | The migration must be additive for the old revision |
| Deploy and split, then migration | The new schema, from the migration on | The old schema, until the migration | The new revision must also work with the old schema |
| Contract: drop, rename, `NOT NULL` on a column the old release does not write | The new schema | The new schema | No session from the old revision, and no plan to roll back to it |

The first row is the usual expand step. The second row is what happens when a migration runs from the application's startup or from a job that finishes after the new revision already serves. The third row is the decision this guide is about: when the old revision is really gone. A move between two shapes of data takes several such steps, which [moving data while two releases share one database](/learn/data-migration-across-service-versions/) follows end to end.

## Check 1: which revisions can still receive requests

The service's status lists every traffic target, each with `revisionName`, `percent` and an optional `tag`. A tag gives the revision its own URL that reaches it regardless of its percentage, so a revision at 0% with a tag can still receive requests from anything that calls that URL. [TrafficTarget fields](https://cloud.google.com/run/docs/reference/rest/v1/TrafficTarget) · [Traffic tags](https://cloud.google.com/sdk/gcloud/reference/run/services/update-traffic)

```
gcloud run services describe orders-api \
  --project shop-prod --region europe-west1 \
  --format='yaml(status.traffic)'
```

Session affinity changes how the percentages apply. With affinity on, a client's later requests return to the revision it first reached, and affinity takes precedence over the split; when the split changes, Cloud Run moves as few of those clients as it can. A revision at 10% can serve more than 10% of requests. [Session affinity and traffic splitting](https://cloud.google.com/run/docs/configuring/session-affinity)

Cloud Run also starts instances for a revision that has a tag when that revision has a revision-level minimum instances setting, even with no traffic. [Minimum instances and revisions](https://cloud.google.com/run/docs/configuring/min-instances)

## Check 2: which revision still holds connections

A revision that receives no new requests can still hold database sessions. Cloud Run may keep an instance idle for up to 15 minutes after its last request, and an idle instance might keep its open database connections. The `run.googleapis.com/container/instance_count` metric, grouped by `revision_name` and its `state` label (`active` or `idle`), shows those instances. [Idle instances](https://cloud.google.com/run/docs/about-instance-autoscaling) · [Cloud Run metrics](https://cloud.google.com/monitoring/api/metrics_gcp_p_z)

The database's view is more direct, if each connection names its revision. Cloud Run sets `K_REVISION` in every container; pass it as the connection's `application_name`, and group the sessions:

```
SELECT application_name, count(*) AS sessions,
       max(backend_start) AS newest, max(state_change) AS last_activity
FROM pg_stat_activity
WHERE datname = 'orders'
GROUP BY application_name
ORDER BY application_name;
```

`backend_start` is when the client connected, and `state_change` when the session last changed state, such as finishing a query. [Container runtime contract](https://cloud.google.com/run/docs/container-contract) · [`pg_stat_activity`](https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW) · [Tag connections with their release](/learn/postgres-which-release-is-connected/)

| Old revision in the traffic block | Old revision's sessions | Reading |
| --- | --- | --- |
| Has a percentage | Any | It serves. Only additive changes |
| 0% with a tag | Sessions with recent `last_activity` | Something calls the tag URL. Find the caller, or remove the tag, before a contract step |
| Not listed | Sessions, no recent activity | Idle instances that have not stopped. Wait, then query again |
| Not listed | None, over a full cycle of the jobs that share the database | No connection from the old revision. Whether to contract is now a rollback decision |

## A worked fixture: the drop that waited

The fixture is illustrative. `orders-api-00017` reads and writes `orders.status`. `orders-api-00018` reads `state` and writes both. At 14:00 UTC an expand migration adds `state` with a trigger that fills it for old writers. At 14:05 the team splits traffic 90/10 to `orders-api-00018`, and at 14:30 moves it to 100%, keeping the tag `prev` on `orders-api-00017`. The contract migration, dropping `status`, is ready.

**Outcome A.** At 14:52 the traffic block shows `orders-api-00018` at 100 and `orders-api-00017` at 0 with tag `prev`. The session query:

| application\_name | sessions | newest | last\_activity |
| --- | --- | --- | --- |
| `orders-api-00017` | 2 | 14:31:10 | 14:51:58 |
| `orders-api-00018` | 21 | 14:50:44 | 14:52:03 |

`orders-api-00017` had no percentage for 22 minutes, longer than the 15 minutes an instance may stay idle, and its sessions were busy a few seconds ago. The request log for the revision shows a synthetic check calling the `prev` URL every minute. Dropping `status` now would turn those requests into `42703` errors, and would leave `orders-api-00017` unable to serve if traffic moved back. The team keeps the column and moves the check to the main URL.

**Outcome B.** The team removes the tag at 14:55. At 15:40 `instance_count` for `orders-api-00017` has been zero since 15:07, and the session query returns only `orders-api-00018`. The nightly export already reads `state`. The remaining question is whether `orders-api-00017` must stay a rollback target. Once `status` is gone, a rollback needs a revision that does not read it. The team records `orders-api-00018` as the earliest rollback target and runs the contract migration at 15:45.

## Where the checks mislead

An empty `application_name` hides which revision a session belongs to. Count such sessions as unknown, never as the new revision's.

Connections that go through a pooler outside Cloud Run report what the pooler sends, and a pool shared by several revisions cannot tell them apart.

The traffic block covers requests. A Cloud Run job, a scheduler target or another service that runs the old code does not appear in it, and only the database's sessions show it.

## Questions

### Can I run a migration while Cloud Run splits traffic between two revisions?

Yes, when the change is additive for the older revision. Both revisions run their queries against the schema from the moment it changes, so a drop or rename fails whichever revision still uses the old name.

### How long after a traffic move does the old revision keep database connections?

Its instances may stay idle for up to 15 minutes and keep their connections during that time. A tag, session affinity or a revision-level minimum instances setting can keep it serving or running longer.

### When can I drop a column the previous revision used?

When no session comes from that revision over a full cycle of the jobs that share the database, and you no longer need it as a rollback target.

## 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

-   ### [Moving data while two application releases share one database](/learn/data-migration-across-service-versions/)
    
    Breaking migrations The Proofline team November 22, 2026 7 min read
    
-   ### [Fix "cached plan must not change result type" after adding a PostgreSQL column](/learn/postgres-cached-plan-result-type/)
    
    Schema conflicts The Proofline team November 20, 2026 3 min read
