Re: Pause streaming replication

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Rita <rmorgan466(at)gmail(dot)com>, Ben Chobot <bench(at)silentmedia(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Pause streaming replication
Date: 2021-11-11 07:21:12
Message-ID: 05046e7ed4b1938a1fbfcefac45f66ed745a0320.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2021-11-10 at 20:36 -0500, Rita wrote:
> On Wed, Nov 10, 2021 at 7:24 PM Ben Chobot <bench(at)silentmedia(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shaozhong SHI 2021-11-11 13:24:10 Why in pgAdmin an active session is marked/highlighted in Red
Previous Message Michael Paquier 2021-11-11 02:41:27 Re: Pause streaming replication