Re: Improve pg_stat_statements scalability

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, lukas(at)fittl(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Improve pg_stat_statements scalability
Date: 2026-06-02 23:53:43
Message-ID: CAA5RZ0s17LnC+31V6=qTrnJGjz7OLb+mkw4dMeiZM6bUOymoxw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > As far as I can see, the current implementation does not apply any
> > throttling to calls of this API. In theory, a large number of backends
> > could invoke it frequently and generate a high flush rate. For
> > example, if 1000 backends were to call it once per second, that would
> > result in 1000 shared-stats updates per second.
> >
> > Whether such a usage pattern would occur in practice is a separate
> > question. However, given that existing pgstat code uses
> > PGSTAT_MIN_INTERVAL to limit flush frequency, it seems to me that
> > anytime stats should probably retain a similar restriction.
>
> Hmm, OK. One cost in this decision is that it could randomly make the
> tests randomly slower, which is one reason why this patch has been
> added to this thread.

The throttling does make the tests longer, but we can do similar to what
was done in f1e251be80a, and disable PGSTAT_MIN_INTERVAL if
injection points are enabled.

- /* 50 tries with 100ms sleep between tries makes 5 sec total wait */
- for (tries = 0; tries < 50; tries++)
+ /*
+ * Retry up to 50 times with 100ms between attempts (max 5s
total). Can be
+ * reduced to 3 attempts (max 0.3s total) to speed up tests.
+ */
+ int ntries = 50;
+
+#ifdef USE_INJECTION_POINTS
+ if (IS_INJECTION_POINT_ATTACHED("procarray-reduce-count"))
+ ntries = 3;
+#endif
+

--
Sami Imseih
Amazon Web Services (AWS)

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Henson Choi 2026-06-02 23:50:28 Re: Row pattern recognition