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 1vzlUR-001IQm-0i for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 01:02:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzlUO-001FDt-0M for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 01:02:24 +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 1vzlUN-001FDk-2h for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 01:02:24 +0000 Received: from mail-qv1-xf2c.google.com ([2607:f8b0:4864:20::f2c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzlUM-00000001NM2-1Vp8 for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 01:02:23 +0000 Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-89a00e8dc04so84024786d6.0 for ; Mon, 09 Mar 2026 18:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773104542; cv=none; d=google.com; s=arc-20240605; b=KkOULhSGyH0RAn7Q7diyDoV2idWEMaQfp0s6MxSBfc3Su7p72uNitQUU3PtTpF/vcd qI+Icn7stbBeie+OkVz5pbCyLH+UdsnY4cEZV2f2LC0cEM1HzhO8Pb+WyNvQBpxg6Sny uLFLSBBpDi8OLNocq3S+kJHwruVTuLs4tzyK755lS/77S6fVTs9afj31FjQjixexp/nq AG212ahY++C+711wiao0Su0MtGacw1/rvT+j6ARpOgrQmeDqcPkpnhNqAkRARZz40xvd 6HNtbw+831RUzaRquDmXWfMwIQmIbt0+jmKyw3DRWGac45ZP1YEzA8oZabfuW3VFMaCa wF9w== 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=BGLPGoZ38BSR8Ud3Suyg53C2COYQjOWMPlRTV2KLqAI=; fh=x4xgi4tdDukVB0fBuAIe3vORvD36rbbTBlhrrGN8QbM=; b=MHxh4ViLd0Hv8saB+iSSwIVM9KqXRBfVWy/Ls4RFRRED18Du3H6YghNW2BM/WbNWXt anj4Ruuw7IOIIJ02V8dAd3uOwgrc5ubwNP76noatDdwdK3RmlZLQ1HHtE9QfoT7pqUAB MQaoITXbyNzGp08B7pDFrGfvdS8l93YRmjQBz35u9LgyW3MDD0eFymm2FsGVsQkjSJym vA3hzsfJBRA6eyg1g8CxCjBAI4P8oD9HzA1ULaIfvVoRqO2j3RJDvF65q2wwEVgVw7s1 TOjXWPPlRoB5wJvXksdaNe5jA3pZA+uOgddxfN4FVwC7NoE7t72s0CVvhn5Iy+vC9Sb1 aTeg==; 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=1773104542; x=1773709342; 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=BGLPGoZ38BSR8Ud3Suyg53C2COYQjOWMPlRTV2KLqAI=; b=VLXe8EKnu7Bjc0GRMXioaz3t3rFl35meGiMjP9qXoSbEfZXmXqtUYCAYRniSO8OBbV FREZFU7YaDJzo/t6lgaFrICNMal3TttDTorzigjH+BjMsYOtbry6RjL/pJKjwPVlTmJr B/1zSH9GFbC5upvB/vOf9YT+QWMSh7SMg2j7iW0nksDWh7ykAXtj2zY7dr5b5FNpQ+OZ ylRO22N4/+Iz529jTYO+dFbrU/NygPA/mL0QG6EjPE2Lmw9Ifv2dklTE5AQuUk/sm3Ko VuXMhCS+YVI6pOz7UFjlwtsYMyPhIrrSHa5CZ5ITTvEQnTr9GuqckIZMnCisHpByLqrY BRKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773104542; x=1773709342; 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=BGLPGoZ38BSR8Ud3Suyg53C2COYQjOWMPlRTV2KLqAI=; b=oLMQjF8f6iLI6PCKMJACiSsCGUldnjvVM9CZNTJWSJjKVUxNY8dUVpK5Qv2ztlL50+ 2BNx/4Bkffiyd/m4pLBmASJiPdcY4d2ySOSGHPEUaIYYPTLRzMVk7+03ZedItCevxo8U dUbErz1cptpooWNonBz/2CnZ86YMMWoZ5fRXb0f0bhm05DVX43YbwuXT7rncDTRXYy9g MK++btcFBsOsYc5FX46w0hURlT15YjhNIk63x0Zqrzu9J/gWmrofncCgsI/RpCV12xuS B4kO7J8ak8761JIESEaUeFX6CJ27T6B3zWnTUTqHl3HqBCaGajp2bTniLrhX9LfgVJx0 BgGA== X-Gm-Message-State: AOJu0YwnKLnocIXgJKf9TuJHLXhduGt7hbe5O2yrjSG7VsH/FGOrlsV+ J690rN6iHemVh8qa0kmZ9xoUcjjKcF6e4yibxi1TcOLQMseVzW1gRBryBqSA0pxtbPXjzfdx8B2 vS5YyTF/3ts7EN/Oz3w6IzkvNEOAlWQ== X-Gm-Gg: ATEYQzzv2cDvdJwpgSGtuzjJbtdtHAUS+TEU2DamfffP8au/9z8XqMF6K4uAOgRLMsM HfPMhFs1IckJN3K5E2N7w/2ePWEY5sixA8PDNJKQgW3i7tK1mVLhk0woBn6LGBq8qgHbn877/o2 M2fooyR2xH8iXanzIGT1+8sFT04YhYc2kItv4PAvOddD+lE+X150a3soyMil2QETBPrLWhwN5u6 0qO1f7XNhfe2xZo0PLbXJetRXXYEhZuuq11mLXWD8Ue8vbBFUd/nsBXFTV8pJxTazeATPEYDAD1 Atv4+U8= X-Received: by 2002:a05:6214:c64:b0:895:9df:cea5 with SMTP id 6a1803df08f44-89a30a5a5d9mr183183596d6.27.1773104541615; Mon, 09 Mar 2026 18:02:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shinya Kato Date: Tue, 10 Mar 2026 10:01:45 +0900 X-Gm-Features: AaiRm52XGGL5JZXtIPi4DTWa_hxKltjNl9Mc6UKVJ4cxSWdWNSqcrmLCeWnRYoU Message-ID: Subject: Re: pg_stat_replication.*_lag sometimes shows NULL during active replication To: Fujii Masao 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 Mon, Mar 9, 2026 at 8:21=E2=80=AFPM Fujii Masao = wrote: > > 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. Thank you for looking into this. > One comment: currently, the lag becomes NULL basically after about one > wal_receiver_status_interval during periods of no activity. OTOH, with th= is > approach, it seems it would take about twice wal_receiver_status_interval= . > Is this understanding correct? Exactly. With this patch, it takes about two wal_receiver_status_interval cycles to show NULL instead of one. I think this is an acceptable trade-off because it is better to take a bit longer to detect inactivity than to incorrectly show NULL during active replication. --=20 Best regards, Shinya Kato NTT OSS Center