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 1u1jWo-007C9I-Uc for pgsql-general@arkaria.postgresql.org; Mon, 07 Apr 2025 10:16:31 +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 1u1jWn-00EtDY-7T for pgsql-general@arkaria.postgresql.org; Mon, 07 Apr 2025 10:16:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u1jWm-00Et8W-MT for pgsql-general@lists.postgresql.org; Mon, 07 Apr 2025 10:16:29 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u1jWk-003Rzg-20 for pgsql-general@lists.postgresql.org; Mon, 07 Apr 2025 10:16:28 +0000 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-30185d00446so3306774a91.0 for ; Mon, 07 Apr 2025 03:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744020985; x=1744625785; 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=Y9Yfp5+NCcBHzUBNmc3xze/a1nONAvLdaY3stqzQJQA=; b=L/vhpSbavptEfhVq81scScAamuRngBbD6Q175/4Dvgfj88vWEr+epR32ut9A9gXMHA r7Tp5UgCWHphebE1DJ79BduLD6VDO6qKoz/qUKcAKBv2PhzRffNWks535AzvB24IWO9C uwlPFdohuqFjcG/Q1aoPRZ2VGqn47ytJjbKGuayiVx6lqg5+3MwgBmcXVLLYyiRT+BvM 8T14vd0HQVMwZHETI91aW4q880Kd5PFFtjtxydEb4gJP+rJ3Q5pJCW+zm+aBsNXocwDr AI4J/yCaggtPdd7HTwH5B5CjbKCUgSJnZCauen8xjrHeyBPf9uxLEVJ2McfSJhIvGUii c2dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744020985; x=1744625785; 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=Y9Yfp5+NCcBHzUBNmc3xze/a1nONAvLdaY3stqzQJQA=; b=IJMgI0n3tsR5Amp7VV8CN3UobsAdksRKhLa3p2YNrM+mbb12AMJyjSJwqAEw2DrQ2B ZOl1xbtPBBJR1fhZNVu6X4jy+cBj8l7udb/vQ49sokOUKDQn/QoKBc9BBqMxdeBrVUhU 9sLdTxO4Ibl/l0KHGtceZdVIKDB0K5hyy34g+uUIAYBYfKDEI4YMsevv9GHYLTee/YwP 7bGvw4riF97UCya++7Se2jjQ2jVuOkSEz0kmAVnmoYh1+QrwgwPyGeLoR4io5LrlT0SN t5kAkEP9tT4zXx2LcA+4vcN5t78F/QbnrclsYS0HC7E3iLmv1rdyAK1t0UPYapkK1VF9 1emA== X-Gm-Message-State: AOJu0Yw+RgRRLgx+rt7ILKKGeXbcJTWpkPFdftCBVugA60PQ7Bpr8gkN XiNaZolIfcmCrHDnAxf0P1DQJEteYc82hU6CZeZpsqRUKorRL4jVyvTE22Y+K8tADT7VVvRjuXJ jb4/HVdXFjWCC6vmAHVyaIl+nq/CWl1sUU7Y= X-Gm-Gg: ASbGncvV8jKfB3TweYyjql0JuG6seeXRMGGnHH8tPpYeQwFyt1/14RF/a/QqWLuHD7V hVhhVwq8cZHr3iuQfn2najMg+OKvD9+Ebhmht3yuMV77nQ3G4Hxcyu6uxo1mZa4vwpwsjZvDCHo BhRMFo1gIV9w+ELdsGucw2bGoQDDuCYK3ESYvU X-Google-Smtp-Source: AGHT+IGhuGq4mm5tLrXlN/9qsC7479pgv16IC7E8OV/ziZg6veR43VDQXoin8LG6TV46py73hoRt0YE+GzYKilPXB7U= X-Received: by 2002:a17:90b:5690:b0:302:fc48:4f0a with SMTP id 98e67ed59e1d1-306a4dad016mr18211697a91.0.1744020984804; Mon, 07 Apr 2025 03:16:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Willy-Bas Loos Date: Mon, 7 Apr 2025 12:16:13 +0200 X-Gm-Features: ATxdqUGfBMobMZ6BMaprkUk50knjaglV3X-ZVlT2hSe8H6G5s5KyAVawA-6o_r8 Message-ID: Subject: Re: find replication slots that "belong" to a publication To: Justin Cc: pgsql-general Content-Type: multipart/alternative; boundary="00000000000047c0a006322d879d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000047c0a006322d879d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Justin, thanks for your anwer! My question is not so much about "can i drop a certain replication slot", more about "does this publication still have any replication slots?". Or, if you will: "what's the publication for this replication slot?". I've double checked the views that you suggested, and I found that I can relate the WAL sender processes to replication slots through pg_replication_slots.active_pid . I've also looked into replication origins. But I can't find a link to the publication. And that's what I need to know. Cheers, Willy-Bas On Sun, Apr 6, 2025 at 3:36=E2=80=AFPM Justin wrote: > 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 >> subscriptions and the replication slots. Especially when you don't want = to >> make assumptions about any subscriber nodes, so you are restricted to th= e >> 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 fo= r, > 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-ST= AT-REPLICATION-VIEW > > > https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-AD= MIN-BACKUP > > Hope this answers your question > > > Justin > --=20 Willy-Bas Loos --00000000000047c0a006322d879d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Justin, thanks for your anwer!=C2=A0
My = question is not so much about "can i drop a certain replication slot&q= uot;,=C2=A0
more about "does this publication still have any= replication slots?". Or, if you will: "what's the publicatio= n for this replication slot?".

I've doubl= e checked the views that you suggested, and I found that I can relate the W= AL sender processes to replication slots through pg_replication_slots.activ= e_pid .
I've also looked into replication origins.
=
But I can't find a link to the publication. And that'= ;s what I need to know.

Cheers,
Willy-Ba= s

On Sun, Apr 6, 2025 at 3:36=E2=80=AFPM Justin= <zzzzz.graf@gmail.com> w= rote:
On Fri, Apr 4, 2025 at 4:58=E2=80=AFAM Willy-Bas = Loos <willybas@g= mail.com> wrote:
Hi!

I'm looking for a way to find out if there are still replicati= on slots active for a publication before dropping the publication in an aut= omated way. The idea is that the publication is thought not to be needed an= y longer, but we want to make sure.

I'm having= trouble finding a link between a publication, the subscriptions and the re= plication slots. Especially when you don't want to make assumptions abo= ut 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 st= ring manipulation on such query strings to get the information I need. Post= gres 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=C2= =A0appear in the views pg_stat_replication and pg_replication_slots.=C2=A0 = Both views have the information you are looking for, the difference is pg_s= tat_replication shows only the active slots.=C2=A0 Keep in mind Temporary S= lots 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 logical repl= ication 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 b= ehind it is. The=C2=A0pg_wal_lsn_diff=C2=A0 can be used to figure out how f= ar behind a slot is



--
Willy-Bas Loos
--00000000000047c0a006322d879d--