2 <sect1 id="pgrowlocks">
3 <title>pgrowlocks</title>
5 <indexterm zone="pgrowlocks">
6 <primary>pgrowlocks</primary>
10 The <literal>pgrowlocks</literal> module provides a function to show row
11 locking information for a specified table.
15 <title>Overview</title>
17 pgrowlocks(text) RETURNS pgrowlocks_type
20 The parameter is a name of table. And <literal>pgrowlocks_type</literal> is
24 CREATE TYPE pgrowlocks_type AS (
25 locked_row TID, -- row TID
26 lock_type TEXT, -- lock type
27 locker XID, -- locking XID
28 multi bool, -- multi XID?
29 xids xid[], -- multi XIDs
30 pids INTEGER[] -- locker's process id
35 <title>pgrowlocks_type</title>
39 <entry>locked_row</entry>
40 <entry>tuple ID(TID) of each locked rows</entry>
43 <entry>lock_type</entry>
44 <entry>"Shared" for shared lock, "Exclusive" for exclusive lock</entry>
48 <entry>transaction ID of locker (Note 1)</entry>
52 <entry>"t" if locker is a multi transaction, otherwise "f"</entry>
56 <entry>XIDs of lockers (Note 2)</entry>
60 <entry>process ids of locking backends</entry>
66 Note1: If the locker is multi transaction, it represents the multi ID.
69 Note2: If the locker is multi, multiple data are shown.
73 The calling sequence for <literal>pgrowlocks</literal> is as follows:
74 <literal>pgrowlocks</literal> grabs AccessShareLock for the target table and
75 reads each row one by one to get the row locking information. You should
81 if the table is exclusive locked by someone else,
82 <literal>pgrowlocks</literal> will be blocked.
87 <literal>pgrowlocks</literal> may show incorrect information if there's a
88 new lock or a lock is freeed while its execution.
93 <literal>pgrowlocks</literal> does not show the contents of locked rows. If
94 you want to take a look at the row contents at the same time, you could do
98 SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p WHERE p.locked_ row = a.ctid;
103 <title>Example</title>
105 <literal>pgrowlocks</literal> returns the following columns:
108 Here is a sample execution of pgrowlocks:
111 test=# SELECT * FROM pgrowlocks('t1');
112 locked_row | lock_type | locker | multi | xids | pids
113 ------------+-----------+--------+-------+-----------+---------------
114 (0,1) | Shared | 19 | t | {804,805} | {29066,29068}
115 (0,2) | Shared | 19 | t | {804,805} | {29066,29068}
116 (0,3) | Exclusive | 804 | f | {804} | {29066}
117 (0,4) | Exclusive | 804 | f | {804} | {29066}