Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iY8s4-0005Mo-HP for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 13:21:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iY8s3-0007GD-8n for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 13:21:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iY8s2-00073t-Kq for pgsql-general@lists.postgresql.org; Fri, 22 Nov 2019 13:21:10 +0000 Received: from mx1.stadt-zuerich.ch ([194.56.33.10]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iY8rv-0006YX-3F for pgsql-general@lists.postgresql.org; Fri, 22 Nov 2019 13:21:09 +0000 X-IronPort-AV: E=Sophos;i="5.69,229,1571695200"; d="scan'208,217";a="108938117" Received: from unknown (HELO SZHM27374.global.szh.loc) ([10.7.50.70]) by mx1.prm.szh.zone with ESMTP/TLS/AES256-GCM-SHA384; 22 Nov 2019 14:21:00 +0100 Received: from SZHM27370.global.szh.loc (10.7.50.50) by SZHM27374.global.szh.loc (10.7.50.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 22 Nov 2019 14:20:59 +0100 Received: from SZHM27370.global.szh.loc ([fe80::25ce:879f:5795:3325]) by SZHM27370.global.szh.loc ([fe80::25ce:879f:5795:3325%10]) with mapi id 15.01.1713.004; Fri, 22 Nov 2019 14:20:59 +0100 From: "Zwettler Markus (OIZ)" To: "pgsql-general@lists.postgresql.org" Subject: sql query for postgres replication check Thread-Topic: sql query for postgres replication check Thread-Index: AdWhLwsIaUTN/nPxSk2013en68ERdw== Date: Fri, 22 Nov 2019 13:20:59 +0000 Message-ID: Accept-Language: de-CH, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.7.48.250] Content-Type: multipart/alternative; boundary="_000_cf8b3fce87404edd836ceb705d36776bzuerichch_" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --_000_cf8b3fce87404edd836ceb705d36776bzuerichch_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable We would like to check the Postgres SYNC streaming replication status with = Nagios using the same query on all servers (master + standby) and versions = (9.6, 10, 12) for simplicity. I came up with the following query which should return any apply lag in sec= onds. select coalesce(replay_delay, 0) replication_delay_in_sec from ( select datname, ( select case when received_lsn =3D latest_end_lsn then 0 else extract(epoch from now() - latest_end_time) end from pg_stat_wal_receiver ) replay_delay from pg_database where datname =3D current_database() ) xview; I would expect delays >0 in case SYNC or ASYNC replication is somehow behin= d. We will do a warning at 120 secs and critical at 300 secs. Would this do the job or am I missing something here? Thanks, Markus --_000_cf8b3fce87404edd836ceb705d36776bzuerichch_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

We w= ould like to check the Postgres SYNC streaming replication status with Nagi= os using the same query on all servers (master + standby) and versions = (9.6, 10, 12) for simplicity.

 

 

I ca= me up with the following query which should return any apply lag in seconds= .

 

 

sele= ct coalesce(replay_delay, 0) replication_delay_in_sec

from= (

&nbs= p;      select datname,

&nbs= p;             = (

&nbs= p;            &= nbsp;  select case

&nbs= p;            &= nbsp;           when rece= ived_lsn =3D latest_end_lsn then 0

&nbs= p;             =            else extr= act(epoch

&nbs= p;            &= nbsp;  from now() - latest_end_time)

&nbs= p;            &= nbsp;         end=

&nbs= p;            &= nbsp;  from pg_stat_wal_receiver

&nbs= p;             = ) replay_delay

&nbs= p;      from pg_database

&nbs= p;      where datname =3D current_database()<= /o:p>

&nbs= p;    ) xview;

 

 

I wo= uld expect delays >0 in case SYNC or ASYNC replication is somehow behind= . We will do a warning at 120 secs and critical at 300 secs.

 

 

Woul= d this do the job or am I missing something here?

 

 

Than= ks, Markus

 

 

 

 

 

 

 

 

--_000_cf8b3fce87404edd836ceb705d36776bzuerichch_--