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 1v1QS7-008X5Q-L4 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Sep 2025 14:26:39 +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 1v1QS4-00DWt5-Sy for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Sep 2025 14:26:36 +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 1v1QS4-00DWsx-GZ for pgsql-hackers@lists.postgresql.org; Wed, 24 Sep 2025 14:26:36 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1QS0-002dld-0r for pgsql-hackers@lists.postgresql.org; Wed, 24 Sep 2025 14:26:36 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-8935b53bb14so208701139f.0 for ; Wed, 24 Sep 2025 07:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758723991; x=1759328791; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=U94PJ9F6W2V45IB7NtJZb0rwmD/hhhK5L4Hqv3YAB9A=; b=LphV1gnEXshgFGsG/NVRb/c0gomftC7qRX5Iz/6if/ZvqZiBQNKLhmdbMGM4eWN2ZD H135SpXUwitjiXtbKasyjiqIaTgWLGPz1rLnliDVuMPaxDmapWmY5J5wrmPTw3kyZf0n sokvV1vvL5fbyK2QIy6/FRDkdtgKS16rlMu0Y8bujB3wQbbtmGc/fIzHzEZGsAHbg1uv 7MeXCagxOazYynsTHeSCe6/3PnmCxEc8A/Ew0DEXZfzf6QjKaCoCWAR6yepwFIKc2ZBK eRpHvIaLTnoizI3KOjNPgOxuH3qLOHLZfM5Eb85nIQjwqfMQImItqn/2Ol/i9MMx0Bca JhAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758723991; x=1759328791; h=content-transfer-encoding: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=U94PJ9F6W2V45IB7NtJZb0rwmD/hhhK5L4Hqv3YAB9A=; b=hWuRY43juFCcXeUDTXiIVm/V5Uod3eGPYgLarrNG5x9yRfwLmBa1qfW+9tgk5BChPi 9ZsKx2SQyP4PC+yI9+ijElM3vDjq641Ns9GaO2/maALP+gfy9QCU4ZSDl33V5efr6uT3 1MWf8T4YwRXwvpEBSGE/l7E/CNHDqjwDOyh03p0Z6BItzCja/1kjoRu4uOoDzPVZ4L4W kvb+/qy0LOhnY8VcU6DI4CYxqSohVEaITUIkJdxxiQabEHWrLI2MvLF0dATgvHCyFofM fXLPJ6eAEjfKTI/J4mMhYdnzMMy3UVbctQ0J3tPUOppcjnP4oVaiBYbyffLAAybJ4KL/ kL0Q== X-Forwarded-Encrypted: i=1; AJvYcCWpqMNr59+0qWjJK167SeZnQffAjySebgu/F/arfk1Q6pRtk+DI1UTeH05gtZaiD2StUJ4ETbh02bdHcjM1@lists.postgresql.org X-Gm-Message-State: AOJu0YwYMUwIonKqtMakjXyDdJNze9OYMp6rYbS7xhSz11V/pP6oD7Jx ov7RUv9A6NDSRN7ZTiAr2yRTYY1nR2wBnFukJIgp826aYatyji78vVMJXE24coolsq0B3v4EMXT eJMZ2H2jlBa8L27KJbTWoyMDCI4U5GtM= X-Gm-Gg: ASbGncu+/ip/kHW75EUVTyBU/lGSQ0bKLMXG2T2YoK63LT8sh9Ax1/sRy4o2a8E6NhQ ylrRGNFpncJKTrcw1JFAUI5xF5s+URKrGbYzwloMFx/d3Z6xLhvaPEeE1EifiOTsTNeeB5URf4B IzpZuoMbG2o/pTw1al69Ug3HMbKeErV+Vcxl0fc+6/POdJJXT4yJNI3O7pY8qsatYBPgRf6r1Zn J4UsaqmLjR4V4z1 X-Google-Smtp-Source: AGHT+IHXSjrxpuHBdOrLigHfodeq2vond0ujI3rcdSIe+L5WzCjXYGgc77y++6Z1DG3ZUhtL96AyZvkQjGCEtFOQmAE= X-Received: by 2002:a05:6e02:1c23:b0:424:8151:6e20 with SMTP id e9e14a558f8ab-42581ead02fmr109433505ab.29.1758723991034; Wed, 24 Sep 2025 07:26:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Wed, 24 Sep 2025 07:26:18 -0700 X-Gm-Features: AS18NWC9vSYHEG5leLoqHpFfco5Rhm3KI3VDWpj4SLtwan902fHKzWMj48LR0qw Message-ID: Subject: Re: Use WALReadFromBuffers in more places To: Jeff Davis Cc: Jingtang Zhang , pgsql-hackers@lists.postgresql.org, Nitin Jadhav Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Mon, Sep 22, 2025 at 8:26=E2=80=AFAM 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? Right. Reading unflushed WAL buffers for replication was one of the motivations. But, in general, WALReadFromBuffers has more benefits since it lets WAL buffers act as a cache for reads, avoiding the need to re-read WAL from disk for (both physical and logical) replication. For example, it makes the use of direct I/O for WAL more realistic and can provide significant performance benefits [1]. [1] https://www.postgresql.org/message-id/20230114203403.4zpg72fw2qb34awf%4= 0awork3.anarazel.de -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com