---
title: "Cap and watch replication slots · Agent Wranglers"
url: https://agentwranglers.se/playbook/events/publishing-events/replication-slot-limits
id: EVT-8
level: Required
risk: outage
updated: 2026-10-27
build: a2a6bdfed830
tokens: 771
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Cap and watch replication slots

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Publishing events](https://agentwranglers.se/playbook/events/publishing-events.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: EVT-8
- Level: Required
- Chapter: [Publishing events](https://agentwranglers.se/playbook/events/publishing-events.md)
- Rule: Cap how much log each replication slot may hold, and alert when a slot falls behind. Drop a slot within a day of retiring the consumer that used it.
- Check: The database settings show a cap on slot log size. Stop the consumer on staging and keep writing. The alert fires before the cap, and the disk stays below 80 percent full. The list of slots matches the list of running consumers.
- Risk: The app down or unusable
- How: A slot makes the database keep its log until the consumer confirms it. When the consumer stops, the log grows until the disk is full and the database stops taking writes. In PostgreSQL, set `max_slot_wal_keep_size`, and from version 18 also `idle_replication_slot_timeout`. Alert on the log each slot holds, as [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-resilience/exhaustion-alerts.md) says. A slot that passes the cap is invalidated, so its consumer must then copy the tables in full again.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### SQL example

```sql
-- PostgreSQL: log held by each slot, for the alert
SELECT slot_name, active,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS log_held
FROM pg_replication_slots
ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) DESC;
```

## Sources

- [PostgreSQL max_slot_wal_keep_size](https://www.postgresql.org/docs/current/runtime-config-replication.html)
- [PostgreSQL Replication slots](https://www.postgresql.org/docs/current/warm-standby.html)

## Related rules

- OPS-42 [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-resilience/exhaustion-alerts.md) in Operations and observability

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/events/publishing-events/replication-slot-limits">Agent Wranglers integration and events playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Read changes from the database log](https://agentwranglers.se/playbook/events/publishing-events/log-based-cdc.md)
- Next: [Choose the partition key for the order you need](https://agentwranglers.se/playbook/events/publishing-events/partition-keys.md)
- [Publishing events](https://agentwranglers.se/playbook/events/publishing-events.md)
