DuckDB
A DuckDB add-on is a fast analytical SQL database: aggregations and joins over large tables, and queries over Parquet and CSV files in S3. It runs as pg_duckdb, PostgreSQL with the DuckDB engine inside it, so every PostgreSQL client, driver and tool connects to it exactly as it connects to a PostgreSQL add-on.
To read a DuckDB database you already have (a MotherDuck database, or a DuckDB or Parquet file in S3), add it as a DuckDB data source instead.
Overview
- Versions: 1.1.1, 1.1.0, 1.0.0 (default: 1.1.1). These are pg_duckdb releases: 1.1.1 and 1.1.0 run on PostgreSQL 18, 1.0.0 on PostgreSQL 17.
- Default Port: 5432
- Cluster Support: No (single node only)
- Minimum Memory: 1 GB
- Use Cases: analytics, reporting, querying Parquet and CSV files
Memory
PostgreSQL and the DuckDB engine share the add-on's memory. DuckDB is given half of it (its duckdb.max_memory setting), read from the add-on's memory size each time the add-on starts. A resize restarts the add-on, so DuckDB's share follows the new size.
Creating a DuckDB Add-on
- Navigate to Add-ons and click Create Add-on
- On the Create New Add-on page, select DuckDB as the type
- Choose a version (1.1.1, 1.1.0 or 1.0.0)
- Enter the Add-on Label, an optional Description, and the CPU, memory (at least 1 GB) and disk
- Optionally enable automatic backups
- Click Create Add-on
Connection Information
The Connection tab shows the internal host, port, database (defaultdb), username, password and connection string, as for PostgreSQL:
postgresql://username:password@host:5432/defaultdb
In STRONGLY_SERVICES the add-on is listed under services.addons.duckdb, with the same connection and auth sections as a PostgreSQL add-on:
import json
import os
import psycopg2
services = json.loads(os.environ['STRONGLY_SERVICES'])
duck = next(a for a in services['services']['addons']['duckdb'] if a['name'] == 'analytics')
conn = psycopg2.connect(duck['connection']['connection_string'])
Running Queries with DuckDB
A query runs in PostgreSQL unless it reads DuckDB tables or files. To run your PostgreSQL tables' queries in the DuckDB engine too, turn on forced execution for the session:
SET duckdb.force_execution = true;
Create a table stored by DuckDB:
CREATE TABLE daily_sales USING duckdb AS
SELECT order_date, sum(amount) AS total FROM orders GROUP BY order_date;
Files in S3
Give DuckDB the bucket's credentials, then read Parquet (or CSV with read_csv) directly. Each row is read as r, and its columns as r['column']:
SELECT duckdb.create_simple_secret(type := 'S3', key_id := 'your_key', secret := 'your_secret', region := 'us-east-1');
SELECT r['product_name'], avg(r['rating']) AS average_rating
FROM read_parquet('s3://your-bucket/reviews.parquet') r
GROUP BY r['product_name'];
Where It Can Be Used
- Apps and workspaces: connect with any PostgreSQL driver (above). A workspace with the add-on attached has the
psycopg2,psycopgandduckdbPython packages installed. - Workflows: the PostgreSQL source and destination nodes list DuckDB add-ons in Select PostgreSQL or DuckDB Add-on.
- AutoML: a job can train from a table or a read-only query on the add-on.
Backups
A backup is a pg_dumpall of every database on the add-on, including roles (backup.sql), as for PostgreSQL. A restore drops every database and role and recreates them from the backup: open connections are closed and queries fail until it finishes. See Backups and Restoring a backup.
Monitoring
The Metrics tab shows CPU, memory and disk use, network traffic, connections, response time and health, and the Logs tab shows PostgreSQL's log output. See Metrics.