---
sidebar_position: 1
title: Connect via the Postgres endpoint
description: Connect to MotherDuck using any Postgres-compatible client via the Postgres wire protocol endpoint
feature_stage: preview
---

MotherDuck's Postgres endpoint lets you query your databases using any client that speaks the [PostgreSQL wire protocol](https://www.postgresql.org/docs/current/protocol.html) — 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](/getting-started/interfaces/client-apis/) instead.

## Before you start

You'll need a [MotherDuck access token](/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck). Set it as an environment variable:

```bash
export MOTHERDUCK_TOKEN="your_token_here"
```

## Connect with psql

```bash
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

```sh
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](https://letsencrypt.org/certs/isrgrootx1.pem) 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](/sql-reference/postgres-endpoint#ssl-and-certificate-verification) 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

- [Connect from Python (psycopg2 / psycopg3)](./python)
- [Connect from Java (JDBC)](./java)
- [Connect from Node.js](./nodejs)
- [Connect from Cloudflare Workers](./cloudflare-workers)

## Reference

For connection parameters, SSL options, session settings, and limitations, see the [Postgres Endpoint reference](/sql-reference/postgres-endpoint).
