From 705e20f8550c0e8e47c0b6b20b5f5ffd6ffd9e33 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Mon, 14 Mar 2022 09:32:40 +0530 Subject: 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 --- 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 ++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 83987a99045..7777d605142 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -7769,6 +7769,16 @@ SCRAM-SHA-256$<iteration count>:&l + + + subdisableonerr bool + + + If true, the subscription will be disabled if one of its workers + detects an error + + + subconninfo text diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 82326c39019..6431d4796db 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -364,8 +364,9 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER the replication origin name can be found from the server log (LSN 0/14C0378 and replication origin pg_16395 in the above case). To skip the transaction, the subscription needs to be disabled temporarily by - ALTER SUBSCRIPTION ... DISABLE first. Then, the transaction - can be skipped by calling the + ALTER SUBSCRIPTION ... DISABLE first or alternatively, the + subscription can be used with the disable_on_error option. + Then, the transaction can be skipped by calling the pg_replication_origin_advance() function with the node_name (i.e., pg_16395) and the diff --git a/doc/src/sgml/ref/alter_subscription.sgml b/doc/src/sgml/ref/alter_subscription.sgml index 0d6f064f58d..58b78a94eab 100644 --- a/doc/src/sgml/ref/alter_subscription.sgml +++ b/doc/src/sgml/ref/alter_subscription.sgml @@ -204,8 +204,8 @@ ALTER SUBSCRIPTION name RENAME TO < information. The parameters that can be altered are slot_name, synchronous_commit, - binary, and - streaming. + binary, streaming, and + disable_on_error. diff --git a/doc/src/sgml/ref/create_subscription.sgml b/doc/src/sgml/ref/create_subscription.sgml index e80a2617a34..b701752fc9b 100644 --- a/doc/src/sgml/ref/create_subscription.sgml +++ b/doc/src/sgml/ref/create_subscription.sgml @@ -290,6 +290,18 @@ CREATE SUBSCRIPTION subscription_name + + + disable_on_error (boolean) + + + Specifies whether the subscription should be automatically disabled + if any errors are detected by subscription workers during data + replication from the publisher. The default is + false. + + + -- cgit v1.2.3