MotherDuck Now Speaks Postgres! Our pg_endpoint is now live!Demo - April 21

Skip to main content

Connect via the Postgres endpoint

Preview
This feature is in preview and is subject to change.

MotherDuck's Postgres endpoint lets you query your databases using any client that speaks the PostgreSQL wire protocol — without installing a DuckDB client library. This is ideal for serverless environments, BI tools, or languages without a DuckDB SDK.

For full-featured access — including hybrid execution, local caching, and the complete DuckDB extension ecosystem — use the DuckDB SDK instead.

Before you start

You'll need a MotherDuck access token. Set it as an environment variable:

export MOTHERDUCK_TOKEN="your_token_here"

Connect with psql

PGPASSWORD=$MOTHERDUCK_TOKEN psql \
-h pg.us-east-1-aws.motherduck.com \
-p 5432 \
-U postgres \
"dbname=md: sslmode=verify-full sslrootcert=system"

Connect with a URI

postgresql://postgres:$MOTHERDUCK_TOKEN@pg.us-east-1-aws.motherduck.com:5432/md:?sslmode=verify-full&sslrootcert=system

Use md: as the database name to connect to your default database. To connect to a specific database, replace md: with the database name, for example sample_data.

info

For security, always use environment variables for your MotherDuck token. Never hardcode tokens in your application code.

Secure your connection

Always connect with SSL enabled. The recommended approach is sslmode=verify-full with sslrootcert=system, which verifies the server certificate against your operating system's trusted roots. If your client doesn't support this, you can download the ISRG Root X1 certificate from Let's Encrypt and set sslrootcert to its path.

Some libraries (psycopg2, JDBC, node-postgres) handle SSL differently — see the language-specific guides below or the SSL reference for details.

Key things to know

  • You're writing DuckDB SQL, not PostgreSQL SQL. Queries and MotherDuck SQL that run entirely inside MotherDuck generally work, but the Postgres endpoint is not a full DuckDB client.
  • Commands that depend on local files, local attachments, or extension management are not currently supported over the Postgres endpoint. Examples: local-file COPY, EXPORT DATABASE, IMPORT DATABASE, ATTACH ':memory:', ATTACH '/path/to/file.duckdb', CREATE DATABASE ... FROM '/path/to/file.duckdb', MD_RUN=LOCAL on table functions, INSTALL, and LOAD.
  • Use the Postgres endpoint for query execution, DDL and DML on MotherDuck tables, metadata inspection, and server-side reads from remote storage.
  • Avoid using SET statements, temporary tables, or result-creation commands — those are not currently supported in Postgres-endpoint server mode.
  • Prefer long-lived connections rather than opening and closing per query. For high-concurrency applications, use a connection pooler.

Language and platform guides

Reference

For connection parameters, SSL options, session settings, and limitations, see the Postgres Endpoint reference.