decoderbufs

将WAL逻辑解码为ProtocolBuffer协议的消息

概览

扩展包名版本分类许可证语言
decoderbufs3.4.1ETLMITC
ID扩展名BinLibLoadCreateTrustReloc模式
9650decoderbufs-
相关扩展pglogical wal2json decoder_raw test_decoding kafka_fdw pglogical_origin pglogical_ticker pg_failover_slots

版本

类型仓库版本PG 大版本包名依赖
EXTPGDG3.4.11817161514decoderbufs-
RPMPGDG3.4.11817161514postgres-decoderbufs_$v-
DEBPGDG3.4.01817161514postgresql-$v-decoderbufs-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
d12.aarch64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
d13.x86_64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
d13.aarch64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
u22.x86_64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
u22.aarch64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
u24.x86_64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
u24.aarch64
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0
PGDG 3.4.0

安装

您可以直接安装 decoderbufs 扩展包的预置二进制包,首先确保 PGDG 仓库已经添加并启用:

pig repo add pgdg -u          # 添加 PGDG 仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install decoderbufs;          # 当前活跃 PG 版本安装
pig ext install -y decoderbufs -v 18  # PG 18
pig ext install -y decoderbufs -v 17  # PG 17
pig ext install -y decoderbufs -v 16  # PG 16
pig ext install -y decoderbufs -v 15  # PG 15
pig ext install -y decoderbufs -v 14  # PG 14
dnf install -y postgres-decoderbufs_18       # PG 18
dnf install -y postgres-decoderbufs_17       # PG 17
dnf install -y postgres-decoderbufs_16       # PG 16
dnf install -y postgres-decoderbufs_15       # PG 15
dnf install -y postgres-decoderbufs_14       # PG 14
apt install -y postgresql-18-decoderbufs   # PG 18
apt install -y postgresql-17-decoderbufs   # PG 17
apt install -y postgresql-16-decoderbufs   # PG 16
apt install -y postgresql-15-decoderbufs   # PG 15
apt install -y postgresql-14-decoderbufs   # PG 14

预加载配置

shared_preload_libraries = 'decoderbufs';

用法

decoderbufs: 使用 Protocol Buffer 格式传递 WAL 流变更的逻辑解码插件

一个 PostgreSQL 逻辑解码输出插件,将 WAL 变更序列化为 Protocol Buffers 格式,主要由 Debezium PostgreSQL 连接器用于变更数据捕获。

配置

postgresql.conf 中:

shared_preload_libraries = 'decoderbufs'
wal_level = logical
max_wal_senders = 8
max_replication_slots = 4

使用 SQL(调试模式)

-- 创建逻辑复制槽
SELECT * FROM pg_create_logical_replication_slot('decoderbufs_demo', 'decoderbufs');

-- 执行表修改
INSERT INTO my_table VALUES (1, 'test');
UPDATE my_table SET col = 'updated' WHERE id = 1;

-- 以调试文本模式查看变更
SELECT data FROM pg_logical_slot_peek_changes(
    'decoderbufs_demo', NULL, NULL, 'debug-mode', '1');

-- 消费变更
SELECT data FROM pg_logical_slot_get_changes(
    'decoderbufs_demo', NULL, NULL, 'debug-mode', '1');

-- 检查槽状态
SELECT * FROM pg_replication_slots WHERE slot_type = 'logical';

类型映射

PostgreSQL 类型Protobuf 字段
BOOLdatum_boolean
INT2, INT4datum_int32
INT8, OIDdatum_int64
FLOAT4datum_float
FLOAT8, NUMERICdatum_double
CHAR, VARCHAR, TEXTdatum_string
JSON, XML, UUIDdatum_string
TIMESTAMP(TZ)datum_string
BYTEAdatum_bytes
POINT, PostGISdatum_point

注意事项

  • 对于 UPDATE/DELETE,需要适当设置 REPLICA IDENTITY
  • 二进制 Protocol Buffer 输出由 Debezium Postgres Connector 消费
  • debug-mode 选项提供人类可读的文本输出,用于 SQL 控制台测试
  • 编译需要 protobuf-c 库和 PostGIS 开发包

最后修改 2026-03-14: update extension metadata (953cbd0)