Subject: Re: pg_stat_statements has duplicate entries for the same query & queryId

From: "Daniel Verite" <[email-masked]>
Date: Mon, 19 May 2025 09:07:35 +0200

Jevon Cowell wrote:

> What I'm seeing is that for the same query *and* query id,
> there are two rows with different statistics data *at the same time*. For
> example one row can have 2 calls while another can have 4

That looks normal. The unicity to expect is on 
(queryid, userid, dbid, toplevel).

From https://www.postgresql.org/docs/current/pgstatstatements.html :

  This view contains one row for each distinct combination of database
  ID, user ID, query ID and whether it's a top-level statement or not
  (up to the maximum number of distinct statements that the module can
  track)

Best regards,
-- 
Daniel Vérité 
https://postgresql.verite.pro/

---

From: Michael Paquier <[email-masked]>
Date: Tue, 20 May 2025 06:51:23 +0900

>   (up to the maximum number of distinct statements that the module can

Yeah.  The uniqueness of the entries in the PGSS hash table is
enforced by pgssHashKey in pg_stat_statements.c.  Or an unknown bug
has been found, but there is no data proving that here.
--
Michael