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 1vzmIq-001JC2-1z for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 01:54:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzmIo-001Ngw-2g for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2026 01:54:31 +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 1vzmIo-001Ngo-1m for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 01:54:31 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzmIm-00000001te0-2M4l for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2026 01:54:30 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-679b072ed3aso7760161eaf.1 for ; Mon, 09 Mar 2026 18:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773107667; cv=none; d=google.com; s=arc-20240605; b=e1Wvm8kT2vrgwDwLiNLBKawmZOAWWFgTxDUSaUx44veTvc9lpQIweQ60XI1WXY6HPw t2CusjezOEYf0arv/K2RD2WLpQwjxSnYotdkc5wwhUEs/kQAUbZxSMJtsoEzNUHh8mgi ZZJeGtMjpihiezjz20CGtv+z3MZy9jWbod84yXVoDWi1wiEAHbBeMXzgDMrN1jMf6snV xGxM8/pezm/gjgko1Fo1q9qL0pPajmuznihDgkapd9VNGojj7c5ZmpUsnxTmSKl4tOxM uCA/+SvjtnblKX4ocUfIgxCpHGdGNd4HnpIyzwlF6FJTIXJVQ7DyWjOvW7O3xwuz8QBZ a3cA== 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=iUENM4wu9jnyFiys4VVisGPRPY/aFATvKl5/1WGG4jE=; fh=SprTjyyUNMFOaPK7zUpaC1EEovCYhXioP7Zs2WMpltw=; b=ZGpLTuG2O0s8bqrBrNEZpJi6V0FB0+f3/kSvekG8jwiVTxxPPTjT56sP0s1L2FsKxJ ll/l1E5S5Woy8EioO7hxA0PfgNbImc1RQRGo1+5B9cMgr4wEHEhHlX+Uj3McqRNNgly0 cv6IyKCJTyt4KrjCpF5r36fJKkWi3KnXy8280Ik01s1lqvnXOPzauTAyHBMYRqnf3X0I JASRcf/rUWlqCQifNW0/7Qbu+yGC5VymyztMBdrNSNdeo1q9s83aET6tHDCY/C0dY62H cEyNzkkHrvEjMTfv1XdAKd8HDmf6JhZjSXTH3E1erXt75vrd2Lr36eggLdNfPuwrkKDO rJUA==; 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=1773107667; x=1773712467; 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=iUENM4wu9jnyFiys4VVisGPRPY/aFATvKl5/1WGG4jE=; b=Aua4G3hUS04WjBN2oGIq3E8fcEgOrEBcMLBDukIN0IIZv7IohqRukXnGIRDZlw1kOO 3P911ZRwgoYjWNb0sKYeaL0A7QWkK2dLVbesT1b6MUX8tiAW79CFE8y6PtHBNKuoHGx0 yxOgS5zKkUNRZPPdaa1l+riMC5TP9psOlPEYd9NecT90FYgZr2JWu+rpUANg1RJDnSsP 1PzWQV/NPKTsxBrtcoY+jYTU3Xa8LdBY42Y/BmmZTbs1ugTMpOv+py4ADp6V9shYwAoh DbWmytRdIdIZKLinD2k5JpgWzja4OxqN7pASSYXp36xEx+px7FJBHvmbtzWq6zZPT/js vcwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773107667; x=1773712467; 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=iUENM4wu9jnyFiys4VVisGPRPY/aFATvKl5/1WGG4jE=; b=NIyU09TIZEUfevO+w/VDVf+7fUoT6mOhA7wQYq0b+sS0h12ldJfrGEe2lTOrVaUxco yBuasccAUG+tYKBLOHVGGVDdbxoLCFO2TY/UsuqKvI0dfD1upjrRWibuUHmKhpjEIfyA dMeQwOIHCxx4vbEmzk/qiav59wYdOirRYWXKbHHVvncFgjsbdEgWzIThjpnCGE2oRvAS zz6J213t7/fZTWsqLhf8JDu6I4puM+ySmsUs7OecxasWWTpNtF3KZlDTj1BOJGeCUUZp bPQX3b34IY8cKf5VqnFIi4/ypOmEdMl93sMUaMVFUVolWrMcc425oPeiA5CxptuXP9OT dShg== X-Gm-Message-State: AOJu0YysH3DuWD+Ydt6CXRehvXRVWpvo8hQxqehZ8pfeJuPIzjuHyXbJ OhWZTzSeHrr9C+weWgjJYQcN8WjagHHfyPcQloUvQADGQBguvr/zldATgPPomhmUQxa0HtToRMN uvu2LAYETo2p73pVX1USCaLCHUkYFUS0= X-Gm-Gg: ATEYQzyYB2hZXJZeUKfD435TgHaFRilbCOvQYON9mcX60HiXTWI421ev0UA+1wdwcF2 GCQG4NY1NMNNATnaE3o54U5WtRJ6h1pKTu+zOq2FB88EA+Ojcwnw0G3GluBToo5F4h+WhMJDfaU Zfu2UxPWSUdNPW2SamwVRukZQbzIi066PWh23AfBMolpdQYToh7bNNC6RlSecEcHVwlUhqgLuaB M/izmiI+R0JzzHlttX6lTDvTPMb4mMfk2FXQttdoInA0jv9+Yt/uo9Hf5DNladXDyPMtE5pZQcT 5nNs6xZg96jlqMK6qi0vLvge7S7DlfbL+ijf X-Received: by 2002:a05:6820:2226:b0:67b:a91f:8f1e with SMTP id 006d021491bc7-67ba91f944cmr5193844eaf.9.1773107666524; Mon, 09 Mar 2026 18:54:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Tue, 10 Mar 2026 10:54:13 +0900 X-Gm-Features: AaiRm53HleeqBKJgmiRqWlUtjt92RAvIim58vTWDDEPQkJQ2kbw6oxKw32gWbj8 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 Tue, Mar 10, 2026 at 10:02=E2=80=AFAM Shinya Kato wrote: > > 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 advanc= ed, new > > > WAL activity must have occurred, so we should not clear the lag value= s > > > 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 = this > > approach, it seems it would take about twice wal_receiver_status_interv= al. > > 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. Even with your latest patch, if we remove fullyAppliedLastTime, and set clearLagTimes to true when applyPtr =3D=3D sentPtr && noLagSamples && positionsUnchanged, wouldn't the time for the lag to become NULL be almost the same as wal_receiver_status_interval? The documentation doesn't clearly specify how long it should take for the lag to become NULL, so doubling that time might be acceptable. However, if we can keep it roughly the same without much complexity, I think that would be preferable. Thought? --=20 Fujii Masao