# PostgreSQL MCP Server

> 只读连接数据库，安全地做数据分析

- **URL**: https://followmcp.com/zh/servers/postgres
- **Category**: 数据库
- **Origin**: 官方
- **Stars**: 307
- **FMRS Score**: 68/100 (Grade C)
- **Source**: https://github.com/modelcontextprotocol/servers-archived/tree/main/src/postgres
- **Transports**: stdio（本地进程）
- **Runtimes**: Node.js
- **Auth**: 需要 API Key / 凭据

## Overview
以只读模式连接 PostgreSQL，自动读取表结构与索引信息，方便模型编写并解释 SQL 查询，避免误操作生产数据，适合数据分析与排障场景。

## Best for
- 需要用自然语言分析 PostgreSQL 数据的分析师和开发者
- 希望向助手开放只读数据库结构与查询能力的团队

## Not for
- 需要执行写入、迁移或数据库管理操作的场景
- 不能让第三方模型接触查询结果的敏感数据库

## Required permissions
- PostgreSQL 网络连接权限
- 专用只读数据库账号及目标 schema 的 SELECT 权限

## Risks
- 查询结果可能包含个人或业务敏感数据
- 复杂查询仍可能消耗大量数据库资源，建议设置超时和只读副本

## Client config (JSON)
```json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://readonly:pwd@localhost/db"
      ]
    }
  }
}
```

## Tools (4)
- `query`: 执行只读 SQL 查询
- `list_schemas`: 列出数据库中的所有 schema
- `list_tables`: 列出指定 schema 下的表
- `describe_table`: 查看表结构与字段类型
