diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2016-04-06 10:05:41 +0100 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2016-04-06 10:05:41 +0100 |
commit | 3fe3511d05127cc024b221040db2eeb352e7d716 (patch) | |
tree | b17a084bec318a70a1c0fcd755596b771871bce7 /doc/src | |
parent | 989be0810dffd08b54e1caecec0677608211c339 (diff) |
Generic Messages for Logical Decoding
API and mechanism to allow generic messages to be inserted into WAL that are
intended to be read by logical decoding plugins. This commit adds an optional
new callback to the logical decoding API.
Messages are either text or bytea. Messages can be transactional, or not, and
are identified by a prefix to allow multiple concurrent decoding plugins.
(Not to be confused with Generic WAL records, which are intended to allow crash
recovery of extensible objects.)
Author: Petr Jelinek and Andres Freund
Reviewers: Artur Zakirov, Tomas Vondra, Simon Riggs
Discussion: 5685F999.6010202@2ndquadrant.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 45 | ||||
-rw-r--r-- | doc/src/sgml/logicaldecoding.sgml | 38 |
2 files changed, 83 insertions, 0 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index c6017e61aee..f60d5784fdd 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -18255,6 +18255,51 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); </entry> </row> + <row> + <entry id="pg-logical-emit-message-text"> + <indexterm> + <primary>pg_logical_emit_message</primary> + </indexterm> + <literal><function>pg_logical_emit_message(<parameter>transactional</parameter> <type>bool</type>, <parameter>prefix</parameter> <type>text</type>, <parameter>content</parameter> <type>text</type>)</function></literal> + </entry> + <entry> + void + </entry> + <entry> + Emit text logical decoding message. This can be used to pass generic + messages to logical decoding plugins through WAL. The parameter + <parameter>transactional</parameter> specifies if the message should + be part of current transaction or if it should be written immediately + and decoded as soon as the logical decoding reads the record. The + <parameter>prefix</parameter> is textual prefix used by the logical + decoding plugins to easily recognize interesting messages for them. + The <parameter>content</parameter> is the text of the message. + </entry> + </row> + + <row> + <entry id="pg-logical-emit-message-bytea"> + <indexterm> + <primary>>pg_logical_emit_message</primary> + </indexterm> + <literal><function>>pg_logical_emit_message(<parameter>transactional</parameter> <type>bool</type>, <parameter>prefix</parameter> <type>text</type>, <parameter>content</parameter> <type>bytea</type>)</function></literal> + </entry> + <entry> + void + </entry> + <entry> + Emit binary logical decoding message. This can be used to pass generic + messages to logical decoding plugins through WAL. The parameter + <parameter>transactional</parameter> specifies if the message should + be part of current transaction or if it should be written immediately + and decoded as soon as the logical decoding reads the record. The + <parameter>prefix</parameter> is textual prefix used by the logical + decoding plugins to easily recognize interesting messages for them. + The <parameter>content</parameter> is the binary content of the + message. + </entry> + </row> + </tbody> </tgroup> </table> diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml index 45fdfeb13fd..8306d9ffaa0 100644 --- a/doc/src/sgml/logicaldecoding.sgml +++ b/doc/src/sgml/logicaldecoding.sgml @@ -363,6 +363,7 @@ typedef struct OutputPluginCallbacks LogicalDecodeBeginCB begin_cb; LogicalDecodeChangeCB change_cb; LogicalDecodeCommitCB commit_cb; + LogicalDecodeMessageCB message_cb; LogicalDecodeFilterByOriginCB filter_by_origin_cb; LogicalDecodeShutdownCB shutdown_cb; } OutputPluginCallbacks; @@ -602,6 +603,43 @@ typedef bool (*LogicalDecodeFilterByOriginCB) ( more efficient. </para> </sect3> + + <sect3 id="logicaldecoding-output-plugin-message"> + <title>Generic Message Callback</title> + + <para> + The optional <function>message_cb</function> callback is called whenever + a logical decoding message has been decoded. +<programlisting> +typedef void (*LogicalDecodeMessageCB) ( + struct LogicalDecodingContext *, + ReorderBufferTXN *txn, + XLogRecPtr message_lsn, + bool transactional, + const char *prefix, + Size message_size, + const char *message +); +</programlisting> + The <parameter>txn</parameter> parameter contains meta information about + the transaction, like the time stamp at which it has been committed and + its XID. Note however that it can be NULL when the message is + non-transactional and the XID was not assigned yet in the transaction + which logged the message. The <parameter>lsn</parameter> has WAL + position of the message. The <parameter>transactional</parameter> says + if the message was sent as transactional or not. + The <parameter>prefix</parameter> is arbitrary null-terminated prefix + which can be used for identifying interesting messages for the current + plugin. And finally the <parameter>message</parameter> parameter holds + the actual message of <parameter>message_size</parameter> size. + </para> + <para> + Extra care should be taken to ensure that the prefix the output plugin + considers interesting is unique. Using name of the extension or the + output plugin itself is often a good choice. + </para> + </sect3> + </sect2> <sect2 id="logicaldecoding-output-plugin-output"> |