跳转到主要内容

etcd_fdw

etcd分布式键值存储外部数据包装器

etcd_fdw · etcd分布式键值存储外部数据包装器

概览

ID扩展软件包版本类别许可证编程语言
8660etcd_fdwetcd_fdw0.0.1FDWMITRust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.0.119 18 17 16 15etcd_fdw-
RPMPIGSTY0.0.119 18 17 16 15etcd_fdw_$v-
DEBPIGSTY0.0.119 18 17 16 15postgresql-$v-etcd-fdw-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el8.aarch64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
软件包版本平台仓库大小下载
etcd_fdw_180.0.1el8.x86_64pigsty2.8 MiBetcd_fdw_18-0.0.1-3PIGSTY.el8.x86_64.rpm
etcd_fdw_180.0.1el8.aarch64pigsty2.6 MiBetcd_fdw_18-0.0.1-3PIGSTY.el8.aarch64.rpm
etcd_fdw_180.0.1el9.x86_64pigsty3.3 MiBetcd_fdw_18-0.0.1-4PGSTY.el9.x86_64.rpm
etcd_fdw_180.0.1el9.aarch64pigsty3.3 MiBetcd_fdw_18-0.0.1-4PGSTY.el9.aarch64.rpm
etcd_fdw_180.0.1el10.x86_64pigsty3.3 MiBetcd_fdw_18-0.0.1-4PGSTY.el10.x86_64.rpm
etcd_fdw_180.0.1el10.aarch64pigsty3.3 MiBetcd_fdw_18-0.0.1-4PGSTY.el10.aarch64.rpm
postgresql-18-etcd-fdw0.0.1d12.x86_64pigsty2.2 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~bookworm_amd64.deb
postgresql-18-etcd-fdw0.0.1d12.aarch64pigsty2.0 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~bookworm_arm64.deb
postgresql-18-etcd-fdw0.0.1d13.x86_64pigsty2.2 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~trixie_amd64.deb
postgresql-18-etcd-fdw0.0.1d13.aarch64pigsty2.0 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~trixie_arm64.deb
postgresql-18-etcd-fdw0.0.1u22.x86_64pigsty2.5 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~jammy_amd64.deb
postgresql-18-etcd-fdw0.0.1u22.aarch64pigsty2.4 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~jammy_arm64.deb
postgresql-18-etcd-fdw0.0.1u24.x86_64pigsty2.5 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~noble_amd64.deb
postgresql-18-etcd-fdw0.0.1u24.aarch64pigsty2.4 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~noble_arm64.deb
postgresql-18-etcd-fdw0.0.1u26.x86_64pigsty2.4 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~resolute_amd64.deb
postgresql-18-etcd-fdw0.0.1u26.aarch64pigsty2.4 MiBpostgresql-18-etcd-fdw_0.0.1-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
etcd_fdw_170.0.1el8.x86_64pigsty2.8 MiBetcd_fdw_17-0.0.1-3PIGSTY.el8.x86_64.rpm
etcd_fdw_170.0.1el8.aarch64pigsty2.6 MiBetcd_fdw_17-0.0.1-3PIGSTY.el8.aarch64.rpm
etcd_fdw_170.0.1el9.x86_64pigsty3.3 MiBetcd_fdw_17-0.0.1-4PGSTY.el9.x86_64.rpm
etcd_fdw_170.0.1el9.aarch64pigsty3.3 MiBetcd_fdw_17-0.0.1-4PGSTY.el9.aarch64.rpm
etcd_fdw_170.0.1el10.x86_64pigsty3.3 MiBetcd_fdw_17-0.0.1-4PGSTY.el10.x86_64.rpm
etcd_fdw_170.0.1el10.aarch64pigsty3.3 MiBetcd_fdw_17-0.0.1-4PGSTY.el10.aarch64.rpm
postgresql-17-etcd-fdw0.0.1d12.x86_64pigsty2.2 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~bookworm_amd64.deb
postgresql-17-etcd-fdw0.0.1d12.aarch64pigsty2.0 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~bookworm_arm64.deb
postgresql-17-etcd-fdw0.0.1d13.x86_64pigsty2.2 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~trixie_amd64.deb
postgresql-17-etcd-fdw0.0.1d13.aarch64pigsty2.0 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~trixie_arm64.deb
postgresql-17-etcd-fdw0.0.1u22.x86_64pigsty2.5 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~jammy_amd64.deb
postgresql-17-etcd-fdw0.0.1u22.aarch64pigsty2.4 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~jammy_arm64.deb
postgresql-17-etcd-fdw0.0.1u24.x86_64pigsty2.4 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~noble_amd64.deb
postgresql-17-etcd-fdw0.0.1u24.aarch64pigsty2.4 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~noble_arm64.deb
postgresql-17-etcd-fdw0.0.1u26.x86_64pigsty2.4 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~resolute_amd64.deb
postgresql-17-etcd-fdw0.0.1u26.aarch64pigsty2.4 MiBpostgresql-17-etcd-fdw_0.0.1-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
etcd_fdw_160.0.1el8.x86_64pigsty2.8 MiBetcd_fdw_16-0.0.1-3PIGSTY.el8.x86_64.rpm
etcd_fdw_160.0.1el8.aarch64pigsty2.5 MiBetcd_fdw_16-0.0.1-3PIGSTY.el8.aarch64.rpm
etcd_fdw_160.0.1el9.x86_64pigsty3.3 MiBetcd_fdw_16-0.0.1-4PGSTY.el9.x86_64.rpm
etcd_fdw_160.0.1el9.aarch64pigsty3.3 MiBetcd_fdw_16-0.0.1-4PGSTY.el9.aarch64.rpm
etcd_fdw_160.0.1el10.x86_64pigsty3.3 MiBetcd_fdw_16-0.0.1-4PGSTY.el10.x86_64.rpm
etcd_fdw_160.0.1el10.aarch64pigsty3.3 MiBetcd_fdw_16-0.0.1-4PGSTY.el10.aarch64.rpm
postgresql-16-etcd-fdw0.0.1d12.x86_64pigsty2.2 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~bookworm_amd64.deb
postgresql-16-etcd-fdw0.0.1d12.aarch64pigsty2.0 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~bookworm_arm64.deb
postgresql-16-etcd-fdw0.0.1d13.x86_64pigsty2.2 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~trixie_amd64.deb
postgresql-16-etcd-fdw0.0.1d13.aarch64pigsty2.0 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~trixie_arm64.deb
postgresql-16-etcd-fdw0.0.1u22.x86_64pigsty2.5 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~jammy_amd64.deb
postgresql-16-etcd-fdw0.0.1u22.aarch64pigsty2.4 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~jammy_arm64.deb
postgresql-16-etcd-fdw0.0.1u24.x86_64pigsty2.4 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~noble_amd64.deb
postgresql-16-etcd-fdw0.0.1u24.aarch64pigsty2.4 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~noble_arm64.deb
postgresql-16-etcd-fdw0.0.1u26.x86_64pigsty2.4 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~resolute_amd64.deb
postgresql-16-etcd-fdw0.0.1u26.aarch64pigsty2.4 MiBpostgresql-16-etcd-fdw_0.0.1-3PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
etcd_fdw_150.0.1el8.x86_64pigsty2.8 MiBetcd_fdw_15-0.0.1-3PIGSTY.el8.x86_64.rpm
etcd_fdw_150.0.1el8.aarch64pigsty2.5 MiBetcd_fdw_15-0.0.1-3PIGSTY.el8.aarch64.rpm
etcd_fdw_150.0.1el9.x86_64pigsty3.3 MiBetcd_fdw_15-0.0.1-4PGSTY.el9.x86_64.rpm
etcd_fdw_150.0.1el9.aarch64pigsty3.3 MiBetcd_fdw_15-0.0.1-4PGSTY.el9.aarch64.rpm
etcd_fdw_150.0.1el10.x86_64pigsty3.3 MiBetcd_fdw_15-0.0.1-4PGSTY.el10.x86_64.rpm
etcd_fdw_150.0.1el10.aarch64pigsty3.3 MiBetcd_fdw_15-0.0.1-4PGSTY.el10.aarch64.rpm
postgresql-15-etcd-fdw0.0.1d12.x86_64pigsty2.2 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~bookworm_amd64.deb
postgresql-15-etcd-fdw0.0.1d12.aarch64pigsty2.0 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~bookworm_arm64.deb
postgresql-15-etcd-fdw0.0.1d13.x86_64pigsty2.2 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~trixie_amd64.deb
postgresql-15-etcd-fdw0.0.1d13.aarch64pigsty2.0 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~trixie_arm64.deb
postgresql-15-etcd-fdw0.0.1u22.x86_64pigsty2.5 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~jammy_amd64.deb
postgresql-15-etcd-fdw0.0.1u22.aarch64pigsty2.4 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~jammy_arm64.deb
postgresql-15-etcd-fdw0.0.1u24.x86_64pigsty2.4 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~noble_amd64.deb
postgresql-15-etcd-fdw0.0.1u24.aarch64pigsty2.3 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~noble_arm64.deb
postgresql-15-etcd-fdw0.0.1u26.x86_64pigsty2.4 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~resolute_amd64.deb
postgresql-15-etcd-fdw0.0.1u26.aarch64pigsty2.3 MiBpostgresql-15-etcd-fdw_0.0.1-3PGSTY~resolute_arm64.deb

