Skip to main content

Postgres Endpoint

MotherDuck's Postgres endpoint lets you query your databases using any client that speaks the PostgreSQL wire protocol — without installing a DuckDB client library.

For a how-to guide on connecting, see Connect through the Postgres endpoint.

Connection parameters​

ParameterValue
Hostpg.<region>-aws.motherduck.com for AWS regions and pg.<region>-azure.motherduck.com for Azure regions (for example, pg.us-east-1-aws.motherduck.com; find your region with md_user_info()). See cloud regions for the list of regions.
Port5432
Databasemd:, or a specific database name
Userpostgres
PasswordYour MotherDuck access token

Connection string formats​

# psql
PGPASSWORD=$MOTHERDUCK_TOKEN psql -h pg.us-east-1-aws.motherduck.com -p 5432 -U postgres "dbname=md: sslmode=verify-full sslrootcert=system"
# libpq URI
postgresql://postgres:$MOTHERDUCK_TOKEN@pg.us-east-1-aws.motherduck.com:5432/md:?sslmode=verify-full&sslrootcert=system
# DSN keyword/value
host=pg.us-east-1-aws.motherduck.com port=5432 dbname=md: user=postgres password=$MOTHERDUCK_TOKEN sslmode=verify-full sslrootcert=system

Use md: as the database name, or specify a database by name, for example sample_data.

If your client tool expects a single database catalog, connect with attach_mode=single. See Compatibility notes.

SSL and certificate verification​

The Postgres endpoint requires encrypted connections. For the best security, verify the server certificate.

SSL modes​

ModeEncryptionServer verificationRecommendation
verify-fullYesYesRecommended for production
requireYesNoFallback if certificate verification is not possible

Set sslmode=verify-full with sslrootcert=system to use your operating system's trusted root certificates. This is supported in libpq 16 and later, and in libraries that wrap libpq (like psycopg v3).

sslmode=verify-full sslrootcert=system

Use a specific certificate file​

If your client doesn't support sslrootcert=system, download the ISRG Root X1 certificate from Let's Encrypt and point your client to it:

sslmode=verify-full sslrootcert=/path/to/isrgrootx1.pem

Library-specific SSL handling​

Some libraries have their own SSL implementations that don't use libpq directly:

LibrarySSL behaviorWorkaround
psycopg (v3)Wraps libpq — sslrootcert=system worksNone needed
psycopg2Bundles its own OpenSSL — sslrootcert=system is not supportedUse sslrootcert=certifi.where() with the certifi package
PostgreSQL JDBCLooks for ~/.postgresql/root.crt by defaultSet sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory to use JVM trust store
node-postgres (pg)Reads sslrootcert as a file path — system causes ENOENTUse config object: ssl: { rejectUnauthorized: true }
Cloudflare Workers (pg-cloudflare)TLS handled by the Workers runtime at the socket level — application-level verification settings are not exposed through the pg clientUse ?sslmode=require in the connection string

Session options​

You can pass DuckDB session options using the PGOPTIONS environment variable:

PGOPTIONS="--attach_mode=single --session_name=pg-using-options" psql -h pg.us-east-1-aws.motherduck.com -p 5432 -U postgres md:

In a connection string, pass session options with the libpq options= parameter:

# libpq URI
postgresql://postgres:$MOTHERDUCK_TOKEN@pg.us-east-1-aws.motherduck.com:5432/<database_name>?sslmode=verify-full&sslrootcert=system&options=--attach_mode=single
OptionDescription
--attach_mode=singleOnly attach the specified database. Recommended when connecting from IDEs or BI tools to avoid seeing objects from other databases. See Attach Modes.

Connection pooling and timeouts​

For production applications, use a connection pool and set client-side timeouts. Recommended starting points:

SettingStarting pointWhy
Connection acquire timeout30 secondsFails fast when no connection can be opened or checked out
Maximum pool size5-10 connections per application instanceCaps how many queries the application runs concurrently
Idle connection lifetime30-60 secondsRecycles unused connections quickly
Maximum connection lifetime10-30 minutesPeriodically replaces long-lived connections
Query timeout60 seconds, or your application SLACancels runaway queries before requests pile up

Always release checked-out connections back to the pool after use. If a connection sees a network, protocol, or server-termination error, discard it instead of returning it to the pool. SQL errors caused by a bad query do not always mean the underlying connection is unhealthy, but failed transactions should be rolled back before reuse.

statement_timeout is not supported through the Postgres endpoint today. Do not rely on SET statement_timeout, options=-c statement_timeout=..., or startup options for query cancellation. Use your client library's timeout or cancellation feature instead, such as node-postgres query_timeout, JDBC Statement.setQueryTimeout, or a client-side cancel call in psycopg.

Supported features and limitations​

DuckDB SQL, not PostgreSQL​

The Postgres endpoint is a PostgreSQL-wire interface to MotherDuck. You write DuckDB SQL, not PostgreSQL SQL.

Best suited for​

  • query execution against MotherDuck tables
  • DDL and DML that run entirely inside MotherDuck
  • metadata inspection
  • server-side reads from remote storage

Use a DuckDB client path instead when you need​

  • local-file workflows such as local-file COPY, EXPORT DATABASE, or IMPORT DATABASE
  • local or in-memory attachments such as ATTACH ':memory:' or ATTACH '/path/to/file.duckdb'
  • local execution paths such as MD_RUN=LOCAL
  • extension-based workflows such as INSTALL, LOAD, or cloud-storage CREATE SECRET
  • DuckDB-client session features such as CREATE RESULT

Compatibility notes​

  • PostgreSQL-specific features such as pg_* functions, PostgreSQL indexes, sequences, and stored procedures are not supported.

  • Transaction semantics follow the DuckDB model. BEGIN, COMMIT, and ROLLBACK work, but nested transactions, SAVEPOINT, and SELECT ... FOR UPDATE don't. See Transactions for concurrent writers and dropped connections.

  • Some commands are further restricted in PG server mode. For example, SET threads and CREATE TEMP TABLE are not supported through the Postgres endpoint.

  • Use attach_mode=single when your client tool expects a single database catalog. Some tools, such as BI tools and IDE schema browsers, expect one database per connection and can show objects from every attached database. Set attach_mode=single to scope the catalog to the database in your connection string:

    postgresql://postgres:$MOTHERDUCK_TOKEN@pg.us-east-1-aws.motherduck.com:5432/<database_name>?sslmode=verify-full&sslrootcert=system&options=--attach_mode=single

Operational limitations​

  • Configuration settings are restricted. The Postgres endpoint connects in SaaS mode, a MotherDuck mode that blocks most DuckDB configuration changes after connecting and disables installing or loading extensions. Avoid using SET statements in your client code.
  • Use connection pooling in production. Each connection consumes server resources. For applications that need many connections, use a connection pooler (for example, Cloudflare Hyperdrive, PgBouncer, or a language-native pool) rather than rapidly opening and closing connections.
  • Third-party tool support is in early stages. Check the Integrations page for tools that support the Postgres endpoint.