天天看點

PostgreSQL 10.1 手冊_部分 III. 伺服器管理_第 28 章 監控資料庫活動_28.1. 标準 Unix 工具

28.1. 标準 Unix 工具

在大部分 Unix 平台上,PostgreSQL會修改由

ps

報告的指令标題,這樣個體伺服器程序可以被辨別。一個顯示樣例是

$ 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 系統)。列在這裡的第一個程序是主伺服器程序。為它顯示的指令參數是當它被啟動時使用的那些。接下來的五個程序是由主程序自動啟動的背景工作者程序(如果你已經設定系統為不啟動統計收集器,“統計收集器”程序将不會出現;同樣“自動清理發動”程序也可以被禁用)。剩餘的每一個程序都是一個處理一個用戶端連接配接的伺服器程序。每個這種程序都會把它的指令行顯示設定為這種形式

postgres: user database host activity      

在該用戶端連接配接的生命期中,使用者、資料庫以及(用戶端)主機項保持不變,但是活動訓示器會改變。活動可以是

閑置

(即等待一個用戶端指令)、

在事務中閑置

(在一個

BEGIN

塊裡等待用戶端)或者一個指令類型名,例如

SELECT

。還有,如果伺服器程序正在等待一個其它會話持有的鎖, 

等待中

會被追加到上述資訊中。在上面的例子中,我們可以推斷:程序 15606 正在等待程序 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

,那麼活動訓示器将不會被更新,程序标題僅在新程序被啟動的時候設定一次。 在某些平台上這樣做可以為每個指令節省可觀的開銷,但在其它平台上卻不明顯。

提示

Solaris需要特别的處理。你必需使用

/usr/ucb/ps

而不是

/bin/ps

。 你還必需使用兩個

w

标志,而不是一個。另外,你對

postgres

指令的最初調用必須用一個比伺服器程序提供的短的

ps

狀态顯示。如果你沒有滿足全部三個要求,每個伺服器程序的

ps

輸出将是原始的

postgres

指令行。 command line.

本文轉自PostgreSQL中文社群,原文連結: