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 1w9Uc8-001Tqm-21 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 21:02:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9Uc7-0050Y0-0R for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 21:02:35 +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 1w9Uc6-0050Xf-1O for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 21:02:35 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w9Uc3-00000000kCh-0Xxo for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 21:02:34 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id E96251400015; Sun, 5 Apr 2026 17:02:29 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Sun, 05 Apr 2026 17:02:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc: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=1775422949; x=1775509349; bh=6H9VL1P1wovwZ628VVaDd/KiyLfeOrNBDoFZXdkpzrM=; b= LMogOT4eLnvHcRF2w2q5ttGLFlNfUPUb7aFmsh/SjDl8H8rU6a7AZFn8nokGJUbU Ivf9LQTW0Bgd+urJ8dLCpcWQn/fkVh0uEa+j6cUPOV5dtahbw4nynuCdT5mC3hRW eh7+mRPlIXOvI4k0+SslX+iN/4rUhxq55sApzkEmp3kmoK2p7ffgSYpCM0YXsiZO kemhC9J+yykdvj6mEiCZ4zyqoanqgQYTrYAsZVYgzkBsJ4CTkbiI3k+lNKju1Itn NEMN9/g39k2eJtQ8g5ndX4HVcHqC83L6ewyZm9pWJkD+ccktbxnJTbSoKAaSJCFF JBU7s2dg79eOz7KnlnZwjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t=1775422949; x= 1775509349; bh=6H9VL1P1wovwZ628VVaDd/KiyLfeOrNBDoFZXdkpzrM=; b=T Q02vyyKoWFk4ura+cB5url1mj9WmsKeibtJBb30YKNbsDrY3i1PcYPwM4LkiYfH9 Uf4iHBLWqp/5XTQcSn19kgaI5dQPnr4Pwdt5bSzJfjqIm/fDQN0gVqALmxiWUB1x REAaR1RXGE1w1jT2l8TWdEUs0nAqKdcHIa4T9hlw4ZDATitfGrnQbeQ9cBet2sT+ 7UIfto82OtpBS9+g/CambUPBcAJUp5UW22rGR5VW/+KDEPGObnUqg1RUSRw3lklV 69T4fppWMbdMg5+b/ve7Ac//l5MHzf3O1dp1nRmMu2vxTcEIi0zUqFDb3R9Leqt+ kNJRcS6alqKLA7SY1Qr/g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduheekudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtugfgjgestheksfdttddtjeenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnheptdelledvgfejvdffieeukeefueelfffhgeffhffgffekveeuheeihefhiefg hfdvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeeipdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehluhhkrghssehfihhtthhlrdgtohhmpdhrtghpth htohepshhmihhthhhpsgdvvdehtdesghhmrghilhdrtghomhdprhgtphhtthhopehhlhhi nhhnrghkrgesihhkihdrfhhipdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslh hishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepiihsohhlthdrphgr rhhrrghgihesphgvrhgtohhnrgdrtghomhdprhgtphhtthhopehtohhmrghssehvohhnug hrrgdrmhgv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 5 Apr 2026 17:02:29 -0400 (EDT) Date: Sun, 5 Apr 2026 17:02:28 -0400 From: Andres Freund To: Lukas Fittl Cc: Heikki Linnakangas , PostgreSQL Hackers , Zsolt Parragi , Tomas Vondra , Peter Smith Subject: Re: Stack-based tracking of per-node WAL/buffer usage Message-ID: References: <57biou6l65r7gr4nunoe6lignz2x6m3w45gihoypaez4pc46di@txj3bakhj66l> 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 2026-04-05 12:38:58 -0700, Lukas Fittl wrote: > On Sun, Apr 5, 2026 at 11:13 AM Andres Freund wrote: > > Unfortunately I think 0001 on its own doesn't actually work correctly. I > > luckily tried an EXPLAIN ANALYZE with triggers and noticed that the time is > > reported as zeroes. > > > > The only reason I tried is because I misread the diff and though you'd changed > > the calls=%.3f to calls=%d, even though the old state is calls=%.0f... > > > > > > The reason it doesn't work is that explain shows tginstr->instr.total, but > > with the patch the trigger instrumentation just computes > > tginstr->instr.{counter,firsttuple}. > > Argh, good catch. That's on me for not manually testing it when I > factored it out. > > I've confirmed this works now, both with 0001 only, and with 0001+0002. I made 'firings' an an int64, rather than int. Could have made it unsigned, but ExplainPropertyInteger accepts an int64... Because the patch did change those lines anyway, I replaced palloc0(sizeof(Instrumentation)) with palloc_object(), and palloc0(n * sizeof(TriggerInstrumentation)) with palloc_array(). It also seemed silly to have an if around the assingments of need_*: if (instrument_options & (INSTRUMENT_BUFFERS | INSTRUMENT_TIMER | INSTRUMENT_WAL)) { instr->need_bufusage = (instrument_options & INSTRUMENT_BUFFERS) != 0; instr->need_walusage = (instrument_options & INSTRUMENT_WAL) != 0; instr->need_timer = (instrument_options & INSTRUMENT_TIMER) != 0; instr->async_mode = async_mode; but that gets cleared up in 0002 anyway. But it did lead me to notice a pre-existing bug: We only set async_mode in the if (INSTRUMENT_BUFFERS | INSTRUMENT_TIMER | INSTRUMENT_WAL) branch. It looks like that doesn't matter today, because all async_mode is used for is /* * In async mode, if the plan node hadn't emitted any tuples before, * this might be the first tuple */ if (instr->async_mode && save_tuplecount < 1.0) instr->firsttuple = instr->counter; and without INSTRUMENT_TIMER instr->counter would be zero anyway. But I guess it's worth noting that in the commit message for 0002? I felt a bit silly leaving the instr->need_* stuff in InstrAlloc(), when there is InstrInit() directly afterwards that does the same thing, but then that leads to removing the redundant memset etc, so I left it for 0002. With that I pushed 0001. Greetings, Andres Freund