From 3fe3511d05127cc024b221040db2eeb352e7d716 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Wed, 6 Apr 2016 10:05:41 +0100 Subject: 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 --- doc/src/sgml/func.sgml | 45 +++++++++++++++++++++++++++++++++++++++ doc/src/sgml/logicaldecoding.sgml | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) (limited to 'doc/src') 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()); + + + + pg_logical_emit_message + + pg_logical_emit_message(transactional bool, prefix text, content text) + + + void + + + Emit text logical decoding message. This can be used to pass generic + messages to logical decoding plugins through WAL. The parameter + transactional 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 + prefix is textual prefix used by the logical + decoding plugins to easily recognize interesting messages for them. + The content is the text of the message. + + + + + + + >pg_logical_emit_message + + >pg_logical_emit_message(transactional bool, prefix text, content bytea) + + + void + + + Emit binary logical decoding message. This can be used to pass generic + messages to logical decoding plugins through WAL. The parameter + transactional 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 + prefix is textual prefix used by the logical + decoding plugins to easily recognize interesting messages for them. + The content is the binary content of the + message. + + + 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. + + + Generic Message Callback + + + The optional message_cb callback is called whenever + a logical decoding message has been decoded. + +typedef void (*LogicalDecodeMessageCB) ( + struct LogicalDecodingContext *, + ReorderBufferTXN *txn, + XLogRecPtr message_lsn, + bool transactional, + const char *prefix, + Size message_size, + const char *message +); + + The txn 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 lsn has WAL + position of the message. The transactional says + if the message was sent as transactional or not. + The prefix is arbitrary null-terminated prefix + which can be used for identifying interesting messages for the current + plugin. And finally the message parameter holds + the actual message of message_size size. + + + 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. + + + -- cgit v1.2.3