バージョンごとのドキュメント一覧

F.31. pgrowlocks — テーブルの行ロックの情報を示す #

<title>pgrowlocks &mdash; show a table's row locking information</title>

The <filename>pgrowlocks</filename> module provides a function to show row locking information for a specified table. pgrowlocksモジュールは、指定したテーブルにおける行ロックの情報を示す関数を提供します。

By default use is restricted to superusers, roles with privileges of the <literal>pg_stat_scan_tables</literal> role, and users with <literal>SELECT</literal> permissions on the table. デフォルトでは、使用は、スーパーユーザ、pg_stat_scan_tables権限を持つロール、そのテーブルのSELECT権限を持つユーザに限定されています。

F.31.1. 概要 #

<title>Overview</title>
pgrowlocks(text) returns setof record

The parameter is the name of a table. The result is a set of records, with one row for each locked row within the table. The output columns are shown in <xref linkend="pgrowlocks-columns"/>. パラメータはテーブルの名前です。 結果はレコードの集合となり、各レコードはテーブル内のロックされた1行を示します。 出力列は表 F.21の通りです。

表F.21 pgrowlocksの出力列

<title><function>pgrowlocks</function> Output Columns</title>
名前説明
locked_rowtidロックされた行のタプルID(TID)
lockerxidロックを獲得したトランザクションのトランザクションID、もしマルチトランザクションの場合はマルチトランザクションID。74.1を参照
multibooleanロックをマルチトランザクションが獲得していた場合は真
xidsxid[]ロックを獲得しているトランザクションのトランザクションID(マルチトランザクションの場合は複数)
modestext[]ロックを獲得しているトランザクションのロックモード(マルチトランザクションの場合は複数)。Key Share, ShareFor No Key UpdateNo Key UpdateFor UpdateUpdateの配列。
pidsinteger[]ロックを獲得しているバックエンドのプロセスID(マルチトランザクションの場合は複数)

<function>pgrowlocks</function> takes <literal>AccessShareLock</literal> for the target table and reads each row one by one to collect the row locking information. This is not very speedy for a large table. Note that: pgrowlocksは対象テーブルに対してAccessShareLockを獲得し、ロック情報の収集のために1行ずつ行を読み取ります。 これは大規模テーブルにおいては高速とは言えません。 以下に注意してください:

  1. If an <literal>ACCESS EXCLUSIVE</literal> lock is taken on the table, <function>pgrowlocks</function> will be blocked. テーブルでACCESS EXCLUSIVEロックが獲得されている場合、pgrowlocksはブロックされます。

  2. <function>pgrowlocks</function> is not guaranteed to produce a self-consistent snapshot. It is possible that a new row lock is taken, or an old lock is freed, during its execution. pgrowlocksでは、自己矛盾のないスナップショットを生成することは保証されません。 その実行中に、新しい行ロックが獲得されることも、古いロックが解放されることもあり得ます。

<function>pgrowlocks</function> does not show the contents of locked rows. If you want to take a look at the row contents at the same time, you could do something like this: pgrowlocksは、ロックされた行の内容は表示しません。 同時に行の内容を参照したい場合には、以下のようにして実現することができます:

SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
  WHERE p.locked_row = a.ctid;

Be aware however that such a query will be very inefficient. しかし、こうした問い合わせが非常に非効率であることに注意してください。

F.31.2. サンプル出力 #

<title>Sample Output</title>
=# SELECT * FROM pgrowlocks('t1');
 locked_row | locker | multi | xids  |     modes      |  pids
------------+--------+-------+-------+----------------+--------
 (0,1)      |    609 | f     | {609} | {"For Share"}  | {3161}
 (0,2)      |    609 | f     | {609} | {"For Share"}  | {3161}
 (0,3)      |    607 | f     | {607} | {"For Update"} | {3107}
 (0,4)      |    607 | f     | {607} | {"For Update"} | {3107}
(4 rows)

F.31.3. 作者 #

<title>Author</title>

Tatsuo Ishii