Commit 0c56c61
Introduce inactive_timeout based replication slot invalidation
Tools that create replication slots (e.g., for migrations or upgrades) may
fail to remove them if an error occurs, leaving behind unused slots that
take up space and resources. Manually cleaning them up can be tedious and
error-prone, and without intervention, these lingering slots can cause
unnecessary WAL retention and system bloat.
Till now, postgres has the ability to invalidate inactive replication slots
based on the amount of WAL (set via max_slot_wal_keep_size GUC) that will
be needed for the slots in case they become active. However, setting an
optimal value for this is tricky since the amount of WAL a database
generates, and the allocated storage per instance will vary greatly in
production. A high value may allow orphaned slots to persist longer than
necessary, leading to system bloat by retaining WAL unnecessarily.
This commit introduces idle_replication_slot_timeout, a simpler and more
intuitive way to manage inactive slots. Instead of relying on WAL size,
users can set a time limit (e.g., 1 or 2 or n days), after which slots that
remain idle for longer than this amount of time are automatically
invalidated during checkpoints.
Note that the idle timeout invalidation mechanism is not applicable
for slots that do not reserve WAL or for slots on the standby server
that are being synced from the primary server (i.e., standby slots
having 'synced' field 'true'). Synced slots are always considered to be
inactive because they don't perform logical decoding to produce changes.1 parent 217919d commit 0c56c61
File tree
15 files changed
+368
-86
lines changed- doc/src/sgml
- src
- backend
- access/transam
- replication
- utils
- adt
- misc
- bin
- pg_basebackup
- pg_upgrade
- include
- replication
- utils
- tools/pgindent
15 files changed
+368
-86
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4429 | 4429 | | |
4430 | 4430 | | |
4431 | 4431 | | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + | |
4432 | 4472 | | |
4433 | 4473 | | |
4434 | 4474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2390 | 2390 | | |
2391 | 2391 | | |
2392 | 2392 | | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
2393 | 2398 | | |
2394 | 2399 | | |
2395 | 2400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2619 | 2619 | | |
2620 | 2620 | | |
2621 | 2621 | | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
2622 | 2629 | | |
2623 | 2630 | | |
2624 | 2631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7337 | 7337 | | |
7338 | 7338 | | |
7339 | 7339 | | |
7340 | | - | |
| 7340 | + | |
7341 | 7341 | | |
7342 | 7342 | | |
7343 | 7343 | | |
| |||
7792 | 7792 | | |
7793 | 7793 | | |
7794 | 7794 | | |
7795 | | - | |
| 7795 | + | |
7796 | 7796 | | |
7797 | 7797 | | |
7798 | 7798 | | |
| |||
0 commit comments