11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/monitoring.sgml,v 1.12 2002/08/20 04:47:52 momjian Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/monitoring.sgml,v 1.13 2002/08/31 17:14:27 tgl Exp $
33-->
44
55<chapter id="monitoring">
@@ -593,22 +593,25 @@ FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS S;
593593
594594 <note>
595595<para>
596- When the <literal>pg_locks</literal> view is accessed,an
597- exclusive lock on an internal lock manager datastructure must be
598- acquired to ensure that thedata produced by the view is
599- consistent. The lock held on this structure conflicts with normal
600- database operations, and can therefore have an effect on overall
601- database performance. Nevertheless, the performanceimpact of
602- accessing this view should be minimal in most situations .
596+ When the <literal>pg_locks</literal> view is accessed,the
597+ internal lock manager datastructures are momentarily locked,
598+ and a copy is made for theview to display. This ensures that
599+ the view produces a consistent set of results, while not blocking
600+ normal lock manager operations longer than necessary. Nonetheless
601+ there could be some impact on database performanceif this view is
602+ examined often .
603603</para>
604604 </note>
605605
606606 <para>
607- The <literal>pg_locks</literal> view contains one row per
608- lock. This means that if there are multiple locks on a single
609- relation (which may or may not conflict with one another), a
610- single relation may show up many times. Furthermore, only
611- table-level locks are displayed (not row-level ones).
607+ The <literal>pg_locks</literal> view contains one row per lockable
608+ object and requested lock mode. Thus, the same lockable object
609+ may appear many times, if multiple transactions are holding or
610+ waiting for locks on it. A lockable object is either a relation
611+ or a transaction ID. (Note that this view includes only table-level
612+ locks, not row-level ones. If a transaction is waiting for a
613+ row-level lock, it will appear in the view as waiting for the
614+ transaction ID of the current holder of that row lock.)
612615 </para>
613616
614617 <table>
@@ -627,53 +630,74 @@ FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS S;
627630 <row>
628631 <entry><structfield>relation</structfield></entry>
629632 <entry><type>oid</type></entry>
630- <entry>The OID of the locked relation. When querying
631- <literal>pg_locks</literal>, this column can be joined with the
632- <literal>pg_class</literal> system catalog to get more
633- information on the locked relation.</entry>
633+ <entry>The OID of the locked relation, or NULL if the lockable
634+ object is a transaction ID. This column can be joined
635+ with the <literal>pg_class</literal> system catalog to get more
636+ information on the locked relation. Note however that this will
637+ only work for relations in the current database (those for which
638+ the <structfield>database</structfield> column is either the
639+ current database's OID or zero).
640+ </entry>
634641 </row>
635642
636643 <row>
637644 <entry><structfield>database</structfield></entry>
638645 <entry><type>oid</type></entry>
639646 <entry>The OID of the database in which the locked relation
640- exists. If the lock is on a globally-shared object, this value
641- will be 0. When querying <literal>pg_locks</literal>, this
642- column can be joined with the <literal>pg_database</literal>
643- system catalog to get more information on the locked object's
644- database.</entry>
647+ exists, or NULL if the lockable object is a transaction ID.
648+ If the lock is on a globally-shared table, this field will be
649+ zero. This
650+ column can be joined with the <literal>pg_database</literal>
651+ system catalog to get more information on the locked object's
652+ database.
653+ </entry>
645654 </row>
646655
647656 <row>
648- <entry><structfield>backendpid</structfield></entry>
657+ <entry><structfield>transaction</structfield></entry>
658+ <entry><type>xid</type></entry>
659+ <entry>The ID of a transaction, or NULL if the lockable object
660+ is a relation. Every transaction holds ExclusiveLock on its
661+ transaction ID for its entire duration. If one transaction finds
662+ it necessary to wait specifically for another transaction, it
663+ does so by attempting to acquire ShareLock on the other transaction
664+ ID. That will succeed only when the other transaction terminates
665+ and releases its locks.
666+ </entry>
667+ </row>
668+
669+ <row>
670+ <entry><structfield>pid</structfield></entry>
649671 <entry><type>int4</type></entry>
650672 <entry>The process ID of the
651673<productname>PostgreSQL</productname> backend that has
652674acquired or is attempting to acquire the lock. If you have
653675enabled the statistics collector, this column can be joined
654- with the <literal>pg_stat_activity</literal> view toaccess
676+ with the <literal>pg_stat_activity</literal> view toget
655677more information on the backend holding or waiting to hold the
656678lock.</entry>
657679 </row>
658680
659681 <row>
660682 <entry><structfield>mode</structfield></entry>
661683 <entry><type>text</type></entry>
662- <entry>The mode of the lock. For more information on the
684+ <entry>The mode of the requested or held lock on the lockable
685+ object. For more information on the
663686 different lock modes available in
664687 <productname>PostgreSQL</productname>, refer to the
665688 <citetitle>User's Guide</citetitle>.</entry>
666689 </row>
667690
668691 <row>
669692 <entry><structfield>isgranted</structfield></entry>
670- <entry><type>text</type></entry>
671- <entry>A boolean column indicating whether or not this
672- particular lock has been granted. If the lock has not been
673- granted, the backend atempting to acquire it will sleep until
674- the lock is released (or a deadlock situation is detected). A
675- single backend can be waiting to acquire at most one lock at
676- any given time.</entry>
693+ <entry><type>bool</type></entry>
694+ <entry>True if this lock has been granted (is held by this
695+ backend). False indicates that this backend is currently
696+ waiting to acquire this lock, which implies that some other
697+ backend is holding a conflicting lock mode on the same lockable
698+ object. This backend will sleep until the other lock is released
699+ (or a deadlock situation is detected). A single backend can be
700+ waiting to acquire at most one lock at a time.</entry>
677701 </row>
678702 </tbody>
679703</tgroup>