test_decoding
是一个逻辑解码输出插件示例。它不会执行任何特别有用的操作,但可以作为开发您自己的输出插件的起点。
test_decoding
通过逻辑解码机制接收 WAL,并将其解码为执行操作的文本表示形式。
通过 SQL 逻辑解码接口使用此插件的典型输出可能是
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)
我们还可以获取正在进行的事务的更改,典型输出可能是
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)