Back to PostgreSQL
GSoC 2026

Reducing pg stat statements LWLock Contention

pg_stat_statements tracks query statistics across a PostgreSQL cluster, but its single-LWLock architecture creates a scalability bottleneck under high unique-query-rate workloads. When pg_stat_statements.max is undersized, deallocation and reset operations hold an exclusive lock while performing expensive operations (O(n log n) sort, full hash table iteration), blocking every backend on the server. My benchmarks on PG 19devel show 90-100% of active backends blocked on the pgss LWLock during deallocation churn. This project proposes a multi-part fix: (1) a pending-entry queue to avoid blocking on new entry insertion, (2) a restructured deallocation critical section that moves the sort outside the exclusive lock, (3) exploration of lock separation between structural changes and counter updates, and (4) an optimized reset path. Deliverables include a repeatable benchmark suite, patches for each optimization formatted for pgsql-hackers review, before/after performance measurements, and documentation.

Project details

Contributor

hoangquan456

Mentors

Not available

Technologies

Not listed in the archive