PostgreSQL primary WAL sender CPU spikes and replication lag after enabling frequent TLS renegotiation on streaming replication
Environment
PostgreSQL 13.7 primary on Debian 11 (8-core VM), three synchronous replicas on separate hosts. Streaming replication over TLS (server certs) through a TCP load balancer that enforces SSL session renegotiation every 60s. wal_level = replica, max_wal_senders = 10, synchronous_commit = on.
Symptoms
After configuring the load balancer for aggressive TLS renegotiation, WAL sender (walsender) CPU usage spikes from <5% to 80–100% during renegotiation events and secondaries lag by several seconds to minutes. Replication slot reports 'streaming' but standby replay falls behind. When the load balancer's renegotiation interval is increased or disabled, CPU and lag return to normal.
Observations
GDB/strace on the walsender processes during spikes shows repeated SSL handshake operations and blocking reads/writes. PostgreSQL logs include repeated 'terminating walsender due to administrative action' messages correlated with load balancer's SSL reconnects. Network captures show TCP sessions closed and new TLS handshakes every 60s. No network packet loss outside the deliberate renegotiation. CPU profiling indicates most time spent inside OpenSSL library crypto operations on the primary host.
Already attempted
Increased max_wal_senders and tuned wal_sender_timeout (no measurable improvement). Upgraded OpenSSL to latest patch in distro (no change). Temporarily bypassed the load balancer (direct IP TLS) — issue disappears. Tried enabling session resumption on the load balancer but sessions still invalidated by its policy.
Question
Why does frequent TLS renegotiation cause WAL sender CPU spikes and replication lag, and what safe configuration changes on server, load balancer, or PostgreSQL can mitigate the problem without removing TLS protection?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases31% match
PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases26% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases25% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases25% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases23% match
PostgreSQL background writer and checkpoint IO spikes after increasing shared_buffers on primary
Open0 answers