Subject: pg_stat_statements_reset

From: Fabrice Chapuis <[email-masked]>
Date: Mon, 16 Dec 2024 16:30:39 +0100

Hi,
This query seems not resetting stats for databae mydb

SELECT pg_stat_statements_reset(
    NULL,  -- userid: NULL means "all users"
    (SELECT oid FROM pg_database WHERE datname = 'mydb'),
    NULL   -- queryid: NULL means "all queries"
);
│ pg_stat_statements_reset │

(1 row)

Something wrong in the use of the function pg_stat_statements_reset?

Regards,

Fabrice

---

From: Tom Lane <[email-masked]>
Date: Mon, 16 Dec 2024 10:47:01 -0500

>     NULL   -- queryid: NULL means "all queries"

Where did you get the idea that NULL means "all"?  AFAICS
that function is strict, meaning it won't run at all for
null input.

			regards, tom lane

---

From: Guillaume Lelarge <[email-masked]>
Date: Mon, 16 Dec 2024 16:55:54 +0100

Hello,

> that function is strict, meaning it won't run at all for
You should try:

select pg_stat_statements_reset(dbid => oid)
from pg_database
where datname='mydb';

Works on my test case (and I find it easier to understand, but that may be
subjective).

-- 
Guillaume.

---

From: Fabrice Chapuis <[email-masked]>
Date: Fri, 20 Dec 2024 10:43:19 +0100

Thanks for your explanations Tom, Guillaume, your solution works fine for
me too.

Regards

Fabrice