Re: Skipping logical replication transactions on subscriber side
Masahiko Sawada <sawada.mshk@gmail.com>
Attachments
- v1-0003-Add-pg_stat_logical_replication_error-statistics-.patch (application/octet-stream) patch v1-0003
- v1-0002-Add-errcontext-to-errors-of-the-applying-logical-.patch (application/octet-stream) patch v1-0002
- v1-0001-Add-ALTER-SUBSCRIPTION-SET-SKIP-TRANSACTION.patch (application/octet-stream) patch v1-0001
On Thu, Jun 17, 2021 at 6:20 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > On Thu, Jun 17, 2021 at 3:24 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > > > > Now, if this function is used by super > > > users then we can probably trust that they provide the XIDs that we > > > can trust to be skipped but OTOH making a restriction to allow these > > > functions to be used by superusers might restrict the usage of this > > > repair tool. > > > > If we specify the subscription id or name, maybe we can allow also the > > owner of subscription to do that operation? > > Ah, the owner of the subscription must be superuser. I've attached PoC patches. 0001 patch introduces the ability to skip transactions on the subscriber side. We can specify XID to the subscription by like ALTER SUBSCRIPTION test_sub SET SKIP TRANSACTION 100. The implementation seems straightforward except for setting origin state. After skipping the transaction we have to update the session origin state so that we can start streaming the transaction next to the one that we just skipped in case of the server crash or restarting the apply worker. We set origin state to the commit WAL record. However, since we skip all changes we don’t write any WAL even if we call CommitTransaction() at the end of the skipped transaction. So the patch sets the origin state to the transaction that updates the pg_subscription system catalog to reset the skip XID. I think we need a discussion of this part. With 0002 and 0003 patches, we report the error information in server logs and the stats view, respectively. 0002 patch adds errcontext for messages that happened during applying the changes: ERROR: duplicate key value violates unique constraint "hoge_pkey" DETAIL: Key (c)=(1) already exists. CONTEXT: during apply of "INSERT" for relation "public.hoge" in transaction with xid 736 committs 2021-06-27 12:12:30.053887+09 0003 patch adds pg_stat_logical_replication_error statistics view discussed on another thread[1]. The apply worker sends the error information to the stats collector if an error happens during applying changes. We can check those errors as follow: postgres(1:25250)=# select * from pg_stat_logical_replication_error; subname | relid | action | xid | last_failure ----------+-------+--------+-----+------------------------------- test_sub | 16384 | INSERT | 736 | 2021-06-27 12:12:45.142675+09 (1 row) I added only columns required for the skipping transaction feature to the view for now. Please note that those patches are meant to evaluate the concept we've discussed so far. Those don't have the doc update yet. Regards, [1] https://www.postgresql.org/message-id/DB35438F-9356-4841-89A0-412709EBD3AB%40enterprisedb.com -- Masahiko Sawada EDB: https://www.enterprisedb.com/
Commits
-
Test ALIGNOF_DOUBLE==4 compatibility under ALIGNOF_DOUBLE==8.
- c1da0acbb06e 15.0 landed
-
Reorder subskiplsn in pg_subscription to avoid alignment issues.
- 79b716cfb7a1 15.0 landed
-
Add ALTER SUBSCRIPTION ... SKIP.
- 208c5d65bbd6 15.0 landed
-
Optionally disable subscriptions on error.
- 705e20f8550c 15.0 cited
-
Update docs of logical replication for commit 8d74fc96db.
- 85c61ba8920b 15.0 landed
-
Respect permissions within logical replication.
- a2ab9c06ea15 15.0 cited
-
Fix regression test failure caused by commit 8d74fc96db.
- 41e66fee0516 15.0 landed
-
Add a view to show the stats of subscription workers.
- 8d74fc96db5f 15.0 landed
-
Add logical change details to logical replication worker errcontext.
- abc0910e2e0a 15.0 landed
-
Rename LOGICAL_REP_MSG_STREAM_END to LOGICAL_REP_MSG_STREAM_STOP.
- 4cd7a1896871 15.0 landed
-
Fix typo in protocol.sgml.
- e1915646658d 14.0 landed
- 0ac1aee0d7d8 15.0 landed
-
Remove unused argument in apply_handle_commit_internal().
- f4b939f1a372 14.0 landed
- 16bd4becee32 15.0 landed
-
Fix replication of in-progress transactions in tablesync worker.
- 0926e96c4934 14.0 cited
-
Reorder pg_sequence columns to avoid alignment issue
- f3b421da5f4a 10.0 cited