Home Explore Blog CI



postgresql

20th chunk of `doc/src/sgml/system-views.sgml`
4f3c6c78fe28b056747b6dedff71afaab347de226a5628cf0000000100000fa0
 transaction that is holding or awaiting this lock
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>pid</structfield> <type>int4</type>
      </para>
      <para>
       Process ID of the server process holding or awaiting this
       lock, or null if the lock is held by a prepared transaction
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>mode</structfield> <type>text</type>
      </para>
      <para>
       Name of the lock mode held or desired by this process (see <xref linkend="locking-tables"/> and <xref linkend="xact-serializable"/>)
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>granted</structfield> <type>bool</type>
      </para>
      <para>
       True if lock is held, false if lock is awaited
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>fastpath</structfield> <type>bool</type>
      </para>
      <para>
       True if lock was taken via fast path, false if taken via main
       lock table
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>waitstart</structfield> <type>timestamptz</type>
      </para>
      <para>
       Time when the server process started waiting for this lock,
       or null if the lock is held.
       Note that this can be null for a very short period of time after
       the wait started even though <structfield>granted</structfield>
       is <literal>false</literal>.
      </para></entry>
     </row>
    </tbody>
   </tgroup>
  </table>

  <para>
   <structfield>granted</structfield> is true in a row representing a lock
   held by the indicated process.  False indicates that this process is
   currently waiting to acquire this lock, which implies that at least one
   other process is holding or waiting for a conflicting lock mode on the same
   lockable object.  The waiting process will sleep until the other lock is
   released (or a deadlock situation is detected).  A single process can be
   waiting to acquire at most one lock at a time.
  </para>

  <para>
   Throughout running a transaction, a server process holds an exclusive lock
   on the transaction's virtual transaction ID.  If a permanent ID is assigned
   to the transaction (which normally happens only if the transaction changes
   the state of the database), it also holds an exclusive lock on the
   transaction's permanent transaction ID until it ends.  When a process finds
   it necessary to wait specifically for another transaction to end, it does
   so by attempting to acquire share lock on the other transaction's ID
   (either virtual or permanent ID depending on the situation). That will
   succeed only when the other transaction terminates and releases its locks.
  </para>

  <para>
   Although tuples are a lockable type of object,
   information about row-level locks is stored on disk, not in memory,
   and therefore row-level locks normally do not appear in this view.
   If a process is waiting for a
   row-level lock, it will usually appear in the view as waiting for the
   permanent transaction ID of the current holder of that row lock.
  </para>

  <para>
   A speculative insertion lock consists of a transaction ID and a speculative
   insertion token. The speculative insertion token is displayed in the
   <structfield>objid</structfield> column.
  </para>

  <para>
   Advisory locks can be acquired on keys consisting of either a single
   <type>bigint</type> value or two integer values.
   A <type>bigint</type> key is displayed with its
   high-order half in the <structfield>classid</structfield> column, its low-order half
   in the <structfield>objid</structfield> column, and

Title: pg_locks View Details
Summary
The pg_locks view provides information about locks held by active processes, including the process ID, lock mode, and granted status. A lock is considered granted if the process is holding it, and not granted if it is waiting to acquire it. The view also includes columns for fastpath locks, wait start time, and speculative insertion locks. Additionally, it displays information about advisory locks, which can be acquired on keys consisting of a single bigint value or two integer values.