---
title: "Cloud SQL storage keeps growing: an inactive replication slot holds WAL | Proofline"
description: "When a Cloud SQL for PostgreSQL instance's storage climbs with no matching growth in data, look for a replication slot whose consumer stopped reading."
url: https://proofline.sh/learn/cloud-sql-inactive-replication-slot-storage/
---

[Learning center](/learn/)

# Cloud SQL storage keeps growing: an inactive replication slot holds WAL

When a Cloud SQL for PostgreSQL instance's storage climbs with no matching growth in data, look for a replication slot whose consumer stopped reading. Such a slot keeps every write-ahead log (WAL) file since its position, without limit. Drop it if its consumer is gone for good; restart the consumer if it is not. The storage that automatic increases added stays allocated until a manual shrink, which needs downtime.

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

## How it shows up

Storage use rises steadily, Cloud SQL's automatic storage increase adds capacity, and the tables are no larger than last month. The Cloud Run service notices nothing until the instance cannot grow any further. When an instance cannot add storage it needs, Cloud SQL says it likely stops accepting incoming connections and could go offline, which the service sees as connections that fail at [the fourth stage](/learn/cloud-run-cloud-sql-connection-errors/#stage). [Automatic storage increase](https://cloud.google.com/sql/docs/postgres/instance-settings)

Cloud SQL's logical replication guide names the cause: a slot that is not actively used makes PostgreSQL hold WAL segments indefinitely, so disk use grows indefinitely. Retained WAL and logical replication snapshots from inactive slots are also included in backups, which can make restores time out. PostgreSQL adds that a slot also keeps `VACUUM` from removing catalog rows the slot still needs. [Configure logical replication](https://cloud.google.com/sql/docs/postgres/replication/configure-logical-replication) · [Replication slots](https://www.postgresql.org/docs/current/logicaldecoding-explanation.html)

## Check 1: find the slots and the WAL each retains

Cloud SQL's `database/disk/bytes_used_by_data_type` metric splits disk use by data type, which shows whether the growth is data or something else. Then list the slots on the primary: [Cloud SQL metrics](https://cloud.google.com/monitoring/api/metrics_gcp_c)

```
SELECT slot_name, slot_type, plugin, active, wal_status,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal,
       confirmed_flush_lsn
FROM pg_replication_slots
ORDER BY restart_lsn;
```

`restart_lsn` is the oldest WAL the slot's consumer might still need, and checkpoints keep WAL from that point on. `pg_wal_lsn_diff` turns the distance from the current position into bytes. `active` is false when nothing streams from the slot, and `confirmed_flush_lsn` is how far a logical consumer has confirmed receiving. On PostgreSQL 17 and later, `inactive_since` adds when the slot went idle. [`pg_replication_slots`](https://www.postgresql.org/docs/current/view-pg-replication-slots.html) · [WAL functions](https://www.postgresql.org/docs/current/functions-admin.html)

To see the WAL directory's total size directly, Cloud SQL documents `pg_ls_waldir()`, which needs a `cloudsqlsuperuser` user such as `postgres`:

```
SELECT pg_size_pretty(sum(size)) AS wal_on_disk FROM pg_ls_waldir();
```

## Check 2: whose slot is it?

A slot knows nothing about its consumer, so the name and plugin are the clues. Two kinds are easy to confuse:

-   **Physical slots** serve streaming replication. Cloud SQL read replicas use a replication slot and a WAL sender each, so a physical slot may belong to a replica that is restarting. List the primary's replicas with `gcloud sql instances describe INSTANCE --format='value(replicaNames)'` before touching one. [Instance fields](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances)
-   **Logical slots** carry a `plugin`, such as `pgoutput` for PostgreSQL's built-in logical replication or `wal2json`, and belong to a subscriber or a change-data-capture tool. Most such tools create and drop their slots themselves, so a leftover usually means the consumer was removed without cleanup. [Decoders and slots on Cloud SQL](https://cloud.google.com/sql/docs/postgres/replication/configure-logical-replication)

| Slot | Reading | Decision |
| --- | --- | --- |
| `active` true, retained WAL small | The consumer reads and keeps up | Not the cause |
| `active` true, retained WAL growing | The consumer reads but falls behind | Look at the consumer's throughput; dropping it would break a working pipeline |
| `active` false, physical | Possibly a read replica that is down or restarting | Check the replicas first. Do not drop it while a replica depends on it |
| `active` false, logical, consumer still deployed | The consumer stopped | Restart it. It resumes from its confirmed position, and the retained WAL drains as it catches up |
| `active` false, logical, consumer retired | Nothing will read this slot again | Drop the slot |

Dropping a logical slot discards the consumer's position. PostgreSQL no longer keeps the changes since `confirmed_flush_lsn` for it, so a consumer that comes back later needs a fresh initial copy.

## Decide: drop, cap, then shrink

Dropping the slot is a state change on the primary. It removes the slot and lets checkpoints remove the WAL it held:

```
SELECT pg_drop_replication_slot('SLOT_NAME');
```

