跳转到主要内容

pg_duckdb

在PostgreSQL中的嵌入式DuckDB扩展

pg_duckdb · 在PostgreSQL中的嵌入式DuckDB扩展

概览

ID扩展软件包版本类别许可证编程语言
2430pg_duckdbpg_duckdb1.2.2OLAPMITC++
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--sLd--否是是是否否
Embeds DuckDB 2.0.1. Preload required. Conflicts with duckdb_fdw.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.2.219 18 17 16 15pg_duckdb-
RPMPIGSTY1.2.219 18 17 16 15pg_duckdb_$v-
DEBPIGSTY1.2.219 18 17 16 15postgresql-$v-pg-duckdb-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el8.aarch64N/APIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el9.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
el9.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
el10.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
el10.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
d12.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
d12.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
d13.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
d13.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u22.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u22.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u24.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u24.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u26.x86_64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
u26.aarch64PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2PIGSTY 1.2.2
软件包版本平台仓库大小下载
pg_duckdb_191.2.2el9.x86_64pigsty32.2 MiBpg_duckdb_19-1.2.2-1PGSTY.el9.x86_64.rpm
pg_duckdb_191.2.2el9.aarch64pigsty29.3 MiBpg_duckdb_19-1.2.2-1PGSTY.el9.aarch64.rpm
pg_duckdb_191.2.2el10.x86_64pigsty33.1 MiBpg_duckdb_19-1.2.2-1PGSTY.el10.x86_64.rpm
pg_duckdb_191.2.2el10.aarch64pigsty30.5 MiBpg_duckdb_19-1.2.2-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-duckdb1.2.2d12.x86_64pigsty20.5 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-duckdb1.2.2d12.aarch64pigsty17.9 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-duckdb1.2.2d13.x86_64pigsty21.4 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~trixie_amd64.deb
postgresql-19-pg-duckdb1.2.2d13.aarch64pigsty18.9 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~trixie_arm64.deb
postgresql-19-pg-duckdb1.2.2u22.x86_64pigsty22.2 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~jammy_amd64.deb
postgresql-19-pg-duckdb1.2.2u22.aarch64pigsty20.3 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~jammy_arm64.deb
postgresql-19-pg-duckdb1.2.2u24.x86_64pigsty22.4 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~noble_amd64.deb
postgresql-19-pg-duckdb1.2.2u24.aarch64pigsty20.9 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~noble_arm64.deb
postgresql-19-pg-duckdb1.2.2u26.x86_64pigsty23.2 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~resolute_amd64.deb
postgresql-19-pg-duckdb1.2.2u26.aarch64pigsty21.6 MiBpostgresql-19-pg-duckdb_1.2.2-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_duckdb_181.2.0el8.x86_64pigsty24.8 MiBpg_duckdb_18-1.2.0-1PGSTY.el8.x86_64.rpm
pg_duckdb_181.2.0el8.aarch64pigsty21.3 MiBpg_duckdb_18-1.2.0-1PGSTY.el8.aarch64.rpm
pg_duckdb_181.2.2el9.x86_64pigsty32.1 MiBpg_duckdb_18-1.2.2-1PGSTY.el9.x86_64.rpm
pg_duckdb_181.2.2el9.aarch64pigsty29.4 MiBpg_duckdb_18-1.2.2-1PGSTY.el9.aarch64.rpm
pg_duckdb_181.2.2el10.x86_64pigsty33.2 MiBpg_duckdb_18-1.2.2-1PGSTY.el10.x86_64.rpm
pg_duckdb_181.2.2el10.aarch64pigsty30.5 MiBpg_duckdb_18-1.2.2-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-duckdb1.2.2d12.x86_64pigsty20.5 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-duckdb1.2.2d12.aarch64pigsty17.9 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-duckdb1.2.2d13.x86_64pigsty21.5 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~trixie_amd64.deb
postgresql-18-pg-duckdb1.2.2d13.aarch64pigsty18.9 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~trixie_arm64.deb
postgresql-18-pg-duckdb1.2.2u22.x86_64pigsty22.2 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~jammy_amd64.deb
postgresql-18-pg-duckdb1.2.2u22.aarch64pigsty20.3 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~jammy_arm64.deb
postgresql-18-pg-duckdb1.2.2u24.x86_64pigsty22.4 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~noble_amd64.deb
postgresql-18-pg-duckdb1.2.2u24.aarch64pigsty20.8 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~noble_arm64.deb
postgresql-18-pg-duckdb1.2.2u26.x86_64pigsty23.3 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~resolute_amd64.deb
postgresql-18-pg-duckdb1.2.2u26.aarch64pigsty21.6 MiBpostgresql-18-pg-duckdb_1.2.2-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_duckdb_171.2.0el8.x86_64pigsty24.7 MiBpg_duckdb_17-1.2.0-1PGSTY.el8.x86_64.rpm
pg_duckdb_171.2.0el8.aarch64pigsty21.3 MiBpg_duckdb_17-1.2.0-1PGSTY.el8.aarch64.rpm
pg_duckdb_171.2.2el9.x86_64pigsty32.2 MiBpg_duckdb_17-1.2.2-1PGSTY.el9.x86_64.rpm
pg_duckdb_171.2.2el9.aarch64pigsty29.4 MiBpg_duckdb_17-1.2.2-1PGSTY.el9.aarch64.rpm
pg_duckdb_171.2.2el10.x86_64pigsty33.2 MiBpg_duckdb_17-1.2.2-1PGSTY.el10.x86_64.rpm
pg_duckdb_171.2.2el10.aarch64pigsty30.7 MiBpg_duckdb_17-1.2.2-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-duckdb1.2.2d12.x86_64pigsty20.5 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-duckdb1.2.2d12.aarch64pigsty17.9 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-duckdb1.2.2d13.x86_64pigsty21.4 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~trixie_amd64.deb
postgresql-17-pg-duckdb1.2.2d13.aarch64pigsty18.9 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~trixie_arm64.deb
postgresql-17-pg-duckdb1.2.2u22.x86_64pigsty22.7 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~jammy_amd64.deb
postgresql-17-pg-duckdb1.2.2u22.aarch64pigsty20.9 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~jammy_arm64.deb
postgresql-17-pg-duckdb1.2.2u24.x86_64pigsty22.4 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~noble_amd64.deb
postgresql-17-pg-duckdb1.2.2u24.aarch64pigsty20.8 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~noble_arm64.deb
postgresql-17-pg-duckdb1.2.2u26.x86_64pigsty23.2 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~resolute_amd64.deb
postgresql-17-pg-duckdb1.2.2u26.aarch64pigsty21.6 MiBpostgresql-17-pg-duckdb_1.2.2-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_duckdb_161.2.0el8.x86_64pigsty24.7 MiBpg_duckdb_16-1.2.0-1PGSTY.el8.x86_64.rpm
pg_duckdb_161.2.0el8.aarch64pigsty21.2 MiBpg_duckdb_16-1.2.0-1PGSTY.el8.aarch64.rpm
pg_duckdb_161.2.2el9.x86_64pigsty32.2 MiBpg_duckdb_16-1.2.2-1PGSTY.el9.x86_64.rpm
pg_duckdb_161.2.2el9.aarch64pigsty29.5 MiBpg_duckdb_16-1.2.2-1PGSTY.el9.aarch64.rpm
pg_duckdb_161.2.2el10.x86_64pigsty33.1 MiBpg_duckdb_16-1.2.2-1PGSTY.el10.x86_64.rpm
pg_duckdb_161.2.2el10.aarch64pigsty30.6 MiBpg_duckdb_16-1.2.2-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-duckdb1.2.2d12.x86_64pigsty20.5 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-duckdb1.2.2d12.aarch64pigsty17.9 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-duckdb1.2.2d13.x86_64pigsty21.4 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~trixie_amd64.deb
postgresql-16-pg-duckdb1.2.2d13.aarch64pigsty18.9 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~trixie_arm64.deb
postgresql-16-pg-duckdb1.2.2u22.x86_64pigsty22.7 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~jammy_amd64.deb
postgresql-16-pg-duckdb1.2.2u22.aarch64pigsty20.8 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~jammy_arm64.deb
postgresql-16-pg-duckdb1.2.2u24.x86_64pigsty22.3 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~noble_amd64.deb
postgresql-16-pg-duckdb1.2.2u24.aarch64pigsty20.8 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~noble_arm64.deb
postgresql-16-pg-duckdb1.2.2u26.x86_64pigsty23.2 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~resolute_amd64.deb
postgresql-16-pg-duckdb1.2.2u26.aarch64pigsty21.6 MiBpostgresql-16-pg-duckdb_1.2.2-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_duckdb_151.2.0el8.x86_64pigsty24.7 MiBpg_duckdb_15-1.2.0-1PGSTY.el8.x86_64.rpm
pg_duckdb_151.2.0el8.aarch64pigsty21.2 MiBpg_duckdb_15-1.2.0-1PGSTY.el8.aarch64.rpm
pg_duckdb_151.2.2el9.x86_64pigsty32.0 MiBpg_duckdb_15-1.2.2-1PGSTY.el9.x86_64.rpm
pg_duckdb_151.2.2el9.aarch64pigsty29.5 MiBpg_duckdb_15-1.2.2-1PGSTY.el9.aarch64.rpm
pg_duckdb_151.2.2el10.x86_64pigsty33.2 MiBpg_duckdb_15-1.2.2-1PGSTY.el10.x86_64.rpm
pg_duckdb_151.2.2el10.aarch64pigsty30.6 MiBpg_duckdb_15-1.2.2-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-duckdb1.2.2d12.x86_64pigsty20.5 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-duckdb1.2.2d12.aarch64pigsty17.8 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-duckdb1.2.2d13.x86_64pigsty21.4 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~trixie_amd64.deb
postgresql-15-pg-duckdb1.2.2d13.aarch64pigsty18.9 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~trixie_arm64.deb
postgresql-15-pg-duckdb1.2.2u22.x86_64pigsty22.7 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~jammy_amd64.deb
postgresql-15-pg-duckdb1.2.2u22.aarch64pigsty20.9 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~jammy_arm64.deb
postgresql-15-pg-duckdb1.2.2u24.x86_64pigsty22.3 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~noble_amd64.deb
postgresql-15-pg-duckdb1.2.2u24.aarch64pigsty20.8 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~noble_arm64.deb
postgresql-15-pg-duckdb1.2.2u26.x86_64pigsty23.2 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~resolute_amd64.deb
postgresql-15-pg-duckdb1.2.2u26.aarch64pigsty21.6 MiBpostgresql-15-pg-duckdb_1.2.2-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_duckdb;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_duckdb;		# install by package name

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

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

