Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
F.44. pgrowlocks — show a table's row locking information
Prev UpAppendix F. Additional Supplied Modules and Extensions Shipped inpostgrespro-std-17-contribHome Next

F.44. pgrowlocks — show a table's row locking information#

Thepgrowlocks module provides a function to show row locking information for a specified table.

By default use is restricted to superusers, roles with privileges of thepg_stat_scan_tables role, and users withSELECT permissions on the table.

F.44.1. Overview#

pgrowlocks(text) returns setof record

The parameter is the name of a table. The result is a set of records, with one row for each locked row within the table. The output columns are shown inTable F.25.

Table F.25. pgrowlocks Output Columns

NameTypeDescription
locked_rowtidTuple ID (TID) of locked row
lockerxidTransaction ID of locker, or multixact ID if multitransaction; seeSection 64.1
multibooleanTrue if locker is a multitransaction
xidsxid[]Transaction IDs of lockers (more than one if multitransaction)
modestext[]Lock mode of lockers (more than one if multitransaction), an array ofFor Key Share,For Share,For No Key Update,No Key Update,For Update,Update.
pidsinteger[]Process IDs of locking backends (more than one if multitransaction)

pgrowlocks takesAccessShareLock for the target table and reads each row one by one to collect the row locking information. This is not very speedy for a large table. Note that:

  1. If anACCESS EXCLUSIVE lock is taken on the table,pgrowlocks will be blocked.

  2. pgrowlocks is not guaranteed to produce a self-consistent snapshot. It is possible that a new row lock is taken, or an old lock is freed, during 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;

Be aware however that such a query will be very inefficient.

F.44.2. Sample Output#

=# SELECT * FROM pgrowlocks('t1'); locked_row | locker | multi | xids  |     modes      |  pids------------+--------+-------+-------+----------------+-------- (0,1)      |    609 | f     | {609} | {"For Share"}  | {3161} (0,2)      |    609 | f     | {609} | {"For Share"}  | {3161} (0,3)      |    607 | f     | {607} | {"For Update"} | {3107} (0,4)      |    607 | f     | {607} | {"For Update"} | {3107}(4 rows)

F.44.3. Author#

Tatsuo Ishii


Prev Up Next
F.43. pg_query_state — a facility to know the current state of query execution on working backend Home F.45. pg_stat_statements — track statistics of SQL planning and execution
pdfepub
Go to Postgres Pro Standard 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp