Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uGjhA-006cyA-4k for pgsql-general@arkaria.postgresql.org; Sun, 18 May 2025 19:29:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uGjh8-00BXFu-RL for pgsql-general@arkaria.postgresql.org; Sun, 18 May 2025 19:29:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uGjh8-00BXFl-G2 for pgsql-general@lists.postgresql.org; Sun, 18 May 2025 19:29:10 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uGjh5-002REX-2m for pgsql-general@lists.postgresql.org; Sun, 18 May 2025 19:29:09 +0000 Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id E207E2540085; Sun, 18 May 2025 15:29:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sun, 18 May 2025 15:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1747596546; x=1747682946; bh=K34DrQpRkSCZ0UWLlTrf5JGT9Fk1zvI37aksIA+Dy+s=; b= yutc74eJcpFQMWwlLiMPfpXTRj3PxoG6beyLfmQpwoKRUgnXKibYGXoaMXFm2xcH W4uM0oWmznyYoVXz0+FnMEG6NOWt0COYT59AW7Tvs6Fqo5WDCC9TcC9w06avp51c jT19tOuXC9AwGXCiiCHIRXSsXbntIgDGNnliMz2wdnwBqzU6EFLT2iGe8P+dDovG pMt3iZ7VtdibLb4alYKi57gmcHrP8B/N9gjCOhAKd5BEMVitj2n6G9qcQXb1+Vkt LVcJ6G/3AacJ1M3lMc7ezCT7EpCqDf3HOtS1+Ysu0zdN2BUvbK/xheyfdnCvS2fY hLVdMd9dscinZs4xIo+xPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1747596546; x=1747682946; bh=K 34DrQpRkSCZ0UWLlTrf5JGT9Fk1zvI37aksIA+Dy+s=; b=wPOsHct/TFHW5bvvl pZKAsyVqwVUth/iKN1aMZveR6SW4Os32+0FUi22xw8NtTrySPpSi+zy2u76zvKGR ptkDJfv9JuJkFmUiqPZNfb1RFaSj8JP49igZHxjv6szL6+JOnUEltEc9imGgKOy/ DNcpJz5P4CL4u74LJXAUNbONT+onLhk0gEiO/XV5+HNIlb2p7IGaqy/FPGd9Hsqx pVqQsCsu3tySzUpJQoxL2L78Dn/zz5J2/xl+fYwqMIbvISF/0fTIZ+VZ+jBelSvn PGqKAfe41NEV7oHkOeJiqnm1T/oCPc5zxwYahfhCIXzk9lWu92TtjtYDWU7tiIvc o5tYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdefudelfeehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddv jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeelgeevkeekkeeuiefg tdevieeluefhfedufeetkeejffekjeeujeehgeehgeektdenucffohhmrghinhepphhosh htghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhgtohif vghllhesrghtlhgrshhsihgrnhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhgvghnvg hrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 18 May 2025 15:29:06 -0400 (EDT) Message-ID: <5b89abb9-1c71-4836-9cf6-56c694e80f01@aklaver.com> Date: Sun, 18 May 2025 12:29:05 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_stat_statements has duplicate entries for the same query & queryId To: Jevon Cowell , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/18/25 12:20, Jevon Cowell wrote: > Hi Folks! > Let me know if there's a better mailing list to ask this in. > > I have a statistics collector that collects data from various postgres > statistics tables, pg_stat_statements being one of them. This is done on > an entire fleet of Postgres databases. From the collected data we record > the timestamp of each collection in the query itself as extract(epoch > from now()) as ts. 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. Anyone else run into this or have any idea why this can occur? From here: https://www.postgresql.org/docs/current/pgstatstatements.html queryid bigint Hash code to identify identical normalized queries. query text Text of a representative statement From here: https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT "now() is a traditional PostgreSQL equivalent to transaction_timestamp()" and "transaction_timestamp() is equivalent to CURRENT_TIMESTAMP, but is named to clearly reflect what it returns." Therefore now() is pinned to the time the transaction started. Consequently it is conceivable that the queries actually ran at different times but got stamped with an identical timestamp via extract(epoch from now()) as ts. > > Regards, > Jevon Cowell -- Adrian Klaver adrian.klaver@aklaver.com