Re: Right way to restore logical replication

From: Игорь Выскорко <vyskorko(dot)igor(at)yandex(dot)ru>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Right way to restore logical replication
Date: 2021-02-09 06:25:29
Message-ID: 441161612850655@mail.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<div>Thanks for reply!<br />It makes sense now why that happened and what to do in case of emergency</div><div> </div><div>09.02.2021, 10:01, "Kyotaro Horiguchi" &lt;horikyota(dot)ntt(at)gmail(dot)com&gt;:</div><blockquote><p>At Mon, 08 Feb 2021 22:42:21 +0700, Игорь Выскорко &lt;<a href="mailto:vyskorko(dot)igor(at)yandex(dot)ru" rel="noopener noreferrer">vyskorko(dot)igor(at)yandex(dot)ru</a>&gt; wrote in</p><blockquote> Hi, community!<br /> Unfortunately can't find answer in docs and google. Hope only for you)<br /> [local]:5433 <a href="mailto:postgres(at)postgres" rel="noopener noreferrer">postgres(at)postgres</a>=# drop publication pub ;<br /> DROP PUBLICATION<br /> Time: 3,793 ms<br /> <br /> [local]:5433 <a href="mailto:postgres(at)postgres" rel="noopener noreferrer">postgres(at)postgres</a>=# insert into tbl(d) values ('test2');<br /> INSERT 0 1<br /> Time: 9,002 ms<br /> <br /> [local]:5433 <a href="mailto:postgres(at)postgres" rel="noopener noreferrer">postgres(at)postgres</a>=# create publication pub for table tbl;<br /> CREATE PUBLICATION<br /> Time: 6,646 ms<br /> <br /> result: nothing changed, same errors appears again and again. I couldn't find<br /> how to restore replication without drop&amp;create subscription again.</blockquote><p><br />If you recreated the publication before the insert, replication would<br />continue.<br /> </p><blockquote> Questions here:<br /> 1. what is going under the hood here - why walsender thinks that "publication<br /> "pub" does not exist" when it actually exists?</blockquote><p><br />The answer is "because the publication did not exist at the time of<br />the INSERT". Thus the insert cannot be replicated using the new<br />publication.<br /><br />It is because logical replication tries to find publications using the<br />same snapshot with the WAL record to be sent. Although it is the<br />designed behavior, I'm not sure that is true also for pg_publication.<br /> </p><blockquote> 2. what is the right way to restore replication in my example?</blockquote><p><br />The most conservative way is just to drop the subscription then delete<br />all rows from the subscriber table then recreate the<br />subscription. This allows the newly created publication to work.<br /><br />Also you can drop the subscription, then manually fix the subscriber<br />table to sync with the publisher table, then create a new subscription<br />using WITH (copy_data = false);<br /><br />regards.<br /> </p>--<br />Kyotaro Horiguchi<br />NTT Open Source Software Center</blockquote>

Attachment Content-Type Size
unknown_filename text/html 2.5 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Förster 2021-02-09 09:16:33 Re: Postgres 9.4 Needed
Previous Message Kyotaro Horiguchi 2021-02-09 03:01:43 Re: Right way to restore logical replication