Re: Conflict detection for update_deleted in logical replication
Amit Kapila <amit.kapila16@gmail.com>
On Tue, Sep 17, 2024 at 6:08 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > On Fri, Sep 13, 2024 at 12:56 AM shveta malik <shveta.malik@gmail.com> wrote: > > > > On Fri, Sep 13, 2024 at 11:38 AM Amit Kapila <amit.kapila16@gmail.com> wrote: > > > > > > > > > > > > > So in brief, this solution is only for bidrectional setup? For non-bidirectional, > > > > > feedback_slots is non-configurable and thus irrelevant. > > > > > > > > Right. > > > > > > > > > > One possible idea to address the non-bidirectional case raised by > > > Shveta is to use a time-based cut-off to remove dead tuples. As > > > mentioned earlier in my email [1], we can define a new GUC parameter > > > say vacuum_committs_age which would indicate that we will allow rows > > > to be removed only if the modified time of the tuple as indicated by > > > committs module is greater than the vacuum_committs_age. We could keep > > > this parameter a table-level option without introducing a GUC as this > > > may not apply to all tables. I checked and found that some other > > > replication solutions like GoldenGate also allowed similar parameters > > > (tombstone_deletes) to be specified at table level [2]. The other > > > advantage of allowing it at table level is that it won't hamper the > > > performance of hot-pruning or vacuum in general. Note, I am careful > > > here because to decide whether to remove a dead tuple or not we need > > > to compare its committs_time both during hot-pruning and vacuum. > > > > +1 on the idea, > > I agree that this idea is much simpler than the idea originally > proposed in this thread. > > IIUC vacuum_committs_age specifies a time rather than an XID age. > Your understanding is correct that vacuum_committs_age specifies a time. > > But > how can we implement it? If it ends up affecting the vacuum cutoff, we > should be careful not to end up with the same result of > vacuum_defer_cleanup_age that was discussed before[1]. Also, I think > the implementation needs not to affect the performance of > ComputeXidHorizons(). > I haven't thought about the implementation details yet but I think during pruning (for example in heap_prune_satisfies_vacuum()), apart from checking if the tuple satisfies HeapTupleSatisfiesVacuumHorizon(), we should also check if the tuple's committs is greater than configured vacuum_committs_age (for the table) to decide whether tuple can be removed. One thing to consider is what to do in case of aggressive vacuum where we expect relfrozenxid to be advanced to FreezeLimit (at a minimum). We may want to just ignore vacuum_committs_age during aggressive vacuum and LOG if we end up removing some tuple. This will allow users to retain deleted tuples by respecting the freeze limits which also avoid xid_wrap around. I think we can't retain tuples forever if the user misconfigured vacuum_committs_age and to avoid that we can keep the maximum limit on this parameter to say an hour or so. Also, users can tune freeze parameters if they want to retain tuples for longer. > > but IIUC this value doesn’t need to be significant; it > > can be limited to just a few minutes. The one which is sufficient to > > handle replication delays caused by network lag or other factors, > > assuming clock skew has already been addressed. > > I think that in a non-bidirectional case the value could need to be a > large number. Is that right? > As per my understanding, even for non-bidirectional cases, the value should be small. For example, in the case, pointed out by Shveta [1], where the updates from 2 nodes are received by a third node, this setting is expected to be small. This setting primarily deals with concurrent transactions on multiple nodes, so it should be small but I could be missing something. [1] - https://www.postgresql.org/message-id/CAJpy0uAzzOzhXGH-zBc7Zt8ndXRf6r4OnLzgRrHyf8cvd%2Bfpwg%40mail.gmail.com -- With Regards, Amit Kapila.
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