decoder_raw
逻辑复制解码输出插件:RAW SQL格式
仓库
main/decoder_raw
https://github.com/michaelpq/pg_plugins/blob/main/decoder_raw/
源码
decoder_raw-1.0.tar.gz
decoder_raw-1.0.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
decoder_raw | 1.0 | ETL | PostgreSQL | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 9660 | decoder_raw | 否 | 是 | 否 | 否 | 否 | 否 | - |
| 相关扩展 | wal2json decoderbufs test_decoding pgoutput wal2mongo pgmqtt kafka_fdw pgq pg_protobuf pgproto |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | decoder_raw | - |
| RPM | PIGSTY | 1.0 | 1817161514 | decoder_raw_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-decoder-raw | - |
构建
您可以使用 pig build 命令构建 decoder_raw 扩展的 RPM / DEB 包:
pig build pkg decoder_raw # 构建 RPM / DEB 包
安装
您可以直接安装 decoder_raw 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install decoder_raw; # 当前活跃 PG 版本安装
pig ext install -y decoder_raw -v 18 # PG 18
pig ext install -y decoder_raw -v 17 # PG 17
pig ext install -y decoder_raw -v 16 # PG 16
pig ext install -y decoder_raw -v 15 # PG 15
pig ext install -y decoder_raw -v 14 # PG 14
dnf install -y decoder_raw_18 # PG 18
dnf install -y decoder_raw_17 # PG 17
dnf install -y decoder_raw_16 # PG 16
dnf install -y decoder_raw_15 # PG 15
dnf install -y decoder_raw_14 # PG 14
apt install -y postgresql-18-decoder-raw # PG 18
apt install -y postgresql-17-decoder-raw # PG 17
apt install -y postgresql-16-decoder-raw # PG 16
apt install -y postgresql-15-decoder-raw # PG 15
apt install -y postgresql-14-decoder-raw # PG 14
此扩展不需要执行
CREATE EXTENSION语句
用法
一个逻辑解码输出插件,将 WAL 变更转换为原始 SQL 语句。是 Michael Paquier 的 pg_plugins 集合的一部分。
配置
在 postgresql.conf 中:
wal_level = logical
max_replication_slots = 10
max_wal_senders = 10
使用 SQL 函数
-- 创建逻辑复制槽
SELECT * FROM pg_create_logical_replication_slot('raw_slot', 'decoder_raw');
-- 执行 DML 操作
INSERT INTO my_table VALUES (1, 'hello');
UPDATE my_table SET val = 'world' WHERE id = 1;
DELETE FROM my_table WHERE id = 1;
-- 获取原始 SQL 变更
SELECT data FROM pg_logical_slot_get_changes('raw_slot', NULL, NULL);
-- 输出:
-- INSERT INTO public.my_table (id, val) VALUES (1, 'hello');
-- UPDATE public.my_table SET val = 'world' WHERE id = 1;
-- DELETE FROM public.my_table WHERE id = 1;
-- 删除槽
SELECT pg_drop_replication_slot('raw_slot');
使用 pg_recvlogical
# 创建槽
pg_recvlogical -d postgres --slot raw_slot --create-slot -P decoder_raw
# 流式传输 SQL 语句变更
pg_recvlogical -d postgres --slot raw_slot --start -f -
# 删除槽
pg_recvlogical -d postgres --slot raw_slot --drop-slot
关键特性
- 输出变更为可执行的 SQL 语句(INSERT、UPDATE、DELETE)
- 适用于调试逻辑解码或在另一个数据库上重放变更
- 表应设置 REPLICA IDENTITY 以获得正确的 UPDATE/DELETE 输出
- 设计为自定义逻辑解码插件的轻量级模板