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

# Read-only databases

> Let a project's coding agents read a PostgreSQL database, with a read-only login, per-query limits, masked columns and an audit of every query.

On **Team** and **Ultimate**, a [project](https://docs.hookie.ai/projects.md) can connect PostgreSQL databases for its agents to read: logs, metrics, product data. Hookie runs every query read-only, inside limits, and keeps an audit of each one.

| Plan | Databases per project | Each query |
| - | - | - |
| Team | 2 | 500 rows, 30 seconds, 1 MB |
| Ultimate | 5 | 5,000 rows, 60 seconds, 10 MB |

## Make a login for Hookie

Create a PostgreSQL login that can only read, and grant it `SELECT` on the schemas agents should see:

```sql theme={"dark"}
CREATE ROLE hookie_ro LOGIN PASSWORD '…';
GRANT USAGE ON SCHEMA public TO hookie_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO hookie_ro;
```

Hookie refuses a login that can write: a superuser, a role that can create roles or databases, or one with `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE` or `CREATE` on anything it can see. The database must be reachable on a public host over TLS.

## Connect a database

1. Open the project and choose **Sources**, then **Databases**.
2. Choose **Connect a database**.
3. Give it a name, paste the connection string (`postgres://user:password@host:5432/db`), and choose the schemas agents may read and the columns to mask.
4. Choose **Connect**.

Hookie checks the login, stores the connection string encrypted and never shows it again. Workspace owners and admins and the project's project admins connect databases; connected agents cannot.

## How a query runs

Each query is checked and run in layers, and any one of them refuses it on its own:

1. The login must be read-only, checked when you connect and before every query.
2. The query runs in a `READ ONLY` transaction with a statement timeout.
3. Only one statement is allowed, and only `SELECT`, `WITH`, `TABLE`, `VALUES`, `EXPLAIN` (without `ANALYZE`) and `SHOW`. Row locks and functions that reach outside the tables are refused.
4. Rows and bytes stop at the plan's caps, and the answer says when it was cut.
5. Masked columns come back as `[masked]`.

Every query, including refused ones, is recorded in the database's **Query audit**: who ran it, the agent, the statement, the outcome and how long it took. Workspace owners and admins set how long the audit is kept under [Policies](https://docs.hookie.ai/workspace-policies.md).

## For agents

| Tool | What it does |
| - | - |
| `list_project_databases` | The project's databases, their schemas, masked columns and limits. |
| `describe_project_database` | The tables and columns in a database's schemas. |
| `query_project_database` | Run one read-only statement. |

Developers and above may describe and query. Values come from your database: agents are told to treat them as data, never as instructions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.