↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Logical Decoding Plugins / Core replication

pgoutput

Core replication

The built-in output plugin used by PostgreSQL logical replication.

Reading PostgreSQL 18.6.

Description

The built-in output plugin used by PostgreSQL logical replication.

Interface family
Logical-decoding output plugin
Handler or routine
_PG_output_plugin_init
Recorded callbacks
20
LOGICALREP_PROTO_MIN_VERSION_NUM
1
LOGICALREP_PROTO_VERSION_NUM
1
LOGICALREP_PROTO_STREAM_VERSION_NUM
2
LOGICALREP_PROTO_TWOPHASE_VERSION_NUM
3
LOGICALREP_PROTO_STREAM_PARALLEL_VERSION_NUM
4

Interface and capability boundaries

The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.

The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed.

Output and protocol boundaries

Callback presence and protocol versions are separate from client negotiation and enabled plugin options. Streaming and two-phase processing require the matching protocol and configuration.

test_decoding is an example/test output format; pgoutput implements the logical-replication protocol. Their output contracts are not interchangeable.

Registered implementation in core source

{
	cb->startup_cb = pgoutput_startup;
	cb->begin_cb = pgoutput_begin_txn;
	cb->change_cb = pgoutput_change;
	cb->truncate_cb = pgoutput_truncate;
	cb->message_cb = pgoutput_message;
	cb->commit_cb = pgoutput_commit_txn;

	cb->begin_prepare_cb = pgoutput_begin_prepare_txn;
	cb->prepare_cb = pgoutput_prepare_txn;
	cb->commit_prepared_cb = pgoutput_commit_prepared_txn;
	cb->rollback_prepared_cb = pgoutput_rollback_prepared_txn;
	cb->filter_by_origin_cb = pgoutput_origin_filter;
	cb->shutdown_cb = pgoutput_shutdown;

	/* transaction streaming */
	cb->stream_start_cb = pgoutput_stream_start;
	cb->stream_stop_cb = pgoutput_stream_stop;
	cb->stream_abort_cb = pgoutput_stream_abort;
	cb->stream_commit_cb = pgoutput_stream_commit;
	cb->stream_change_cb = pgoutput_change;
	cb->stream_message_cb = pgoutput_message;
	cb->stream_truncate_cb = pgoutput_truncate;
	/* transaction streaming - two-phase commit */
	cb->stream_prepare_cb = pgoutput_stream_prepare_txn;
}

Registered interface handlers

Interface operationSource observationCallbackImplementation
Begin transactionHandler registered; conditions applybegin_cbpgoutput_begin_txn
Row changesHandler registered; conditions applychange_cbpgoutput_change
CommitHandler registered; conditions applycommit_cbpgoutput_commit_txn
TRUNCATEHandler registered; conditions applytruncate_cbpgoutput_truncate
Logical messagesHandler registered; conditions applymessage_cbpgoutput_message
Start streamed transactionHandler registered; conditions applystream_start_cbpgoutput_stream_start
Stream row changesHandler registered; conditions applystream_change_cbpgoutput_change
Prepare transactionHandler registered; conditions applyprepare_cbpgoutput_prepare_txn
Commit preparedHandler registered; conditions applycommit_prepared_cbpgoutput_commit_prepared_txn
Rollback preparedHandler registered; conditions applyrollback_prepared_cbpgoutput_rollback_prepared_txn

Documented options

OptionSame-version definition
proto_versionProtocol version. Currently versions 1 , 2 , 3 , and 4 are supported. A valid version is required. Version 2 is supported only for server version 14 and above, and it allows streaming of large in-progress transactions. Version 3 is supported only for server version 15 and above, and it allows streaming of two-phase commits. Version 4 is supported only for server version 16 and above, and it allows streams of large in-progress transactions to be applied in parallel.
publication_namesComma-separated list of publication names for which to subscribe (receive changes). The individual publication names are treated as standard objects names and can be quoted the same as needed. At least one publication name is required.
binaryBoolean option to use binary transfer mode. Binary mode is faster than the text mode but slightly less robust.
messagesBoolean option to enable sending the messages that are written by pg_logical_emit_message .
streamingOption to enable streaming of in-progress transactions. Valid values are off (the default), on and parallel . The setting parallel enables sending extra information with some messages to be used for parallelization. Minimum protocol version 2 is required to turn it on . Minimum protocol version 4 is required for the parallel value.
two_phaseBoolean option to enable two-phase transactions. Minimum protocol version 3 is required to turn it on.
originOption to send changes by their origin. Possible values are none to only send the changes that have no origin associated, or any to send the changes regardless of their origin. This can be used to avoid loops (infinite replication of the same data) among replication nodes.

Option names recognized by this plugin build

Extracted from the option parser; names alone do not describe defaults, accepted values or protocol requirements.

Source option name
binary
messages
origin
proto_version
publication_names
streaming
two_phase

