]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/test-decoding.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / test-decoding.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>F.45. test_decoding — SQL-based test/example module for WAL logical decoding</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="tcn.html" title="F.44. tcn — a trigger function to notify listeners of changes to table content" /><link rel="next" href="tsm-system-rows.html" title="F.46. tsm_system_rows — the SYSTEM_ROWS sampling method for TABLESAMPLE" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.45. test_decoding — SQL-based test/example module for WAL logical decoding</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="tcn.html" title="F.44. tcn — a trigger function to notify listeners of changes to table content">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules and Extensions</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="tsm-system-rows.html" title="F.46. tsm_system_rows —&#10;   the SYSTEM_ROWS sampling method for TABLESAMPLE">Next</a></td></tr></table><hr /></div><div class="sect1" id="TEST-DECODING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.45. test_decoding — SQL-based test/example module for WAL logical decoding <a href="#TEST-DECODING" class="id_link">#</a></h2></div></div></div><a id="id-1.11.7.55.2" class="indexterm"></a><p>
3   <code class="filename">test_decoding</code> is an example of a logical decoding
4   output plugin. It doesn't do anything especially useful, but can serve as
5   a starting point for developing your own output plugin.
6  </p><p>
7   <code class="filename">test_decoding</code> receives WAL through the logical decoding
8   mechanism and decodes it into text representations of the operations
9   performed.
10  </p><p>
11   Typical output from this plugin, used over the SQL logical decoding
12   interface, might be:
13
14 </p><pre class="programlisting">
15 postgres=# SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'include-xids', '0');
16    lsn     | xid |                       data
17 -----------+-----+--------------------------------------------------
18  0/16D30F8 | 691 | BEGIN
19  0/16D32A0 | 691 | table public.data: INSERT: id[int4]:2 data[text]:'arg'
20  0/16D32A0 | 691 | table public.data: INSERT: id[int4]:3 data[text]:'demo'
21  0/16D32A0 | 691 | COMMIT
22  0/16D32D8 | 692 | BEGIN
23  0/16D3398 | 692 | table public.data: DELETE: id[int4]:2
24  0/16D3398 | 692 | table public.data: DELETE: id[int4]:3
25  0/16D3398 | 692 | COMMIT
26 (8 rows)
27 </pre><p>
28  </p><p>
29   We can also get the changes of the in-progress transaction, and the typical
30   output might be:
31
32 </p><pre class="programlisting">
33 postgres[33712]=#* SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'stream-changes', '1');
34     lsn    | xid |                       data
35 -----------+-----+--------------------------------------------------
36  0/16B21F8 | 503 | opening a streamed block for transaction TXN 503
37  0/16B21F8 | 503 | streaming change for TXN 503
38  0/16B2300 | 503 | streaming change for TXN 503
39  0/16B2408 | 503 | streaming change for TXN 503
40  0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503
41  0/16B21F8 | 503 | opening a streamed block for transaction TXN 503
42  0/16BECA8 | 503 | streaming change for TXN 503
43  0/16BEDB0 | 503 | streaming change for TXN 503
44  0/16BEEB8 | 503 | streaming change for TXN 503
45  0/16BEBA0 | 503 | closing a streamed block for transaction TXN 503
46 (10 rows)
47 </pre><p>
48  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tcn.html" title="F.44. tcn — a trigger function to notify listeners of changes to table content">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tsm-system-rows.html" title="F.46. tsm_system_rows —&#10;   the SYSTEM_ROWS sampling method for TABLESAMPLE">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.44. tcn — a trigger function to notify listeners of changes to table content </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> F.46. tsm_system_rows —
49    the <code class="literal">SYSTEM_ROWS</code> sampling method for <code class="literal">TABLESAMPLE</code></td></tr></table></div></body></html>