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 1vzYfq-00177P-1m for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 11:21:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzYfo-00Fih7-2l for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 11:21:21 +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.96) (envelope-from ) id 1vzYfo-00Figz-1e for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 11:21:21 +0000 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzYfm-00000001mrW-2Etf for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 11:21:20 +0000 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-67bb5c2e0fdso206020eaf.0 for ; Mon, 09 Mar 2026 04:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773055276; cv=none; d=google.com; s=arc-20240605; b=bKQzF6awO7JhQEeykEtkeJsLRkvFloMsMxYR3WlurpwGsrpq0hfuYgPi4A49PArTjM WHnP7qEiLTv48aJG3dyXz8wn0YJOY+qqjb1chUpbkFi/XBdd7dr3jYAs5gD7l9XgYPQv dE/sTzLvTwGhcM6kfxsm9Fp2pDprl+yNbVtzh2B3VWQlRCNayUzvF1PQsB6mMOzoQz7J dloxFnefiLhpUHbXN8M86I9qkuHQK7XtBdXF0PDZ14CfMSUh2+jVyVDZwQS56djzfr0P VS4RFK0Kqez7yENcNlvDOF0Uyd4k/ZdA1/lTI0EffKCIR7DbA+JCDDMEtX7zwZJQZfkU QShA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3BYLUeT69fF25F2tWVjc5tIoXHU51opea/WTz2rzg9Y=; fh=SprTjyyUNMFOaPK7zUpaC1EEovCYhXioP7Zs2WMpltw=; b=DAw08YNP9qSIRO0HB62naKZWq4xAsANhiNsus8ypk5Cmk+pFiQrR27bHa6NHKjGE9j IbidyKeOPaxK9VBZuy06KDLW1qLEP8aT9VUPLdJEgH1himswxNcQf4sgUuE0Y1DnZAtU tnrtWR8FuirIKSB4Xb2Sx/ULwKGGr35EvzgChE1S93KJD4xak2o2NUXHo+qXlNEoxs+s MEjSb2/vxmDywt+TY44lcQmFNUikzm/eA9uoz3msvA4gn195+z4laz4dXp5ThaojBXzl 5+amr5nwiNcWi7vwzsdwohFUQ7XVHw8E0Pe27GSg0JKRe121Re+KJW2POdM/DTKroLoA p1Mg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773055276; x=1773660076; 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=3BYLUeT69fF25F2tWVjc5tIoXHU51opea/WTz2rzg9Y=; b=IVTOpTu24fe8pO2YTOjLIo7NUSoA/V2gB9zO/jTGPJDXESDi6J+kXxfORGHYr7xIt/ vqdQAEJRm3E2SDmkqy4wX8IWY59fnLj7NirGvjyH+0aHNSXRAoeweYJjehgka7Fdzdwe ytoEPqebH5Mfagzljxf1Yx1aeTr3Cg/nLsT/+mHV/JUGtyr/U02Je71xWjOWI1XryHqW TknPZ7EVBb6U3NOW058WEqsofYLo2SBIkGgyIXLa71CjmhbhyV7578er/7kBsQ/GnqyJ tEHhRoQEw4QLVH+Oqri08SKMB1wM+V5CMyKZt05MsCBnE5SICAttJpUalpfhbDgsDAjz pQNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773055276; x=1773660076; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3BYLUeT69fF25F2tWVjc5tIoXHU51opea/WTz2rzg9Y=; b=Qyz/rvgQZsTAr/rhv7GfyyNGMt7a0ea/st3ml1S2IM5Q2XM3Eh4gAe3CT/WNelMO8a xZ6/2VKdOutg/MojTxPvKN7W863bIeFmw1+2ePrN6OMH/WkWAK3BRUD32R6aPHMkHPMY ffI7+Ze5kn4z61ljZNy95BSzHX1HduWnn83sVf3drMLknSq+TjlS28Uw2SBBm4Ei7e7j 99h20s9aZKiy2oGfUYVY3ja0xj6IL4T+4eHp3b90pZSwQg6QhP54CjGFWjRD06jHTNqM Q9YQ9WFqO8oYbKv8wJGf6a7UIqxqs+RjXzR7wFQeLHjtA9Hu11HcslWk930pxj1GYqPb kHlg== X-Gm-Message-State: AOJu0YyCnYlN3mC7Cw4OM7mqIo6Vx1BUH5diODJUrBxs14QEa6ZUGZwT FAFYwKLhFCwMnYbhcXM363x+Oh7NmTT45BtEhQR5lloZ9QX2/CRUYzpC+GHItCbK9F0XYGcJmsb kEh9hkZzKaRqf/Zgs0wTlQRxL7zpTiek= X-Gm-Gg: ATEYQzxCwM1xLOzhSswThpHQUCbhWJx54F91cMdsgRTodkQQVSWrjHc4G6CewjOIjJn gocvadIc7qlsl58HOF+aIS8H3ve4hXmWPWVT7wws4fAMGgFu/wwBmW6Plnd8OoDAZAL1T9KUrDu hbwPqdFv6OjTF7mHK3ykX/JkacOGwqcj0hYDqSBK0QwMtbDFWlkNaKxgZV5+x1CpyI7zHi9QMUf a686XcjCqAd6IoKr7qXpnlqJKDG3JXWuXV+bwsNVWyenqrqsSZ6YG1xRnyBWMTVBHbQE7YTSJTk 12a1U+bOz4oYbMc7dWiRzLaA09n36FVN/sxM9DeePw== X-Received: by 2002:a05:6820:498a:b0:67b:ba0a:1cb3 with SMTP id 006d021491bc7-67bba0a1e5fmr112736eaf.49.1773055275911; Mon, 09 Mar 2026 04:21:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Mon, 9 Mar 2026 20:21:03 +0900 X-Gm-Features: AaiRm50RhXS_JSFE3jmFXk2oOdwUrzrUXdrkDic7Q5PElBuYWMSpDdE7FDq5W9s Message-ID: Subject: Re: pg_stat_replication.*_lag sometimes shows NULL during active replication To: Shinya Kato Cc: PostgreSQL Hackers 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 On Fri, Mar 6, 2026 at 4:13=E2=80=AFPM Shinya Kato wrote: > > On Mon, Mar 2, 2026 at 11:44=E2=80=AFPM Fujii Masao wrote: > > With the patch applied, I set up a logical replication and inserted a r= ow every > > second. Even with continuous inserts, NULL was shown in the lag columns= of > > pg_stat_replication. That makes me wonder whether the patch's approach = is > > sufficient to address the issue. > > Thank you for the review and testing! I had only considered the issue > in the context of physical replication, but as you pointed out, my > approach is insufficient for logical replication. > > > Relying solely on replies from the standby or subscriber seems a bit fr= agile to > > me. If the goal is to keep showing the last measured lag for some time, > > perhaps we should introduce a rate limit on when NULL is displayed in t= he lag > > columns? > > My primary goal was to ensure that the source code comments match the > actual behavior, as the comment stating "the second such message must > result from wal_receiver_status_interval expiring on the standby" is > inaccurate. However, as you noted, the patch alone is not sufficient > to fully address the issue. > > > For example, if there has been no activity (i.e., sentPtr =3D=3D applyP= tr and > > applyPtr has not changed since the previous cycle) for, say, 10 seconds= , > > then we could allow NULL to be shown. Thought? > > I considered a time-based rate limit, but it is difficult to choose an > appropriate threshold. Furthermore, the walsender has no way of > knowing the standby's or subscriber's wal_receiver_status_interval > setting. > > The attached v2 patch takes a different approach: it additionally > requires that all reported positions (write/flush/apply) remain > unchanged from the previous reply. This directly detects a truly idle > system without relying on timeouts=E2=80=94if any position has advanced, = new > WAL activity must have occurred, so we should not clear the lag values > even if the lag tracker is empty. This approach looks good to me. One comment: currently, the lag becomes NULL basically after about one wal_receiver_status_interval during periods of no activity. OTOH, with this approach, it seems it would take about twice wal_receiver_status_interval. Is this understanding correct? Regards, --=20 Fujii Masao