Обсуждение: Implicit table removal from logical replication publication

Поиск
Список
Период
Сортировка

Implicit table removal from logical replication publication

От
Avi Weinberg
Дата:

Hi Experts

 

I had a case where a  team member deleted and recreated an empty table which participated in logical replication.  After that action the table no longer was part of the replication and new inserts were not copied to the subscribers.

 

How can I check existing publication for the list of participating tables so I will know (from the publication side) that a table was removed?

 

It is possible for table to be removed from publication using the following steps:

 

create a publication with 2 tables

create a subscription to that publication

verify you have two lines for the following query on subscriber side "select * from pg_subscription_rel"

delete one of the tables from the publisher side

run alter subscription the_name refresh publication

run select * from pg_subscription_rel and see that only one row remain

even if you now add the deleted table on the publisher side, it will no longer participate in the publication until you add it explicitly again using "alter publication add table"

 

How can I know that the table was removed from publication so I will know to add it?

 

Thanks!

 

 

 

IMPORTANT - This email and any attachments is intended for the above named addressee(s), and may contain information which is confidential or privileged. If you are not the intended recipient, please inform the sender immediately and delete this email: you should not copy or use this e-mail for any purpose nor disclose its contents to any person.

Re: Implicit table removal from logical replication publication

От
Vijaykumar Jain
Дата:
Wow, the drop table silently removes entry from publication without any logs.

I could not find any monitoring view to help me figure out if the publication is broken due to ddl change.
pg_stat_replication on publisher, and pg_stat_subscription on subscriber only help with lsn based lag.
unless this is not an issue but a feature ?
i'll check more on the better part of monitoring logical replication stuff.

but for your case, 
you can set up an event trigger that would avoid dropping the table. 
basically any drop of a table or any ddl that would break publication.


you can have a custom query filter that would prevent dropping of objects part of publication accidentally.

and then you want to exclusively drop the table, once not part of publication, you have to first remove the table from publication and then drop.

I have not run this in production, so I believe others may chime in, but logical replication issues from logs are not the best.
I am happy to be corrected.
I'll update on more scenarios.



Вложения

Re: Implicit table removal from logical replication publication

От
Cory Nemelka
Дата:


On Thu, Jun 10, 2021 at 12:39 PM Vijaykumar Jain <vijaykumarjain.github@gmail.com> wrote:
Wow, the drop table silently removes entry from publication without any logs.

I could not find any monitoring view to help me figure out if the publication is broken due to ddl change.
pg_stat_replication on publisher, and pg_stat_subscription on subscriber only help with lsn based lag.
unless this is not an issue but a feature ?
i'll check more on the better part of monitoring logical replication stuff.

but for your case, 
you can set up an event trigger that would avoid dropping the table. 
basically any drop of a table or any ddl that would break publication.


you can have a custom query filter that would prevent dropping of objects part of publication accidentally.

and then you want to exclusively drop the table, once not part of publication, you have to first remove the table from publication and then drop.

I have not run this in production, so I believe others may chime in, but logical replication issues from logs are not the best.
I am happy to be corrected.
I'll update on more scenarios.

is pg_publication_tables what you are looking for?


--
--cnemelka

Re: Implicit table removal from logical replication publication

От
Vijaykumar Jain
Дата:
pg_subscription_rel
pg_publication_rel

have the relation part of the publication concerned.
OP has an issue to figure out if publication has a list of tables not in sync in subscription and has subscription broken.
there may be ways to query tables on subscriber dbs via dblink or fdw, 
but there is no view of metric for individual relation level subscription to help figure out if it is broken.

I mean like for replication slots, we have an active flag to easily figure out issues with replication, but not with pub/sub.
I only used logical replication for upgrades, so not have little idea wrt ddl changes issues.