Decoderbufs is a PostgreSQL logical decoder output plug-in for logical replication in the Protocol Buffers format.
Prerequisites
Decoderbufs is supported on the following PolarDB for PostgreSQL clusters:
PostgreSQL 14 (revision version 14.5.1.0 or later)
PostgreSQL 11 (revision version 1.1.28 or later)
NoteYou can execute the following statement to view the minor version that is used by PolarDB for PostgreSQL:
PostgreSQL 14
SELECT version();
PostgreSQL 11
SHOW polar_version;
Decoderbufs depends on the following libraries:
PostgreSQL 9.6 or later
Protobuf-c: 1.2 or later for data serialization
PostGIS: 2.1 or later to support PostgreSQL Geo type.
Configuration and usage
Decoderbufs is automatically loaded by default. You must modify the wal_level
parameter to logical
.
This parameter can be modified in the console. For more information, see Procedure. The cluster restarts after you modify the parameter. Proceed with caution.
Examples for logical replication:
Create a logical replication slot and set the codec plug-in to decoderbufs.
SELECT * FROM pg_create_logical_replication_slot('decoderbufs_demo', 'decoderbufs');
Modify the published table.
View WAL logs by using decoderbufs debug mode.
SELECT data FROM pg_logical_slot_peek_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');
Obtain WAL changes by using decoderbufs to update the WAL position.
SELECT data FROM pg_logical_slot_get_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');
Check the WAL position of logical replicators.
SELECT * FROM pg_replication_slots WHERE slot_type = 'logical';
Data type mappings
The following table lists how current PostgreSQL type OIDs are mapped to decoderbuf fields.
PostgreSQL type OID | 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 |