home / mcp / postgres mcp server

Postgres MCP Server

MCP server for PostgreSQL database management and operations, built with a sophisticated enterprise-grade architecture.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "itsalfredakku-postgres-mcp": {
      "command": "node",
      "args": [
        "C:\\path\\to\\postgres-mcp\\dist\\index.js"
      ],
      "env": {
        "POOL_MAX": "20",
        "LOG_LEVEL": "info",
        "DATABASE_URL": "postgresql://username:password@localhost:5432/dbname"
      }
    }
  }
}

You run a PostgreSQL MCP server that provides comprehensive database operations, schema and index management, data handling, and admin capabilities through a centralized, scalable interface. This MCP server lets you perform queries, manage schemas and permissions, handle transactions, and monitor performance all from a unified client workflow.

How to use

You will connect to the PostgreSQL MCP server from your MCP client to perform operating tasks such as querying data, managing schemas, handling transactions, and administering users and permissions. Use the client’s toolset to call the available MCP endpoints for database operations, data management, administration, and security. Expect structured results, detailed metadata for database objects, and built‑in validation and error handling to guide you through complex tasks. You can enable caching and tuned logging to optimize performance and troubleshoot issues as needed.

How to install

npm install
npm run build

Configuration and environment

Configure the MCP server using environment variables or a desktop config. The server supports a primary database connection string and optional pooling, logging, and caching controls.

# Option: environment variables
DATABASE_URL=postgresql://username:password@localhost:5432/dbname
POOL_MIN=2
POOL_MAX=10
POOL_IDLE_TIMEOUT=30000
POOL_ACQUIRE_TIMEOUT=60000
LOG_LEVEL=info
CACHE_ENABLED=true
CACHE_TTL=300000

Database connection and environment details

Provide the primary connection string or individual host/port/user/database components. You can also configure a non‑SSL or SSL connection, depending on your environment.

# Individual components (alternative to DATABASE_URL)
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_DATABASE=your_database
POSTGRES_SSL=false

Usage patterns and capabilities

Leverage the built‑in tools for database operations, data management, administration, and security. Use the following capabilities to perform common tasks: querying data, creating and altering tables, managing schemas, handling transactions, backing up and restoring data, and administering users and permissions. Monitoring provides performance metrics and query analysis to help you optimize workloads.

Troubleshooting

If you encounter issues, check that your database server is running and reachable with the configured credentials. Review connection pool settings and enable verbose logging during debugging.

# Example: test connectivity
psql -h localhost -p 5432 -U postgres -d your_database

Notes

For production, tune pool settings and enable appropriate logging levels to balance performance and observability. Use the monitoring features to identify slow queries and index usage opportunities, and manage permissions to enforce least privilege.

Security and administration

The server includes security features for SSL, authentication, encryption, auditing, and comprehensive administration tools to manage users, roles, and privileges.

Available tools

query

Execute SQL queries with transaction support, explain plans, and analysis.

tables

List, create, alter, and drop tables with detailed metadata.

schemas

Create, drop, list schemas and manage permissions.

indexes

Create, drop, analyze, and reindex indexes with usage statistics.

data

Insert, update, delete operations with bulk support.

transactions

Begin, commit, rollback transactions with savepoint support.

admin

Complete database administration and maintenance.

permissions

Manage users, roles, and privileges.

security

SSL, authentication, encryption, auditing.

monitoring

Performance metrics and query analysis.

connections

Connection pool management.