]> begriffs open source - ai-pg/blob - full-docs/txt/pgrowlocks.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / pgrowlocks.txt
1
2 F.31. pgrowlocks — show a table's row locking information #
3
4    F.31.1. Overview
5    F.31.2. Sample Output
6    F.31.3. Author
7
8    The pgrowlocks module provides a function to show row locking
9    information for a specified table.
10
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
13    table.
14
15 F.31.1. Overview #
16
17 pgrowlocks(text) returns setof record
18
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.
22
23    Table F.21. pgrowlocks Output Columns
24    Name Type Description
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
30    multitransaction)
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,
33    For Update, Update.
34    pids integer[] Process IDs of locking backends (more than one if
35    multitransaction)
36
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
41        be blocked.
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.
45
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
48    something like this:
49 SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
50   WHERE p.locked_row = a.ctid;
51
52    Be aware however that such a query will be very inefficient.
53
54 F.31.2. Sample Output #
55
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}
63 (4 rows)
64
65 F.31.3. Author #
66
67    Tatsuo Ishii