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 1vgMIy-00BLRu-2v for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 12:18:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgMIx-00Gn1m-2u for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 12:18:24 +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 1vgMIx-00Gn1e-1u for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 12:18:23 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgMIv-000c7I-1n for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 12:18:23 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-47f5c2283b6so5205925e9.1 for ; Thu, 15 Jan 2026 04:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768479495; x=1769084295; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=+oJolgnCFlxVb0KwlGa4S5eTF0SR7v4+OpuCYmOuvD0=; b=M3JimfYFe/NuJ/42PWqtDLG/y2JKvVISbTGGLSITYEMAqIgJxAMqG+9ecOB5a4Z14X gu2xA4MWmbxCyatdUjrHm4YPtMaE6atgkDK3SWAkHm2OMJZYKrZ9H9QrA7+YoqIreCOc Ko5PbZqLxLls/V7noJZQeVnswodsDKoFbtM/kGSYAGhCOqmE4Tf2BmNquIoFzeq7ufAQ ytMWJOhREQ+jp9nbuZeN6SH08QnQI26CrSMMF8mTHpwPXu1y1niGtHtahQ+5pGiS19nc UAUpmyMvyJt3zE4NedVbgm6sc91mbGSQJayMYAcgT1SM9FjCaUtMHVO/uqacvC2su34s hBkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768479495; x=1769084295; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+oJolgnCFlxVb0KwlGa4S5eTF0SR7v4+OpuCYmOuvD0=; b=naXt01Wi+QHT64c4dwYDeoPHRzRVs5gud865qcU1YUAMqo5acB6BVATO3QshOuuZ9A Hkns6bBL+9hiSoN11dE6ESvDzEuW4cw5FoM5HhxiWnWP2+u1ldhU5KQI9sCAkN/G+RR8 i3RGDMOBUb92BmDS9y3ReKP9zELD98zbO9kM6ltSPZ0sy7Sa4d3BBa6go1pR6CSGJvEb a/YxT69TkOMYAeXXNsjER5cOQaVChC1PD/Prwk2qKYrcQPNdn7u+LfDm6wor1D6KWR5U 2vMWF+UsFYFBGtvrmnwtl79OY9bWfasXnlDUw1R2cTl9EEKKeBDqdCvVzMSde82lNePc mgNA== X-Gm-Message-State: AOJu0Yw23TiWUrJQ1BxlwbvZ+d5Dhy/ZaF7Zlef2ZUNATCu7F5xasKSj LOvSbXUCOYBFC7NeSnazMNJo3vSvdDnSHt3ziq5CkcdD+wghMgyar8XEdPKj5w== X-Gm-Gg: AY/fxX6labOTMY57OZosIT2k+/QQTyfwF0NL0okj+LjyWnoF4M/dzG7dsfsky8MRfmz N5VFOUofo/ZVTi4kF20WE41+0r4KzzOA2Gu0NxI9uSA+AaikhF0jCDYyxWCZosDXNGEaAaWwsXP AdHWtAi03GQUCQfCZoTUOrzkzYtjLzxwYaoPoeq2ycqQ3eM8qqUnio407aubWrOdIcdkRFVgKLR 4Nxgr5t4RiPODtPq3qZl8K5itMtrrNn5gDKyid510rmqHdPEZ871NuoOZkkmqi8VJ0gfLEbsyE/ Jt0Gri13rlwCoFuI04ek4MOQ/WWkzc52dH1Z53fj0oTdi+ZmehYkhy8g4Ml/O87yUjKLKjtf2Vd YzfgoqUoFeQJmsR5dwMjxr9FIWD6tUYY2M/WOijR9+iPftxvKvSqk3Hy1rix28xAzO8aLj2tbPg u4tEWlch4l4wx7aySjV/KiOdwTXqG4zM95cHxs6GHorF/c66C/1VBYvqImSpUv3o1TDcvQirNZO TNNJpS2p/V5qxC8heWMdUIGMbLuQwTYH6L7fpVtzClDLA== X-Received: by 2002:a05:600c:8b76:b0:477:5c58:3d42 with SMTP id 5b1f17b1804b1-47ee32ffaa7mr64598895e9.10.1768479495194; Thu, 15 Jan 2026 04:18:15 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-434af6d90aasm5503915f8f.29.2026.01.15.04.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 04:18:14 -0800 (PST) Date: Thu, 15 Jan 2026 12:18:13 +0000 From: Bertrand Drouvot To: Sami Imseih Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Flush some statistics within running transactions Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Jan 14, 2026 at 09:54:17PM -0600, Sami Imseih wrote: > I took a quick look at the patches and I have some general comments. Thanks! > > > Long running transactions can accumulate significant statistics (WAL, IO, ...) > > that remain unflushed until the transaction ends. This delays visibility of > > resource usage in monitoring views like pg_stat_io and pg_stat_wal. > > +1. I do think this is a good idea. Long-running transactions cause accumulated > stats to appear as spikes in monitoring tools rather than as gradual activity. > This would help level out, though not eliminate, those artificial spikes. Yeah. > > The 1 second flush interval is currently hardcoded but we could imagine increase > > it or make it configurable. > > Someone may want to turn this off as well. I think a GUC will be needed. I gave this more thoughts and I wonder if this should be configurable at all. I mean, we don't do it for PGSTAT_MIN_INTERVAL, PGSTAT_MAX_INTERVAL and PGSTAT_IDLE_INTERVAL. We could imagine make it configurable if it produces noticeable performance impact but that's not what I observed. > > RELATION stats are making use of FLUSH_MIXED: > > > stats: numscans, tuples_returned, tuples_fetched, blocks_fetched, > > blocks_hit > > I’m concerned that fields being temporarily out of sync might impact monitoring > calculations, if the formula is dealing with fields that have > different flush strategies. That's a good point. Maybe we should document the fields flush strategy? > That said, minor discrepancies are usually tolerable for monitoring > data analysis. > > For the numscans, should we not also update the scan timestamp? The problem is that we could not call GetCurrentTransactionStopTimestamp(), so we would need to call GetCurrentTimestamp() instead. I'm not sure that calling GetCurrentTimestamp() every second would be a real issue though, and if it is maybe we could increase this 1s value. That said I agree that having seq_scan being updated and not last_seq_scan is not that great. Maybe we should keep this in mind and see what to do depending where this thread is going (I mean if the current proposed design has to be changed). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com