linux查看pg数据库运行状态
时间: 2024-09-18 18:06:48 浏览: 339
在Linux系统上查看PostgreSQL (PG) 数据库的运行状态,通常可以使用`pg_ctl`命令行工具或者通过系统的进程管理器如`systemd`, `service`, 或`top`, `htop`等来监控。以下是几种常见的方法:
1. **使用pg_ctl**: 进入PostgreSQL的数据目录(如 `/var/lib/postgresql/data`),然后运行以下命令:
```
sudo -u postgres pg_ctl status
```
这将显示数据库的状态,如"running"、"stopped"等。
2. **使用systemctl (System V Init)** 如果你正在使用systemd管理系统服务:
```
sudo systemctl status postgresql
```
3. **使用service (Upstart) 或 systemctl (Docker Compose)** 对于基于upstart或systemd的服务,你可以输入:
```
sudo service postgresql status
```
4. **使用top或htop**:
```bash
sudo top -H | grep postgres
```
或者
```bash
htop -p $(pidof postgres)
```
这样可以实时看到postgres进程的资源占用情况。
5. **查询pg_stat_activity表**:
```
\c your_db_name
SELECT * FROM pg_stat_activity;
```
这将列出当前活动的连接及它们的状态。
阅读全文
相关推荐


















