To build pg_duckdb, you need:
- Postgres 14-17
- Ubuntu 22.04-24.04 or MacOS
- Standard set of build tools for building Postgres extensions
- Build tools that are required to build DuckDB
- For full details on required dependencies you can check out our Github Action.
To build and install, run:
make installIf you want to link libduckdb statically, set DUCKDB_STATIC=1 when interacting with make(1).
Add pg_duckdb to the shared_preload_libraries in your postgresql.conf file:
shared_preload_libraries = 'pg_duckdb'Next, create the pg_duckdb extension:
CREATE EXTENSION pg_duckdb;This example uses Postgres 17. If you wish to use another version, substitute the version number in the commands as necessary.
We recommend using PGDG for Postgres, but you are welcome to use any Postgres packages or install from source. To install Postgres 17 from PGDG:
sudo apt install postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install postgresql-17 postgresql-server-dev-17If you do not install from PGDG, please note that you must have the server-dev package installed to compile extensions.
sudo apt install \
build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev \
libxslt-dev libssl-dev libxml2-utils xsltproc pkg-config libc++-dev \
libc++abi-dev libglib2.0-dev libtinfo6 cmake libstdc++-12-dev \
liblz4-dev ninja-buildCheckout pg_duckdb:
git clone https://github.com/duckdb/pg_duckdb
cd pg_duckdbBuild and install:
make -j16
sudo make installecho "shared_preload_libraries = 'pg_duckdb'" | sudo tee /etc/postgresql/17/main/conf.d/pg_duckdb.confAlternatively, you can directly edit /etc/postgresql/17/main/postgresql.conf if desired.
sudo service postgresql restartYou may wish to now create databases and users as desired. To use pg_duckdb immediately, you can use
the postgres superuser to connect to the default postgres database:
$ sudo -u postgres psql
postgres=# CREATE EXTENSION pg_duckdb;TODO
Q: How do I build for multiple versions of Postgres?
A: If you have multiple versions of Postgres installed, set PG_CONFIG to the path of the pg_config
binary that you would like to use for building before compilation.
export PG_CONFIG=/usr/bin/pg_configQ: make clean didn't remove all the build artifacts. How do I clean the entire project?
A: make clean will clean the pg_duckdb build files, but not libduckdb, which only needs to rebuilt on a DuckDB
version change. To clean both pg_duckdb and libduckdb, use make clean-all.