ERROR database replication_error ai_generated true

ERROR: replication slot "slot_name" is active for PID 0. WARNING: terminating connection because of crash of another server process

ID: database/pg-replication-slot-inactive

Also available as: JSON · Markdown
85%Fix Rate
87%Confidence
42Evidence
2023-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
16 active

Root Cause

A logical or physical replication slot is inactive, causing WAL segments to accumulate on the primary because PostgreSQL cannot discard WAL that the slot's consumer has not yet processed. This leads to disk exhaustion. Common when a subscriber disconnects, a Debezium connector goes down, or a standby is removed without dropping its slot.

generic

Workarounds

  1. 92% success Drop the inactive replication slot to release accumulated WAL
    Identify inactive slots: SELECT slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS lag FROM pg_replication_slots; Drop unused slots: SELECT pg_drop_replication_slot('slot_name'); Then recreate the slot and re-sync the subscriber.
  2. 85% success Fix the subscriber or connector that owns the slot to resume consumption
    Check the subscriber's logs for connection errors. Restart the logical replication subscriber (ALTER SUBSCRIPTION sub_name ENABLE) or Debezium connector. Verify connectivity between primary and subscriber. Monitor replication lag with pg_stat_replication.

Dead Ends

Common approaches that don't work:

  1. Deleting WAL segments manually from pg_wal directory 95% fail

    Manually removing WAL files corrupts the replication stream and can make the database unrecoverable. PostgreSQL manages WAL files internally and requires them for crash recovery and replication. The slot will still retain its position, so new WAL segments will continue to accumulate.

  2. Setting max_slot_wal_keep_size without also monitoring and dropping unused slots 60% fail

    max_slot_wal_keep_size caps WAL retention per slot, but when the limit is reached, the slot becomes invalidated and the subscriber must be re-initialized from scratch. This does not fix the root cause of why the slot consumer is not keeping up.

Error Chain

Leads to:
Preceded by:
Frequently confused with: