2 F.31. pgrowlocks — show a table's row locking information #
8 The pgrowlocks module provides a function to show row locking
9 information for a specified table.
11 By default use is restricted to superusers, roles with privileges of
12 the pg_stat_scan_tables role, and users with SELECT permissions on the
17 pgrowlocks(text) returns setof record
19 The parameter is the name of a table. The result is a set of records,
20 with one row for each locked row within the table. The output columns
21 are shown in Table F.21.
23 Table F.21. pgrowlocks Output Columns
25 locked_row tid Tuple ID (TID) of locked row
26 locker xid Transaction ID of locker, or multixact ID if
27 multitransaction; see Section 67.1
28 multi boolean True if locker is a multitransaction
29 xids xid[] Transaction IDs of lockers (more than one if
31 modes text[] Lock mode of lockers (more than one if multitransaction),
32 an array of For Key Share, For Share, For No Key Update, No Key Update,
34 pids integer[] Process IDs of locking backends (more than one if
37 pgrowlocks takes AccessShareLock for the target table and reads each
38 row one by one to collect the row locking information. This is not very
39 speedy for a large table. Note that:
40 1. If an ACCESS EXCLUSIVE lock is taken on the table, pgrowlocks will
42 2. pgrowlocks is not guaranteed to produce a self-consistent snapshot.
43 It is possible that a new row lock is taken, or an old lock is
44 freed, during its execution.
46 pgrowlocks does not show the contents of locked rows. If you want to
47 take a look at the row contents at the same time, you could do
49 SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
50 WHERE p.locked_row = a.ctid;
52 Be aware however that such a query will be very inefficient.
54 F.31.2. Sample Output #
56 =# SELECT * FROM pgrowlocks('t1');
57 locked_row | locker | multi | xids | modes | pids
58 ------------+--------+-------+-------+----------------+--------
59 (0,1) | 609 | f | {609} | {"For Share"} | {3161}
60 (0,2) | 609 | f | {609} | {"For Share"} | {3161}
61 (0,3) | 607 | f | {607} | {"For Update"} | {3107}
62 (0,4) | 607 | f | {607} | {"For Update"} | {3107}