PostgreSQL 8.3beta4 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Appendix F. Additional Supplied Modules | Fast Forward | Next |
The pgrowlocks module provides a function to show row locking information for a specified table.
pgrowlocks(text) RETURNS pgrowlocks_type
The parameter is a name of table. And pgrowlocks_type is defined as:
CREATE TYPE pgrowlocks_type AS ( locked_row TID, -- row TID lock_type TEXT, -- lock type locker XID, -- locking XID multi bool, -- multi XID? xids xid[], -- multi XIDs pids INTEGER[] -- locker's process id );
Table F-17. pgrowlocks_type
locked_row | tuple ID(TID) of each locked rows |
lock_type | "Shared" for shared lock, "Exclusive" for exclusive lock |
locker | transaction ID of locker (Note 1) |
multi | "t" if locker is a multi transaction, otherwise "f" |
xids | XIDs of lockers (Note 2) |
pids | process ids of locking backends |
Note1: If the locker is multi transaction, it represents the multi ID.
Note2: If the locker is multi, multiple data are shown.
The calling sequence for pgrowlocks is as follows: pgrowlocks grabs AccessShareLock for the target table and reads each row one by one to get the row locking information. You should notice that:
if the table is exclusive locked by someone else, pgrowlocks will be blocked.
pgrowlocks may show incorrect information if there's a new lock or a lock is freeed while its execution.
pgrowlocks 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:
SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p WHERE p.locked_ row = a.ctid;
pgrowlocks returns the following data type:
Here is a sample execution of pgrowlocks:
test=# SELECT * FROM pgrowlocks('t1'); locked_row | lock_type | locker | multi | xids | pids ------------+-----------+--------+-------+-----------+--------------- (0,1) | Shared | 19 | t | {804,805} | {29066,29068} (0,2) | Shared | 19 | t | {804,805} | {29066,29068} (0,3) | Exclusive | 804 | f | {804} | {29066} (0,4) | Exclusive | 804 | f | {804} | {29066} (4 rows)