MCP server
PostgreSQL MCP server
Lets AI assistants explore a PostgreSQL database, run SQL in a restricted read-only mode and check query performance and database health.
- Community server
- Databases
At a glance
- Maintained by
- Crystal DBA
- Tools exposed
- 9 listed below
- Reviewed
- September 24, 2026
Why it matters
What it does and why it matters
PostgreSQL holds the core data of many business apps: customers, orders, bookings and invoices. A PostgreSQL MCP server lets an AI assistant look at the schema, write SQL and explain the results in plain English. A manager can ask "how many bookings did we take last month, by channel" and get an answer without waiting for a report.
The original reference server from the MCP project was archived in May 2025. The best-maintained option we found is Postgres MCP Pro by Crystal DBA, a community server. Besides querying, it can explain query plans, find slow queries and suggest indexes, which also makes it useful for developers and database administrators.
Its restricted access mode runs read-only transactions with time limits, which is the setting we recommend for business users. Unrestricted mode allows writes and should be kept for development databases. We connect it to a read replica with a dedicated user, so even a badly written query cannot slow down or change production.
Use cases
Best business use cases
Plain-English reporting
Data exploration
Performance checks
Database health
Agent lookups
Tools
Available tools
Tool names as published by the maintainer at review time. Versions change, so check the repository for the current list.
Read and write: Read and write in unrestricted mode; restricted mode runs read-only transactions with time limits.
-
list_schemasLists the schemas in the database.
-
list_objectsLists tables, views, sequences and extensions in a schema.
-
get_object_detailsShows columns, constraints and indexes for an object.
-
execute_sqlRuns SQL, limited by the chosen access mode.
-
explain_queryShows the execution plan, including with hypothetical indexes.
-
get_top_queriesReports the slowest queries using pg_stat_statements.
-
analyze_workload_indexesRecommends indexes for the heaviest queries.
-
analyze_query_indexesRecommends indexes for specific queries.
-
analyze_db_healthChecks buffer cache, connections, constraints, indexes, sequences and vacuum health.
Workflows
Example workflows
Monthly sales questions
-
1
Connect the server to a read replica in restricted mode.
-
2
Ask for last month's revenue by product line.
-
3
The assistant inspects the schema and writes the SQL.
-
4
It runs the query and summarizes the result.
-
5
You ask a follow-up, such as the same numbers for last year.
Slow page investigation
-
1
A developer reports a slow page.
-
2
The assistant lists the top slow queries.
-
3
It explains the plan for the worst one.
-
4
It suggests an index and shows the expected plan.
-
5
The developer reviews and applies the change in a migration.
Prompts
Example prompts
“Show me the ten customers with the highest order value this quarter, with their order count.”
“Which tables hold booking data, and how are they related?”
“List the slowest queries this week and suggest indexes for the top three.”
Setup
Installation and configuration
Examples for Claude Desktop and Claude Code. Replace the placeholder values with your own keys, and store secrets outside version control.
Claude Desktop: claude_desktop_config.json
{
"mcpServers": {
"postgres": {
"command": "uvx",
"args": [
"postgres-mcp",
"--access-mode=unrestricted"
],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}
Claude Code: terminal
claude mcp add postgres -e DATABASE_URI="postgresql://username:password@localhost:5432/dbname" -- uvx postgres-mcp --access-mode=restricted
- Local server: stdio. PyPI: postgres-mcp (uvx postgres-mcp or pipx install postgres-mcp). Docker: crystaldba/postgres-mcp.
- Needs: DATABASE_URI (Postgres connection string, required); OPENAI_API_KEY (optional, only for experimental LLM-based index tuning).
Security
Security considerations
-
Least privilege
Create a dedicated database user that can read only the tables the assistant needs.
-
Use a replica
Point the server at a read replica or copy, not the primary production database.
-
Log every query
Keep a log of the queries the assistant runs, and review it in the first weeks.
-
Watch for sensitive data
Mask or exclude columns with personal or payment data from the user the assistant uses.
Related servers
Servers that pair well with it
Supabase
Supabase's official hosted MCP server lets AI work with your Supabase projects: tables, SQL, migrations, edge functions, branches and docs.
MySQL
A community MCP server that lets AI run SQL against MySQL, read-only by default, with insert, update and delete each switched on separately.
BigQuery
Google's remote BigQuery MCP server lets AI list datasets and tables and run SQL, with a read-only query tool and IAM controls.
Keep exploring
Solutions and services that use it
Related services
View all related services- MCP integration Connect AI assistants to your CRM, files, databases and tools through Model Context Protocol servers, with safe permissions.
- Database design Data models that stay fast and correct as your business grows, with backups and access rules in place.
- Web applications Custom browser-based software for the work your team does every day, from booking tools to operations systems.
- Dashboards and reporting Dashboards that pull numbers from the systems you already use and show what matters without a spreadsheet.
- Multi-tenant architecture One product serving many customer accounts, with each account's data kept separate and secure.
- Product scaling Keep a growing product fast and stable as users, data and features increase.
Solutions
View all solutions- Automated reporting Reports that build themselves from your systems on schedule, with a plain-language summary of what changed.
- Knowledge assistant (RAG) Ask a question in plain words and get an answer from your own documents, with links to the sources.
- AI automation and integrations Connect the tools you already use so data moves once, correctly, and AI reads the parts that arrive as text or documents.
- Forecasting dashboards Forecast demand from your sales history and seasonality, and flag items to reorder before they run out.
- Feedback analysis Read every review, survey and ticket, group them by theme and sentiment, and show what customers keep asking for.
- Payroll automation Turn pay rules, attendance and leave into tested software so the monthly run becomes a review and payslips go out in one batch.
Industries
View all industriesCase studies
View all case studiesGuides and articles
View all guides and articles- How to connect AI to your database safely Let staff ask questions of your data in plain English without risking production systems or sensitive records.
- PostgreSQL vs MySQL The two most popular open-source databases compared for business applications.
- What are AI agents and how do businesses use them? What AI agents are, real business uses, the controls they need and how to start with one safely.
- How to build an AI workflow with MCP servers Plan, connect and test an AI workflow that uses MCP servers, from a single task to a reliable process.
- How to automate reporting with AI and MCP Build reports that assemble themselves from your systems through MCP, with a written summary people can trust.
- How to set up automated reporting Replace manual weekly and monthly reports with dashboards and summaries that update themselves.
AI models
View all ai models- text-embedding-3-large OpenAI's most capable embedding model for search and retrieval, with 3,072-dimension vectors and support for English and other languages.
- text-embedding-3-small OpenAI's efficient, lowest-cost embedding model, with 1,536-dimension vectors for search, retrieval and similarity at scale.
- Cohere Embed v4 Cohere's multimodal embedding model for enterprise search, embedding text, images and mixed documents, with flexible vector sizes and long inputs.
- Voyage 4 Voyage AI's current embedding series, now part of MongoDB, with large, standard and lite models that share one embedding space.
- Embeddings Models that turn text into vectors for search, retrieval, clustering and recommendations.
- Claude Opus 5.5 Anthropic's recommended starting point for most serious work: long-running agentic coding and knowledge work, with a 1M token context window.
Glossary terms
View all glossary terms- Database A database is an organized store of data that software can search, update and keep consistent, such as customers, orders or bookings.
- AI agent An AI agent is software that uses a language model to plan steps, call tools and act toward a goal, instead of only answering one question.
- MCP server An MCP server is a program or hosted service that exposes a system's data and actions as tools that AI assistants can use through the Model Context Protocol.
- Model Context Protocol The Model Context Protocol, or MCP, is an open standard for connecting AI assistants to external tools and data in a consistent way.
- Vector database A vector database stores embeddings, lists of numbers that represent meaning, and quickly finds the ones most similar to a query.
- Backend The backend is the part of an application that runs on servers, storing data, applying business rules and serving the frontend through APIs.
FAQ
Questions people ask us
Have a question that is not here? Ask us directly.
The MCP project reference server was archived in May 2025. Postgres MCP Pro by Crystal DBA is a well-maintained community option.
In restricted mode it runs read-only transactions. Unrestricted mode allows writes, which we keep for development only.
It connects with a standard connection string, so it works with most managed PostgreSQL services.