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

Skip to main content

Postgres endpoint (thin client)

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 — no DuckDB installation required. This is ideal for serverless environments, BI tools, or languages without a DuckDB SDK.

Quick start with psql

Set your access token and connect:

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

Run a query:

SELECT title, score
FROM sample_data.hn.hacker_news
WHERE type = 'story'
ORDER BY score DESC
LIMIT 5;

Quick start with Python

# /// script
# dependencies = ["psycopg"]
# ///

import psycopg, os

conn = psycopg.connect(
host="pg.us-east-1-aws.motherduck.com",
port=5432,
dbname="sample_data",
user="postgres",
password=os.environ["MOTHERDUCK_TOKEN"],
sslmode="verify-full",
sslrootcert="system",
)

with conn.cursor() as cur:
cur.execute("SELECT title, score FROM sample_data.hn.hacker_news WHERE type='story' LIMIT 5")
for row in cur:
print(row)

conn.close()

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.
  • The Postgres endpoint is best for query execution, DDL and DML on MotherDuck tables, metadata inspection, and server-side reads from remote storage.
  • Features that depend on DuckDB client session state, such as temporary tables or result creation, require a DuckDB client path instead.
  • Always connect with SSL enabled (sslmode=verify-full recommended).
  • Use your MotherDuck access token as the password.

Next steps