On Fri, Aug 15, 2025 at 04:13:30PM -0400, Andres Freund wrote: > IMO, the only way to actually make pg_stat_statements scale is to move to a > model much more like our regular stats. I.e. accumulate counters in backend > local memory and only occasionally update the shared stats.
Agreed. I remember discussing something similar at pgconf.dev this year. > FWIW, I'd not be surprised if moving to atomics would often cause *slowdowns* > compared to using the spinlocks. You'd replace one atomic operation with > dozens, to update all those fields individually. With loads of cacheline > pingpong inbetween. Right. At some point I tried moving most things to atomics and leaving the rest behind the spinlock, and IIRC there wasn't really any improvement. I didn't dig into whether that was because of atomic-related cache line ping-pong or the existing spinlock, but regardless, I quickly discarded that idea. -- nathan