pgsql-mcp
Provides comprehensive PostgreSQL database management tools including schema inspection, SQL execution, query explanation with EXPLAIN plans, index tuning recommendations, workload analysis, and database health checks with support for pg_stat_statements and hypopg extensions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@pgsql-mcpshow me the top 5 slowest queries from the last hour"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pgsql-mcp
pgsql-mcp gives MCP clients safe PostgreSQL inspection, bounded SQL, reviewed changes, and operational diagnostics.
The server starts in restricted mode. Write tools require an explicit unrestricted configuration.
Why use pgsql-mcp
Control | Behavior | Evidence |
Safe default | Restricted mode permits bounded read operations | Database read-only transactions and SQL validation |
Reviewed change | Migration and maintenance plans require a review hash | Durable ledgers and commit guards |
Bounded output | Public tools apply row, time, and result limits | Server-side cursors and hard ceilings |
Broad catalog | Core catalogs expose relations, types, extensions, and providers | OID-backed identities and deterministic results |
Release quality | Main commits run the complete quality system | Tests, coverage, mutation, stress, and compatibility jobs |
Related MCP server: PostgreSQL MCP Server
Safety boundary
Use a dedicated PostgreSQL role with the minimum required privileges.
Use stdio for local clients when possible. Put remote transports behind authentication and transport encryption.
Read the security model before production use.
Quick start
Set a read-only database URI.
DATABASE_URI='postgresql://readonly_user:password@localhost:5432/app' \
uvx pgsql-mcpUse unrestricted mode only for a controlled environment.
DATABASE_URI='postgresql://developer:password@localhost:5432/app_dev' \
uvx pgsql-mcp --access-mode=unrestrictedDo not use a production owner or superuser role.
MCP configuration
{
"mcpServers": {
"postgres": {
"command": "uvx",
"args": ["pgsql-mcp"],
"env": {
"DATABASE_URI": "postgresql://readonly_user:password@localhost:5432/app"
}
}
}
}Docker
docker run -i --rm \
-e DATABASE_URI='postgresql://readonly_user:password@host.docker.internal:5432/app' \
pgsql-mcpServer profiles
Command | Scope | Pool | Write access |
| Full catalog, SQL, diagnostics, and reviewed changes | Configured pool | Explicit unrestricted mode |
| Six focused read-only tools | Two connections | No |
| Replication and failover inspection | Focused pool | No |
Capability map
Catalog and diagnostics
Inspect schemas, relations, routines, types, privileges, policies, and partitions.
Search trusted PostgreSQL catalogs.
Report installed and available extension profiles.
Inventory objects that belong to an installed extension.
Report PostGIS columns and spatial indexes.
Report pgvector columns and indexes.
Report provider capabilities without reading secrets.
Inspect replication topology and failover readiness.
SQL and data
Execute one bounded read-only SQL statement.
Bind values with native PostgreSQL parameters.
Select typed pages with stable keyset pagination.
Insert, upsert, update, and delete rows with commit guards.
Execute guarded atomic transactions in unrestricted mode.
Reviewed operations
Create and hash transactional migration plans.
Apply and roll back reviewed migrations.
Create and hash nontransactional maintenance plans.
Apply maintenance and reconcile an unknown outcome.
Analysis
Explain validated queries.
Read bounded workload statistics.
Analyze query and workload index opportunities.
Run database health checks.
Publish privacy-preserving runtime metrics.
Hard limits
Surface | Limit |
Full server rows | 5,000 |
Lite server rows | 500 |
Typed data rows | 500 |
Extension objects | 500 |
PostGIS columns and indexes | 500 combined |
pgvector columns and indexes | 500 combined |
Protected operations also apply query, lock, and idle-transaction timeouts.
Production use
The current release scope is ready for trusted internal and operator workflows when all checklist items are true.
Use a dedicated database role.
Keep restricted mode unless a reviewed write workflow is required.
Keep remote transports behind authentication and TLS.
Set explicit row and timeout limits.
Monitor the main branch quality jobs.
Test each upgrade against a disposable PostgreSQL database.
Review production readiness before deployment.
Future roadmap items are not release guarantees. Read the project plan for planned work.
Documentation
Topic | Guide |
Security and deployment | |
Production review | |
Architecture | |
Compatibility | |
Catalog model | |
Typed data | |
Reviewed changes | |
Extensions | |
High availability | |
Quality system | |
Writing profile |
Development
uv sync --all-extras
uv run ruff format --check .
uv run ruff check .
uv run pyright
uv run pytest -v
python scripts/check_ste_docs.py .Run the complete gates locally before merge. GitHub Actions run only after a commit reaches main.
Read CONTRIBUTING.md before you change the project.
Release
Main branch jobs build and validate the package and container. They do not publish artifacts.
Read PUBLISHING.md for the manual release procedure.
License
MIT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityFmaintenanceEnables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.Last updated61Apache 2.0
- Alicense-qualityDmaintenanceProvides comprehensive PostgreSQL database access with 36 tools for querying, managing schemas, JSONB operations, and database administration. Includes security features like query validation, rate limiting, SSL/TLS support, and optional write operations.Last updatedMIT
- AlicenseBqualityDmaintenanceEnables comprehensive PostgreSQL database management including index tuning, query plan analysis, health monitoring, schema-aware SQL generation, and safe SQL execution with configurable access control for both development and production environments.Last updated9MIT
- Alicense-qualityDmaintenanceEnables AI agents to interact with PostgreSQL databases through schema intelligence, query execution, and DBA tooling including index analysis and health monitoring. Features configurable access levels and audit logging for secure database operations.Last updated576MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Manage Supabase projects end to end across database, auth, storage, realtime, and migrations. Moni…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/surajmandalcell/pgsql-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server