pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Optionally disable subscriptions on error.
Date: Mon, 14 Mar 2022 04:14:30 +0000
Message-ID: <E1nTc6H-000f9J-Ld@gemulon.postgresql.org> (raw)

Optionally disable subscriptions on error.

Logical replication apply workers for a subscription can easily get stuck
in an infinite loop of attempting to apply a change, triggering an error
(such as a constraint violation), exiting with the error written to the
subscription server log, and restarting.

To partially remedy the situation, this patch adds a new subscription
option named 'disable_on_error'. To be consistent with old behavior, this
option defaults to false. When true, both the tablesync worker and apply
worker catch any errors thrown and disable the subscription in order to
break the loop. The error is still also written in the logs.

Once the subscription is disabled, users can either manually resolve the
conflict/error or skip the conflicting transaction by using
pg_replication_origin_advance() function. After resolving the conflict,
users need to enable the subscription to allow apply process to proceed.

Author: Osumi Takamichi and Mark Dilger
Reviewed-by: Greg Nancarrow, Vignesh C, Amit Kapila, Wang wei, Tang Haiying, Peter Smith, Masahiko Sawada, Shi Yu
Discussion : https://postgr.es/m/DB35438F-9356-4841-89A0-412709EBD3AB%40enterprisedb.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/705e20f8550c0e8e47c0b6b20b5f5ffd6ffd9e33

Modified Files
--------------
doc/src/sgml/catalogs.sgml                      |  10 ++
doc/src/sgml/logical-replication.sgml           |   5 +-
doc/src/sgml/ref/alter_subscription.sgml        |   4 +-
doc/src/sgml/ref/create_subscription.sgml       |  12 ++
src/backend/catalog/pg_subscription.c           |  40 ++++++
src/backend/catalog/system_views.sql            |   3 +-
src/backend/commands/subscriptioncmds.c         |  27 +++-
src/backend/replication/logical/worker.c        | 162 +++++++++++++++++-------
src/bin/pg_dump/pg_dump.c                       |  14 +-
src/bin/pg_dump/pg_dump.h                       |   1 +
src/bin/psql/describe.c                         |  10 +-
src/bin/psql/tab-complete.c                     |   4 +-
src/include/catalog/catversion.h                |   2 +-
src/include/catalog/pg_subscription.h           |   7 +
src/test/regress/expected/subscription.out      | 119 ++++++++++-------
src/test/regress/sql/subscription.sql           |  15 +++
src/test/subscription/t/029_disable_on_error.pl |  94 ++++++++++++++
17 files changed, 421 insertions(+), 108 deletions(-)



Message-ID: <E1nTc6H-000f9J-Ld@gemulon.postgresql.org>
Permalink:  ../E1nTc6H-000f9J-Ld@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nTc6H-000f9J-Ld@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: akapila@postgresql.org
  Subject: Re: pgsql: Optionally disable subscriptions on error.
  In-Reply-To: <E1nTc6H-000f9J-Ld@gemulon.postgresql.org>
  References: <E1nTc6H-000f9J-Ld@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox