# Postgres DBA MCP

> Postgres DBA MCP is an open-source MCP server for databases. Bounded, read-only PostgreSQL access for assistants, with compact CSV results. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, macOS, Linux, Windows, Self-hosted
- **Repository:** https://github.com/a-lafon/postgres-dba-mcp
- **MCP Registry name:** io.github.a-lafon/postgres-dba-mcp
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-11-23

## About

This Go server is pitched as a drop-in replacement for crystaldba/postgres-mcp 0.3.0, keeping its nine tools under the same names and parameters and adding analyze_locks. The README's complaints about the original are specific: unbounded Python-repr results that can run to hundreds of thousands of tokens, a restricted mode that could be bypassed through function calls such as pg_read_file, and a heavy container.

Results come back as compact CSV with a footer giving row count and timing, capped at 32 kB, with NULL kept distinct from an empty string and every cut announced. Restricted mode is on by default: each statement is parsed with PostgreSQL's own parser (libpg_query), every function call is checked, and the work runs in a read-only transaction. The author reports 131 of 131 attack statements refused, about 61% fewer tokens per execute_sql response, 9 MB of memory against 246 MB and a 13 ms cold start, measured on a PostgreSQL 17 database against the original, and says the tool definitions are 39% larger.

It ships as a single static binary, a Homebrew formula, an install script or a Docker image, and needs a DATABASE_URI for the database it serves. The first tool call opens the connection.

## Features

- **Capped CSV output:** Results are bounded by rows, bytes and cell length, with a footer saying what was cut.
- **Parser-checked SQL:** Statements are parsed with libpg_query and every function call is checked.
- **Read-only transaction:** Queries run inside a read-only transaction in the default restricted mode.
- **DBA tool set:** Schema, SQL, plans with hypothetical indexes, top queries and health checks.
- **Lock analysis:** analyze_locks is an extra tool beyond the original nine.
- **Single static binary:** Starts in milliseconds; also available as a non-root Docker image.

## Good for

- Let an assistant explore a production schema safely
- Find the slowest queries and read their plans
- Test hypothetical indexes before creating them
- Check database health from a chat
- Replace crystaldba/postgres-mcp with one config line

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add postgres-dba-mcp --env DATABASE_URI='<DATABASE_URI>' -- docker run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:0.4.3
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add postgres-dba-mcp --env DATABASE_URI='<DATABASE_URI>' -- docker run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:0.4.3
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.postgres-dba-mcp]
command = "docker"
args = ["run", "-i", "--rm", "-e", "DATABASE_URI", "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"]
env = { DATABASE_URI = "<DATABASE_URI>" }
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e DATABASE_URI='<DATABASE_URI>' postgres-dba-mcp docker -- run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:0.4.3

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "postgres-dba-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "ghcr.io/a-lafon/postgres-dba-mcp:0.4.3"
      ],
      "env": {
        "DATABASE_URI": "<DATABASE_URI>"
      }
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 1 of 2 tools changes data. From the server's own tool labels and tool names; not verified by us.

- `execute_sql` (name suggests: changes): Run a bounded SQL statement and return compact CSV
- `analyze_locks` (name suggests: reads): Analyze database locks

## FAQ

### Is Postgres DBA MCP really read-only?

In its default restricted mode, yes: statements are parsed, function calls checked and run in a read-only transaction.

### How do I connect to a database?

Set DATABASE_URI in the environment or pass the URI as the first argument.

### How do I install Postgres DBA MCP?

Via Homebrew, an install script, Docker, a release archive or go install.

### Does Postgres DBA MCP cost anything?

The README lists no price; it is an open-source project.

### How do I add Postgres DBA MCP to Claude Code?

Run this command in your terminal: claude mcp add postgres-dba-mcp --env DATABASE_URI='<DATABASE_URI>' -- docker run -i --rm -e DATABASE_URI ghcr.io/a-lafon/postgres-dba-mcp:0.4.3

### What are the best alternatives to Postgres DBA MCP?

The closest alternatives to Postgres DBA MCP are Midplane, Datatomcp, Gulliver, GaussDB Read-Only MCP and Zektor.

## Where this comes from

- Description: written from the project's README.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [Midplane](https://ai-powered.com/mcp/midplane): Midplane is an open-source MCP server for databases.
- [Datatomcp](https://ai-powered.com/mcp/datatomcp-2): Datatomcp is a freemium MCP server for analytics and data.
- [Gulliver](https://ai-powered.com/mcp/gulliver): Gulliver is an open-source MCP server for databases.
- [GaussDB Read-Only MCP](https://ai-powered.com/mcp/gaussdb-read-only-mcp): GaussDB Read-Only MCP is an open-source MCP server for databases.
- [Zektor](https://ai-powered.com/mcp/zektor): Zektor is a freemium MCP server for databases.
- [Sqlite Graph MCP](https://ai-powered.com/mcp/sqlite-graph-mcp): Sqlite Graph MCP is an MCP server for databases.
- [Trino](https://ai-powered.com/mcp/trino-2): Trino is an open-source MCP server for databases.
- [APoint MS SQL](https://ai-powered.com/mcp/apoint-ms-sql): APoint MS SQL is a free MCP server for databases.

---
Source: https://ai-powered.com/mcp/postgres-dba-mcp
