# Let your AI read your Postgres database, safely (read-only)

Level 3: Connect AI to your tools · 8 min · Updated 19 November 2026 · Path: Connect MCP servers to your assistant

By the end you'll connect an assistant to a Postgres database through a role that can only read, and keep production data out of reach.

"How many customers signed up last week, by plan?" You know the answer is in Postgres; you just don't want to write the SQL. With a database [MCP](https://ai-powered.com/academy/glossary/mcp) server your assistant can look at the schema, write the query, run it and explain the result. The question is how to let it read without ever letting it write, drop or leak.

The answer doesn't depend on which server you pick: **the database decides what the assistant can do**, through the role you give it.

## 1. Use a copy, not production

Point the assistant at a read replica, a nightly copy or a staging database. If something goes wrong, nothing that customers use is touched.

## 2. Create a role that can only read

Connect as an admin and create a role for the assistant:

```sql
CREATE ROLE ai_reader LOGIN PASSWORD 'choose-a-long-random-password';
GRANT USAGE ON SCHEMA public TO ai_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO ai_reader;
```

`GRANT SELECT ON ALL TABLES IN SCHEMA` covers the tables, views and foreign tables that exist now; tables you create later need their own grant. Leave out schemas or tables with personal data, or grant only the columns the assistant needs: PostgreSQL lets you grant SELECT per column.

## 3. Pick a server you've checked

Database servers in the directory, with their status and install config on each page:

MCP servers for databases from the directory:

- [Baserow](https://ai-powered.com/mcp/baserow): MCP server letting AI agents read and build Baserow databases, automations and dashboards
- [Midplane](https://ai-powered.com/mcp/midplane): Postgres gateway for AI agents with table grants, column masking and approval for writes
- [SchemaSketch](https://ai-powered.com/mcp/schemasketch): MCP server letting AI assistants read, edit and export SchemaSketch DBML database diagrams
- [GaussDB Read-Only MCP](https://ai-powered.com/mcp/gaussdb-read-only-mcp): Read-only MCP server letting coding agents inspect Huawei GaussDB databases safely
- [Elasticsearch Redis Stack Generator](https://ai-powered.com/mcp/elasticsearch-redis-stack-generator): MCP and A2A agent that composes Elasticsearch, Kibana and Redis stacks

Before you choose, go through [Is this MCP server safe?](https://ai-powered.com/academy/connect-mcp-servers/is-this-mcp-server-safe). For a database server look especially for: tools you can read and understand, a read-only mode if it has one, and an active repository. A tool marked `readOnlyHint` is a useful signal, but the MCP project is clear that annotations are hints, not guarantees. Your read-only role is the guarantee.

## 4. Connect it with the read-only role

Give the server a connection string for `ai_reader`, never for your admin user, and keep it in an environment variable or your app's secret input rather than in a committed file. Then add the server to your assistant the way the [Claude Code](https://ai-powered.com/academy/connect-mcp-servers/claude-code), [Cursor](https://ai-powered.com/academy/connect-mcp-servers/cursor) or [VS Code](https://ai-powered.com/academy/connect-mcp-servers/vs-code) lessons show.

**Try it**

Ask: "List the tables, then count sign-ups per plan for last week." Then ask it to "delete the test users". The query should fail with a permission error: that's your role doing its job.

**Watch out**

Rows can contain text written by anyone: support messages, names, notes. An assistant that reads them can meet [prompt injection](https://ai-powered.com/academy/glossary/prompt-injection). A read-only role means injected instructions can't change data, but keep approvals on, and don't connect the same chat to tools that send email or post messages.

## Key takeaways

- The database role, not the server, is what keeps the assistant read-only.
- Use a copy of the data, and grant only the schemas and columns needed.
- Check the server like any other, and keep its credentials out of files.

## What to try next

- Find a database server for your stack: browse [MCP servers](https://ai-powered.com/mcp) and filter by category.
- Practise the whole flow on a server that is read-only by design: [connect ours](https://ai-powered.com/academy/connect-mcp-servers/connect-ai-powered-mcp-server).

## Sources

Official documentation, checked on 19 November 2026:

- [GRANT (PostgreSQL 18 documentation)](https://www.postgresql.org/docs/current/sql-grant.html)
- [Tool annotations as risk vocabulary (MCP blog, 16 March 2026)](https://blog.modelcontextprotocol.io/posts/2026-03-16-tool-annotations/)
- [Security best practices (modelcontextprotocol.io)](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices)
