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 1w4gTB-002RsR-29 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2026 14:41: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 1w4gT9-000nVl-2j for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2026 14:41: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 1w4gT9-000nVc-1o for pgsql-hackers@lists.postgresql.org; Mon, 23 Mar 2026 14:41:27 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w4gT7-00000000hpa-1yrF for pgsql-hackers@lists.postgresql.org; Mon, 23 Mar 2026 14:41:27 +0000 Received: from [10.0.2.15] (unknown [130.41.208.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4ffbTC3GQDz49Px5; Mon, 23 Mar 2026 16:41:19 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1774276880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Lwhu6kv8v6V/O3LDcETfZdMXfB5uBImo/uyhoaXLvw=; b=QbB6it/hSLza5K7OiCD7/+eONh7OiC7EXaNE6U+A25y2gCUTf4+Zjjf3UTcoPb9Ds2xR1s 81XAbSCEUhw4OP8G1nM5Ay0qMIwZhLNWcJTMv8LxvFMqAy3a3ODmzEVZc8El0p55VY43FT 39x8ggPK0JsyfmjsZImh7kQSwPiDSFF2Vcli0PBROb2Yh4d7yDiQocgN92AgzD7caxjgaA ndusc0sLAX5hBLmnntdWBU6ZVMPeuRgNtsC++S5IyYZA6bhML4PHRrBrjNnNRQrz90wUAc QvqrT+71B1J0yLAnrDY5o3hY4pkxyZbKREtIz7rZJNvVw8GpZj7DwsZ7kTsZ9Q== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1774276880; b=gIKpbdUVvLp24uU35OXMHX3IS0YTbdRyXy4SgHlTHZQCSM7ycXAEpbIOiQSY+FD2ItywrD sG4odFMC0jPPfmG/tBDKT6rkgAPcwafKA5rcRZKVaHq0a0HOuO4mUGGFpx4lAUD3YcmZht PcTfPghzEpYOCvUQGj1ui09MF3mIwWL/eV1o98RwT6j1PD1JN98gHBhw57VvPcG711Eq+L wanNmdLiumYOxKCry8o1pJgcITaTY2ZlyOnwjiCU7P6TQbYPGMsKe/RViqdGfGAkcOYysJ XicbwuWMjBNJYvT2e82Sqf3iZtV1tfBOOHvHi6J65w+J68CLHv/PZSdgNXGNZw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1774276880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Lwhu6kv8v6V/O3LDcETfZdMXfB5uBImo/uyhoaXLvw=; b=LXZYqXyCvjJKhP9Zdc7NsMO3zwF4DLTJMp30qCK+e5ydxp5GH5MzpD+orb/Y5Z/WrkYAdT dU57U/XMDtdeJ9ewhun6owI5C8vf3jcNHd7fMLnjlpZ9RuhUuTy8gxsns/SY7PyPdBwA7I R9mOoOp+KDpWRf4VvXFeRWFIMFMfheYnnaQ7fs+u7cFZw19KkOhqnfgdqsxXPJ8Osf1JHj 3h01yc58ZF0xUxXHiNOnKW3m3UM01XmADzlVlCleEM9DmClHBgQaKpiZcGQd6JloCeXC6G Uunvx4KdSvgO2ZYcN/HWr/xLadBwDujzSQa4HOiQ96SCsHmGUZnPM0YaJqhPyQ== Message-ID: Date: Mon, 23 Mar 2026 16:41:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Stack-based tracking of per-node WAL/buffer usage To: Lukas Fittl , Zsolt Parragi Cc: Tomas Vondra , PostgreSQL Hackers , Andres Freund , Peter Smith References: <06086cb4-881b-4f5a-96af-f275220ff52d@vondra.me> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 19/03/2026 02:45, Lukas Fittl wrote: > On Wed, Mar 18, 2026 at 4:36 PM Lukas Fittl wrote: >> On Wed, Mar 18, 2026 at 1:49 PM Zsolt Parragi wrote: >>> There seems to be one more bug in this: >>> >>> 1. EXPLAIN ANALYZE fires a trigger >>> 2. The trigger function throws ERROR, InstrStopTrigger never runs >>> 3. ResOwnerReleaseInstrumentation runs but only checks >>> unfinalized_children, not triggers >>> 4. InstrStopFinalize discards the trigger entry >>> 5. Trigger instrumentation information shows 0 >> >> Hmm, so I think you're correct that a trigger function error would >> cause any stack-based instrumentation from the trigger to get lost. >> >> In practice that doesn't matter today, since triggers never capture >> WAL/buffer usage data (only timing), > > After twisting and turning this in my head more, I realize that's > actually not correct - as it stands, trigger instrumentation is > inheriting the instrumentation options from the overall query, and so > that will cause a typical EXPLAIN (ANALYZE) to also capture Buffer/WAL > usage for triggers - it just won't be shown in EXPLAIN. > > Since its not used in practice, we could fix that by explicitly > setting INSTRUMENT_TIMER for triggers, but AFAIR Andres had noted on a > prior iteration that special casing this doesn't seem right, since we > should probably output buffer/WAL usage for triggers anyway. > > So I guess that brings us back to, we should fix it with one of the > ways I mentioned. FWIW, I was able to create a test case in the > pg_session_buffer_usage module to that effect, so there is indeed a > current issue where activity during triggers gets lost and won't be > added to the overall totals on abort. I'm looking at this finalize at resowner part of this patch, and this maybe a stupid question, but: Why does the instrumentation need to be "finalized" on abort? If you run EXPLAIN ANALYZE and the query aborts, you don't get to see the stats anyway. - Heikki