源码

pig build pkg etcd_fdw;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install etcd_fdw;		# install by package name

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

在数据库中创建扩展。

CREATE EXTENSION etcd_fdw;

用法

来源:介绍博客、GitHub repo、v0.0.1 release


快速上手

1. 启用扩展

CREATE EXTENSION etcd_fdw;

2. 创建外部数据包装器

CREATE FOREIGN DATA WRAPPER etcd_fdw
  HANDLER etcd_fdw_handler
  VALIDATOR etcd_fdw_validator;

3. 创建服务器

-- 基本连接
CREATE SERVER etcd_plain
  FOREIGN DATA WRAPPER etcd_fdw
  OPTIONS (connstr '127.0.0.1:2379');

-- 生产环境 etcd,启用认证和 SSL
CREATE SERVER etcd FOREIGN DATA WRAPPER etcd_fdw OPTIONS (
    connstr '127.0.0.1:2379',
    username 'root',
    password 'Etcd.Root',
    ssl_ca '/pg/cert/ca.crt',
    ssl_cert '/pg/cert/server.crt',
    ssl_key '/pg/cert/server.key'
);

4. 创建外部表

-- 基本表,映射所有键
CREATE FOREIGN TABLE etcd_kv (key TEXT, value TEXT) SERVER etcd OPTIONS (rowid_column 'key');

