All Products
Search
Document Center

PolarDB:decoderbufs (decode to ProtoBuf)

Last Updated:Mar 28, 2026

decoderbufs is a logical decoding output plugin for PolarDB for PostgreSQL that serializes write-ahead logging (WAL) change events into Protocol Buffers (ProtoBuf) format. Use it when your downstream consumers—such as stream processors or data pipelines—expect binary ProtoBuf-encoded change events.

Prerequisites

Before you begin, ensure that you have:

  • A PolarDB for PostgreSQL cluster running a supported version (see Applicability)

  • The wal_level parameter set to logical in the cluster parameters

Set wal_level in the console. For instructions, see Set cluster parameters. Changing this parameter restarts the cluster—plan your maintenance window accordingly.

Applicability

decoderbufs is supported on the following PolarDB for PostgreSQL versions:

PostgreSQL versionMinimum minor engine version
PostgreSQL 172.0.17.6.4.0
PostgreSQL 162.0.16.9.9.0
PostgreSQL 152.0.15.14.6.0
PostgreSQL 142.0.14.5.1.0
PostgreSQL 112.0.11.9.28.0

To check your minor engine version, run SHOW polardb_version; or view it in the console. If your version doesn't meet the requirement, upgrade the minor engine version.

The decoderbufs extension requires the following libraries:

LibraryMinimum versionPurpose
PostgreSQL9.6Database engine
Protobuf-c1.2Data serialization
PostGIS2.1Spatial geographic type support

How it works

decoderbufs is loaded automatically—no manual setup is required. When wal_level is set to logical, PostgreSQL writes additional metadata to the WAL that enables logical decoding. decoderbufs reads this metadata and emits each row change as a ProtoBuf-encoded message.

A logical replication slot holds the WAL stream for a given consumer. Two functions let you interact with the slot:

  • pg_logical_slot_peek_changes — reads change events without advancing the WAL position. Use this to inspect events during debugging without consuming them.

  • pg_logical_slot_get_changes — reads change events and advances the WAL position. Use this for normal consumption, where processed events should not be replayed.

Set up logical replication

  1. Create a logical replication slot with decoderbufs as the output plugin.

    SELECT * FROM pg_create_logical_replication_slot('decoderbufs_demo', 'decoderbufs');
  2. On the publisher instance, modify the table you want to replicate.

  3. Inspect the WAL log without advancing the position (useful for debugging).

    SELECT data FROM pg_logical_slot_peek_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');
  4. Consume the WAL changes and advance the position.

    SELECT data FROM pg_logical_slot_get_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');
  5. Verify the current WAL position of the replication slot.

    SELECT * FROM pg_replication_slots WHERE slot_type = 'logical';

Type mapping

decoderbufs maps PostgreSQL types to the following ProtoBuf fields:

PostgreSQL typedecoderbufs field
BOOLOIDdatum_boolean
INT2OIDdatum_int32
INT4OIDdatum_int32
INT8OIDdatum_int64
OIDOIDdatum_int64
FLOAT4OIDdatum_float
FLOAT8OIDdatum_double
NUMERICOIDdatum_double
CHAROIDdatum_string
VARCHAROIDdatum_string
BPCHAROIDdatum_string
TEXTOIDdatum_string
JSONOIDdatum_string
XMLOIDdatum_string
UUIDOIDdatum_string
TIMESTAMPOIDdatum_string
TIMESTAMPTZOIDdatum_string
BYTEAOIDdatum_bytes
POINTOIDdatum_point
PostGIS geometrydatum_point
PostGIS geographydatum_point