[`pg_drop_replication_slot`](https://www.postgresql.org/docs/current/functions-admin.html)

To bound the next one, `max_slot_wal_keep_size` limits how much WAL slots may retain at checkpoint time. A slot that falls further behind loses the WAL it needed, its `wal_status` becomes `unreserved` and then `lost`, and its consumer cannot continue. Cloud SQL lists the flag with a range of 102,400 to 10,485,760 MB and no restart. The limit trades a full disk for a broken consumer, which is the right side of the trade only if the consumer can re-sync. [`max_slot_wal_keep_size`](https://www.postgresql.org/docs/current/runtime-config-replication.html) · [Cloud SQL flags](https://cloud.google.com/sql/docs/postgres/flags)

Freed WAL does not give back provisioned capacity. Automatic storage increases are permanent unless you shrink the storage manually, and a shrink requires downtime: the instance restarts when the operation completes, and no other operation can run until then. The documentation compares the downtime with restoring a read replica, and recommends migrating to a smaller instance when downtime must stay short. A cap on automatic increases, `--storage-auto-increase-limit`, keeps the next runaway slot from growing the instance unbounded, at the cost of reaching the limit sooner. [Storage shrink](https://cloud.google.com/sql/docs/postgres/about-storage-shrink) · [`gcloud sql instances patch`](https://cloud.google.com/sdk/gcloud/reference/sql/instances/patch)

## A worked fixture: two slots, two decisions

The fixture is illustrative. `shop-prod:europe-west1:orders-db` has `cloudsql.logical_decoding` on and one read replica. Since 2026-11-02 its storage has grown from 180 GB used to 610 GB, and automatic increases took the disk from 250 GB to 700 GB. The `orders` tables have grown by 6 GB. On 2026-11-23 at 08:40 UTC the slot query returns:

| slot\_name | slot\_type | plugin | active | wal\_status | retained\_wal |
| --- | --- | --- | --- | --- | --- |
| `orders_db_replica_slot` | physical |  | t | reserved | 48 MB |
| `orders_cdc` | logical | `pgoutput` | f | extended | 418 GB |
| `orders_search_sync` | logical | `wal2json` | f | reserved | 512 MB |

`pg_ls_waldir()` reports 419 GB. The 418 GB that `orders_cdc` retains is nearly all of it, and accounts for most of the 430 GB growth.

**`orders_cdc`: drop.** The slot belonged to `orders-cdc`, a Cloud Run service that streamed order changes to an analytics pipeline. It was deleted on 2026-11-02 when the pipeline moved to a nightly export. Nothing will read the slot again. The team drops it at 08:52. By 09:30, after checkpoints, `pg_ls_waldir()` reports 1.1 GB, and the disk shows 192 GB used of 700 GB. They set `max_slot_wal_keep_size` to 204800 MB (200 GB) and plan a storage shrink for the next maintenance slot, accepting its restart.

**`orders_search_sync`: restart.** The slot is inactive since 08:15. Its consumer, the Cloud Run job `search-sync`, still runs every 30 minutes, and its 08:30 execution failed at startup on a missing secret version. The slot holds 512 MB, the WAL since the 08:00 run. Dropping it would force a full re-index. The team fixes the secret reference; the 09:00 execution resumes from the slot's confirmed position, and its retained WAL falls back to a few megabytes.

## Where the checks mislead

A slot can be inactive between runs of a consumer that connects on a schedule. Look at the retained WAL over a few cycles before calling a slot abandoned.

`retained_wal` measures from `restart_lsn`, and WAL removal happens at checkpoints, so disk use falls some time after the drop, not at once.

Long transactions and `wal_keep_size` also keep WAL. If `pg_ls_waldir()` is much larger than the largest slot's retained WAL, look there too.

Dropping the last logical slot is how [a cutover to a logically replicated database](/learn/postgres-logical-replication-sequences-cutover/) ends; do it as part of that plan, not before it. If the slot came with the [logical decoding flag and its restart](/learn/cloud-sql-logical-decoding-flag-restart/), turning the flag off is another restart.

## Questions

### Why is my Cloud SQL storage growing when my data is not?

A common cause is WAL retained by a replication slot whose consumer stopped reading. `pg_replication_slots` with `pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)` shows how much each slot holds.

### Can I drop an inactive replication slot?

It depends on its consumer. A physical slot may belong to a read replica, and a logical slot's consumer loses its position and needs a fresh copy if it returns. Drop a slot only after you have found its consumer and confirmed it is retired.

### Will Cloud SQL storage shrink after the WAL is removed?

Used storage falls once checkpoints remove the WAL, but provisioned capacity that automatic increases added stays. Reducing it takes a manual storage shrink, which restarts the instance.

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

-   ### [Turning on Cloud SQL logical decoding: what the restart costs Cloud Run](/learn/cloud-sql-logical-decoding-flag-restart/)
    
    Breaking migrations The Proofline team November 23, 2026 6 min read
    
-   ### [Set sequences before cutting over to a logically replicated database](/learn/postgres-logical-replication-sequences-cutover/)
    
    Breaking migrations The Proofline team November 22, 2026 2 min read
