From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Rita <rmorgan466@gmail.com>
To: Ben Chobot <bench@silentmedia.com>
Cc: " <pgsql-general@postgresql.org>
Subject: Re: Pause streaming replication
Date: Thu, 11 Nov 2021 08:21:12 +0100
Message-ID: <05046e7ed4b1938a1fbfcefac45f66ed745a0320.camel@cybertec.at> (raw)
In-Reply-To: <CAOF-Kfi7_YXDGCNcPKX_aRd1ikMLapKOooZbM0YTPZd9+CZcrA@mail.gmail.com>
References: <CAOF-KfjFT1wo-j1vO1k14niiaGr=75Daw+MM8U4+PRp9vbgTGw@mail.gmail.com>
<476bcc51-c1e4-1fb1-24c6-07cd5f6d5d80@silentmedia.com>
<CAOF-Kfi7_YXDGCNcPKX_aRd1ikMLapKOooZbM0YTPZd9+CZcrA@mail.gmail.com>
On Wed, 2021-11-10 at 20:36 -0500, Rita wrote:
> On Wed, Nov 10, 2021 at 7:24 PM Ben Chobot <bench@silentmedia.com> wrote:
> >Rita wrote on 11/10/21 1:25 PM:
> > > Hello.
> > >
> > > I am testing alerting on my primary and standby setup. I have async
> > > replication working but I would like to temporarily pause it so the
> > > value of 'state' isn't streaming. (select * from pg_stat_replication).
> > >
> > > How can I do that?
> >
> > By reading the fine manual:
> > https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-RECOVERY-CONTROL-TABLE
> >
> > The function you are looking for is pg_wal_replay_pause().
>
> Yes, I have read the manual and seen this. It pauses the replication (select pg_is_wal_replay_paused()).
> But on the primary, when I look at pg_stat_replication, it still says 'streaming' in the
> state column. My question was how do I get it from 'streaming' to anything else?
> (https://www.postgresql.org/docs/11/monitoring-stats.html#PG-STAT-REPLICATION-VIEW) ?
>
> I want to trigger an alert when 'streaming' isn't there. Or is there a better way to do it?
If the standby is no longer streaming, that certainly should trigger an alert.
But if you want to monitor replication delay, you should instead use a query like
SELECT pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)
FROM pg_stat_replication;
That will measure the replay delay in bytes, and you can alert if the value exceeds a certain amount.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, rmorgan466@gmail.com, bench@silentmedia.com
Subject: Re: Pause streaming replication
In-Reply-To: <05046e7ed4b1938a1fbfcefac45f66ed745a0320.camel@cybertec.at>
References: <CAOF-KfjFT1wo-j1vO1k14niiaGr=75Daw+MM8U4+PRp9vbgTGw@mail.gmail.com> <476bcc51-c1e4-1fb1-24c6-07cd5f6d5d80@silentmedia.com> <CAOF-Kfi7_YXDGCNcPKX_aRd1ikMLapKOooZbM0YTPZd9+CZcrA@mail.gmail.com> <05046e7ed4b1938a1fbfcefac45f66ed745a0320.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox