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 1v1HdU-006ic5-L5 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Sep 2025 05:01:48 +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 1v1HdS-00AFTB-2G for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Sep 2025 05:01:46 +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 1v1HdR-00AFT3-MB for pgsql-hackers@lists.postgresql.org; Wed, 24 Sep 2025 05:01:45 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1HdN-002YeE-2Y for pgsql-hackers@lists.postgresql.org; Wed, 24 Sep 2025 05:01:45 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-36a6a397477so36366001fa.3 for ; Tue, 23 Sep 2025 22:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758690102; x=1759294902; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rpQqIppUokQUPmG34lAQFN3ny04Y8bOGq2pQb7tYILY=; b=fO1TYxaa7EgYmQyyPWxn/jdDtaKriGJ/6r6vGqmEzEqrdP2Z3R3aKJTG+97mxQehYz pbjmCe6zqK9D2cMaUnnkxcZMAKWvG85fIvsk0KwYpIxuc8bqHAqhZl5g8pLK2asup5sD 8d1/aexP7tDr8p0sdxgtUR6q/E7PfeWK2fokxcMt/Su1HUdFrGj3knVt7tr781wWNSuY WWc+qfMByyxzPUH4i63ghx0n+rZPqh+qikKsmQlQGoOFZhsWYjEDrsZ89oz/6ByBhNym 1KBOPuN+6ACb4eTY10QCqdBQnvYNIWwiRGJm/oOOxp0GW7XpLMyHMSsXn0s+QGdzKCVX edQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758690102; x=1759294902; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rpQqIppUokQUPmG34lAQFN3ny04Y8bOGq2pQb7tYILY=; b=XpJ1WGbXNoY9zI4Mf+gN1FBsjNPkalWaMDLLwBJmn9QRgFipzhf/c5E9YnZ39krxJc uE2y7F77ZFZS5XTWPbXt3cljkrTcm3b9HvSuXCRLt9QJmNWCKm4znoqBD5OJnQxD2nDh UUT6nI0ng4EfZ21up+jZKK9Sy240IEH6oNq0O3HArnd3QXn7PL59Pw54PWkIvl/kWma1 fHSQ7yFk6GLhZvN/fNsDhrCnUIOtTrQfF+t36VS/LmLAxrTMqNFSKKHHyTbNQ2aOUdl4 6xEE+Y39LCGiA8c2xdL4CCpJnB25FOAJNI1G5Ky/41FqYCAHEP8afjvgenvh5/8GiakL pZSQ== X-Forwarded-Encrypted: i=1; AJvYcCXE78uO2sQLxl3+jy/P9seoPSptjYAG2wYhwe04153fnmNjPSrjnHbMsYbKfStfGP94F0a+n0d5Tz8xWo7Z@lists.postgresql.org X-Gm-Message-State: AOJu0YwY5cYCVm1+HfP+uz1n3KPOSo1gbF5ueMtgPVbxv2z/QQ2fPWNr tTq/zJYt6m4DMVGCp81bPCM1yVdTmgwVWWtM+qoD0SobaVpF2c7hsGoBZOrXaFMwe/18mkpkpJ+ pXzYY+PqIzR6KnqmRMl5bSK9GveN7YnQ= X-Gm-Gg: ASbGncvxciws7RpR8/chz0aZrMtSIBZO++wTy8C4jhPkn2lh5NYi2SWbCFPAExJHj52 dnflKpBYHgLWs7qEh255wtDgRLNapFH7Ipmuzf+Rb97VMgZyExK5NDPLXwLcsLJdyxztN3kdOmR j5UjaQb6QKZ9xFALnp4IxdjHenqLh3WkmyMdbIP7Vx47Ut96rh7L2452OLxIPkD6reo7mPqFJJA zcZ6o0JopwWK9Iz+3m76TahbwQj7DLZEKfbposUJyaSGtbEWfQ5i6KNdj45ozzwZhswVJ/05YxZ 1AHZx6PPfa/F2GRPPF6V X-Google-Smtp-Source: AGHT+IFlCU6cZnzOiZfTSoJU5Ud96VrReVDG3PmxXAUpHjpzrYumwoACyDlaO0DYdpLbpLb0Ojetr/GBm3aCxDIkxWo= X-Received: by 2002:a2e:a004:0:b0:336:d481:8891 with SMTP id 38308e7fff4ca-36d17bce855mr9574351fa.42.1758690101792; Tue, 23 Sep 2025 22:01:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rahila Syed Date: Wed, 24 Sep 2025 10:31:29 +0530 X-Gm-Features: AS18NWAN-r4SdgpojFy3UEUXzBwmM-9upuHHPZr2KXyFdPkgchvJdcTZe1-ECrk Message-ID: Subject: Re: Use WALReadFromBuffers in more places To: Jeff Davis Cc: Bharath Rupireddy , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000c99412063f84f20d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c99412063f84f20d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Mon, Sep 22, 2025 at 8:56=E2=80=AFPM Jeff Davis wrot= e: > On Sat, 2025-09-13 at 22:04 -0700, Bharath Rupireddy wrote: > > Thanks for looking at this. Yes, the WAL writers can zero out flushed > > buffers before WALReadFromBuffers gets to them. However, > > WALReadFromBuffers was intentionally designed as an opportunistic > > optimization - it's a "try this first, quickly" approach before > > falling back to reading from WAL files. > > IIRC, one motivation (perhaps the primary motivation?) was to make it > possible to read buffers before they are flushed. It was always > possible to read already-flushed buffers. > The benefit of reading unflushed buffers is that we can replicate the > WAL sooner (though it can't be replayed until the primary flushes it). > Is that right? > I'm not certain about the primary motivation, but as it stands, WALReadFromBuffers only reads WAL records present in buffers up to the flush pointer. This is because XLogSendPhysical currently sends records only up to the flush pointer, not beyond. I am currently testing a patch developed by Melih Mutlu that implements the functionality you described, sending unflushed buffers during physical replication. After some tuning, the patch has shown a 5 percent improvement in TPS for synchronous replication with remote_write. I am working on further improving the patch before sharing it on the hackers mailing list. Thank you, Rahila Syed --000000000000c99412063f84f20d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Mon, Sep 22, = 2025 at 8:56=E2=80=AFPM Jeff Davis <pgsql@j-davis.com> wrote:
On Sat, 2025-09-13 at 22:04 -0700, Bharath Rupireddy wrot= e:
> Thanks for looking at this. Yes, the WAL writers can zero out flushed<= br> > buffers before WALReadFromBuffers gets to them. However,
> WALReadFromBuffers was intentionally designed as an opportunistic
> optimization - it's a "try this first, quickly" approach= before
> falling back to reading from WAL files.

IIRC, one motivation (perhaps the primary motivation?) was to make it
possible to read buffers before they are flushed. It was always
possible to read already-flushed buffers.=C2=A0
The benefit of reading unflushed buffers is that we can replicate the
WAL sooner (though it can't be replayed until the primary flushes it).<= br> Is that right?

=C2=A0I'm not certain about the= primary motivation, but as it stands, WALReadFromBuffers only reads WAL re= cords present in buffers up to the flush pointer. This is because XLogSendP= hysical currently sends records only up to the flush pointer, not beyond.= =C2=A0=C2=A0

I am currently testing a patch developed by Melih Mutlu= that implements the functionality you described, sending unflushed buffers= during physical replication. After some tuning, the patch has shown a 5 pe= rcent improvement in TPS for synchronous replication with remote_write. I a= m working on further improving the patch before sharing it on the hackers m= ailing list.

Thank you,
Rahila Syed
--000000000000c99412063f84f20d--