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 1vofno-00CAg8-17 for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Feb 2026 10:44:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vofnl-006YGU-2U for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Feb 2026 10:44:33 +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 1vofnl-006YGK-1C for pgsql-hackers@lists.postgresql.org; Sat, 07 Feb 2026 10:44:33 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vofni-00000001Vni-42th for pgsql-hackers@postgresql.org; Sat, 07 Feb 2026 10:44:32 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4f7SJC0qKVzyQx; Sat, 07 Feb 2026 12:44:26 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1770461068; 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=UMLq5CAUQzy7fdLT5ek0JDORLaDVRiewfmvawa8qpLY=; b=w0gT9Ms/MhmJ7aMR7tiMwMrFIvUi2IAxgUjlBZqpiyYvkbMsIGeiXcfPru4lfexYuZBNnn Vtk+npQ7JX2pChOYSROH7S2vn1hJQOJLIN/G/DJ9Imy5tHGbV4I7lT0ROQd5pERv6JMvSx bintneAX6hOZl7JUU8+F4uqIfBFsbsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1770461068; 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=UMLq5CAUQzy7fdLT5ek0JDORLaDVRiewfmvawa8qpLY=; b=dxXju9uNtQn7Doy+1lppUNPSrbLbDekQrsLIAtEHrGw0JCCc4GrVxhNyOK7dsoKg1106AP hfLm+4JFyMl7C+fvmUmECbPOuymYDB3irU6+//bXTdybJo6OJl5tV5u2xKN+kbmWbwZ1ty wZV0SRJ3R0t3dNUpf0rOsVvYWhW+kvg= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1770461068; b=CH/6t6fFraDKCD84FeUBNvygtEeVrsq4GyxIvYO6madQnrEV92zvcthS01WFmIOyoYtsRu +77KtyDt+5UlPscBSx5GaXqMwhvYPxQo4SDQb8alkXSXN5hyve9JisIjcKVIt5nVP6Bz75 8uP68m8Zz3VOJIICv1o773ZsnMQ9esI= Message-ID: <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> Date: Sat, 7 Feb 2026 12:44:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Buffer locking is special (hints, checksums, AIO writes) To: Andres Freund , Melanie Plageman , Noah Misch Cc: Kirill Reshke , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Robert Haas , Michael Paquier References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/02/2026 00:33, Andres Freund wrote: > - The way MarkBufferDirtyHint() operates was copied into > heap_inplace_update_and_unlock(). Now that MarkBufferDirtyHint() won't work > that way anymore, it seems better to go with the alternative approach the > comments already outlined, namely to only delay updating of the buffer > contents. > > I've done this in a prequisite commit, as it doesn't actually depend on any > of the other changes. Noah, any chance you could take a look at this? Patch 0001 Looks correct to me. However: > * ["D" is a VACUUM (ONLY_DATABASE_STATS)] > * ["R" is a VACUUM tbl] > * D: vac_update_datfrozenxid() -> systable_beginscan(pg_class) > * D: systable_getnext() returns pg_class tuple of tbl > * R: memcpy() into pg_class tuple of tbl > * D: raise pg_database.datfrozenxid, XLogInsert(), finish > * [crash] > * [recovery restores datfrozenxid w/o relfrozenxid] > * > * As we hold an exclusive lock - preventing the buffer from being written > * out once dirty - we can work around this as follows: MarkBufferDirty(), > * XLogInsert(), memcpy(). That last reference to 'memcpy' is a little orphaned now. The comment used to talk about the stack copy of the page, but now there's no mention of that except for this reference to memcpy(). To make things worse, the steps have "memcpy() into pg_class tuple of tbl", so one could think that the "memcpy" refers to that. How about this: * We avoid that by using a temporary copy of the buffer to hide our * change from other backends until it's been WAL-logged. We apply our * change to the temporary copy and WAL-log it before modifying the real * page. That way any action a reader of the in-place-updated value takes * will be WAL logged after this change. - Heikki