Skip to main content
Glama

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-mcp

Use unrestricted mode only for a controlled environment.

DATABASE_URI='postgresql://developer:password@localhost:5432/app_dev' \
uvx pgsql-mcp --access-mode=unrestricted

Do 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-mcp

Server profiles

Command

Scope

Pool

Write access

pgsql-mcp

Full catalog, SQL, diagnostics, and reviewed changes

Configured pool

Explicit unrestricted mode

pgsql-mcp-lite

Six focused read-only tools

Two connections

No

pgsql-mcp-ha

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

Security model

Production review

Production readiness

Architecture

Execution safety

Compatibility

PostgreSQL compatibility

Catalog model

Catalog inspection

Typed data

Data operations

Reviewed changes

Migrations and maintenance

Extensions

Profiles, objects, PostGIS, and pgvector

High availability

Replication

Quality system

Testing and documentation index

Writing profile

ASD-STE100 project 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 tools
analyze_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

    B3.4/5.0

    Scored across 35 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count4/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides 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
    • A
      license
      B
      quality
      D
      maintenance
      Enables 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.
      9
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables 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
    • A
      license
      A
      quality
      D
      maintenance
      Enables 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.
      15
      MIT