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 1txBsx-004QXl-AX for pgsql-general@arkaria.postgresql.org; Tue, 25 Mar 2025 21:32:35 +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 1txBsw-00ALPq-01 for pgsql-general@arkaria.postgresql.org; Tue, 25 Mar 2025 21:32:34 +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.94.2) (envelope-from ) id 1txBsv-00ALPi-Ld for pgsql-general@lists.postgresql.org; Tue, 25 Mar 2025 21:32:33 +0000 Received: from smtp67.iad3b.emailsrvr.com ([146.20.161.67]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txBst-0017Mz-2z for pgsql-general@postgresql.org; Tue, 25 Mar 2025 21:32:32 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp17.relay.iad3b.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 82122A0153; Tue, 25 Mar 2025 17:32:30 -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 14:31:59 -0700 Cc: pgsql-general@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <270FB587-2E83-4EB0-9FD6-07541F2A6A17@thebuild.com> References: To: Phillip Diffley X-Mailer: Apple Mail (2.3776.700.51.11.1) X-Classification-ID: 539c403e-60f5-458e-afe6-7026859b8a50-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 25, 2025, at 13:58, Phillip Diffley = wrote: >=20 > Oh I see! I was conflating the data I see coming out of a replication = slot with the internal organization of the WAL. I think the more = specific question I am trying to answer is, as a consumer of a = replication slot, how do I reason about what replication records will be = made unavailable when I confirm an LSN? Here I am worried about = situations where the replication connection is interrupted or the = program processing the records crashes, and we need to replay records = that may have been previously sent but were not fully processed. It's up to the consuming client to keep track of where it is in the WAL = (using an LSN). When the client connects, it specifies what LSN to = start streaming at. If that LSN is no longer available, the publisher / = primary returns an error. The client shouldn't confirm the flush of an LSN unless it is = crash-proof to that point, since any WAL before that should be assumed = to be unavailable. > For example, are the records sent by a replication slot always sent in = the same order such that if I advance the confirmed_flush_lsn of a slot = to the LSN of record "A", I will know that any records that had been = streamed after record "A" will be replayable? You know that any WAL generated after `confirmed_flush_lsn` is available = for replay. That's the oldest LSN that the client can specify on = connection (although it can specify a later one, if it exists). You = shouldn't need to manually advance the replication slot. Instead, the = client specifies where it wants to start when it connects. The client = is also expected to send back regular messages letting the publisher / = primary know that it has successfully consumed up to a particular point = in the WAL, so the publisher / primary knows it can release that WAL = information.=