Provides safe, controlled access to PostgreSQL databases with tools for executing queries, schema introspection, query analysis, and database statistics. Features granular permission control, query safety mechanisms, and AI-powered query optimization suggestions.
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., "@PostgreSQL MCP Servershow me the schema for the users table"
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.
postgres-mcp
A Model Context Protocol (MCP) server for PostgreSQL integration. Give your AI assistant safe, controlled access to your databases.
Status: v0.7.0
Author: Claude + MOD
License: MIT
Org: ArktechNWA
Why?
Your AI assistant can write SQL but can't see your schema, can't run queries to verify, can't explore your data model. It's guessing.
"Just give it database credentials" — bad idea. One missing index + large table = hung query = frozen assistant. One hallucinated DELETE = disaster. No guardrails, no recovery.
postgres-mcp is an intelligent interface, not a connection wrapper:
Problem | postgres-mcp Solution |
Queries can hang forever | NEVERHANG — adaptive timeouts, circuit breaker |
No visibility into database health | Health monitoring with degraded state detection |
Failures cascade | Circuit breaker opens, queries fail fast, auto-recovery |
All-or-nothing access | Granular: read-only default, table blacklist, permission tiers |
AI can't verify its SQL | Schema introspection + natural language queries |
Prometheus tells you the database is on fire. NEVERHANG lets you walk through the fire without getting burned.
Philosophy
Safety first — Read-only by default, write explicitly enabled
Query safety — Statement timeouts, row limits, dangerous pattern blocking
Schema awareness — Introspection without data exposure
NEVERHANG — Circuit breaker, adaptive timeouts, health monitoring, graceful degradation
Natural language — Ask questions in plain English, get SQL + results
Features
Natural Language (v0.6)
pg_ask — Ask questions in plain English, get SQL + results
Powered by Claude Sonnet for accurate SQL generation
Automatic schema context gathering
Fallback mode works without API key (returns schema for caller to generate SQL)
Perception (Read)
Execute SELECT queries
Schema introspection (tables, columns, indexes, constraints)
pg_schema — Unified table view (columns + indexes + constraints in one call)
pg_sample — Sample rows with blacklist filtering
Explain query plans
Database statistics
Active connections and locks
Action (Write)
INSERT, UPDATE, DELETE (permission-gated)
DDL operations (permission-gated)
Transaction support
Reliability (v0.5 NEVERHANG + v0.7 A.L.A.N.)
Circuit breaker with automatic recovery
Adaptive timeouts based on query complexity
Health monitoring with degraded state handling
Connection pool management
A.L.A.N. persistence: Circuit state and query history survive restarts
Permission Model
CRITICAL: Database access requires careful permission management.
Permission Levels
Level | Description | Default |
| SELECT queries, schema introspection | ON |
| INSERT, UPDATE, DELETE | OFF |
| CREATE, ALTER, DROP | OFF |
| VACUUM, REINDEX, connection management | OFF |
Table/Schema Filtering
Rules:
Blacklist always wins
Column-level filtering supported
Pattern matching:
schema.table.column
Query Safety
Bypass Mode
Full database access. DANGER ZONE.
Authentication
Or connection string:
Recommendation: Use a read-only database user for maximum safety.
Tools
Queries
pg_query
Execute a SELECT query.
Returns:
pg_execute
Execute INSERT/UPDATE/DELETE. Requires write permission.
Returns:
Natural Language (v0.6)
pg_ask
Ask a question in natural language — translates to SQL and executes.
Returns:
Fallback mode: If ANTHROPIC_API_KEY is not set, returns schema context for the caller to generate SQL:
Schema Introspection
pg_tables
List tables with metadata.
Returns:
pg_columns
Get column information for a table.
Returns:
pg_indexes
Get index information.
pg_constraints
Get constraint information (PK, FK, unique, check).
pg_schema
Get complete schema for a table (columns, indexes, constraints) in one call.
Returns:
pg_sample
Get sample rows from a table (respects column blacklist).
Returns:
Query Analysis
pg_explain
Get query execution plan.
Returns:
Statistics
pg_stats
Get database/table statistics.
pg_connections
Get active connections.
pg_locks
Get current locks.
Analysis
pg_analyze_query
AI-powered query analysis.
Returns:
pg_suggest_schema
Get schema improvement suggestions.
NEVERHANG v2.0 Architecture
Database queries can hang indefinitely. A missing index + large table = disaster. NEVERHANG is a multi-layered reliability system that ensures postgres-mcp never blocks your AI assistant.
Circuit Breaker
Automatic trip: 3 failures in 60s → circuit opens
Cooldown: 5 minute recovery period
Health states:
healthy→degraded→unhealthyGraceful degradation: Returns cached/safe responses when circuit is open
Adaptive Timeouts
Query complexity analysis: Simple queries get shorter timeouts
Pattern recognition: Known-slow patterns (JOINs, subqueries) get longer timeouts
Learning: Adjusts based on historical query performance
Override: Per-query timeout always available
Health Monitor
Continuous ping: Background health checks
State tracking: Monitors connection pool health
Recovery detection: Automatic circuit close when health returns
Metrics: Success rate, average latency, failure patterns
Connection Management
Pool limits: Configurable min/max connections
Idle timeout: Releases unused connections (default: 60s)
Connection timeout: Fast fail on connection issues (default: 10s)
Row Limits
Default max: 1000 rows
Auto-LIMIT injection: Adds LIMIT to unbounded SELECTs
Prevents: Accidental
SELECT *disasters
A.L.A.N. Persistence (v0.7)
As Long As Necessary — persistent memory for NEVERHANG:
Circuit state survives restarts: No cold-start amnesia
Query history tracking: 7 days of execution metrics
P95 latency by complexity: Adaptive timeout learning
Health check logs: 24 hours for trend analysis
Location:
~/.cache/postgres-mcp/neverhang.db(XDG compliant)Auto-cleanup: Prunes old data on startup
AI Integration (v0.6)
pg_ask uses Claude Sonnet to translate natural language to SQL.
Configuration: Add ANTHROPIC_API_KEY to your MCP server environment:
Fallback mode: If no API key is set, pg_ask returns schema context with instructions for the caller to generate SQL. This allows the tool to provide value even without a separate API key.
Configuration
~/.config/postgres-mcp/config.json:
Claude Code Integration
Installation
Requirements
Node.js 18+
PostgreSQL 12+
Optional: Anthropic API key for fallback AI
Security Considerations
Use read-only user — Create a DB user with SELECT-only grants
Blacklist sensitive tables — Passwords, secrets, PII
Statement timeout — Prevent runaway queries
Row limits — Prevent accidental data dumps
No credential exposure — Connection strings never logged
Credits
Created by Claude (claude@arktechnwa.com) in collaboration with Meldrey. Part of the ArktechNWA MCP Toolshed.