□postgreSQL ロック確認方法(実行中ジョブ確認)


下記の様なコマンドで、postgreSQLでLock中のオブジェクトが確認できます。
また、postgreSQLでは、各SQL操作はプロセスが分かれる為、そのコマンドから処理内容も
分かる場合があります。

psql iplocksdb -c "select b.relname, a.* from pg_locks a,pg_class b where a.relation=b.relfilenode order by a.pid;"


postgreSQL関連のプロセスを下記の様にして、表示します。

(実行コマンド等の処理状況)
[iplocks@del-vm146 iplocks]$ ps -aef | grep post | grep -v grep
iplocks  18556     1  0 17:14 pts/2    00:00:00 /usr/bin/postmaster -i
iplocks  18558 18556  0 17:14 pts/2    00:00:00 postgres: stats buffer process
iplocks  18559 18558  0 17:14 pts/2    00:00:00 postgres: stats collector process
iplocks  21209 18556 67 18:11 pts/2    00:01:27 postgres: iplocks iplocksdb [local] DELETE
※OSのプロセスID=21209にてdelete文実行中

次に、Locks確認用のコマンドを実行します。

(ポストグレス内でのロック状況)
[iplocks@del-vm146 iplocks]$ psql iplocksdb -c "select b.relname, a.* from pg_locks a LEFT OUTER JOIN pg_class b ON a.relation=b.relfilenode order by a.pid;"
   relname    | relation | database | transaction |  pid  |       mode      | granted
--------------+----------+----------+-------------+-------+------------------+---------
 alarms       |   902497 |   902367 |             | 21209 |AccessShareLock  | t      <- delet処理の為のロック
 alarms       |   902497 |   902367 |             | 21209 |RowExclusiveLock | t        <- delet処理の為のロック
 alertmsgs    |   902502 |   902367 |             | 21209 |AccessShareLock  | t        <- delet処理の為のロック
 alertmsgs    |   902502 |   902367 |             | 21209 |RowExclusiveLock | t        <- delet処理の為のロック
 ubmdrilldown |   902668 |   902367 |             | 21209 |AccessShareLock  | t        <- delet処理の為のロック
 ubmdrilldown |   902668 |   902367 |             | 21209 |RowExclusiveLock | t        <- delet処理の為のロック
 pg_class     |     1259 |   902367 |             | 21252 |AccessShareLock  | t
 pg_locks     |    16757 |   902367 |             | 21252 |AccessShareLock  | t
(8 rows)※pid項目からOSプロセスIDとの比較から、どの処理がロックを使用して
いるか分かります。
最終更新:2006年09月12日 18:28