↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / 逻辑解码插件

test_decoding

A test and example output plugin that renders logical changes in a textual format.

当前阅读 PG 18·选择有来源记录的版本

此版本暂无所选语言的定义,以下显示原始英文内容。

Interface family
Logical-decoding output plugin
Handler or routine
_PG_output_plugin_init
Recorded callbacks
21
evidence kind
source and documentation
manual path
/docs/18/test-decoding.html
runtime verified
false

版本定义 PG 18

F.45. test_decoding — SQL-based test/example module for WAL logical decoding

test_decoding is an example of a logical decoding output plugin. It doesn't do anything especially useful, but can serve as a starting point for developing your own output plugin.

test_decoding receives WAL through the logical decoding mechanism and decodes it into text representations of the operations performed.

Typical output from this plugin, used over the SQL logical decoding interface, might be:

postgres=# SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'include-xids', '0');
   lsn     | xid |                       data
-----------+-----+--------------------------------------------------
 0/16D30F8 | 691 | BEGIN
 0/16D32A0 | 691 | table public.data: INSERT: id[int4]:2 data[text]:'arg'
 0/16D32A0 | 691 | table public.data: INSERT: id[int4]:3 data[text]:'demo'
 0/16D32A0 | 691 | COMMIT
 0/16D32D8 | 692 | BEGIN
 0/16D3398 | 692 | table public.data: DELETE: id[int4]:2
 0/16D3398 | 692 | table public.data: DELETE: id[int4]:3
 0/16D3398 | 692 | COMMIT
(8 rows)

We can also get the changes of the in-progress transaction, and the typical output might be:

postgres[33712]=#* SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'stream-changes', '1');
    lsn    | xid |                       data
-----------+-----+--------------------------------------------------
 0/16B21F8 | 503 | opening a streamed block for transaction TXN 503
 0/16B21F8 | 503 | streaming change for TXN 503
 0/16B2300 | 503 | streaming change for TXN 503
 0/16B2408 | 503 | streaming change for TXN 503
 0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503
 0/16B21F8 | 503 | opening a streamed block for transaction TXN 503
 0/16BECA8 | 503 | streaming change for TXN 503
 0/16BEDB0 | 503 | streaming change for TXN 503
 0/16BEEB8 | 503 | streaming change for TXN 503
 0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503
(10 rows)

Registered interface handlers

Interface operationSource observationCallbackImplementation
Begin transactionHandler registered; conditions applybegin_cbpg_decode_begin_txn
Row changesHandler registered; conditions applychange_cbpg_decode_change
CommitHandler registered; conditions applycommit_cbpg_decode_commit_txn
TRUNCATEHandler registered; conditions applytruncate_cbpg_decode_truncate
Logical messagesHandler registered; conditions applymessage_cbpg_decode_message
Start streamed transactionHandler registered; conditions applystream_start_cbpg_decode_stream_start
Stream row changesHandler registered; conditions applystream_change_cbpg_decode_stream_change
Prepare transactionHandler registered; conditions applyprepare_cbpg_decode_prepare_txn
Commit preparedHandler registered; conditions applycommit_prepared_cbpg_decode_commit_prepared_txn
Rollback preparedHandler registered; conditions applyrollback_prepared_cbpg_decode_rollback_prepared_txn

Option names recognized by this plugin build

Source option name
force-binary
include-rewrites
include-timestamp
include-xids
only-local
skip-empty-xacts
stream-changes

比较版本

完整来源事实

callbacks

{"begin_cb":"pg_decode_begin_txn","begin_prepare_cb":"pg_decode_begin_prepare_txn","change_cb":"pg_decode_change","commit_cb":"pg_decode_commit_txn","commit_prepared_cb":"pg_decode_commit_prepared_txn","filter_by_origin_cb":"pg_decode_filter","filter_prepare_cb":"pg_decode_filter_prepare","message_cb":"pg_decode_message","prepare_cb":"pg_decode_prepare_txn","rollback_prepared_cb":"pg_decode_rollback_prepared_txn","shutdown_cb":"pg_decode_shutdown","startup_cb":"pg_decode_startup","stream_abort_cb":"pg_decode_stream_abort","stream_change_cb":"pg_decode_stream_change","stream_commit_cb":"pg_decode_stream_commit","stream_message_cb":"pg_decode_stream_message","stream_prepare_cb":"pg_decode_stream_prepare","stream_start_cb":"pg_decode_stream_start","stream_stop_cb":"pg_decode_stream_stop","stream_truncate_cb":"pg_decode_stream_truncate","truncate_cb":"pg_decode_truncate"}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

正文语言: en · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f