-- 带前缀过滤的表(仅包含以 '/config/' 开头的键)
CREATE FOREIGN TABLE etcd_config (key TEXT, value TEXT)
  SERVER etcd OPTIONS (rowid_column 'key', prefix '/config/');

5. 查询数据

-- 读取所有键
SELECT * FROM etcd_kv;

-- 按键模式过滤(支持下推)
SELECT * FROM etcd_kv WHERE key LIKE '/app/%';

-- 范围查询
SELECT * FROM etcd_kv WHERE key >= '/a' AND key < '/b';

-- 插入新键
INSERT INTO etcd_kv (key, value) VALUES ('/mykey', 'myvalue');

-- 删除键
DELETE FROM etcd_kv WHERE key = '/mykey';

6. 与 etcd 实时同步

在 PostgreSQL 外部所做的变更会立即可见:

# 通过 etcdctl 插入
etcdctl put '/config/db_pool_size' '20'
-- 在 PostgreSQL 中即时可见
SELECT * FROM etcd_config;
     key               | value
-----------------------+-------
 /config/db_pool_size  | 20
(1 row)

参考

服务器选项

选项必填说明
connstr是etcd 端点地址(例如 127.0.0.1:2379)
username否认证用户名
password否认证密码
ssl_ca否CA 证书文件路径
ssl_cert否客户端证书文件路径
ssl_key否客户端私钥文件路径
ssl_servername否TLS 验证使用的域名
connect_timeout否连接超时时间(默认:10s)
request_timeout否请求超时时间(默认:30s)

外部表选项

选项默认值说明
rowid_column必填用作唯一行标识符的列
prefix无仅包含具有此前缀的键
keys_onlyfalse仅获取键,跳过值
revision0从指定的 etcd 修订版本读取
key\0范围扫描的起始键
range_end无范围扫描的终止键(不包含)
consistencyll(线性一致性)或 s(串行化)

查询下推

以下操作会下推至 etcd 执行以提升性能:

  • WHERE:=、>=、>、<=、<、BETWEEN、LIKE 'prefix%'
  • ORDER BY:远程排序
  • LIMIT/OFFSET:远程分页

限制

  • 不支持对键列执行 UPDATE 操作。替代方案:先 INSERT 新键,再 DELETE 旧键。
  • 需要 etcd v3 API。

版本说明

etcd_fdw 0.0.1 是第一个公开版本。它使用 pgrx 0.18.1;文档化 SQL surface 是上面的 FDW/server/table workflow。

表格阅读器