duckdb_fdw
duckdb_fdw : DuckDB Foreign Data Wrapper
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2470 | duckdb_fdw | duckdb_fdw | 2.0.2 |
OLAP | MIT | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_duckdb pg_ducklake pg_mooncake pg_clickhouse pg_parquet pg_lake aws_s3 file_fdw pg_bulkload pg_stat_ch |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.0.2 |
18 17 16 15 14 | duckdb_fdw |
- |
| RPM | PIGSTY | 2.0.2 |
18 17 16 15 14 | duckdb_fdw_$v |
- |
| DEB | PIGSTY | 2.0.2 |
18 17 16 15 14 | postgresql-$v-duckdb-fdw |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| el8.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| el9.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| el9.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| el10.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| el10.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| d12.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| d12.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| d13.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| d13.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u22.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u22.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u24.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u24.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u26.x86_64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
| u26.aarch64 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 2.0.2 | PIGSTY 1.4.3 |
Source
github.com/alitrack/duckdb_fdw
duckdb_fdw-2.0.2.tar.gz duckdb-2.0.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
- 2.0.2 README
- 2.0.2 control file
- 2.0.2 SQL functions and privileges
- Server, mapping and table options
- Scan, write and diagnostic functions
- Connection and transaction handling
- Schema import implementation
- 2.0.1 to 2.0.2 upgrade
duckdb_fdw 2.0.2 exposes DuckDB tables and data sources as PostgreSQL foreign tables through DuckDB’s native C API. Use it to query a DuckDB database, read Parquet, or access optional DuckDB catalogs. Foreign tables support reads and inserts; PostgreSQL UPDATE and DELETE through the FDW are not supported.
Enable and Map a DuckDB Table
Install the extension as a superuser. A new installation does not require preloading or a PostgreSQL restart. Use a persistent DuckDB file in a directory accessible to the PostgreSQL service account; the example assumes that directory already exists.
The catalog query reports the extension version; despite its name, duckdb_fdw_version() reports the linked DuckDB engine version. A user mapping is optional for a local file without credentials. Database-file permissions are those of the PostgreSQL operating-system account.
Import Tables and Read Parquet
Use DuckDB’s schema name, normally main, rather than PostgreSQL’s public. To read an existing Parquet file, declare matching PostgreSQL column types:
Options and Privileges
| Object | Purpose |
|---|---|
Server database |
DuckDB file path, or a connection-local in-memory database |
Server force_readonly |
Open file databases read-only and reject FDW writes and non-read-only helper statements |
Server extensions, attach_catalogs |
Load optional DuckDB extensions and attach catalogs |
Table table |
Map a DuckDB table or a Parquet path |
Column column_name |
Map a PostgreSQL column to a differently named DuckDB column |
duckdb_execute(server, statement) |
Execute DuckDB SQL; returns void, not a result table |
duckdb_create_s3_secret(...) |
Create an S3 secret in the DuckDB connection |
duckdb_fdw_preflight() |
Inspect runtime compatibility before using DuckDB |
Grant application roles only the foreign-server, schema and foreign-table privileges they need. EXECUTE on the arbitrary-SQL and secret helpers is revoked from PUBLIC on installation; grant it only to trusted roles.
For S3, MotherDuck or Quack credentials, prefer user mappings. Server options are visible in PostgreSQL catalogs and are unsuitable for secrets. Remote examples additionally depend on the relevant DuckDB extensions, network access and credentials; their availability is not implied by installing the FDW.
Connection and Transaction Boundaries
- Connections close at transaction end by default. With
database ':memory:', keep setup and queries in the same explicit transaction or the temporary database disappears. duckdb_fdw.keep_connectiondefaults to off. Enabling it retains connections after commit, but a writable file connection holds the DuckDB file lock across transactions and can block other PostgreSQL sessions from opening that file.- Foreign-table inserts follow the top-level PostgreSQL commit or rollback. Savepoint rollback does not undo individual DuckDB writes: if the outer transaction commits, writes from an aborted subtransaction can remain.
- DuckDB does not participate in PostgreSQL two-phase commit. Do not use prepared transactions or assume crash-atomic commits across PostgreSQL and DuckDB. Arbitrary SQL sent through the helper also does not acquire PostgreSQL transaction semantics automatically.
Compatibility and Upgrade
The Pigsty 2.0.2 packages target PostgreSQL 15-18. Upstream’s README advertises PostgreSQL 13-18, which is broader than this package range. Version 2.0.2 accepts DuckDB 1.5.x and 2.0.x runtimes; it does not change the SQL function set from 2.0.1.
Runtime execution is guarded against loading pg_duckdb in the same backend. Keep the two extensions in separate PostgreSQL instances. When switching away from a preloaded pg_duckdb, remove its preload entry and restart PostgreSQL; replacing files does not unload libraries from existing processes.
After installing matching files, use fresh backend sessions and update each database: