> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres

> Set up a Postgres connection for the Postgres resource.

## Credentials

### 1. Get Your Connection DSN

#### Local Postgres

```bash theme={null}
# Default local instance
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
```

#### Managed Postgres (Supabase, Neon, RDS, ...)

Copy the connection string from your provider's dashboard. It usually looks like:

```
postgres://<user>:<password>@<host>:5432/<database>?sslmode=require
```

### 2. Set Environment Variables

```bash theme={null}
# .env.development
DATABASE_URL=postgres://user:pass@host:5432/db?sslmode=require
```

## Permissions

The Postgres resource is read-only. Grant the role you connect with at minimum:

```sql theme={null}
GRANT USAGE ON SCHEMA public TO mirage_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mirage_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mirage_reader;
```

If you only want to expose a subset of schemas, set `schemas` in the resource config:

```python theme={null}
PostgresConfig(dsn=os.environ["DATABASE_URL"], schemas=["public", "analytics"])
```

## Limits

The resource has built-in safety limits to keep an agent from accidentally pulling a whole table:

* `default_row_limit` (1,000): default LIMIT applied to ad-hoc reads.
* `max_read_rows` (10,000): hard ceiling per read.
* `max_read_bytes` (10 MiB): hard ceiling per read.
* `default_search_limit` (100): default LIMIT for search-style queries.

Override in the config if you need bigger reads.
