The rds_duckdb extension accelerates complex analytical queries by offloading them to DuckDB's column-oriented storage and vectorized execution engine. No changes to your SQL are required.
For questions or feedback, join the ApsaraDB RDS for PostgreSQL Extensions DingTalk group (ID: 103525002795).
Overview
The rds_duckdb extension embeds DuckDB into ApsaraDB RDS for PostgreSQL. You export local tables as column-oriented tables, and qualifying analytical queries are automatically routed to DuckDB for faster execution.
Prerequisites
-
Your ApsaraDB RDS for PostgreSQL instance runs major version PostgreSQL 13 or later.
-
Your instance runs minor engine version 20260130 or later.
-
You have added rds_duckdb to the running value of the shared_preload_libraries parameter.
Configure this in Set instance parameters. For example, set the running value to
'pg_stat_statements,auto_explain,rds_duckdb'.
For minor engine version 20250228 and later, automatic incremental data synchronization for column-oriented tables is enabled by default.
Create and drop the extension
Use a privileged account to create or drop the extension.
Create the extension
CREATE EXTENSION rds_duckdb;
Check the DuckDB version
SELECT rds_duckdb.duckdb_version();
Drop the extension
DROP EXTENSION rds_duckdb;
Manage column-oriented tables
Create a column-oriented table
Export a local table (user table, materialized view, or foreign table) into a column-oriented table:
On PostgreSQL 15 with minor engine version 20250228 or later, automatic incremental synchronization is enabled by default. Complete the setup in Configure automatic incremental synchronization for column-oriented tables before creating a column-oriented table.
SELECT rds_duckdb.create_duckdb_table('local_table_name');
Refresh a column-oriented table
Refresh a column-oriented table with the latest schema and data from its source table:
SELECT rds_duckdb.refresh_duckdb_table('local_table_name');
Check the table size
SELECT rds_duckdb.duckdb_table_size('local_table_name');
Check the total size of exported tables
SELECT rds_duckdb.duckdb_database_size();
Drop a column-oriented table
SELECT rds_duckdb.drop_duckdb_table('local_table_name');
Manage AP acceleration
The rds_duckdb extension currently accelerates read-only queries. When enabled, queries that exclusively reference tables with DuckDB column-oriented counterparts are offloaded to DuckDB. Queries involving DML, DDL, or tables without a column-oriented counterpart fall back to the PostgreSQL engine automatically.
Fallback returns a warning such as: WARNING: Trying to execute an operation with non-duckdb tables(test), fallback to PG. Tables in parentheses lack a column-oriented counterpart.
Write operations trigger: WARNING: Modification operations on DuckDB tables are currently not supported, fallback to PG.
Enable AP acceleration
SET rds_duckdb.execution = on;
Configure AP acceleration parameters
Tune these session-level parameters to control AP query acceleration:
SET rds_duckdb.worker_threads = 32;
SET rds_duckdb.memory_limit = 16384;
|
Parameter |
Description |
Suggestion |
|
rds_duckdb.worker_threads |
The number of worker threads for AP query acceleration. Valid values: 1 to 255. Default value: 1. |
|
|
rds_duckdb.memory_limit |
The memory limit for AP query acceleration. Unit: MB. Do not include the unit when you set the parameter value. Valid values: 1 to INT32_MAX. Default value: 100 (which indicates 100 MB). |
|
For more details on DuckDB parameters, see the DuckDB documentation.
Disable AP acceleration
SET rds_duckdb.execution = off;
Configure auto-sync for column-oriented tables
On PostgreSQL 15 with minor engine version 20250228 or later, automatic incremental synchronization is enabled by default. Complete these steps before creating a column-oriented table:
-
In extension management, check the
rds_duckdbversion and upgrade it to 1.3 or later. -
Set instance parameters to change the running value of the wal_level parameter to logical.
-
(Optional) If the target local table does not have a primary key, run the following command to set a REPLICA IDENTITY index as the replication key.
ALTER TABLE <local_table_name> REPLICA IDENTITY USING INDEX <index_name>; -
Use an account with replication permission or a privileged account to create the column-oriented table.
Check the synchronization status and progress of column-oriented tables
SELECT * FROM rds_duckdb.duckdb_sync_stat;
View SQL execution plans
Use EXPLAIN to compare execution plans with and without AP acceleration:
-
Execution plan with AP acceleration enabled:
-
Execution plan with AP acceleration disabled:
Performance testing
TPC-H benchmark results in a Linux environment are available in Performance test for the rds_duckdb extension.