Provides tools for querying, monitoring, and analyzing PostgreSQL databases, including schema exploration, performance metrics tracking, and optional write operations for data management.
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., "@MCP SQL Servershow me the schema for the Users table and its indexes"
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.
MCP PostgreSQL
A Model Context Protocol (MCP) server for PostgreSQL integration with Claude Code. Query, monitor, and analyze your PostgreSQL databases directly from Claude.
Features
Query Execution - Execute SELECT queries with parameterized inputs
Schema Exploration - Browse tables, columns, procedures, and indexes
Database Monitoring - Track active queries, blocking sessions, wait stats, and connections
Performance Analysis - Identify missing indexes, unused indexes, and fragmentation
Write Operations - INSERT, UPDATE, DELETE when enabled (READONLY=false)
Installation
Option 1: From npm (recommended)
npx @fabriciofs/mcp-postgresOption 2: Global installation
npm install -g @fabriciofs/mcp-postgresOption 3: Clone and build locally
git clone https://github.com/fabriciofs/mcp-postgres.git
cd mcp-postgres
npm install
npm run buildConfiguration
Claude Code Integration
Add to your Claude Code MCP settings (~/.claude/settings.json or project .claude/settings.json):
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@fabriciofs/mcp-postgres"],
"env": {
"SQL_CONNECTION_URL": "postgres://user:password@localhost:5432/database",
"READONLY": "true"
}
}
}
}Or with individual connection parameters:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@fabriciofs/mcp-postgres"],
"env": {
"SQL_SERVER": "localhost",
"SQL_DATABASE": "mydb",
"SQL_USER": "postgres",
"SQL_PASSWORD": "yourpassword",
"SQL_PORT": "5432",
"SQL_SSL": "false",
"READONLY": "true"
}
}
}
}Environment Variables
Connection (choose one method)
Method 1: Connection URL
SQL_CONNECTION_URL=postgres://user:password@host:port/database?ssl=falseMethod 2: Individual Parameters
SQL_SERVER=localhost
SQL_DATABASE=mydb
SQL_USER=postgres
SQL_PASSWORD=yourpassword
SQL_PORT=5432 # Optional, default: 5432
SQL_SSL=false # Optional, default: falseRequired Settings
Variable | Description |
| Required. Set to |
Optional Settings
Variable | Default | Description |
|
| Query timeout in milliseconds (max: 120000) |
|
| Maximum rows to return (max: 5000) |
|
| Minimum connection pool size |
|
| Maximum connection pool size |
|
| Log level: debug, info, warn, error |
Available Tools
Query Tools
Tool | Description |
| Execute SELECT queries with parameterized inputs |
Schema Tools
Tool | Description |
| List all tables and views in the database |
| Get detailed table information (columns, indexes, foreign keys) |
| Search for columns across all tables |
| List stored procedures |
| List indexes with usage statistics |
Monitor Tools
Tool | Description |
| Monitor currently running queries |
| Monitor blocking sessions and lock chains |
| Monitor wait statistics for performance bottlenecks |
| Monitor database size and file usage |
| Monitor active connections |
| Monitor PostgreSQL performance metrics |
Analysis Tools
Tool | Description |
| Analyze query execution plan and statistics |
| Suggest missing indexes based on query patterns |
| Find indexes that are not being used |
| Find duplicate or overlapping indexes |
| Analyze index fragmentation levels |
| Analyze table statistics for stale data |
Write Tools (READONLY=false only)
Tool | Description |
| Insert a row into a table |
| Update rows in a table |
| Delete rows from a table |
Usage Examples
Once configured, you can ask Claude to interact with your database:
"List all tables in the database"
"Describe the Users table"
"Show me active queries running for more than 5 seconds"
"Find unused indexes in the Orders table"
"Analyze the fragmentation of all indexes"
"What are the top wait statistics?"Security Considerations
Always use READONLY=true in production unless write access is explicitly required
Store credentials securely using environment variables
Use PostgreSQL roles with minimal required permissions
Consider network security (VPN, firewall rules) for remote connections
Requirements
Node.js >= 20.0.0
PostgreSQL 12 or later
Appropriate PostgreSQL permissions for the operations you want to perform
Development
# Install dependencies
npm install
# Build
npm run build
# Development mode (watch)
npm run dev
# Type check
npm run typecheck
# Run MCP Inspector
npm run inspectorLicense
MIT License - see LICENSE file for details.