summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/test-decoding.sgml
blob: 9b0719542789526f1c3063eae274b9d244b7f800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!-- doc/src/sgml/test-decoding.sgml -->

<sect1 id="test-decoding" xreflabel="test_decoding">
 <title>test_decoding</title>

 <indexterm zone="test-decoding">
  <primary>test_decoding</primary>
 </indexterm>

 <para>
  <filename>test_decoding</filename> 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.
 </para>

 <para>
  <filename>test_decoding</filename> receives WAL through the logical decoding
  mechanism and decodes it into text representations of the operations
  performed.
 </para>

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

<programlisting>
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)
</programlisting>
 </para>

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

<programlisting>
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)
</programlisting>
 </para>

</sect1>