duckdb_fdw
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
duckdb_fdw | 2.0.2 | OLAP | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2470 | duckdb_fdw | No | Yes | No | Yes | No | Yes | - |
| Related | pg_duckdb pg_ducklake pg_mooncake pg_clickhouse pg_parquet pg_lake aws_s3 file_fdw pg_bulkload pg_stat_ch |
|---|
PGSTY 2.0.2 embeds DuckDB 2.0.0 statically, has no pg_duckdb runtime dependency, and conflicts with pg_duckdb for the same PG major. Switching from pg_duckdb requires removing its preload setting and restarting. Current builds support PG15-18; PG14 fails upstream boolVal/makeBoolean API use despite the README claiming PG13-18. Historical PG14 1.4.3 packages remain available.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.0.2 | 1817161514 | duckdb_fdw | - |
| RPM | PIGSTY | 2.0.2 | 1817161514 | duckdb_fdw_$v | - |
| DEB | PIGSTY | 2.0.2 | 1817161514 | postgresql-$v-duckdb-fdw | - |
Build
You can build the RPM / DEB packages for duckdb_fdw using pig build:
Install
You can install duckdb_fdw directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
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:
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)