Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ml4Oc-000239-PC for pgsql-general@arkaria.postgresql.org; Thu, 11 Nov 2021 07:21:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ml4Ob-0001Dw-Om for pgsql-general@arkaria.postgresql.org; Thu, 11 Nov 2021 07:21:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ml4Ob-0001Dn-9n for pgsql-general@lists.postgresql.org; Thu, 11 Nov 2021 07:21:17 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ml4OY-0007D7-Fm for pgsql-general@postgresql.org; Thu, 11 Nov 2021 07:21:16 +0000 Received: by mail-wm1-x32d.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso3730892wme.3 for ; Wed, 10 Nov 2021 23:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=XaAqm4kpXxbvcuwLRSOGKy9Q5h3cSluZOU0WLqwzAs8=; b=Mz9ufe/hknYXZXVhLYN+vnBhvB9GONOe82SmrVcDiJr8NlBUIt0pmPW29XFR2A6J02 LyblVElyOZm5K4BUNL50CNb1k2+4c7faBn4kwBWVH1D0Vt5Jr5SVD/D4dveMGAv8v3nb bXAJa6rst3C4JHz5pWfJ/7WBQZTxvSc39ueO1WB8gOs7w2MjfxxPFZ3G+9r/E518Z9s0 bhWmLyR/XT6rjSoEluLvri6oowBV2vUpv0KFj4TO37xw9ollt5Lf5DHb9tzNFVfrkuca pjnwbnMDVslyQKObih3x/tPTLMInOigHhTu7u8cB25l4irktz1216MmPY3x3Pvt5Bupz 8YIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=XaAqm4kpXxbvcuwLRSOGKy9Q5h3cSluZOU0WLqwzAs8=; b=8PDT3jathWtkTgJIG+js4UuAjxdNr4G8iCl2FoXgE9+YXXsKr4hSmqPSDMf7RRVNKk 5WTXbqoGJec/J8yV+WG5i4s6qGszhG72UYNgBrnTml7nrFAvQ5Smcv/+o3Nq/oQovwMR JH65vA6ZEMk1Rp5sI3qZrWgfANyFEjauQAFRjV6LIlxsMVYnY+0tWg/C1+SipzQvq/1L pJRIjtD2llqRyBfi/QEAFQyTdaTi6GpEnyJaSudRKZ5A0zn6W4ES/gqjSeV+ZqPKvOAY 1KRa/iJZ3njDbEZGtbWpT/GvSmdz9ru2Gcmr2ScmUBgxvYIP9G/vzs5EvFznGk2Cr59l QInQ== X-Gm-Message-State: AOAM5322pCKaCufTkensiuqZ+Cm3tuelCnFRKUuKzbywmhyLWEoQw7ZX OLTU+sBiAaHrgd58tF/noRGYGQ== X-Google-Smtp-Source: ABdhPJz03oiuYhbMWYyxZ95gwwTeWa5U/rur3g6y1LZpYbz30wWN9i4LjwF7OJqF615HG24BaH5+nA== X-Received: by 2002:a05:600c:1914:: with SMTP id j20mr23424516wmq.26.1636615273400; Wed, 10 Nov 2021 23:21:13 -0800 (PST) Received: from localhost.localdomain (62-46-249-181.adsl.highway.telekom.at. [62.46.249.181]) by smtp.gmail.com with ESMTPSA id n32sm8970896wms.1.2021.11.10.23.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 23:21:13 -0800 (PST) Message-ID: <05046e7ed4b1938a1fbfcefac45f66ed745a0320.camel@cybertec.at> Subject: Re: Pause streaming replication From: Laurenz Albe To: Rita , Ben Chobot Cc: "pgsql-general@postgresql.org >> PG-General Mailing List" Date: Thu, 11 Nov 2021 08:21:12 +0100 In-Reply-To: References: <476bcc51-c1e4-1fb1-24c6-07cd5f6d5d80@silentmedia.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2021-11-10 at 20:36 -0500, Rita wrote: > On Wed, Nov 10, 2021 at 7:24 PM Ben Chobot 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