RE: Slow catchup of 2PC (twophase) transactions on replica in LR
Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'Ajin Cherian' <itsajin@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>
Cc: Давыдов Виталий <v.davydov@postgrespro.ru>, Heikki Linnakangas <hlinnaka@iki.fi>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2024-04-22T08:56:42Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix random failure in 021_twophase.
- 0dcea330babd 18.0 landed
-
Allow altering of two_phase option of a SUBSCRIPTION.
- 1462aad2e447 18.0 landed
-
Doc: use true|false rather than on|off for "failover" option
- fa65a022db26 17.0 cited
-
Support an optional asynchronous commit mode, in which we don't flush WAL
- 4a78cdeb6b59 8.3.0 cited
Attachments
- v5-0001-Allow-altering-of-two_phase-option-of-a-SUBSCRIPT.patch (application/octet-stream) patch v5-0001
- v5-0002-Alter-slot-option-two_phase-only-when-altering-tr.patch (application/octet-stream) patch v5-0002
- v5-0003-Abort-prepared-transactions-while-altering-two_ph.patch (application/octet-stream) patch v5-0003
- v5-0004-Add-force_alter-option.patch (application/octet-stream) patch v5-0004
Dear hackers,
> Looking at this a bit more, maybe rolling back all prepared transactions on the
> subscriber when toggling two_phase from true to false might not be desirable
> for the customer. Maybe we should have an option for customers to control
> whether transactions should be rolled back or not. Maybe transactions should
> only be rolled back if a "force" option is also set. What do people think?
And here is a patch for adds new option "force_alter" (better name is very welcome).
It could be used only when altering two_phase option. Let me share examples.
Assuming that there are logical replication system with two_phase = on, and
there are prepared transactions:
```
subscriber=# SELECT * FROM pg_prepared_xacts ;
transaction | gid | prepared | owner | database
-------------+------------------+-------------------------------+----------+----------
741 | pg_gid_16390_741 | 2024-04-22 08:02:34.727913+00 | postgres | postgres
742 | pg_gid_16390_742 | 2024-04-22 08:02:34.729486+00 | postgres | postgres
(2 rows)
```
At that time, altering two_phase to false alone will be failed:
```
subscriber=# ALTER SUBSCRIPTION sub DISABLE ;
ALTER SUBSCRIPTION
subscriber=# ALTER SUBSCRIPTION sub SET (two_phase = off);
ERROR: cannot alter two_phase = false when there are prepared transactions
```
It succeeds if force_alter is also expressly set. Prepared transactions will be
aborted at that time.
```
subscriber=# ALTER SUBSCRIPTION sub SET (two_phase = off, force_alter = on);
ALTER SUBSCRIPTION
subscriber=# SELECT * FROM pg_prepared_xacts ;
transaction | gid | prepared | owner | database
-------------+-----+----------+-------+----------
(0 rows)
```
Best Regards,
Hayato Kuroda
FUJITSU LIMITED
https://www.fujitsu.com/global/