shared_preload_libraries = 'pg_duckdb';

在数据库中创建扩展。

CREATE EXTENSION pg_duckdb;

用法

来源:

pg_duckdb 将 DuckDB 分析引擎嵌入 PostgreSQL,可查询普通 PostgreSQL 表和外部文件。1.2.1 内嵌 DuckDB 2.0.1,上游列出支持 PostgreSQL 14–18。扩展不可重定位,需要实例预加载。

启用并比较查询

将库加入现有设置,然后重启 PostgreSQL:

shared_preload_libraries = 'pg_duckdb'

以超级用户安装,检查分析查询:

CREATE EXTENSION pg_duckdb;
CREATE TABLE orders (category text, amount numeric);
INSERT INTO orders VALUES ('a', 10), ('a', 20), ('b', 5);
SET duckdb.force_execution = true;
EXPLAIN SELECT category, sum(amount) FROM orders GROUP BY category;
SELECT category, sum(amount) FROM orders GROUP BY category;
SET duckdb.force_execution = false;

普通查询默认使用 PostgreSQL,强制执行后才切换;DuckDB 专用函数或远程存储操作会自动选择 DuckDB。应检查计划并以代表性数据测量。read_parquet、read_csv 和 read_json 读取外部数据,duckdb.create_simple_secret 配置存储凭据。避免将密钥写入共享 SQL 历史,授权执行前先核验访问边界。

