跳转到主要内容

kafgres

在 PostgreSQL 中运行 Kafka 协议消息代理

kafgres · 在 PostgreSQL 中运行 Kafka 协议消息代理

概览

ID扩展软件包版本类别许可证编程语言
9440kafgreskafgres0.3.3SIMElastic-2.0Rust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--sLd--否是是是否否
Preload; wait for broker; back up segments separately.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.3.319 18 17 16 15kafgres-
RPMPIGSTY0.3.319 18 17 16 15kafgres_$v-
DEBPIGSTY0.3.319 18 17 16 15postgresql-$v-kafgres-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.2PIGSTY 0.3.3
el8.aarch64N/APIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.2PIGSTY 0.3.3
el9.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
el9.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
el10.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
el10.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
d12.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
d12.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
d13.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
d13.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u22.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u22.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u24.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u24.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u26.x86_64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
u26.aarch64PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3PIGSTY 0.3.3
软件包版本平台仓库大小下载
kafgres_180.3.3el8.x86_64pigsty4.0 MiBkafgres_18-0.3.3-1PGSTY.el8.x86_64.rpm
kafgres_180.3.3el8.aarch64pigsty3.6 MiBkafgres_18-0.3.3-1PGSTY.el8.aarch64.rpm
kafgres_180.3.3el9.x86_64pigsty4.8 MiBkafgres_18-0.3.3-1PGSTY.el9.x86_64.rpm
kafgres_180.3.3el9.aarch64pigsty4.5 MiBkafgres_18-0.3.3-1PGSTY.el9.aarch64.rpm
kafgres_180.3.3el10.x86_64pigsty4.8 MiBkafgres_18-0.3.3-1PGSTY.el10.x86_64.rpm
kafgres_180.3.3el10.aarch64pigsty4.5 MiBkafgres_18-0.3.3-1PGSTY.el10.aarch64.rpm
postgresql-18-kafgres0.3.3d12.x86_64pigsty3.5 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~bookworm_amd64.deb
postgresql-18-kafgres0.3.3d12.aarch64pigsty3.0 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~bookworm_arm64.deb
postgresql-18-kafgres0.3.3d13.x86_64pigsty3.5 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~trixie_amd64.deb
postgresql-18-kafgres0.3.3d13.aarch64pigsty3.0 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~trixie_arm64.deb
postgresql-18-kafgres0.3.3u22.x86_64pigsty3.8 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~jammy_amd64.deb
postgresql-18-kafgres0.3.3u22.aarch64pigsty3.5 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~jammy_arm64.deb
postgresql-18-kafgres0.3.3u24.x86_64pigsty3.7 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~noble_amd64.deb
postgresql-18-kafgres0.3.3u24.aarch64pigsty3.5 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~noble_arm64.deb
postgresql-18-kafgres0.3.3u26.x86_64pigsty3.7 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~resolute_amd64.deb
postgresql-18-kafgres0.3.3u26.aarch64pigsty3.5 MiBpostgresql-18-kafgres_0.3.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
kafgres_170.3.3el8.x86_64pigsty4.0 MiBkafgres_17-0.3.3-1PGSTY.el8.x86_64.rpm
kafgres_170.3.3el8.aarch64pigsty3.6 MiBkafgres_17-0.3.3-1PGSTY.el8.aarch64.rpm
kafgres_170.3.3el9.x86_64pigsty4.8 MiBkafgres_17-0.3.3-1PGSTY.el9.x86_64.rpm
kafgres_170.3.3el9.aarch64pigsty4.5 MiBkafgres_17-0.3.3-1PGSTY.el9.aarch64.rpm
kafgres_170.3.3el10.x86_64pigsty4.8 MiBkafgres_17-0.3.3-1PGSTY.el10.x86_64.rpm
kafgres_170.3.3el10.aarch64pigsty4.5 MiBkafgres_17-0.3.3-1PGSTY.el10.aarch64.rpm
postgresql-17-kafgres0.3.3d12.x86_64pigsty3.4 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~bookworm_amd64.deb
postgresql-17-kafgres0.3.3d12.aarch64pigsty3.0 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~bookworm_arm64.deb
postgresql-17-kafgres0.3.3d13.x86_64pigsty3.4 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~trixie_amd64.deb
postgresql-17-kafgres0.3.3d13.aarch64pigsty3.0 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~trixie_arm64.deb
postgresql-17-kafgres0.3.3u22.x86_64pigsty3.8 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~jammy_amd64.deb
postgresql-17-kafgres0.3.3u22.aarch64pigsty3.5 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~jammy_arm64.deb
postgresql-17-kafgres0.3.3u24.x86_64pigsty3.7 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~noble_amd64.deb
postgresql-17-kafgres0.3.3u24.aarch64pigsty3.5 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~noble_arm64.deb
postgresql-17-kafgres0.3.3u26.x86_64pigsty3.7 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~resolute_amd64.deb
postgresql-17-kafgres0.3.3u26.aarch64pigsty3.5 MiBpostgresql-17-kafgres_0.3.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
kafgres_160.3.2el8.x86_64pigsty4.7 MiBkafgres_16-0.3.2-1PGSTY.el8.x86_64.rpm
kafgres_160.3.2el8.aarch64pigsty4.0 MiBkafgres_16-0.3.2-1PGSTY.el8.aarch64.rpm
kafgres_160.3.3el9.x86_64pigsty4.8 MiBkafgres_16-0.3.3-1PGSTY.el9.x86_64.rpm
kafgres_160.3.3el9.aarch64pigsty4.5 MiBkafgres_16-0.3.3-1PGSTY.el9.aarch64.rpm
kafgres_160.3.3el10.x86_64pigsty4.8 MiBkafgres_16-0.3.3-1PGSTY.el10.x86_64.rpm
kafgres_160.3.3el10.aarch64pigsty4.5 MiBkafgres_16-0.3.3-1PGSTY.el10.aarch64.rpm
postgresql-16-kafgres0.3.3d12.x86_64pigsty3.4 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~bookworm_amd64.deb
postgresql-16-kafgres0.3.3d12.aarch64pigsty3.0 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~bookworm_arm64.deb
postgresql-16-kafgres0.3.3d13.x86_64pigsty3.4 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~trixie_amd64.deb
postgresql-16-kafgres0.3.3d13.aarch64pigsty3.0 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~trixie_arm64.deb
postgresql-16-kafgres0.3.3u22.x86_64pigsty3.8 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~jammy_amd64.deb
postgresql-16-kafgres0.3.3u22.aarch64pigsty3.5 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~jammy_arm64.deb
postgresql-16-kafgres0.3.3u24.x86_64pigsty3.7 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~noble_amd64.deb
postgresql-16-kafgres0.3.3u24.aarch64pigsty3.5 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~noble_arm64.deb
postgresql-16-kafgres0.3.3u26.x86_64pigsty3.7 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~resolute_amd64.deb
postgresql-16-kafgres0.3.3u26.aarch64pigsty3.5 MiBpostgresql-16-kafgres_0.3.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
kafgres_150.3.3el8.x86_64pigsty4.0 MiBkafgres_15-0.3.3-1PGSTY.el8.x86_64.rpm
kafgres_150.3.3el8.aarch64pigsty3.6 MiBkafgres_15-0.3.3-1PGSTY.el8.aarch64.rpm
kafgres_150.3.3el9.x86_64pigsty4.8 MiBkafgres_15-0.3.3-1PGSTY.el9.x86_64.rpm
kafgres_150.3.3el9.aarch64pigsty4.5 MiBkafgres_15-0.3.3-1PGSTY.el9.aarch64.rpm
kafgres_150.3.3el10.x86_64pigsty4.8 MiBkafgres_15-0.3.3-1PGSTY.el10.x86_64.rpm
kafgres_150.3.3el10.aarch64pigsty4.5 MiBkafgres_15-0.3.3-1PGSTY.el10.aarch64.rpm
postgresql-15-kafgres0.3.3d12.x86_64pigsty3.4 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~bookworm_amd64.deb
postgresql-15-kafgres0.3.3d12.aarch64pigsty3.0 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~bookworm_arm64.deb
postgresql-15-kafgres0.3.3d13.x86_64pigsty3.4 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~trixie_amd64.deb
postgresql-15-kafgres0.3.3d13.aarch64pigsty3.0 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~trixie_arm64.deb
postgresql-15-kafgres0.3.3u22.x86_64pigsty3.7 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~jammy_amd64.deb
postgresql-15-kafgres0.3.3u22.aarch64pigsty3.5 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~jammy_arm64.deb
postgresql-15-kafgres0.3.3u24.x86_64pigsty3.7 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~noble_amd64.deb
postgresql-15-kafgres0.3.3u24.aarch64pigsty3.5 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~noble_arm64.deb
postgresql-15-kafgres0.3.3u26.x86_64pigsty3.7 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~resolute_amd64.deb
postgresql-15-kafgres0.3.3u26.aarch64pigsty3.5 MiBpostgresql-15-kafgres_0.3.3-1PGSTY~resolute_arm64.deb

