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 1vs6kG-0063qh-27 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Feb 2026 22:07:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vs6kE-0068k5-1k for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Feb 2026 22:07:06 +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 1vs6kE-0068jv-0p for pgsql-hackers@lists.postgresql.org; Mon, 16 Feb 2026 22:07:06 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vs6kB-00000000xWP-2liN for pgsql-hackers@lists.postgresql.org; Mon, 16 Feb 2026 22:07:05 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-b8fa79b9fcdso607088766b.0 for ; Mon, 16 Feb 2026 14:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771279622; cv=none; d=google.com; s=arc-20240605; b=l2nuOCZJb8BzbWCfsKBoP6231Fv1wmsv5eeLAtjyk72u3+17lQuC7VWpnGioXTimee XHmC7tL0Baqk8XwOOrok/6TyNa45h5YMcgt7Wo9fp9BC9IMkNc9S0HzKaMb7gBpMrrMy 8vz4FFsrgVHIWMWu8cw6T1YsZfIFBRlYBU4otysKmf9u/RHVWp7jxV+uotcSh7YWc6F4 ybZzCIjpt6LqWNzVwIZz0Xps65ZcXhDQPT7ikgBZ4DXFyb/+xPGsqEkt71o6x6xRiLOe qSgnSOTiDpbZ+mi9q/QE2vI5M7ced8dzkVAql15Fehem4rIugyPm7Ssx6eFlLSfxO02X o+6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=wzhOWdWGolhY+SrMayg0abjDFvgugX5ryC58e2kFaD8=; fh=/50Z1POH2onda3WVMZJEpfZ8clyxOaGhoWS6t+dkYbE=; b=eq17oMzCYFqthkBt16lXYLMekY2PZlWB0+Xyg7pUNrLBnzs8p/TGDVH+FWthuGVFP3 jYwWjr8wcDCcJCAgczFDhWLgAsQUQlQ1neAvBaS3qx4UggI0UtVJvf4SvrkE3EAdIYlh wwQ6oImJLFMRJz9T4ICEd+Zbpi2JxxuJeT5et7s3FYogZV+1EYjNs9hcVZ2+OVE9qApO eRDvTD7EomYfpGaNCyD3b8S/+/7afjh536pLUjvLkO/TEZOvklLayZrD6OkHKO0Hw6Oi ZhilAm1ts8eSxPFBEzKB0wLOIW2VpAEIK4yuA7zwhY18gN5blUcgVKCG2w5KiFqGvsD0 Qx/w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771279622; x=1771884422; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wzhOWdWGolhY+SrMayg0abjDFvgugX5ryC58e2kFaD8=; b=iDjPxjDcF6JvVS+pnEuNoVw05q1pNGPG2fLZ//luLCi1x1dCU/5qlGvLhOMLrTrSub NJG/vdPNe2NyI46VEy4TfyIYIiqOvjwrtqOf8N5CTmuYZ8/P44cHI54N3xtIP9GEC6lv ruLlH2ncBTeFJRb5zi3cYX5VEuOKyWtyc0w7vspvT0AH8myRlu2JSx+Jdlr48gEqmx+W Hn3UA7yA6EZSF+GTHo13hu8Q0PU7duAjcTdoCyef088brNWtNIVHvxEFZxM7zPLeHt3Q KcB/qKrDbYvneiVUuBPZfaFXjJoru6NmsMSBG0KfzHOKdiVxpJoNfT5mGCa1gqnGa+NO Qh8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771279622; x=1771884422; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wzhOWdWGolhY+SrMayg0abjDFvgugX5ryC58e2kFaD8=; b=bsxm5ni4TPH1Dbrt0GlmqY9hyvGijwzw2SHkJPAcVwiACbVXd82ZhyEWxL/q9fe9sH FMumve7324IgI/hp6PqEruktwCgpskG36jk3FDPIHobEQ52iSaNm7waRsOIWWL2DfiIS qJwmxbjp3ORxeod+YbTnRY5iggk/0zz8rwAtkw69FHBWyv15JUaDTx4qeAHyxQsOkaop 3nX7B1vhRab2iqF4BLA4JiwFcCo4qtSIKRxmVhVEUQF/B/dhZ4a8Ta4PfdaUQyvHcO9V 1hbdwHKu5xSbXEWi+y7f0xStwYPQtIEegHLXf1FBjOC1Ljh4qjXmr32z8kE19I6PwTak wvEA== X-Forwarded-Encrypted: i=1; AJvYcCXnw5ELoCxSqr34eHuIsI7EjQS0EkG8Vme+Av09gN4vQugR0TtQmiEAvpKP8+CQYy7Sfu6WueNvx6HmZbah@lists.postgresql.org X-Gm-Message-State: AOJu0Yz82lM2ib9ng+jmzGGUDfcAFbxxtLBjCS3qBposG005EmtHLIUT s1b9tgzsG+VmCtOhCS5CvWwBPgi1Jg7yg/xixZJKBOl448sO5hCWy+F4CkkgFQcdlDfspE+D/h7 YM0cmmGyisve/LRS1mpmcpdAdhDniKa4= X-Gm-Gg: AZuq6aKT9iCo/YJ3jPv1Atq7reKFcl3JjVJn4RK/HpmYHD2Eocz6N8CJ7kaVjVwiPHI YO77QEk9+XX4WyKfTK6RXY7A3c0aptd8qRG60us+/6epARb7T6C2ioLgh84s6p62Rx76bHuzCjD 6g4aBssV1maPtinvE7XzVCBDg5F39wvchXu9dwy9uYrpfc6vVr+oTHFWQZ0KqSWfm5HwdZDxn6+ vwbwuZe1xKq7OOoY1ozdIhXvQjghUobPNjyvFtfDeIhRbCh1xUR4K9Qfnhx4y0USjf1FzYHUZ51 ew== X-Received: by 2002:a17:906:fe0c:b0:b3a:8070:e269 with SMTP id a640c23a62f3a-b8fc0548fc0mr644536266b.14.1771279621575; Mon, 16 Feb 2026 14:07:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Mon, 16 Feb 2026 16:06:50 -0600 X-Gm-Features: AaiRm53rCrf37-uW2-ZckkvzIbzRR-qhxZnmK4Z72yIq2_ss3PeX9njQVqyHEm4 Message-ID: Subject: Re: [PATCH] Add last_executed timestamp to pg_stat_statements To: Pavlo Golub Cc: Christoph Berg , Bertrand Drouvot , "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, > I simplified the implementation to use GetCurrentTimestamp() directly > instead of calculating the timestamp from I don't think it will be acceptable to add GetCurrentTimestamp() at the end of every execution. We take extra measures to avoid such overhead in core, and I don't think we should impose this on pg_stat_statements users as well. For example, in c037471832e which tracks lastscan: " To make it easier to detect the last time a relation has been scanned, track that time in each relation's pgstat entry. To minimize overhead a) the timestamp is updated only when the backend pending stats entry is flushed to shared stats b) the last transaction's stop timestamp is used as the timestamp. " My opinion is still that using the last_start_time will be useful for monitoring as you demonstrated [0], albeit with some complexity involved for the monitoring client, will be the best way and safest way forward. Others may disagree. > GetCurrentStatementStartTimestamp() + total_time. The previous optimization was > premature, benchmark testing proves GetCurrentTimestamp() adds no > measurable overhead. I am not sure if this benchmark is enough to build confidence in this approach. Workloads with nested queries and tack. 'all' are now paying an even heavier cost. Also, quickly looking at v4, you probably want to call GetCurrentTimestamp() when kind == PGSS_EXEC only. Assert(kind == PGSS_PLAN || kind == PGSS_EXEC); + /* + * Get current timestamp before acquiring spinlock to avoid holding + * the lock during syscall. + */ + stats_updated_at = GetCurrentTimestamp(); + /* [0] https://www.postgresql.org/message-id/ema0100e49-522e-4b8f-9c25-9257af1f0793%40cybertec.at -- Sami Imseih Amazon Web Services (AWS)