diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index ebde12dee87..14ab4264428 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -7711,16 +7711,27 @@
The pid column can be joined to the
- pid column of the
- pg_stat_activity view to get more
- information on the session holding or waiting to hold each lock.
+ pid column of the pg_stat_activity
+ view to get more
+ information on the session holding or waiting to hold each lock,
+ for example
+
+SELECT * FROM pg_locks pl LEFT JOIN pg_stat_activity psa
+ ON pl.pid = psa.pid;
+
Also, if you are using prepared transactions, the
- transaction> column can be joined to the
- transaction column of the
- pg_prepared_xacts view to get more
- information on prepared transactions that hold locks.
+ virtualtransaction> column can be joined to the
+ transaction column of the pg_prepared_xacts
+ view to get more information on prepared transactions that hold locks.
(A prepared transaction can never be waiting for a lock,
but it continues to hold the locks it acquired while running.)
+ For example:
+
+SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
+ ON pl.virtualtransaction = '-1/' || ppx.transaction;
+