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.94.2) (envelope-from ) id 1tx7kj-003Ewv-SS for pgsql-general@arkaria.postgresql.org; Tue, 25 Mar 2025 17:07:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tx7ki-007Bht-J7 for pgsql-general@arkaria.postgresql.org; Tue, 25 Mar 2025 17:07:48 +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.94.2) (envelope-from ) id 1tx7ki-007Bfd-5Z for pgsql-general@lists.postgresql.org; Tue, 25 Mar 2025 17:07:48 +0000 Received: from smtp126.ord1d.emailsrvr.com ([184.106.54.126]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tx7kf-0017MD-2i for pgsql-general@postgresql.org; Tue, 25 Mar 2025 17:07:47 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp16.relay.ord1d.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 7BADD40099; Tue, 25 Mar 2025 13:07:43 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: Replication slot WAL reservation From: Christophe Pettus In-Reply-To: Date: Tue, 25 Mar 2025 10:07:12 -0700 Cc: pgsql-general@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <8760F666-DF81-4BEA-9CA9-80BBC569210E@thebuild.com> References: To: Phillip Diffley X-Mailer: Apple Mail (2.3776.700.51.11.1) X-Classification-ID: 0b6eea23-0bb1-43af-ac90-ff6b6b423ed9-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 25, 2025, at 09:56, Phillip Diffley = wrote: > 1. Every DML operation (insert, update, delete, truncate) will have a = row in the WAL and that row will have an LSN assigned to it.=20 > 2. The LSNs are assigned when the operation happens. > 3. Operations within a transaction are written to the WAL in a = contiguous block when the transaction commits. > 4. Each transaction block in the WAL has a commit timestamp associated = with it, and these timestamps are monotonically increasing (I'm only = inferring this, so please correct me if this is not always the case). This isn't *quite* right. LSNs are byte offsets, not operation sequence = numbers (despite the name), so they don't have to be "assigned"; they're = just an offset to a particular point in the (virtual) WAL bytestream. The WAL is written as it is generated (allowing for buffering etc.). A = transaction end flushes out any remaining WAL that is involved in that = transaction (and any other WAL that might be between operations for that = transaction), unless you are not in synchronous_commit mode. It's not quite the "transaction block" that has the commit timestamp; = it's the commit record for a particular transaction. I can't come up = with a scenario off the top of my head in which the commit timestamp = would go down, but I wouldn't absolutely bet on it never doing so.=