pg_duckdb

DuckDB Embedded in Postgres

Overview

PIGSTY 3rd Party Extension: pg_duckdb : DuckDB Embedded in Postgres

Information

Metadata

  • Latest Version: 0.2.0
  • Postgres Support: 17,16,15,14
  • Need Load: Explicit Loading Required
  • Need DDL: Need CREATE EXTENSION DDL
  • Relocatable: Can be installed into other schemas
  • Trusted: Untrusted, Require Superuser to Create
  • Schemas: N/A
  • Requires: N/A

RPM / DEB

  • RPM Repo: PIGSTY
  • RPM Name: pg_duckdb_$v*
  • RPM Ver : 0.2.0
  • RPM Deps: N/A
  • DEB Repo: PIGSTY
  • DEB Name: postgresql-$v-pg-duckdb
  • DEB Ver : 0.2.0
  • DEB Deps: N/A

Packages

OS Arch PG17 PG16 PG15 PG14 PG13
el8 x86_64 pg_duckdb_17
PIGSTY 0.2.0
pg_duckdb_16
PIGSTY 0.2.0
pg_duckdb_15
PIGSTY 0.2.0
pg_duckdb_14
PIGSTY 0.2.0
el8 aarch64 pg_duckdb_17
PIGSTY 0.2.0
pg_duckdb_16
PIGSTY 0.2.0
pg_duckdb_15
PIGSTY 0.2.0
pg_duckdb_14
PIGSTY 0.2.0
el9 x86_64 pg_duckdb_17
PIGSTY 0.2.0
pg_duckdb_16
PIGSTY 0.2.0
pg_duckdb_15
PIGSTY 0.2.0
pg_duckdb_14
PIGSTY 0.2.0
el9 aarch64 pg_duckdb_17
PIGSTY 0.2.0
pg_duckdb_16
PIGSTY 0.2.0
pg_duckdb_15
PIGSTY 0.2.0
pg_duckdb_14
PIGSTY 0.2.0
d12 x86_64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0
d12 aarch64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0
u22 x86_64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0
u22 aarch64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0
u24 x86_64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0
u24 aarch64 postgresql-17-pg-duckdb
PIGSTY 0.2.0
postgresql-16-pg-duckdb
PIGSTY 0.2.0
postgresql-15-pg-duckdb
PIGSTY 0.2.0
postgresql-14-pg-duckdb
PIGSTY 0.2.0

Installation

Install pg_duckdb via the pig CLI tool:

pig ext install pg_duckdb

Install pg_duckdb via Pigsty playbook:

./pgsql.yml -t pg_extension -e '{"pg_extensions": ["pg_duckdb"]}' # -l <cls>

Install pg_duckdb RPM from YUM repo directly:

dnf install pg_duckdb_17*;
dnf install pg_duckdb_16*;
dnf install pg_duckdb_15*;
dnf install pg_duckdb_14*;

Install pg_duckdb DEB from APT repo directly:

apt install postgresql-17-pg-duckdb;
apt install postgresql-16-pg-duckdb;
apt install postgresql-15-pg-duckdb;
apt install postgresql-14-pg-duckdb;

Extension pg_duckdb has to be added to shared_preload_libraries

shared_preload_libraries = 'pg_duckdb'; # add to pg cluster config

Enable pg_duckdb extension on PostgreSQL cluster:

CREATE EXTENSION pg_duckdb;

Usage

Add pg_duckdb to shared_preload_libraries via patronictl

pg edit-config --force -p shared_preload_libraries='pg_duckdb, pg_stat_statements, auto_explain'
pg restart --force pg-meta

Create Extension

CREATE EXTENSION pg_duckdb;

Generate some data

pgbench -is100
\timing on

SELECT count(*) FROM pgbench_accounts;
-- 3268.023ms

# use the duckdb execution engine
SET duckdb.force_execution = true;


postgres@el8:5432/postgres=# explain SELECT count(*) FROM pgbench_accounts;
                                   QUERY PLAN
---------------------------------------------------------------------------------
Custom Scan (DuckDBScan)  (cost=0.00..0.00 rows=0 width=0)
DuckDB Execution Plan:

┌───────────────────────────┐
│    UNGROUPED_AGGREGATE    │
│    ────────────────────   │
│        Aggregates:        │
│        count_star()└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│     POSTGRES_SEQ_SCAN     │
│    ────────────────────   │
│         Function:         │
│     POSTGRES_SEQ_SCAN     │
│                           │
│       ~10000000 Rows      │
└───────────────────────────┘


JIT:
Functions: 1
Options: Inlining false, Optimization false, Expressions true, Deforming true
(22 rows)


postgres@el8:5432/postgres=# SELECT count(*) FROM pgbench_accounts;
count
----------
10000000
(1 row)

Time: 696.801 ms

According some user feedbacks, the duckdb engine can achieve 100x - 1000x speed up on certain queries.

Check more details @ https://github.com/duckdb/pg_duckdb





Last modified 2025-02-17: add extension part (cfa504b)