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.96) (envelope-from ) id 1vpMvL-006fhC-2P for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Feb 2026 08:47:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vpMvK-009pb6-2V for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Feb 2026 08:47:14 +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.96) (envelope-from ) id 1vpMvK-009pay-1Z for pgsql-hackers@lists.postgresql.org; Mon, 09 Feb 2026 08:47:14 +0000 Received: from goedel.df7cb.de ([49.13.90.212]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vpMvH-00000001FRk-48a7 for pgsql-hackers@lists.postgresql.org; Mon, 09 Feb 2026 08:47:13 +0000 Received: from msg.df7cb.de (unknown [IPv6:2a02:908:1472:9340:f0ad:fc6e:9c86:f1dc]) by goedel.df7cb.de (Postfix) with ESMTPSA id 6FF1972BF; Mon, 09 Feb 2026 08:47:08 +0000 (UTC) Date: Mon, 9 Feb 2026 09:47:07 +0100 From: Christoph Berg To: Pavlo Golub , Sami Imseih Cc: Bertrand Drouvot , "pgsql-hackers@lists.postgresql.org" Subject: Re: [PATCH] Add last_executed timestamp to pg_stat_statements Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Re: Pavlo Golub > How about > TimestampTz stmt_end = TimestampTzPlusMilliseconds( > GetCurrentStatementStartTimestamp(), > (int64) total_time > ); > We have total_time as an argument already! No kernel calls, sweet and easy! Cool idea! Re: Sami Imseih > I think it's better because last_execution_start is already a known > timestamp in pg_stat_activity.query_start and some tool that finds a > long running query in pg_stat_activity, knowing the > query_start they could then go look it up in pg_stat_statements. That only works if a) the query was not yet overwritten in pg_stat_activity and b) neither in pg_stat_statements. Optimizing for that use case seems pretty narrow. > What I'm really getting at is separating these fields will open up > more use cases, IMO. Generally, I think pgss should have cumulative statistics, and less about individual executions, so I'm not really sure what practical problem "last start" and "last runtime" would solve. The last_stats_update column we are talking about here is different in the sense that it's not about an individual execution, but infrastructure for retrieving the stats sensibly. Christoph