home / mcp / postgres mcp server
MCP server for PostgreSQL database management and operations, built with a sophisticated enterprise-grade architecture.
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.
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.
npm install
npm run buildConfigure 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=300000Provide 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=falseLeverage 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.
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_databaseFor 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.
The server includes security features for SSL, authentication, encryption, auditing, and comprehensive administration tools to manage users, roles, and privileges.
Execute SQL queries with transaction support, explain plans, and analysis.
List, create, alter, and drop tables with detailed metadata.
Create, drop, list schemas and manage permissions.
Create, drop, analyze, and reindex indexes with usage statistics.
Insert, update, delete operations with bulk support.
Begin, commit, rollback transactions with savepoint support.
Complete database administration and maintenance.
Manage users, roles, and privileges.
SSL, authentication, encryption, auditing.
Performance metrics and query analysis.
Connection pool management.