权限与配置

duckdb.postgres_role 指定可执行 DuckDB、管理密钥并使用 MotherDuck 数据的角色;默认仅超级用户可用。安装时可能创建所配置的角色。成员资格会开放共享的 DuckDB 密钥与数据,应有意授权。本地文件系统访问另外受 PostgreSQL 服务器文件角色与 DuckDB 文件系统设置约束。社区扩展加载由管理员显式选择。

事务与兼容性限制

同一事务不能同时写 PostgreSQL 和 DuckDB 表,也不能混用两种引擎的 DDL。应保持 duckdb.unsafe_allow_mixed_transactions 关闭,绕过限制可能只提交一侧,破坏一致性。默认也禁止在 PostgreSQL 函数内执行 DuckDB;相应的不安全设置存在已知崩溃风险。

1.2.1 支持嵌套定长数组,改善 numeric 与浮点转换,并修复并行工作进程的内存读取、取消清理和日志/统计中含密钥内容的处理。这些修复不能替代凭据权限控制及类型、查询兼容性检查。安装匹配动态库,遵循预加载重启要求,并在各数据库更新 SQL 扩展后再依赖新行为。

1.2.2 发行版

1.2.2 内嵌 DuckDB 2.0.1,增加 PostgreSQL 19 发布制品,并调整 CA 证书包加载。安装匹配服务器主版本的文件后,遵循扩展既有的预加载与 SQL 升级流程;远程对象凭据和 TLS 配置仍需单独管理。

表格阅读器