pg_logical_emit_message()

A function for emitting a logical decoding message

pg_logical_emit_message() is a system function for emitting a logical decoding message into WAL.

pg_logical_emit_message() was added in PostgreSQL 9.6.

Usage

pg_logical_emit_message ( transactional boolean, prefix text, content text ) → pg_lsn
pg_logical_emit_message ( transactional boolean, prefix text, content bytea ) → pg_lsn

This function can be used to pass arbitrary messages in either text or bytea formats to logical decoding plugins via WAL.

To assist plugins with filtering messages, a prefix value can be provided, typically as the name of the plugin's extension. Note that this is purely advisory and it is up to each plugin to decide whether it should read the message. The prefix may be provided as an empty value.

Change history

Examples

Basic usage example for pg_logical_emit_message():

postgres=# SELECT pg_logical_emit_message(false, 'foo', 'bar');
 pg_logical_emit_message 
-------------------------
 0/14A24B0
(1 row)

The corresponding WAL record is:

rmgr: LogicalMessage len (rec/tot):     57/    57, tx:          0, lsn: 0/014A2470, prev 0/014A22C8, desc: MESSAGE non-transactional, prefix "foo"; payload (3 bytes): 62 61 72

Both prefix and content may be provided as empty strings:

postgres=# SELECT pg_logical_emit_message(false, '', '');
 pg_logical_emit_message 
-------------------------
 0/2002960
(1 row)

Categories

Logical replication, System function