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 1w4uNg-002gCd-0U for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 05:32:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4uNe-004F1Z-1K for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 05:32:42 +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.96) (envelope-from ) id 1w4uNe-004F1O-0M for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 05:32:42 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4uNZ-00000000jsy-33Mn for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 05:32:41 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-35a09e0dd63so4706875a91.3 for ; Mon, 23 Mar 2026 22:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774330356; x=1774935156; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UiHb6DPx/kehRdL8O4oB1RiIkHf66dKBYrS+FMmlM2g=; b=A/uwg1KMeY9TZDQNRvihSVzYcqHRZ0Oi8bKG5eTL+oirbYDArC+6BuxAQZq2KtHnJL t1mzBc9eBcR78orZYqqVeToKeviwOmgSuOA08C+EKur72f6OxYZS3IyXk378QDOkLLmv wBbkJtemmzoEFCt8j5cGi4Kyfkh/qvCy022VjWcf0kRd6e6wIlK4xugHAKHXIBUTjSHZ htKnC4WlZkiR04YVAWOyV5Yt8AN0bwfmWXO9A6LSvS+7ZcmFS2xrk8IT/bpnryn/auVU pUZ6rGwrZzK/EX3ctJjiqeGFd/adYFP1eNHozC+FFLINewTmjzid2FroGHXWDx0cWvYQ VTXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774330356; x=1774935156; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UiHb6DPx/kehRdL8O4oB1RiIkHf66dKBYrS+FMmlM2g=; b=qlJKhW7yr94C7/Cl3cx5jtIro3mU71rQKbVNOn9+ESmK5+x5d9BAHP6hMWgow89ktn 8yYzOtjXF1WXLcmM94WraUcAfIzqnFPZdQ60ZeKCDKCB3DoIaRHH3IP1LKr8mXAWtQgn 75alA6Tqgj1H44cvqbA4AAlJxZW535Y5dH3XfhgqElzOzHXCCxBaesTpBghzsRH8rkXD GIqhJKPW2pbnYTziFe31tPn58Z+KnMYwnOlN+xeSP/o+tKYuIeUJttHDZ3s2eJ87E13+ KXdwZwDqo0/Nxcg7fsmlGEcrMsDC9XT2ZMVCmEyTmGNAa1mETAtKZib/WViOnlDpF+cz cD3w== X-Forwarded-Encrypted: i=1; AJvYcCUmhnWyg4AGrWqM1mnXkGHBCiZ2hojZewwFglY4o9GOcC58q4xv6Suxlr1lnzB7rStqq6WarbqrgfopoXzb@lists.postgresql.org X-Gm-Message-State: AOJu0YxKG1TOmAtEjE2BPrDHmDaTKsEt9BVx5WBBhaAdZHHoO+931rPG cQTuJWqKlbw0+xaHf6JgTwzgydTyV3uvK+ojuHEumdFTrI2VTl2P6ceG X-Gm-Gg: ATEYQzyMgbY2Q9XyKH9ZeXSAIUwfhLja0sLkNOW3X59JRpOFSYK4aNANpCbZHsCiZl+ plO6SWJNNOpDOMnI14ULkHLNKgIRHv3yo+E19F6XRebHbH+zQYMpanZlutbfboeV30eDdKTMmTB vYOl3z/tyyyfxk+yzL3dWZAfQmoMZBekABSS0HHZRTFuYRiJmX/D/bwlfcc7TZBiIzUORNO6Ay2 OsBat4rBBMJgYsx1DWF4uCDJZnJM39iwvG0ddAkUYyP+LBLZIE9usuyMAeHxfeZ1sm8M+FJk2Pt 4zlqQ9upfUR6tjaxA/QKEvyNlNnbjJGv73STGUffXh06R5pY6nLnRoZYYX+a39YCygYxebFcw0E dY4WRuoyIDM3jXb6xo5vnVikBdlaELHr29PXUsAdDh/mr4YxYhzVzAchRXXVmt5DzT49uqAaRRh l5lereOsVcc8IDM0AKgE7uf4RfSVm7Aqs= X-Received: by 2002:a17:90b:3e45:b0:35b:a1b6:5bf5 with SMTP id 98e67ed59e1d1-35bd2d79c38mr12317077a91.31.1774330355928; Mon, 23 Mar 2026 22:32:35 -0700 (PDT) Received: from smtpclient.apple ([103.62.49.186]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c0312f1a5sm925648a91.3.2026.03.23.22.32.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2026 22:32:35 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: pg_stat_replication.*_lag sometimes shows NULL during active replication From: Chao Li In-Reply-To: Date: Tue, 24 Mar 2026 13:32:00 +0800 Cc: Shinya Kato , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Fujii Masao X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 23, 2026, at 23:31, Fujii Masao wrote: >=20 > On Sat, Mar 21, 2026 at 11:05=E2=80=AFAM Shinya Kato = wrote: >>=20 >> On Fri, Mar 20, 2026 at 2:13=E2=80=AFAM Fujii Masao = wrote: >>> I think the issue occurs when the positions in the first message = point to >>> the same LSN (e.g., 0/030D5230), and the second message reports the = same but >>> larger LSN (e.g., 0/030D52E0). >>=20 >> Thanks for the explanation! >>=20 >>> I've updated the patch to address this. It removes = fullyAppliedLastTime, >>> tracks the positions from the previous reply, and clears the lag = values only >>> when the positions remain unchanged across two consecutive messages. >>>=20 >>> Patch attached. Could you test and review this updated patch? >>=20 >> The patch works properly. I think it looks nice to me, except for the >> typo I sent in the previous message. >=20 > Thanks for the review! >=20 > I've fixed the typo and attached an updated patch. I also incorporated > Chao's comments from upthread. I'm planning to commit this to master. >=20 > As for backpatching, I'm hesitant to backpatch the full patch since it = may > reduce the number of replication feedback messages, which feels too = invasive > for stable branches. >=20 > That said, the patch's changes in walsender.c could be backpatched. > As discussed earlier, they don't fully address the reported issue, > but they do help mitigate cases where lag becomes NULL unexpectedly > in logical replication. So it might be worth considering those changes > for stable branches. >=20 > Thoughts? >=20 > Regards, >=20 > --=20 > Fujii Masao > Thank you for updating the patch. I saw that the variable name and = function name were changed to reflect my earlier comments. v6 looks good to me. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/