Wal files not being removed from pg_wal folder

I have postgres V15. 2 node cluster with streaming replication enabled. I have wal_keep_size set to 256 and archiving is off. This should leave me with around 16 wal files in the pg_wal folder (16 MB each) but I have more than 30. Any ideas why they are not falling off?

HI,

All things being equal I would suggest that your WALs are being kept intentionally by postgres i.e. long running transactions, checkpoints etc.

Refer to this link and read the documentation regarding parameter wal_keep_size.

“… This sets only the minimum size of segments retained in pg_wal ; the system might need to retain more segments for WAL archival or to recover from a checkpoint …”

TIP: check replication latency when you see sudden increases in WALs as long running transactions can cause this to increase.

Hope this helps.