On this page
28.1. 标准 Unix 工具
在大多数 Unix 平台上,PostgreSQL 修改ps
所报告的命令标题,以便可以轻松识别各个服务器进程。samples 显示为
$ ps auxww | grep ^postgres
postgres 15551 0.0 0.1 57536 7132 pts/0 S 18:02 0:00 postgres -i
postgres 15554 0.0 0.0 57536 1184 ? Ss 18:02 0:00 postgres: writer process
postgres 15555 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: checkpointer process
postgres 15556 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: wal writer process
postgres 15557 0.0 0.0 58504 2244 ? Ss 18:02 0:00 postgres: autovacuum launcher process
postgres 15558 0.0 0.0 17512 1068 ? Ss 18:02 0:00 postgres: stats collector process
postgres 15582 0.0 0.0 58772 3080 ? Ss 18:04 0:00 postgres: joe runbug 127.0.0.1 idle
postgres 15606 0.0 0.0 58772 3052 ? Ss 18:07 0:00 postgres: tgl regression [local] SELECT waiting
postgres 15610 0.0 0.0 58772 3056 ? Ss 18:07 0:00 postgres: tgl regression [local] idle in transaction
(ps
的适当调用在不同的平台上有所不同,显示的内容也有所不同.该示例来自最新的 Linux 系统.)此处列出的第一个进程是主服务器进程。显示的命令参数与启动时使用的参数相同。接下来的五个进程是由主进程自动启动的后台工作进程。 (如果已将系统设置为不启动统计信息收集器,则“统计信息收集器”进程将不存在;同样,可以禁用“自动真空启动器”进程.)其余的每个进程都是一个处理一个 Client 端连接的服务器进程。每个这样的过程都以以下形式设置其命令行显示
postgres: user database host activity
在 Client 端连接的生命周期内,用户,数据库和(Client 端)主机项保持不变,但活动指示器会更改。活动可以是idle
(即 awaitClient 端命令),idle in transaction
(正在BEGIN
块内 awaitClient 端)或命令类型名称,例如SELECT
。另外,如果服务器进程当前正在 await 另一个会话持有的锁,则会附加waiting
。在以上示例中,我们可以推断出进程 15606 正在 await 进程 15610 完成其事务并因此释放一些锁定。 (进程 15610 必须是阻止程序,因为没有其他活动的会话.在更复杂的情况下,有必要查看pg_locks系统视图以确定谁阻止了谁。)
如果已配置cluster_name,则群集名称也将显示在ps
输出中:
$ psql -c 'SHOW cluster_name'
cluster_name
--------------
server1
(1 row)
$ ps aux|grep server1
postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: server1: writer process
...
如果您已关闭update_process_title,则活动指示器不会更新;启动新流程时,流程标题仅设置一次。在某些平台上,这节省了可观的每命令开销。在其他方面则无关紧要。
Tip
Solaris 需要特殊处理。您必须使用/usr/ucb/ps
而不是/bin/ps
。您还必须使用两个w
标志,而不仅仅是一个。此外,原始的postgres
命令调用必须比每个服务器进程提供的ps
状态显示短。如果您无法完成所有三件事,则每个服务器进程的ps
输出将是原始的postgres
命令行。