---
title: "Is this slow Cloud SQL query new with the Cloud Run release? | Proofline"
description: "To tell whether a slow Cloud SQL query arrived with a Cloud Run release, attribute the query load to the revision that sent it."
url: https://proofline.sh/learn/cloud-sql-query-insights-by-revision/
---

[Learning center](/learn/)

# Is this slow Cloud SQL query new with the Cloud Run release?

To tell whether a slow Cloud SQL query arrived with a Cloud Run release, attribute the query load to the revision that sent it. Query Insights groups load by application tags, so a tag carrying the revision name separates the two revisions during a rollout. A query that only the new revision sends came with the release; one that slowed for both revisions points at the data or the database.

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

## How the question comes up

A deploy goes out, database CPU rises, and Query Insights shows a query near the top of the load table. The release seems to explain it, but the window also holds a backfill, a traffic peak and a nightly job. Rolling back costs a release, and rolling back for a query the old revision also sends gains nothing. The general version of this split is in [bad release or unhealthy dependency?](/learn/bad-release-or-unhealthy-dependency/); this guide does it with the database's own load data.

Nothing fails at any of [the four connection stages](/learn/cloud-run-cloud-sql-connection-errors/#stage). The connections work and the queries are slow.

## What Query Insights can group by

Query Insights shows database load by normalized query, with literals removed, and lets you filter by database, user and client address. It also groups load by tags, which the application adds to its SQL as comments in the sqlcommenter format. Only six keys are kept, `action`, `controller`, `framework`, `route`, `application` and `db driver`; Query Insights drops all others. Recording tags is an instance setting, `--insights-config-record-application-tags`. [Query Insights](https://cloud.google.com/sql/docs/postgres/using-query-insights) · [`gcloud sql instances patch`](https://cloud.google.com/sdk/gcloud/reference/sql/instances/patch)

None of those dimensions is the Cloud Run revision. Every revision usually connects as the same user, and Cloud Run's outbound traffic leaves from a shared pool of dynamic addresses unless you configure a static one, so the client address does not name a revision either. [Outbound IP addresses](https://cloud.google.com/run/docs/configuring/static-outbound-ip) Two ways put the revision into the data:

-   **A tag.** Set the `application` key from the `K_REVISION` environment variable, which Cloud Run sets to the revision's name. The tags table then has one row per revision, with load, average execution time and call count. [Container runtime contract](https://cloud.google.com/run/docs/container-contract)
-   **`application_name`.** Set the connection's `application_name` from `K_REVISION`. Query Insights does not group by it, but `pg_stat_activity` shows it beside each running query. [Tag connections with their release](/learn/postgres-which-release-is-connected/)

Retention limits how far back you can compare: query metrics are kept for 7 days on Cloud SQL Enterprise edition and 30 days on Enterprise Plus. A comparison with last week's release needs the earlier window to still be there. [Query Insights retention](https://cloud.google.com/sql/docs/postgres/using-query-insights)

## Check 1: place the release in time

```
gcloud run revisions describe NEW_REVISION \
  --project shop-prod --region europe-west1 \
  --format='value(metadata.name, metadata.creationTimestamp)'

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

The creation time says when the revision existed, and the traffic block what serves now. The revision's first request log entries say when it began serving; use that time as the boundary for the comparison. [ObjectMeta fields](https://cloud.google.com/run/docs/reference/rest/v1/ObjectMeta) · [TrafficTarget fields](https://cloud.google.com/run/docs/reference/rest/v1/TrafficTarget)

## Check 2: compare the query by revision

With revision tags, open the Tags view for the window in which both revisions served, select the query, and compare the rows. Without tags, compare the Queries view for equal windows before and after the boundary, and sample `pg_stat_activity` during the slow period:

```
SELECT application_name, count(*) AS running,
       max(now() - query_start) AS longest,
       left(query, 80) AS query
FROM pg_stat_activity
WHERE state = 'active' AND backend_type = 'client backend'
GROUP BY application_name, left(query, 80)
ORDER BY running DESC;
```

`query_start` is when the active query started, and `query` its text. A sample shows only what runs at that moment, so repeat it a few times during the slow period. [`pg_stat_activity`](https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW)

| What the comparison shows | Reading |
| --- | --- |
| The query appears only under the new revision, or only after the boundary | The release added it. Look at the code path and its plan |
| Both revisions send it; average time rose for both at the same moment | Not the release. Something shared changed: data volume, a plan, a lock, another workload |
| Both send it; only the new revision's call count rose | The release calls an existing query more often, for example in a loop. Its average time may not change |
| Both send it; only the new revision's average time rose | Different parameters or a different statement shape from the new code; read the sampled plans for each |

Query Insights samples query plans, and the Query details page splits load into CPU, IO wait and lock wait. A query that rose in lock wait for both revisions points at a lock, not at the release. [Query details](https://cloud.google.com/sql/docs/postgres/using-query-insights#specific-query)

## A worked fixture: one query, two answers

The fixture is illustrative. `orders-api` tags its queries with `application` set to `K_REVISION` and `route` set to the request path. `orders-api-00018` takes 10% of traffic at 14:05 UTC and 50% at 14:30. Database load on `orders-db` rises in the 14:30 hour, and the top query in Query Insights is a `SELECT` on `order_events` filtered by `order_id`.

**Outcome A.** The Tags view for 14:30 to 14:50, all queries:

| application | route | Avg execution time (ms) | Times called |
| --- | --- | --- | --- |
| `orders-api-00018` | `/orders/{id}/history` | 412 | 18,240 |
| `orders-api-00017` | `/orders/{id}` | 6 | 21,050 |

Filtered to the `order_events` query, only the `orders-api-00018` row remains; `orders-api-00017` has no history route. The release added the query, and its sampled plan shows a sequential scan of `order_events`. The team moves traffic back to `orders-api-00017` at 14:52, and CPU returns to its earlier level by 14:55. The fix is an index, rehearsed before the next rollout.

**Outcome B.** Same deploy, a different picture:

| application | route | Avg execution time (ms) before 14:20 | after 14:20 |
| --- | --- | --- | --- |
| `orders-api-00017` | `/orders/{id}` | 7 | 380 |
| `orders-api-00018` | `/orders/{id}` | 7 | 395 |

Both revisions send the same query, and its average rose for both at 14:20, ten minutes before the second traffic step. The load is mostly IO wait. A backfill job began writing to `order_events` at 14:19. The release is not the cause, and a rollback would leave the query just as slow. The team pauses the backfill.

## Where the checks mislead

A tag is only as good as the code that sets it. A path that skips the ORM, or a connection pool shared by several services, sends untagged queries, and those are missing from the Tags view. Check that the tagged load roughly accounts for the total.

Query Insights stores normalized queries. Two calls that differ only in their literals are one row, so a slow parameter value hides inside a fast average.

During a traffic split, each revision's load scales with its share. Compare average execution time, and call counts weighed against each revision's traffic share: at 10% traffic, the new revision's total load looks small even when every call is slow.

The [traffic split guide](/learn/cloud-run-traffic-split-schema-change/) covers the related case of a schema change that only one revision tolerates.

## Questions

### Can Query Insights show query load per Cloud Run revision?

Not by itself: it groups by query, database, user, client address and application tags. Put the revision name into a tag, such as the `application` key set from `K_REVISION`, and the Tags view shows load per revision.

### How do I know if a slow query started with a deploy?

Compare the query's load and average execution time per revision while both serve, or before and after the moment the new revision took traffic. A query only the new revision sends came with the release.

### Does Query Insights use PostgreSQL's application\_name?

Its documented filters are database, user, client address and tags, and its tags come from sqlcommenter comments in the SQL. `application_name` is visible in `pg_stat_activity`, which shows the queries running at the moment you look.

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

-   ### [Bad release or unhealthy dependency?](/learn/bad-release-or-unhealthy-dependency/)
    
    Deployment failures The Proofline team November 20, 2026 10 min read
    
-   ### [Tag PostgreSQL connections with the release that opened them](/learn/postgres-which-release-is-connected/)
    
    Breaking migrations The Proofline team November 22, 2026 3 min read
