PostgreSQL MCP server - query, schema introspection, explain, and health checks for AI assistants
Postgres MCP server is a locally run integration for AI assistants that speak the Model Context Protocol. PostgreSQL MCP server - query, schema introspection, explain, and health checks for AI assistants.
One click adds this to your local Yaw MCP config so it's available in every Yaw Terminal session. Or install manually below.
Once Postgres is connected, these are the calls the assistant has available:
pg_readonly — Run a SQL statement guaranteed read-only - always inside BEGIN READ ONLY, regardless of ALLOW_WRITES. The recommended tool for read access; safe forpg_query — Run a SQL query. Writes gated by the role in DATABASE_URL first, ALLOW_WRITES second. Supports parameterized queries via params. Result fieldspg_list_schemas — List non-system schemaspg_list_tables — List tables (and optionally views) in a schema with estimated row counts. Paginated via limit/offsetpg_describe_table — Kind, columns, PK, outgoing FKs, incoming FKs (referenced_by), CHECK / UNIQUE / EXCLUDE constraints, indexes, and partition parent/children for apg_list_views — List views and materialized views in a schema, including their SQL definitionspg_list_functions — List functions, procedures, and aggregates in a schema with signatures and return typespg_list_extensions — List installed extensions (pgvector, postgis, pg_stat_statements, etc.) with versionspg_search_columns — Find columns by name pattern across all user schemas. Case-insensitive, supports SQL LIKE wildcardspg_explain — EXPLAIN or EXPLAIN ANALYZE for a SQL statement. Text or JSON output. Optional hypothetical_indexes (requires thepg_health — Server version, database size, connection count, active queries, table countpg_top_queries — Top N queries by total/mean execution time. Requires the pg_stat_statements extensionSetup follows the usual MCP pattern — install or clone the server, register it in your client's configuration file, restart the client. The configuration blocks on this page cover the common clients.
You will need 3 environment variables: DATABASE_URL, ALLOW_WRITES, POSTGRES_SSL_REJECT_UNAUTHORIZED. The server will not start without them, which is usually why the tools fail to appear on a first run. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.
Plenty of database access servers cover similar ground. The differences that matter in practice are scope of access and how much setup stands between you and a working tool call. Postgres's toolset — pg_readonly, pg_query, pg_list_schemas and 11 more — is a fair guide to whether it matches your workflow. It is maintained by jeffyaw; worth a glance at recent repository activity before you build anything load-bearing on it.
We check each listing at SyncDev against the project's documentation before it goes live — if something here drifts out of date, it is a bug worth reporting.
| Tool | What it does |
|---|---|
| pg_readonly | Run a SQL statement guaranteed read-only - always inside BEGIN READ ONLY, regardless of ALLOW_WRITES. The recommended tool for read access; safe for hosts to auto-allow. |
| pg_query | Run a SQL query. Writes gated by the role in DATABASE_URL first, ALLOW_WRITES second. Supports parameterized queries via params. Result fields include dataTypeName (e.g. int4, jsonb) alongside dataTypeID. |
| pg_list_schemas | List non-system schemas. |
| pg_list_tables | List tables (and optionally views) in a schema with estimated row counts. Paginated via limit/offset. |
| pg_describe_table | Kind, columns, PK, outgoing FKs, incoming FKs (referenced_by), CHECK / UNIQUE / EXCLUDE constraints, indexes, and partition parent/children for a relation. |
| pg_list_views | List views and materialized views in a schema, including their SQL definitions. |
| pg_list_functions | List functions, procedures, and aggregates in a schema with signatures and return types. |
| pg_list_extensions | List installed extensions (pgvector, postgis, pg_stat_statements, etc.) with versions. |
| pg_search_columns | Find columns by name pattern across all user schemas. Case-insensitive, supports SQL LIKE wildcards. |
| pg_explain | EXPLAIN or EXPLAIN ANALYZE for a SQL statement. Text or JSON output. Optional hypothetical_indexes (requires the [HypoPG](https://github.com/HypoPG/hypopg) extension) lets you ask "what would the plan be with these index |
| pg_health | Server version, database size, connection count, active queries, table count. |
| pg_top_queries | Top N queries by total/mean execution time. Requires the pg_stat_statements extension. |
| pg_seq_scan_tables | Tables with heavy sequential scans - missing-index candidates. |
| pg_unused_indexes | Non-unique, non-primary indexes with low scan counts - drop candidates. |
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@yawlabs/postgres-mcp@latest"],
"env": {
"DATABASE_URL": "postgres://user:password@host:5432/dbname"
}
}
}
}Configuration as documented by the project. Restart the client after saving.
| Variable | Description | Required |
|---|---|---|
| DATABASE_URL | Endpoint or connection string the server talks to. | Yes |
| ALLOW_WRITES | Configuration value read at startup. | Optional |
| POSTGRES_SSL_REJECT_UNAUTHORIZED | Configuration value read at startup. | Optional |
Read-only SQL access to Postgres — let your assistant inspect schemas and answer questions from real data.
Manage your whole Supabase project in conversation — database, auth, storage, Edge Functions and branches.
Query, modify and analyse local SQLite databases in conversation — the fastest way to chat with a data file.
Metabase ships its own MCP endpoint — search your BI content, build and run queries, and save questions and dashboards without leaving the chat.
Official MongoDB server covering data, schemas and Atlas management — from find queries to spinning up clusters.
Serverless Postgres with database branching — point your assistant at Neon and let it work on disposable copies.