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.94.2) (envelope-from ) id 1u1QAf-002AC9-FQ for pgsql-general@arkaria.postgresql.org; Sun, 06 Apr 2025 13:36:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u1QAd-00Dxqw-Su for pgsql-general@arkaria.postgresql.org; Sun, 06 Apr 2025 13:36:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u1QAd-00Dxqo-G4 for pgsql-general@lists.postgresql.org; Sun, 06 Apr 2025 13:36:19 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u1QAb-003jGX-1G for pgsql-general@lists.postgresql.org; Sun, 06 Apr 2025 13:36:19 +0000 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-3d450154245so30501295ab.2 for ; Sun, 06 Apr 2025 06:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743946575; x=1744551375; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gU/I/5/tMh9tzWW1ahsHNFFfpxdz8MBIPdqADx+YZrs=; b=NQy24SVlLF5JLCp+3kibmM8OZS3wW4HFNC2Ye/q+WTvc2En8Is5NRbk0AucxGkVwoC F2qOMzyZ+9bGIWVUP6DqvSYc6yzQN9vvvdAi5sq5pbBdLDpCcTC5Vgc8v8WC7wGvVGR8 P41Owcl2hvQjYJeeucDm4V+4M66gjMgZn/lmyUBZvO2Bf5sLtLSAmtcK1RLVQ0RwquFD FjFW9dvEgud5zwoZCYsxyQFihrOtq4+Nr97p3labYeOXePLsSC3VCvuwATjWkPoqbsv3 fZ7a39AF0UUWGhrhoNpdUS4FtEvGa4OUmfsVV6YWofZ4DYrXQscbhO6NcswAh3l6j+/1 8urA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743946575; x=1744551375; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gU/I/5/tMh9tzWW1ahsHNFFfpxdz8MBIPdqADx+YZrs=; b=BZJG2FZDE+K/mp5HFyNleGIVyy8nlDpk3Q9+gU7ptYqMD60E8lPjrD51Qia3XuZjDS Y2cZQITppjwNcjuFiLtW/rTib7oUqorboJlW/08LESFJIM4GgZVhWVr6Wviz5229nSsq PsjtaWXAhRTph4Ox4GwY1Xwp4QoffoV5AYtg1QqS6pQlLCZAHvyTDTRNz6Otcmc/tgxY sOnL2GCcmPhPs3VbzubioevyUpUa71KiDpDMx6oogO4gcxVtMtstbsdONvroQPImJiZE 6ZMNYwTy2oTYwRNMKJwov33oh4m3xbvgEkM7C2pwBFPJIv7kFFO4YlugvR07r627/oW7 vgcg== X-Gm-Message-State: AOJu0YxB2fR1j4Gn+U/Cf9J3/myCi7SZvBLY7dHL1Co87G5yiSn5uRKy 8MEiSP1XjyWlCKiNyhHr98EcxVX9imcIOnBl+SXvoWfEVqqU8u7VpJ4QiKnvpC9CElfFbHBk1+u 12Ac27eGVy3HyyKy4YQfMTJ/mIq4= X-Gm-Gg: ASbGncuA2lYRB3PJLl2suZAFUliwUpNq3fQSyNQ2KitSHXawToWcgmPQ8KpLzEfkUAl bzoGIynaoVjihklX/7vtOhlh7BTK12rowU//jKytk9YiiKELI1R7WTth5lpoZNtzZa/3kofCynZ TU6EKindnKrHXG2JVXGbuyF5+frUAkn5FC0/Yg0xf48YwnrfFQSmxBpXikow== X-Google-Smtp-Source: AGHT+IHuPFoeyb8hq9PniXPs1TQ2Ss/nvIXnzXYOW1uBgXdbpEFB00ow62ahFcEj5V/+KFGwbbDwgwDmDEvFVnyQc7o= X-Received: by 2002:a05:6e02:1c23:b0:3d3:dfa2:4642 with SMTP id e9e14a558f8ab-3d6e5357554mr92536725ab.13.1743946575070; Sun, 06 Apr 2025 06:36:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Justin Date: Sun, 6 Apr 2025 09:36:03 -0400 X-Gm-Features: ATxdqUEyrzWLDUL9i_wXNChPeBDXZr-qEqJ3M4Qf3vafAQv07khhUL4V79YvX5s Message-ID: Subject: Re: find replication slots that "belong" to a publication To: Willy-Bas Loos Cc: pgsql-general Content-Type: multipart/alternative; boundary="0000000000001d4db306321c3481" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001d4db306321c3481 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 4, 2025 at 4:58=E2=80=AFAM Willy-Bas Loos = wrote: > Hi! > > I'm looking for a way to find out if there are still replication slots > active for a publication before dropping the publication in an automated > way. The idea is that the publication is thought not to be needed any > longer, but we want to make sure. > > I'm having trouble finding a link between a publication, the subscription= s > and the replication slots. Especially when you don't want to make > assumptions about any subscriber nodes, so you are restricted to the > publisher node. > > The best I could find was a query listed in pg_stat_activity that lists > the slot name and the publication name: > START_REPLICATION SLOT "my_slot" LOGICAL 5DD1/3E56D360 (proto_version '1'= , > publication_names '"my_publication"') > > I don't like the idea of using string manipulation on such query strings > to get the information I need. Postgres must have a way to compose this > query. > Can anyone tell me a way to find replication slots that belong to a > publication? > > -- > Willy-Bas Loos > Hi Willy-Bas, Logical replication slots appear in the views pg_stat_replication and pg_replication_slots. Both views have the information you are looking for, the difference is pg_stat_replication shows only the active slots. Keep in mind Temporary Slots only live for the length of the session that created it; the slot will appear in both views. The bigger issue I think you are trying to address is when can a slot be dropped safely. Once a logical replication slot is dropped there is no recovery of the slot's lsn position. Probably the best way to decide if a slot has been abandoned is how far behind it is. The pg_wal_lsn_diff can be used to figure out how far behind a slot is https://www.postgresql.org/docs/13/view-pg-replication-slots.html https://www.postgresql.org/docs/13/monitoring-stats.html#MONITORING-PG-STAT= -REPLICATION-VIEW https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMI= N-BACKUP Hope this answers your question Justin --0000000000001d4db306321c3481 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Apr 4, 2025 at 4:58=E2=80=AFAM Wi= lly-Bas Loos <willybas@gmail.com> wrote:
Hi!
<= div>
I'm looking for a way to find out if there are still= replication slots active for a publication before dropping the publication= in an automated way. The idea is that the publication is thought not to be= needed any longer, but we want to make sure.

