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 "Deploy 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-mcp show 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: Postgres MCP Pro
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
Available Tools
35 toolsanalyze_db_healthB
Analyze database health. Valid values: index, connection, vacuum, sequence, replication, buffer, constraint, all; comma-separated values are accepted.
Inputs: health_type.
analyze_query_indexesC
Analyze up to ten SQL queries and recommend indexes
Inputs: queries (required), method, max_index_size_mb.
analyze_workload_indexesC
Analyze frequently executed queries and recommend indexes
Inputs: method, max_index_size_mb.
apply_maintenance_planC
Apply an exact reviewed nontransactional maintenance plan
Inputs: name (required), operation (required), review_hash (required), schema_name (required), +6 more.
apply_migration_planB
Apply a reviewed fully transactional migration and its ledger row atomically
Inputs: name (required), steps (required), review_hash (required), timeout_seconds, +1 more.
create_maintenance_planB
Create a reviewed nontransactional PostgreSQL maintenance plan
Inputs: name (required), operation (required), schema_name (required), target_name (required), +3 more.
create_migration_planA
Create a deterministic reviewed PostgreSQL migration plan without touching the database
Inputs: name (required), steps (required).
delete_rowsB
Delete rows with mandatory filters, optimistic predicates, and commit guards
Inputs: where (required), schema_name (required), relation_name (required), returning, +3 more.
execute_sqlA
Execute exactly one read-only, parameterized SQL statement with bounded results
Inputs: sql (required), params, max_rows.
explain_queryA
Explain a SQL query and optionally simulate hypothetical indexes
Inputs: sql (required), analyze, hypothetical_indexes.
get_deployment_profileB
Report conservative PostgreSQL deployment-provider capabilities without secrets
Inputs: provider_hint.
get_extension_objectsB
Inventory PostgreSQL objects owned by one installed extension through core catalogs
Inputs: extension_name (required), limit.
get_extension_profilesA
List installed or available PostgreSQL extension capability profiles
Inputs: include_available.
get_maintenance_statusC
List redacted reviewed maintenance status records
Inputs: limit.
get_migration_statusC
List redacted reviewed migration ledger metadata
Inputs: limit.
get_object_detailsB
Show columns, constraints, indexes, and comments for a database object
Inputs: object_name (required), schema_name (required), object_type.
get_pgvector_diagnosticsA
Report bounded pgvector columns and indexes through PostgreSQL core catalogs
Inputs: max_columns, max_indexes.
get_postgis_diagnosticsB
Report bounded PostGIS columns and indexes through PostgreSQL core catalogs
Inputs: max_columns, max_indexes.
get_postgres_typeA
Inspect any PostgreSQL type, including enum, domain, composite, range, multirange, array, and extension types
Inputs: type_oid, type_name, schema_name.
get_relation_detailsA
Inspect a relation's columns, constraints, indexes, triggers, policies, partitions, and privileges
Inputs: schema_name (required), relation_name (required).
get_runtime_metricsA
Return privacy-preserving aggregate runtime metrics for the current process
Inputs: no named parameters.
get_server_capabilitiesA
Report the active profile, access policy, and hard execution limits
Inputs: no named parameters.
get_server_infoB
Report PostgreSQL version, database, role, recovery, locale, and installed extensions
Inputs: no named parameters.
get_top_queriesC
Report slow or resource-intensive queries using pg_stat_statements
Inputs: limit, sort_by.
insert_rowsC
Insert bounded typed rows with exact affected-row commit guards
Inputs: rows (required), schema_name (required), relation_name (required), returning, +2 more.
list_objectsB
List tables, views, sequences, or extensions
Inputs: schema_name (required), object_type.
list_postgres_typesB
List built-in, user-defined, and extension-owned PostgreSQL types by OID
Inputs: limit, offset, type_kind, schema_name, +1 more.
list_relationsC
List tables, partitions, views, sequences, foreign tables, indexes, and other relations
Inputs: limit, offset, schema_name, relation_kind, +1 more.
list_schemasA
List all schemas in the database
Inputs: no named parameters.
reconcile_maintenance_operationA
Reconcile a reviewed maintenance operation after external outcome verification
Inputs: name (required), resolution (required), review_hash (required).
rollback_migrationA
Atomically roll back the latest reviewed migration using its stored verified plan
Inputs: name (required), review_hash (required), timeout_seconds, lock_timeout_seconds.
search_catalogB
Search relations, routines, types, collations, and extensions
Inputs: term (required), limit, offset, object_kind, +2 more.
select_rowsA
Select bounded rows using catalog-validated identifiers, typed filters, and keyset pagination
Inputs: schema_name (required), relation_name (required), limit, where, +3 more.
update_rowsB
Update typed values with mandatory filters, optimistic predicates, and commit guards
Inputs: where (required), values (required), schema_name (required), relation_name (required), +4 more.
upsert_rowsA
Upsert typed rows through a verified primary or unique conflict key
Inputs: rows (required), schema_name (required), relation_name (required), conflict_columns (required), +4 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 35 tools
Each tool targets a distinct operation or resource (e.g., schema listing vs. object details, migration planning vs. maintenance), with clear descriptions that prevent ambiguity. Even similar tools like 'list_objects' and 'list_relations' differentiate by scope.
All tool names follow a consistent 'verb_noun' pattern in snake_case (e.g., 'get_runtime_metrics', 'create_migration_plan'). No mixed conventions (camelCase, different verb styles) are present.
35 tools is slightly high for typical MCP servers (most have 3-15), but each tool serves a well-defined PostgreSQL operation. The count is justified by the broad domain coverage, though some tools like the three 'analyze_*' variants could potentially be consolidated.
The tool set covers CRUD, migration lifecycle, maintenance, diagnostics, and schema inspection comprehensively. Minor gaps exist (e.g., no explicit tools for role/permission management, transaction control beyond migrations), but overall it's sufficient for database interaction.
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides 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.MIT
- 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.9MIT
- AlicenseNot gradedqualityDmaintenanceEnables 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.MIT
- AlicenseAqualityDmaintenanceEnables AI agents to analyze, optimize, and safely interact with PostgreSQL databases, including health checks, index recommendations, query planning, and SQL execution with read-only and production protection modes.15MIT