Manual definition

54.5. Logical Streaming Replication Protocol

This section describes the logical replication protocol, which is the message flow started by the START_REPLICATION SLOT slot_name LOGICAL replication command.

The logical streaming replication protocol builds on the primitives of the physical streaming replication protocol.

PostgreSQL logical decoding supports output plugins. pgoutput is the standard one used for the built-in logical replication.

54.5.1. Logical Streaming Replication Parameters

Using the START_REPLICATION command, pgoutput accepts the following options:

proto_version

Protocol version. Currently versions 1, 2, 3, and 4 are supported. A valid version is required.

Version 2 is supported only for server version 14 and above, and it allows streaming of large in-progress transactions.

Version 3 is supported only for server version 15 and above, and it allows streaming of two-phase commits.

Version 4 is supported only for server version 16 and above, and it allows streams of large in-progress transactions to be applied in parallel.

publication_names

Comma-separated list of publication names for which to subscribe (receive changes). The individual publication names are treated as standard objects names and can be quoted the same as needed. At least one publication name is required.

binary

Boolean option to use binary transfer mode. Binary mode is faster than the text mode but slightly less robust.

messages

Boolean option to enable sending the messages that are written by pg_logical_emit_message.

streaming

Option to enable streaming of in-progress transactions. Valid values are off (the default), on and parallel. The setting parallel enables sending extra information with some messages to be used for parallelization. Minimum protocol version 2 is required to turn it on. Minimum protocol version 4 is required for the parallel value.

two_phase

Boolean option to enable two-phase transactions. Minimum protocol version 3 is required to turn it on.

origin

Option to send changes by their origin. Possible values are none to only send the changes that have no origin associated, or any to send the changes regardless of their origin. This can be used to avoid loops (infinite replication of the same data) among replication nodes.

54.5.2. Logical Replication Protocol Messages

The individual protocol messages are discussed in the following subsections. Individual messages are described in Section 54.9.

All top-level protocol messages begin with a message type byte. While represented in code as a character, this is a signed byte with no associated encoding.

Since the streaming replication protocol supplies a message length there is no need for top-level protocol messages to embed a length in their header.

54.5.3. Logical Replication Protocol Message Flow

With the exception of the START_REPLICATION command and the replay progress messages, all information flows only from the backend to the frontend.

The logical replication protocol sends individual transactions one by one. This means that all messages between a pair of Begin and Commit messages belong to the same transaction. Similarly, all messages between a pair of Begin Prepare and Prepare messages belong to the same transaction. It also sends changes of large in-progress transactions between a pair of Stream Start and Stream Stop messages. The last stream of such a transaction contains a Stream Commit or Stream Abort message.

Every sent transaction contains zero or more DML messages (Insert, Update, Delete). In case of a cascaded setup it can also contain Origin messages. The origin message indicates that the transaction originated on different replication node. Since a replication node in the scope of logical replication protocol can be pretty much anything, the only identifier is the origin name. It's downstream's responsibility to handle this as needed (if needed). The Origin message is always sent before any DML messages in the transaction.

Every DML message contains a relation OID, identifying the publisher's relation that was acted on. Before the first DML message for a given relation OID, a Relation message will be sent, describing the schema of that relation. Subsequently, a new Relation message will be sent if the relation's definition has changed since the last Relation message was sent for it. (The protocol assumes that the client is capable of remembering this metadata for as many relations as needed.)

Relation messages identify column types by their OIDs. In the case of a built-in type, it is assumed that the client can look up that type OID locally, so no additional data is needed. For a non-built-in type OID, a Type message will be sent before the Relation message, to provide the type name associated with that OID. Thus, a client that needs to specifically identify the types of relation columns should cache the contents of Type messages, and first consult that cache to see if the type OID is defined there. If not, look up the type OID locally.

Related entries

Documentation and source

Source build
Version
18.6
Build
PostgreSQL 18.6 source archive
Source fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Compare versions

PostgreSQL 11 → 12: changed.

--- PostgreSQL 11
+++ PostgreSQL 12
@@ -10,11 +10,11 @@
   },
   "options": [
     {
-      "definition": "Protocol version. Currently only version 1 is supported.",
+      "definition": "Protocol version. Currently only version 1 is supported. A valid version is required.",
       "name": "proto_version"
     },
     {
-      "definition": "Comma separated list of publication names for which to subscribe (receive changes). The individual publication names are treated as standard objects names and can be quoted the same as needed.",
+      "definition": "Comma separated list of publication names for which to subscribe (receive changes). The individual publication names are treated as standard objects names and can be quoted the same as needed. At least one publication name is required.",
       "name": "publication_names"
     }
   ],

Compares recorded interfaces and attributes. Source fingerprints and build metadata are excluded; an absent sample is not proof of the introduction or removal release.

Export JSON · Back to Logical Decoding Plugins · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.