decoderbufs is an output plugin for the PostgreSQL logical decoder that decodes data into the Protocol Buffers format for logical replication.
Applicability
The following versions of PolarDB for PostgreSQL are supported:
PostgreSQL 17 (minor engine version 2.0.17.6.4.0 or later)
PostgreSQL 16 (minor engine version 2.0.16.9.9.0 or later)
PostgreSQL 15 (minor engine version 2.0.15.14.6.0 or later)
PostgreSQL 14 (minor engine version 2.0.14.5.1.0 or later)
PostgreSQL 11 (minor engine version 2.0.11.9.28.0 or later)
NoteYou can view the minor engine version in the console or by running the
SHOW polardb_version;statement. If your version does not meet the requirements, upgrade the minor engine version.The decoderbufs extension depends on the following libraries:
PostgreSQL: Engine version 9.6 or later.
Protobuf-c: Version 1.2 or later, for data serialization.
PostGIS: Version 2.1 or later, to support PostgreSQL spatial geographic types.
Usage instructions
The decoderbufs extension is loaded automatically by default, so you do not need to load it manually. You must set the `wal_level` parameter to `logical`. This setting adds the information required for logical decoding to the write-ahead logging (WAL).
You can set the `wal_level` parameter in the console. For more information, see Set cluster parameters. Changing this parameter restarts the cluster, so proceed with caution and plan your business operations accordingly.
The following example shows how to perform logical replication:
Create a logical replication slot and set the decoder plugin to decoderbufs.
SELECT * FROM pg_create_logical_replication_slot('decoderbufs_demo', 'decoderbufs');On the publisher instance, modify the table that you want to replicate.
Use the decoderbufs debug mode to view the WAL log.
SELECT data FROM pg_logical_slot_peek_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');Use decoderbufs to retrieve WAL changes and update the WAL position.
SELECT data FROM pg_logical_slot_get_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');View the WAL position of the logical replication.
SELECT * FROM pg_replication_slots WHERE slot_type = 'logical';
Type mapping
The following table describes the mapping between PostgreSQL types and decoderbufs fields.
PostgreSQL type | Decoderbuf field |
BOOLOID | datum_boolean |
INT2OID | datum_int32 |
INT4OID | datum_int32 |
INT8OID | datum_int64 |
OIDOID | datum_int64 |
FLOAT4OID | datum_float |
FLOAT8OID | datum_double |
NUMERICOID | datum_double |
CHAROID | datum_string |
VARCHAROID | datum_string |
BPCHAROID | datum_string |
TEXTOID | datum_string |
JSONOID | datum_string |
XMLOID | datum_string |
UUIDOID | datum_string |
TIMESTAMPOID | datum_string |
TIMESTAMPTZOID | datum_string |
BYTEAOID | datum_bytes |
POINTOID | datum_point |
PostGIS geometry | datum_point |
PostGIS geography | datum_point |