源码

pig build pkg kafgres;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install kafgres;		# install by package name

pig install kafgres -v 19;   # install for PG 19
pig install kafgres -v 18;   # install for PG 18
pig install kafgres -v 17;   # install for PG 17
pig install kafgres -v 16;   # install for PG 16
pig install kafgres -v 15;   # install for PG 15

将扩展加入 shared_preload_libraries,详见配置说明。

shared_preload_libraries = 'kafgres';

在数据库中创建扩展。

CREATE EXTENSION kafgres;

用法

来源:

kafgres 在 PostgreSQL 中提供 Kafka 协议代理。上游 0.3.2 构建并测试 PostgreSQL 13–18。需要超级用户安装、共享预加载及重启,许可为 Elastic License 2.0。

启用代理

shared_preload_libraries = 'kafgres'
wal_level = logical
kafgres.database = 'postgres'
kafgres.bind_host = '127.0.0.1'
kafgres.advertised_host = '127.0.0.1'
kafgres.port = 9092
CREATE EXTENSION kafgres;
SELECT kafgres_create_topic('demo', 1);
BEGIN;
SELECT kafgres_produce('demo', 'key', 'value');
COMMIT;
SELECT * FROM kafgres_partition_offsets('demo');

Kafka 客户端连接配置的代理端口,SQL 消息生产参与调用者的事务。将监听器暴露到受信任本地环境之外前,应配置 TLS、身份认证和访问控制。

