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 1wlp3H-000PAI-1U for pgsql-admin@arkaria.postgresql.org; Mon, 20 Jul 2026 14:33:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wlp3F-003hZX-2N for pgsql-admin@arkaria.postgresql.org; Mon, 20 Jul 2026 14:33:01 +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 1wlp3F-003hZO-17 for pgsql-admin@lists.postgresql.org; Mon, 20 Jul 2026 14:33:01 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wlp3C-000000017qK-2PDl for pgsql-admin@lists.postgresql.org; Mon, 20 Jul 2026 14:33:00 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4955de8797cso6446465e9.3 for ; Mon, 20 Jul 2026 07:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1784557977; x=1785162777; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:to:from:subject:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=ltbNvPwzk7ITPuizdk2GouoDg4KVjeusUc3kpAKTK7M=; b=Z0GuS0k9vVfOHIStD3lAZTEnSnPWahnLbBx1UO/x5ji7YZ3ikKnw+7jAaZKac3X/g+ sSoxDCGPUYDA+MT70xJZRL4wZJChXU5xSIuatq3oQWjBfgrf42l5DXRULh5f4g9O+7Ae byw6fdP64/8f6w8zQ0Z7o5Z31bKiIxXDGuev9aLxXWibT71Sfd8+2vG62w+0IbVj7NTX +mrQXdgVAZd5hAWCRiLkAnpLs2nZ5diUvyodIDEkLWMh0Ol8Eu8gXLeeXCM7d/tin3v0 yk6GSfpI+32Dt2ITmHL8FuF4JPNt0rI0jalnBaJRXT4OJYIWy8Kr/85C0cS4mxJIkCOE KwUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784557977; x=1785162777; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ltbNvPwzk7ITPuizdk2GouoDg4KVjeusUc3kpAKTK7M=; b=U/3ausGxg8aQgQgCgkhdzkPWB/q/oEVDsUGRWGfrnG0UmS2BthuZOYPClKbmteqtWa oGMwEPqFXoTOu152eUbdpKhabpRa3z023JZuP2cI+iRF6Qj7XVl5/xdG7U//NaILarsb 2kVIVQc9MO6EyE5cw3Jl/1P0O6VNQJQupfHjpcvpOgDWgN0p8g/X9s+W6p8qiOwT4X5K WQnaUfUM2RShHPwqXB/iV1ZeRvRz+wAmQexp9J98Z/hwqmkAueNYDLevY/F27sOmjnps dUTubz5vVQbOG2uoFZJryBmHR0t1ta5k1TT3tzSs6cag/X1Z35sXfdH6awRRNwMjxfbO dFRA== X-Forwarded-Encrypted: i=1; AHgh+RoRtLhwY7ardeQNz9bgNRti528BA7RPEAj3xyul7i5QmidMcoE4NUEudP1PDGRKtVO2AmaatIYfP8/T6A==@lists.postgresql.org X-Gm-Message-State: AOJu0YwrmxlpgYeN9CFmazOt52lMcYKIcofRxpw6/Anpkq4adN4iCgrY +YnMfdEbLmLsXCFWpQZ7QkUoctsJOGxpq46s8+rpkz/kUJSmI0K9gv7Vpj9VFh6ltuo= X-Gm-Gg: AfdE7cnJvmT1CrtcstYqhEfpETuvtewmTGSaz5gtCewL9NBHhIbDycVOXOrS5p0junp 9tJ+WRPGskNZyvw54Ct8qHk3dK3IfP4RIfRMkYEObDr1gKq3bJBFtCkXUbmiljdHazKMwEU1Hnv BDOLjJcEvdravacd64ipd98shlVqFoGMnPVVoQ4IL5HjrvN5z3fVomBvwNL1dJDXTyXV7kUJH36 zelUgEt7qAZHhv0Xk/L3dMLo+DSeDEn2MLLsJn1ZAmX6RZMdB+3UnksBVA9GnRRHoAbTybuNObj O2tzyvJh7JyLnn7xXThVzX8ZPiSwMngIFjhGfW7EpHQKVfDTtl9JggqgdzmfX3g7HoODmhpsl6z umjUTt2y+S6dI8JfWty0deEvwOh7j4dcLan7UvL5i2aJMsM4vJAWw+axwqfGO7FKrWD+WIAd9lq 5pSXKIei+UbxjNZpDRcInOifCnJwkn+M0= X-Received: by 2002:a05:600c:354e:b0:495:4811:7998 with SMTP id 5b1f17b1804b1-4954a3eabb6mr175636985e9.17.1784557977427; Mon, 20 Jul 2026 07:32:57 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:70:80b7:25e1:93b6:261a:ce02]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4954a2a2511sm244293315e9.1.2026.07.20.07.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 07:32:56 -0700 (PDT) Message-ID: Subject: Re: Monitoring Streaming Replication From: Laurenz Albe To: Daulat , pgsql-admin Date: Mon, 20 Jul 2026 16:32:54 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2026-07-20 at 19:04 +0530, Daulat wrote: > We are currently using the following script on our PostgreSQL 10 standby = server > to monitor streaming replication lag: >=20 > replication_lag=3D$(psql -U gateway postgres -tAc " > SELECT CASE > =C2=A0 =C2=A0 WHEN pg_last_xlog_receive_location() =3D pg_last_xlog_repla= y_location() > =C2=A0 =C2=A0 =C2=A0 =C2=A0 THEN 0 > =C2=A0 =C2=A0 ELSE EXTRACT(EPOCH FROM now() - pg_last_xact_replay_timesta= mp()) > END; > ") >=20 > This script appears to measure only the replay lag on the standby. > However, I am concerned that it may not detect certain replication failur= e > scenarios and could incorrectly report a healthy status. >=20 > Specifically, I would like to know how to monitor the following situation= s: >=20 > 1. The standby is disconnected from the primary. >=20 > 2. The WAL receiver process has stopped. >=20 > 3. The standby cannot continue replication because the required WAL files > have already been removed from the primary (for example, requested WAL > segment ... has already been removed). The best is to monitor replication on the primary using pg_stat_replication= . "application_name" can identify the standby servers (if you set that parame= ter in primary_conninfo) and you get the various lag entries (NULL if there is = no activity). If the standby is disconnected, its row in the view is missing. That will also be the normal state if the required WAL has already been rem= oved from the primary, because that terminates the replication connection. So you can simply alert on missing rows in the view. If you are using replication slots, pg_replication_slots provides additiona= l information. Yours, Laurenz Albe