How to Set Up a PostgreSQL MCP Server

March 28, 2026 databases postgresql guide setup

One of the most useful MCP integrations is connecting an AI assistant directly to your PostgreSQL database. This guide walks through setting up the CrystalDBA PostgreSQL MCP server, one of the most popular database MCP servers.

Prerequisites

  • PostgreSQL database running and accessible
  • Node.js 18+ or Python 3.10+
  • An MCP-compatible client (Claude Desktop, Cursor, Windsurf, etc.)

Option 1: CrystalDBA Postgres MCP

The crystaldba/postgres-mcp server provides read-only access to your PostgreSQL database with schema inspection, query execution, and performance analysis.

Installation

npm install -g @crystaldba/postgres-mcp

Configuration

Add the server to your MCP client configuration. For Claude Desktop, edit ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "postgres": {
      "command": "postgres-mcp",
      "args": ["postgresql://user:password@localhost:5432/mydb"]
    }
  }
}

Replace the connection string with your actual database credentials.

What You Can Do

Once connected, your AI assistant can:

  • Explore schema — list tables, columns, indexes, and constraints
  • Run queries — execute SELECT statements against your data
  • Analyze performance — get query plans and optimization suggestions

Option 2: Supabase MCP

If you are using Supabase, the supabase-community/supabase-mcp server provides a more integrated experience with Supabase-specific features.

npx supabase-mcp-server

This server supports table management, Edge Functions, and authentication in addition to SQL queries.

Security Best Practices

When exposing a database to AI, always follow these guidelines:

  1. Use read-only credentials — create a dedicated database user with SELECT-only permissions
  2. Limit accessible schemas — restrict the user to specific schemas or tables
  3. Use connection pooling — avoid overwhelming your database with connections
  4. Never use production credentials in development — use a staging or read replica instead

Next Steps

Once your PostgreSQL MCP server is running, try asking your AI assistant to analyze your schema, generate reports from your data, or help optimize slow queries. Browse more database MCP servers to find tools for MySQL, SQLite, MongoDB, and other databases.

← Back to blog