存储与变更捕获

kafgres.storage_engine 默认为 segment,日志保存在独立文件中,需要使用扩展自己的复制与归档流程。依赖 segment 保留和恢复能力前,应配置 kafgres.segment_archive_command 并监控 kafgres_archive_status()。普通 PostgreSQL WAL/PITR 无法覆盖整个 segment 日志。table 引擎将日志保存在 PostgreSQL 表内;切换引擎不会迁移已有记录。

CDC 还需要 wal_level = logical;部分 PostgreSQL 构建另外要求配置 output_plugin_libraries 白名单。0.3.0 支持带投影和过滤的 SQL CDC 映射。部署前应审阅映射与恢复流程;标签中的 CI 矩阵及发行产物覆盖 PostgreSQL 13–18。

持久性设置

0.3.0 默认开启 kafgres.fsync_before_ack,默认关闭 kafgres.relaxed_produce_commit。放宽前者可能在断电时丢失已经确认的分段记录;放宽后者可能在崩溃后丢失最新的幂等生产者状态,使重试产生重复记录。这些参数的作用范围小于事务性 SQL 生产,并不统一作用于表引擎。应保留严格默认值,直到明确接受对应的持久性取舍。

0.3.0 升级

安装匹配的 0.3.0 库并重启后,在 broker 数据库执行 ALTER EXTENSION kafgres UPDATE。SQL 升级收紧管理函数授权,并固定生产函数的 search_path。段存储引擎首次启动时会移除 0.2.0 的旧时间戳索引;旧段仍可通过扫描读取,新段生成当前格式的索引。

0.3.1 的 CDC 安装边界

CDC 需要 wal_level = logical。若 PostgreSQL 构建启用了输出插件允许列表,且代理报告不能把 kafgres 用作输出插件,应将其加入 output_plugin_libraries 并重载配置。库预加载仍需重启。已有事务式段记录应按上游 0.3.1 升级说明处理;单纯替换库不是存储迁移。

0.3.2 修复与升级

0.3.2 修复并发 SQL 生产的可见性、压缩主题处理、CDC 排空以及旧生产者隔离。安装匹配的库并重启 PostgreSQL 后,在代理使用的数据库执行:

ALTER EXTENSION kafgres UPDATE TO '0.3.2';

0.3.1 到 0.3.2 的 SQL 脚本只推进扩展版本,不改变 SQL 对象。从 0.3.0 升级时还需处理旧事务标记:Sarama 无法解码缺少 EndTransactionMarker 值的旧标记,它们会一直保留到对应分段被保留策略删除;按上游说明选择消费起点或重建主题。

0.3.3 配置

0.3.3 发布制品覆盖 PostgreSQL 13–18。官方代理配置要求逻辑 WAL,并设置客户端可达的通告主机。在限制输出插件的构建上,应将 kafgres 加入 output_plugin_libraries 并保留已有项;出现禁止使用插件的错误时可重载配置。共享预加载仍须重启,配置重载不能替代它。

表格阅读器