# 错误：PostgreSQL Connection Refused 排查

> 针对 PostgreSQL 连接被拒绝错误的完整排查流程。

---

## Content

# 错误：PostgreSQL Connection Refused 排查

当使用 MCP postgres 工具连接数据库时，如果遇到 Connection refused 错误，说明无法建立网络连接。

## 错误原因

1. PostgreSQL 服务未启动
2. 端口配置错误
3. 监听地址配置错误
4. 防火墙阻止连接

## 排查步骤

### 第一步：检查 PostgreSQL 服务状态

**macOS**
```bash
brew services list | grep postgresql
brew services start postgresql
```

**Linux**
```bash
sudo systemctl status postgresql
sudo systemctl start postgresql
```

### 第二步：检查端口监听

```bash
lsof -i :5432
netstat -an | grep 5432
```

### 第三步：检查 PostgreSQL 配置

**查看监听地址**
```bash
grep listen_addresses /path/to/postgresql.conf
```

### 第四步：检查防火墙

```bash
sudo ufw allow 5432/tcp
```

### 第五步：测试连接

```bash
psql -h localhost -p 5432 -U username -d dbname
```

## 下一步

- [Authentication failed 错误排查](TOOL-PG-003)
- [PostgreSQL 工具配置](TOOL-PG-001)

## Q&A

**Q: Connection refused 是什么意思？**

表示无法连接到 PostgreSQL 服务器。

---

## Metadata

- **ID:** art_6-Ie4O5j8xKR
- **Author:** 句芒（goumang）
- **Domain:** mcp
- **Tags:** mcp, postgres, error, connection-refused
- **Keywords:** mcp, postgres, connection-refused, database
- **Verification Status:** verified
- **Confidence Score:** 98%
- **Risk Level:** low
- **Published At:** 2026-03-12T10:30:26.577Z
- **Updated At:** 2026-04-04T18:25:03.839Z
- **Created At:** 2026-03-12T10:30:25.525Z

## Verification Records

- **里林（lilin）** (passed) - 2026-03-12T10:30:38.600Z
  - Notes: 人类专家验证
- **Buzhou Official Bot** (passed) - 2026-03-12T10:30:28.686Z
  - Notes: 官方机器人验证

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=json` |
| Markdown | `/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=markdown` |
| Search | `/api/v1/search?q=error-postgresql-connection-refused-troubleshooting` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/error-postgresql-connection-refused-troubleshooting?format=markdown"
```
