1 <!-- doc/src/sgml/pgrowlocks.sgml -->
3 <sect1 id=
"pgrowlocks" xreflabel=
"pgrowlocks">
4 <title>pgrowlocks
— show a table's row locking information
</title>
6 <indexterm zone=
"pgrowlocks">
7 <primary>pgrowlocks
</primary>
11 The
<filename>pgrowlocks
</filename> module provides a function to show row
12 locking information for a specified table.
16 By default use is restricted to superusers, roles with privileges of the
17 <literal>pg_stat_scan_tables
</literal> role, and users with
18 <literal>SELECT
</literal> permissions on the table.
22 <sect2 id=
"pgrowlocks-overview">
23 <title>Overview
</title>
26 <primary>pgrowlocks
</primary>
30 pgrowlocks(text) returns setof record
34 The parameter is the name of a table. The result is a set of records,
35 with one row for each locked row within the table. The output columns
36 are shown in
<xref linkend=
"pgrowlocks-columns"/>.
39 <table id=
"pgrowlocks-columns">
40 <title><function>pgrowlocks
</function> Output Columns
</title>
47 <entry>Description
</entry>
53 <entry><structfield>locked_row
</structfield></entry>
54 <entry><type>tid
</type></entry>
55 <entry>Tuple ID (TID) of locked row
</entry>
58 <entry><structfield>locker
</structfield></entry>
59 <entry><type>xid
</type></entry>
60 <entry>Transaction ID of locker, or multixact ID if
61 multitransaction; see
<xref linkend=
"transaction-id"/></entry>
64 <entry><structfield>multi
</structfield></entry>
65 <entry><type>boolean
</type></entry>
66 <entry>True if locker is a multitransaction
</entry>
69 <entry><structfield>xids
</structfield></entry>
70 <entry><type>xid[]
</type></entry>
71 <entry>Transaction IDs of lockers (more than one if multitransaction)
</entry>
74 <entry><structfield>modes
</structfield></entry>
75 <entry><type>text[]
</type></entry>
76 <entry>Lock mode of lockers (more than one if multitransaction),
77 an array of
<literal>For Key Share
</literal>,
<literal>For Share
</literal>,
78 <literal>For No Key Update
</literal>,
<literal>No Key Update
</literal>,
79 <literal>For Update
</literal>,
<literal>Update
</literal>.
</entry>
83 <entry><structfield>pids
</structfield></entry>
84 <entry><type>integer[]
</type></entry>
85 <entry>Process IDs of locking backends (more than one if multitransaction)
</entry>
93 <function>pgrowlocks
</function> takes
<literal>AccessShareLock
</literal> for the
94 target table and reads each row one by one to collect the row locking
95 information. This is not very speedy for a large table. Note that:
101 If an
<literal>ACCESS EXCLUSIVE
</literal> lock is taken on the table,
102 <function>pgrowlocks
</function> will be blocked.
107 <function>pgrowlocks
</function> is not guaranteed to produce a
108 self-consistent snapshot. It is possible that a new row lock is taken,
109 or an old lock is freed, during its execution.
115 <function>pgrowlocks
</function> does not show the contents of locked
116 rows. If you want to take a look at the row contents at the same time, you
117 could do something like this:
120 SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
121 WHERE p.locked_row = a.ctid;
124 Be aware however that such a query will be very inefficient.
128 <sect2 id=
"pgrowlocks-sample-output">
129 <title>Sample Output
</title>
132 =# SELECT * FROM pgrowlocks('t1');
133 locked_row | locker | multi | xids | modes | pids
134 ------------+--------+-------+-------+----------------+--------
135 (
0,
1) |
609 | f | {
609} | {
"For Share"} | {
3161}
136 (
0,
2) |
609 | f | {
609} | {
"For Share"} | {
3161}
137 (
0,
3) |
607 | f | {
607} | {
"For Update"} | {
3107}
138 (
0,
4) |
607 | f | {
607} | {
"For Update"} | {
3107}
143 <sect2 id=
"pgrowlocks-author">
144 <title>Author
</title>