RE: Conflict detection for update_deleted in logical replication
Zhijie Hou (Fujitsu) <houzj.fnst@fujitsu.com>
Attachments
- v35-0003-Add-a-retain_conflict_info-option-to-subscriptio.patch (application/octet-stream) patch v35-0003
- v35-0001-Maintain-the-oldest-non-removable-transaction-ID.patch (application/octet-stream) patch v35-0001
- v35-0002-Maintain-the-replication-slot-in-logical-launche.patch (application/octet-stream) patch v35-0002
- v35-0004-Introduce-a-new-GUC-max_conflict_retention_durat.patch (application/octet-stream) patch v35-0004
- v35-0005-Re-create-the-replication-slot-if-the-conflict-r.patch (application/octet-stream) patch v35-0005
- v35-0006-Add-a-tap-test-to-verify-the-management-of-the-n.patch (application/octet-stream) patch v35-0006
- v35-0007-Support-the-conflict-detection-for-update_delete.patch (application/octet-stream) patch v35-0007
- v35-0008-Allow-altering-retain_conflict_info-for-enabled-.patch (application/octet-stream) patch v35-0008
On Fri, Jun 6, 2025 at 7:34 PM Amit Kapila wrote:
>
> On Wed, Jun 4, 2025 at 4:12 PM Zhijie Hou (Fujitsu)
> <houzj.fnst@fujitsu.com> wrote:
> >
> > Here is the V33 patch set which includes the following changes:
> >
>
> Few comments:
> 1.
> + if (sub->enabled)
> + ereport(ERROR,
> + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("cannot set option %s for enabled subscription",
> + "retain_conflict_info")));
>
> Isn't it better to call CheckAlterSubOption() for this check, as we do
> for failover and two_phase options?
Moved.
>
> 2.
> postgres=# Alter subscription sub1 set (retain_conflict_info=true);
> ERROR: cannot set option retain_conflict_info for enabled subscription
> postgres=# Alter subscription sub1 disable;
> ALTER SUBSCRIPTION
> postgres=# Alter subscription sub1 set (retain_conflict_info=true);
> WARNING: information for detecting conflicts cannot be purged when
> the subscription is disabled
> ALTER SUBSCRIPTION
>
> The above looks odd to me because first we didn't allow setting the
> option for enabled subscription, and then when the user disabled the
> subscription, a WARNING is issued. Isn't it better to give NOTICE
> like: "enable the subscription to avoid accumulating deleted rows for
> detecting conflicts" in the above case?
Yes, a NOTICE would be better.
I think we normally only describe the current situation of the operation in a
NOTICE message, and the suggested message sounds like a hint.
So I used the following message:
"deleted rows will continue to accumulate for detecting conflicts until the subscription is enabled"
>
> Also in this,
> postgres=# Alter subscription sub1 set (retain_conflict_info=true);
> WARNING: information for detecting conflicts cannot be fully retained
> when "track_commit_timestamp" is disabled
> WARNING: information for detecting conflicts cannot be purged when
> the subscription is disabled
> ALTER SUBSCRIPTION
>
> What do we mean by this WARNING message? If track_commit_timestamp is
> not enabled, we won't be able to detect certain conflicts, including
> update_delete, but how can it lead to not retaining information
> required for conflict detection? BTW, shall we consider giving ERROR
> instead of WARNING for this case because without
> track_commit_timestamp, there is no benefit in retaining deleted rows?
> If we just want to make the user aware to enable
> track_commit_timestamp to detect conflicts, then we can even consider
> making this a NOTICE.
I think it's an unexpected case that track_commit_timestamp is not enabled, so
NOTICE may not be appropriate. Giving ERROR is also OK, but since user can
change the track_commit_timestamp setting at anytime after creating/modifying a
subscription, we can't catch all cases, so we considered simply issuing a
warning directly and document this case.
> postgres=# Alter subscription sub1 Enable;
> ALTER SUBSCRIPTION
> postgres=# Alter subscription sub1 set (retain_conflict_info=false);
> ERROR: cannot set option retain_conflict_info for enabled subscription
> postgres=# Alter subscription sub1 disable;
> WARNING: information for detecting conflicts cannot be purged when
> the subscription is disabled
> ALTER SUBSCRIPTION
>
> Here, we should have a WARNING like: "deleted rows to detect conflicts
> would not be removed till the subscription is enabled"; this should be
> followed by errdetail like: "Consider setting retain_conflict_info to
> false."
Changed as suggested.
Here is the V35 patch set which includes the following changes:
0001:
No change.
0002:
* Added an errdetail for reserved slot name error per off-list discussion with Shveta.
* Moves the codes in launcher's foreach loop to a new function to improve the readability.
0003:
* Addressed all above comments sent by Amit.
* Adjusted some comments per off-list discussion with Amit.
* Check track_commit_timestamp when enabling the subscription. This is to avoid
passing track_commit_timestamp as a parameter to the check function.
0004:
Rebased
0005:
Rebased
0006:
Rebased
0007:
Rebased
0008:
Rebased
Best Regards,
Hou zj
Commits
-
Fix intermittent BF failures in 035_conflicts.
- 0f42206531b3 19 (unreleased) landed
-
Resume conflict-relevant data retention automatically.
- 0d48d393d465 19 (unreleased) landed
-
Fix intermittent test failure introduced in 6456c6e2c4.
- 01d793698f59 19 (unreleased) landed
-
Fix Coverity issue reported in commit a850be2fe.
- 5ac3c1ac22cb 19 (unreleased) landed
-
Add test to prevent premature removal of conflict-relevant data.
- 6456c6e2c4ad 19 (unreleased) landed
-
Post-commit review fixes for 228c370868.
- 1f7e9ba3ac4e 19 (unreleased) landed
-
Add max_retention_duration option to subscriptions.
- a850be2fe653 19 (unreleased) landed
-
Detect and report update_deleted conflicts.
- fd5a1a0c3e56 19 (unreleased) landed
-
Preserve conflict-relevant data during logical replication.
- 228c37086855 19 (unreleased) landed
-
Integrate FullTransactionIds deeper into two-phase code
- 62a17a92833d 19 (unreleased) cited
-
Improve checks for GUC recovery_target_timeline
- fd7d7b719137 19 (unreleased) cited
-
Prevent excessive delays before launching new logrep workers.
- fd519419c948 18.0 cited
-
Keep WAL segments by slot's last saved restart LSN
- ca307d5cec90 18.0 cited
-
Rework some code handling pg_subscription data in psql and pg_dump
- 08691ea958c2 18.0 cited
-
Use generateClonedIndexStmt to propagate CREATE INDEX to partitions.
- 68dfecbef210 18.0 cited