Thread

  1. Re: Improve pg_stat_statements scalability

    Julien Rouhaud <rjuju123@gmail.com> — 2026-05-23T23:25:57Z

    Hi,
    
    On Fri, May 22, 2026 at 06:15:00PM -0700, Lukas Fittl wrote:
    >
    > For archive's sake and others reading along, we had a productive
    > discussion about this today at PGConf.Dev.
    >
    > I've created a new wiki page combining the prior 2025 discussion, and
    > notes from today:
    >
    > https://wiki.postgresql.org/wiki/Scalability_of_pg_stat_statements
    
    Thanks a lot Lukas!
    
    Just a small clarification, I wasn't asking for a way to remember the last time
    a query was executed (although I think it's a very good thing to have), but
    remembering the time each query text was saved.
    
    In a reasonable system (that is a system where the number of entries doesn't
    grow much more than pg_stat_statements.max, ie, you can actually use the
    current version pg_stat_statements) you will likely get a lot of entries even
    if you filter out the entries that didn't get executed in the last X minutes.
    However, the vast majority of them should not be new queries.  So if you
    maintain an external system that snapshot pg_stat_statements once in a while
    you only care about the (possibly) missing query texts, which should be a very
    small fraction of all the records you otherwise need.