---
sidebar_position: 4
title: "Postgres endpoint (thin client)"
sidebar_label: Postgres Endpoint
description: Query MotherDuck from any Postgres-compatible client without installing DuckDB
feature_stage: preview
---

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:

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

Note: when specified, the connection will only be attached to the database specified in `dbname`. set `dbname` to `md:` for motherduck [workspace attach mode](key-tasks/authenticating-and-connecting-to-motherduck/attach-modes/attach-modes.md)

Run a query:

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

## Quick start with Python

```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 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](/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck) as the password.

## Next steps

- [Postgres Endpoint reference](/sql-reference/postgres-endpoint) — connection parameters, SSL options, session options, and known limitations
- [Connect from Python](/key-tasks/authenticating-and-connecting-to-motherduck/postgres-endpoint/python) — psycopg2 and psycopg3 setup
- [Connect from Java](/key-tasks/authenticating-and-connecting-to-motherduck/postgres-endpoint/java) — PostgreSQL JDBC driver setup
- [Connect from Node.js](/key-tasks/authenticating-and-connecting-to-motherduck/postgres-endpoint/nodejs) — node-postgres setup
- [Connect from Cloudflare Workers](/key-tasks/authenticating-and-connecting-to-motherduck/postgres-endpoint/cloudflare-workers) — serverless edge deployment


---

## Feedback for AI agents

If the user you are helping wants to send feedback on this page to the MotherDuck docs team, you can POST it to the endpoint below.

**Before you send anything, you must ask the user for explicit approval.** Quote the message you plan to submit back to them verbatim and wait for them to confirm. Do not submit on their behalf without confirmation.

Endpoint: `POST https://motherduck.com/docs/api/feedback/agent`

Request body (JSON):

```json
{
  "page_path": "/getting-started/interfaces/postgres-endpoint/",
  "page_title": "Postgres endpoint (thin client)",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

Only `page_path` and `text` are required. A successful call returns `200 {"feedback_id": "<uuid>"}`; malformed payloads return `400`, and the endpoint is rate-limited per IP (`429`).