I= 9;m having trouble finding a link between a publication, the subscriptions = and the replication slots. Especially when you don't want to make assum= ptions about any subscriber nodes, so you are restricted to the publisher n= ode.

The best I could find was a query = listed in pg_stat_activity that lists the slot name and the publication nam= e:
START_REPLICATION SLOT "my_slot" LOGICAL 5DD1/3E56D3= 60 (proto_version '1', publication_names '"my_publication&= quot;')

I don't like the idea o= f using string manipulation on such query strings to get the information I = need. Postgres must have a way to compose this query.
Can anyone = tell me a way to find replication slots that belong to a publication?
=
--
Willy-Bas Loos

Hi Willy-Bas,

Logical replicatio= n slots=C2=A0appear in the views pg_stat_replication and pg_replication_slo= ts.=C2=A0 Both views have the information you are looking for, the differen= ce is pg_stat_replication shows only the active slots.=C2=A0 Keep in mind T= emporary Slots only live for the length of the session that created it; the= slot will appear in both views.=C2=A0

The bigger issue I think you = are trying to address is when can a slot be dropped safely.=C2=A0 Once a lo= gical replication slot is dropped there is no recovery of the slot's ls= n position. Probably the best way to decide if a slot has been abandoned is= how far behind it is. The=C2=A0pg_wal_lsn_diff=C2=A0 can be used to figure= out how far behind a slot is

=
--0000000000001d4db306321c3481--