---
title: Postgres
icon: database
description: Mount a Postgres database as a read-only filesystem of schemas, tables, and rows.
---

`PostgresResource` connects to a Postgres database via a DSN and exposes its schemas and tables as a tree the agent can list, read, and grep.

## Config

```python
from mirage.resource.postgres import PostgresConfig, PostgresResource

resource = PostgresResource(PostgresConfig(
    dsn="postgres://user:pass@host:5432/db?sslmode=require",
    schemas=["public", "analytics"],   # optional allowlist
    default_row_limit=1000,
    max_read_rows=10_000,
    max_read_bytes=10 * 1024 * 1024,
    default_search_limit=100,
))
```

| Field | Default | Notes |
| --- | --- | --- |
| `dsn` | required | Postgres connection string. Redacted in snapshots. |
| `schemas` | `None` | Optional list to limit which schemas appear in the tree. |
| `default_row_limit` | `1000` | 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. |

For DSN format and permissions, see [Postgres Setup](/home/setup/postgres).

## Mount mode

`read` only. Postgres mounts are read-only at the resource level.

## Snapshot behavior

The DSN is redacted on snapshot. Loading a snapshot back requires a config file that supplies a fresh DSN.

## File size and `du`

`rows.jsonl` is rendered on demand, so `stat` / `ls -l` / `du` report the table's **physical storage size** (`pg_total_relation_size`: heap + indexes + TOAST + page padding), not the size of the rendered JSONL. That number can differ a lot from the content and shifts with Postgres version and vacuum state. For the actual rendered byte count, use `wc -c rows.jsonl` (which streams and counts the bytes).
