| 1 |
<!-- doc/src/sgml/test-decoding.sgml --> |
| 2 |
|
| 3 |
<sect1 id="test-decoding" xreflabel="test_decoding"> |
| 4 |
<title>test_decoding — SQL-based test/example module for WAL logical decoding</title> |
| 5 |
|
| 6 |
<indexterm zone="test-decoding"> |
| 7 |
<primary>test_decoding</primary> |
| 8 |
</indexterm> |
| 9 |
|
| 10 |
<para> |
| 11 |
<filename>test_decoding</filename> is an example of a logical decoding |
| 12 |
output plugin. It doesn't do anything especially useful, but can serve as |
| 13 |
a starting point for developing your own output plugin. |
| 14 |
</para> |
| 15 |
|
| 16 |
<para> |
| 17 |
<filename>test_decoding</filename> receives WAL through the logical decoding |
| 18 |
mechanism and decodes it into text representations of the operations |
| 19 |
performed. |
| 20 |
</para> |
| 21 |
|
| 22 |
<para> |
| 23 |
Typical output from this plugin, used over the SQL logical decoding |
| 24 |
interface, might be: |
| 25 |
|
| 26 |
<programlisting> |
| 27 |
postgres=# SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'include-xids', '0'); |
| 28 |
lsn | xid | data |
| 29 |
-----------+-----+-------------------------------------------------- |
| 30 |
0/16D30F8 | 691 | BEGIN |
| 31 |
0/16D32A0 | 691 | table public.data: INSERT: id[int4]:2 data[text]:'arg' |
| 32 |
0/16D32A0 | 691 | table public.data: INSERT: id[int4]:3 data[text]:'demo' |
| 33 |
0/16D32A0 | 691 | COMMIT |
| 34 |
0/16D32D8 | 692 | BEGIN |
| 35 |
0/16D3398 | 692 | table public.data: DELETE: id[int4]:2 |
| 36 |
0/16D3398 | 692 | table public.data: DELETE: id[int4]:3 |
| 37 |
0/16D3398 | 692 | COMMIT |
| 38 |
(8 rows) |
| 39 |
</programlisting> |
| 40 |
</para> |
| 41 |
|
| 42 |
<para> |
| 43 |
We can also get the changes of the in-progress transaction, and the typical |
| 44 |
output might be: |
| 45 |
|
| 46 |
<programlisting> |
| 47 |
postgres[33712]=#* SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'stream-changes', '1'); |
| 48 |
lsn | xid | data |
| 49 |
-----------+-----+-------------------------------------------------- |
| 50 |
0/16B21F8 | 503 | opening a streamed block for transaction TXN 503 |
| 51 |
0/16B21F8 | 503 | streaming change for TXN 503 |
| 52 |
0/16B2300 | 503 | streaming change for TXN 503 |
| 53 |
0/16B2408 | 503 | streaming change for TXN 503 |
| 54 |
0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503 |
| 55 |
0/16B21F8 | 503 | opening a streamed block for transaction TXN 503 |
| 56 |
0/16BECA8 | 503 | streaming change for TXN 503 |
| 57 |
0/16BEDB0 | 503 | streaming change for TXN 503 |
| 58 |
0/16BEEB8 | 503 | streaming change for TXN 503 |
| 59 |
0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503 |
| 60 |
(10 rows) |
| 61 |
</programlisting> |
| 62 |
</para> |
| 63 |
|
| 64 |
</sect1> |