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 1voJs1-001HjT-1g for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 11:19:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1voJs0-003WqF-28 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 11:19:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1voJs0-003Wq7-15 for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 11:19:28 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1voJrx-00000001Lsn-46VY for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 11:19:27 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-42fb4eeb482so309394f8f.0 for ; Fri, 06 Feb 2026 03:19:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1770376765; x=1770981565; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:user-agent:reply-to :references:in-reply-to:message-id:date:cc:subject:to:from:from:to :cc:subject:date:message-id:reply-to; bh=M8Hc4HsRLgd5Uf1ej0zPGuiYRNh1Z6zT2G1CY8Aoax0=; b=Sq1ZMM5ktDn/+FRTkGCLImgXJIX1SPlyTLoe1KS3wTnzKm1NZQ9N4LRJ3xUNTBJCAn 6229uuCj2DMrYua6tyIjC4+d6ow48QhpNQKxQkS41ER/3ASNaiwy7oBHWw7r4lo69Ds4 hYvXfuy0teBxN2aWM2rJFNnBEuWkezaDl8X3ZS6zBvkZtKjbUj+yKwd0qxXVZ24zRo2V /oao4ksEpxMT28tGb8UsFZiizo4zWJc+63ZBudTqTMz+7JKzJMvA+xcprsJTD1a2sdlx FRbyqmjko4bkG7D81LFYkC2QZ98M9OJWH4Cqb9KBQKRmSLzzrtLKu/4dJIU75XbL0T7+ fV2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770376765; x=1770981565; h=content-transfer-encoding:mime-version:user-agent:reply-to :references:in-reply-to:message-id:date:cc:subject:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M8Hc4HsRLgd5Uf1ej0zPGuiYRNh1Z6zT2G1CY8Aoax0=; b=AuYyOFup4TlJequ+KjK7oeALcwOllSEMfP4Uzh0nm+2IbpirXJ+OoQc/SepbbRw2c5 NwCSX0vj37pH71Z7xAd1+BAeTjoj8xJ4rVJCmbEUXcs+BOk3HlYXdT603euGq/Qgcq8U kDBwnXeqLyUuEhv6WSjzUvm0rYksQqf4wPhIGUPsA6LI60WvU41W0Yrwjro16KUlz0RK YgfVev4aH1XS/zKi/o72rInMVyZrnNL53SjAhd2tNVtUkIYDPTUttrYIkxFCF9mG2SNO GcLOoHZCV9mIpgSupWyf33zV0UUH/7pt82xGRdPpJFbP/JdKknKwZbHDYHu83ene7MYB i2eQ== X-Forwarded-Encrypted: i=1; AJvYcCWjqkHtmZqdFKS5CCwnysACcTLobl0w6y817/pVH+RhdBvfwkpZLXkTR4PYcBiSfgmY0/2XzDZbRhlUBgZ5@lists.postgresql.org X-Gm-Message-State: AOJu0Yx+M4m/zOgor39pAFsOMcCP8CO3vabb/Cpyx2ccBRpulLLGPnqb OlU4PSObwjt/iDG16BfcHBcelSodm3nJI/+VIev9mEWaaCfrloiZ1jqzTy31OhgRnfI= X-Gm-Gg: AZuq6aLT8ASNIwOLbKV6zbWwrUpOvk4EzjAqjoBh5ovbyALG6rwBHl2z6KDWiChGCBy kpt8iMqnABDzdgfHs3Y7ko22MmPwabekgmRs0sG5HEtMtoLijpNfvSzmyz37bl4byjUSQUW6FZZ Bw4F98xhW1wcpBK0Dp+5JPrnnmI1h/INw/nMxivU4M7e8B7Izsrf+6T6Bkw4KCTiULesESKHdcq +OBM97u5GOu7dKhyEKbScNpNUYVUwdxLV5VX7MJMNUEhzQasV9NA7DK7oS6T6WDaN7s0IXyBYiP pVmUqB4MkUWOftXZvVpd5IyUQE3VcqNQQNC5I7H20QWM/e9mw/0v1IYIZ+rX6wYVgrYs90w/jE8 V2T1AztvZEArKmXfj28j5DZBgKKz0bZCyrdFtJbr3YhPlibJqpUqPR2jAvKDCe5zJiZJ/r3q3B+ 11/PSgv+QWQ4R2Ka93LILarypsnLVB/ETpIJub8MsyhOyDF8rBfQ== X-Received: by 2002:a5d:5f50:0:b0:431:b6e:8be3 with SMTP id ffacd0b85a97d-43629380ed0mr3931877f8f.38.1770376764685; Fri, 06 Feb 2026 03:19:24 -0800 (PST) Received: from ?IPv6:::ffff:192.168.0.101? ([62.197.243.85]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43629745f7asm4696238f8f.33.2026.02.06.03.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 03:19:24 -0800 (PST) From: "Pavlo Golub" To: "Christoph Berg" Subject: Re[2]: [PATCH] Add last_executed timestamp to pg_stat_statements Cc: "Sami Imseih" , "Bertrand Drouvot" , "pgsql-hackers@lists.postgresql.org" Date: Fri, 06 Feb 2026 11:19:26 +0000 Message-Id: In-Reply-To: References: Reply-To: "Pavlo Golub" User-Agent: eM_Client/10.4.4209.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > >I still believe that storing execution start time is the wrong thing >to do as it will miss all long-running statements. Consider this >timeline: > >09:55 get all stats changed since 09:50 > -> doesn't see the statement because it hasn't started yet >09:57 start long-running statement >10:00 get all stats changed since 09:55 > -> doesn't see the statement because it's still running >10:02 long-running statement terminates, storing 09:57 as timestamp >10:05 get all stats changed since 10:00 > -> doesn't see the statement because it's too old > Thanks for sharing this. I spent a sleepless night and it seems I found=20 the solution for the issue. If we do WHERE last_execution_start + max_exec_time * INTERVAL '1 ms' > NOW() -= =20 polling_interval we will grab all long-running statements. The worst thing that might=20 happen, if some query has significant run time deviation, then we could grab it several times.=20 But again this is far better than re-fetching thousands of rows every time. For short queries it will just work as expected. "Issues" might be only=20 with long queries with a high deviation longer than polling interval. But fetching one or two=20 rows once in a while is not a problem.