]> granicus.if.org Git - postgresql/blob - doc/src/sgml/monitoring.sgml
doc: Add security information about pg_stat_activity
[postgresql] / doc / src / sgml / monitoring.sgml
1 <!-- doc/src/sgml/monitoring.sgml -->
2
3 <chapter id="monitoring">
4  <title>Monitoring Database Activity</title>
5
6  <indexterm zone="monitoring">
7   <primary>monitoring</primary>
8   <secondary>database activity</secondary>
9  </indexterm>
10
11  <indexterm zone="monitoring">
12   <primary>database activity</primary>
13   <secondary>monitoring</secondary>
14  </indexterm>
15
16  <para>
17   A database administrator frequently wonders, <quote>What is the system
18   doing right now?</quote>
19   This chapter discusses how to find that out.
20  </para>
21
22   <para>
23    Several tools are available for monitoring database activity and
24    analyzing performance.  Most of this chapter is devoted to describing
25    <productname>PostgreSQL</productname>'s statistics collector,
26    but one should not neglect regular Unix monitoring programs such as
27    <command>ps</command>, <command>top</command>, <command>iostat</command>, and <command>vmstat</command>.
28    Also, once one has identified a
29    poorly-performing query, further investigation might be needed using
30    <productname>PostgreSQL</productname>'s <xref linkend="sql-explain"/> command.
31    <xref linkend="using-explain"/> discusses <command>EXPLAIN</command>
32    and other methods for understanding the behavior of an individual
33    query.
34   </para>
35
36  <sect1 id="monitoring-ps">
37   <title>Standard Unix Tools</title>
38
39   <indexterm zone="monitoring-ps">
40    <primary>ps</primary>
41    <secondary>to monitor activity</secondary>
42   </indexterm>
43
44   <para>
45    On most Unix platforms, <productname>PostgreSQL</productname> modifies its
46    command title as reported by <command>ps</command>, so that individual server
47    processes can readily be identified.  A sample display is
48
49 <screen>
50 $ ps auxww | grep ^postgres
51 postgres  15551  0.0  0.1  57536  7132 pts/0    S    18:02   0:00 postgres -i
52 postgres  15554  0.0  0.0  57536  1184 ?        Ss   18:02   0:00 postgres: background writer
53 postgres  15555  0.0  0.0  57536   916 ?        Ss   18:02   0:00 postgres: checkpointer
54 postgres  15556  0.0  0.0  57536   916 ?        Ss   18:02   0:00 postgres: walwriter
55 postgres  15557  0.0  0.0  58504  2244 ?        Ss   18:02   0:00 postgres: autovacuum launcher
56 postgres  15558  0.0  0.0  17512  1068 ?        Ss   18:02   0:00 postgres: stats collector
57 postgres  15582  0.0  0.0  58772  3080 ?        Ss   18:04   0:00 postgres: joe runbug 127.0.0.1 idle
58 postgres  15606  0.0  0.0  58772  3052 ?        Ss   18:07   0:00 postgres: tgl regression [local] SELECT waiting
59 postgres  15610  0.0  0.0  58772  3056 ?        Ss   18:07   0:00 postgres: tgl regression [local] idle in transaction
60 </screen>
61
62    (The appropriate invocation of <command>ps</command> varies across different
63    platforms, as do the details of what is shown.  This example is from a
64    recent Linux system.)  The first process listed here is the
65    master server process.  The command arguments
66    shown for it are the same ones used when it was launched.  The next five
67    processes are background worker processes automatically launched by the
68    master process.  (The <quote>stats collector</quote> process will not be present
69    if you have set the system not to start the statistics collector; likewise
70    the <quote>autovacuum launcher</quote> process can be disabled.)
71    Each of the remaining
72    processes is a server process handling one client connection.  Each such
73    process sets its command line display in the form
74
75 <screen>
76 postgres: <replaceable>user</replaceable> <replaceable>database</replaceable> <replaceable>host</replaceable> <replaceable>activity</replaceable>
77 </screen>
78
79   The user, database, and (client) host items remain the same for
80   the life of the client connection, but the activity indicator changes.
81   The activity can be <literal>idle</literal> (i.e., waiting for a client command),
82   <literal>idle in transaction</literal> (waiting for client inside a <command>BEGIN</command> block),
83   or a command type name such as <literal>SELECT</literal>.  Also,
84   <literal>waiting</literal> is appended if the server process is presently waiting
85   on a lock held by another session.  In the above example we can infer
86   that process 15606 is waiting for process 15610 to complete its transaction
87   and thereby release some lock.  (Process 15610 must be the blocker, because
88   there is no other active session.  In more complicated cases it would be
89   necessary to look into the
90   <link linkend="view-pg-locks"><structname>pg_locks</structname></link>
91   system view to determine who is blocking whom.)
92   </para>
93
94   <para>
95    If <xref linkend="guc-cluster-name"/> has been configured the
96    cluster name will also be shown in <command>ps</command> output:
97 <screen>
98 $ psql -c 'SHOW cluster_name'
99  cluster_name
100 --------------
101  server1
102 (1 row)
103
104 $ ps aux|grep server1
105 postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: server1: background writer
106 ...
107 </screen>
108   </para>
109
110   <para>
111    If you have turned off <xref linkend="guc-update-process-title"/> then the
112    activity indicator is not updated; the process title is set only once
113    when a new process is launched.  On some platforms this saves a measurable
114    amount of per-command overhead;  on others it's insignificant.
115   </para>
116
117   <tip>
118   <para>
119   <productname>Solaris</productname> requires special handling. You must
120   use <command>/usr/ucb/ps</command>, rather than
121   <command>/bin/ps</command>. You also must use two <option>w</option>
122   flags, not just one. In addition, your original invocation of the
123   <command>postgres</command> command must have a shorter
124   <command>ps</command> status display than that provided by each
125   server process.  If you fail to do all three things, the <command>ps</command>
126   output for each server process will be the original <command>postgres</command>
127   command line.
128   </para>
129   </tip>
130  </sect1>
131
132  <sect1 id="monitoring-stats">
133   <title>The Statistics Collector</title>
134
135   <indexterm zone="monitoring-stats">
136    <primary>statistics</primary>
137   </indexterm>
138
139   <para>
140    <productname>PostgreSQL</productname>'s <firstterm>statistics collector</firstterm>
141    is a subsystem that supports collection and reporting of information about
142    server activity.  Presently, the collector can count accesses to tables
143    and indexes in both disk-block and individual-row terms.  It also tracks
144    the total number of rows in each table, and information about vacuum and
145    analyze actions for each table.  It can also count calls to user-defined
146    functions and the total time spent in each one.
147   </para>
148
149   <para>
150    <productname>PostgreSQL</productname> also supports reporting dynamic
151    information about exactly what is going on in the system right now, such as
152    the exact command currently being executed by other server processes, and
153    which other connections exist in the system.  This facility is independent
154    of the collector process.
155   </para>
156
157  <sect2 id="monitoring-stats-setup">
158   <title>Statistics Collection Configuration</title>
159
160   <para>
161    Since collection of statistics adds some overhead to query execution,
162    the system can be configured to collect or not collect information.
163    This is controlled by configuration parameters that are normally set in
164    <filename>postgresql.conf</filename>.  (See <xref linkend="runtime-config"/> for
165    details about setting configuration parameters.)
166   </para>
167
168   <para>
169    The parameter <xref linkend="guc-track-activities"/> enables monitoring
170    of the current command being executed by any server process.
171   </para>
172
173   <para>
174    The parameter <xref linkend="guc-track-counts"/> controls whether
175    statistics are collected about table and index accesses.
176   </para>
177
178   <para>
179    The parameter <xref linkend="guc-track-functions"/> enables tracking of
180    usage of user-defined functions.
181   </para>
182
183   <para>
184    The parameter <xref linkend="guc-track-io-timing"/> enables monitoring
185    of block read and write times.
186   </para>
187
188   <para>
189    Normally these parameters are set in <filename>postgresql.conf</filename> so
190    that they apply to all server processes, but it is possible to turn
191    them on or off in individual sessions using the <xref
192    linkend="sql-set"/> command. (To prevent
193    ordinary users from hiding their activity from the administrator,
194    only superusers are allowed to change these parameters with
195    <command>SET</command>.)
196   </para>
197
198   <para>
199    The statistics collector transmits the collected information to other
200    <productname>PostgreSQL</productname> processes through temporary files.
201    These files are stored in the directory named by the
202    <xref linkend="guc-stats-temp-directory"/> parameter,
203    <filename>pg_stat_tmp</filename> by default.
204    For better performance, <varname>stats_temp_directory</varname> can be
205    pointed at a RAM-based file system, decreasing physical I/O requirements.
206    When the server shuts down cleanly, a permanent copy of the statistics
207    data is stored in the <filename>pg_stat</filename> subdirectory, so that
208    statistics can be retained across server restarts.  When recovery is
209    performed at server start (e.g. after immediate shutdown, server crash,
210    and point-in-time recovery), all statistics counters are reset.
211   </para>
212
213  </sect2>
214
215  <sect2 id="monitoring-stats-views">
216   <title>Viewing Statistics</title>
217
218   <para>
219    Several predefined views, listed in <xref
220    linkend="monitoring-stats-dynamic-views-table"/>, are available to show
221    the current state of the system. There are also several other
222    views, listed in <xref
223    linkend="monitoring-stats-views-table"/>, available to show the results
224    of statistics collection.  Alternatively, one can
225    build custom views using the underlying statistics functions, as discussed
226    in <xref linkend="monitoring-stats-functions"/>.
227   </para>
228
229   <para>
230    When using the statistics to monitor collected data, it is important
231    to realize that the information does not update instantaneously.
232    Each individual server process transmits new statistical counts to
233    the collector just before going idle; so a query or transaction still in
234    progress does not affect the displayed totals.  Also, the collector itself
235    emits a new report at most once per <varname>PGSTAT_STAT_INTERVAL</varname>
236    milliseconds (500 ms unless altered while building the server).  So the
237    displayed information lags behind actual activity.  However, current-query
238    information collected by <varname>track_activities</varname> is
239    always up-to-date.
240   </para>
241
242   <para>
243    Another important point is that when a server process is asked to display
244    any of these statistics, it first fetches the most recent report emitted by
245    the collector process and then continues to use this snapshot for all
246    statistical views and functions until the end of its current transaction.
247    So the statistics will show static information as long as you continue the
248    current transaction.  Similarly, information about the current queries of
249    all sessions is collected when any such information is first requested
250    within a transaction, and the same information will be displayed throughout
251    the transaction.
252    This is a feature, not a bug, because it allows you to perform several
253    queries on the statistics and correlate the results without worrying that
254    the numbers are changing underneath you.  But if you want to see new
255    results with each query, be sure to do the queries outside any transaction
256    block.  Alternatively, you can invoke
257    <function>pg_stat_clear_snapshot</function>(), which will discard the
258    current transaction's statistics snapshot (if any).  The next use of
259    statistical information will cause a new snapshot to be fetched.
260   </para>
261
262   <para>
263    A transaction can also see its own statistics (as yet untransmitted to the
264    collector) in the views <structname>pg_stat_xact_all_tables</structname>,
265    <structname>pg_stat_xact_sys_tables</structname>,
266    <structname>pg_stat_xact_user_tables</structname>, and
267    <structname>pg_stat_xact_user_functions</structname>.  These numbers do not act as
268    stated above; instead they update continuously throughout the transaction.
269   </para>
270
271   <para>
272    Some of the information in the dynamic statistics views shown in <xref
273    linkend="monitoring-stats-dynamic-views-table"/> is security restricted.
274    Ordinary users can only see all the information about their own sessions
275    (sessions belonging to a role that they are a member of).  In rows about
276    other sessions, many columns will be null.  Note, however, that the
277    existence of a session and its general properties such as its sessions user
278    and database are visible to all users.  Superusers and members of the
279    built-in role <literal>pg_read_all_stats</literal> (see also <xref
280    linkend="default-roles"/>) can see all the information about all sessions.
281   </para>
282
283   <table id="monitoring-stats-dynamic-views-table">
284    <title>Dynamic Statistics Views</title>
285
286    <tgroup cols="2">
287     <thead>
288      <row>
289       <entry>View Name</entry>
290       <entry>Description</entry>
291      </row>
292     </thead>
293
294     <tbody>
295      <row>
296       <entry>
297        <structname>pg_stat_activity</structname>
298        <indexterm><primary>pg_stat_activity</primary></indexterm>
299       </entry>
300       <entry>
301        One row per server process, showing information related to
302        the current activity of that process, such as state and current query.
303        See <xref linkend="pg-stat-activity-view"/> for details.
304       </entry>
305      </row>
306
307      <row>
308       <entry><structname>pg_stat_replication</structname><indexterm><primary>pg_stat_replication</primary></indexterm></entry>
309       <entry>One row per WAL sender process, showing statistics about
310        replication to that sender's connected standby server.
311        See <xref linkend="pg-stat-replication-view"/> for details.
312       </entry>
313      </row>
314
315      <row>
316       <entry><structname>pg_stat_wal_receiver</structname><indexterm><primary>pg_stat_wal_receiver</primary></indexterm></entry>
317       <entry>Only one row, showing statistics about the WAL receiver from
318        that receiver's connected server.
319        See <xref linkend="pg-stat-wal-receiver-view"/> for details.
320       </entry>
321      </row>
322
323      <row>
324       <entry><structname>pg_stat_subscription</structname><indexterm><primary>pg_stat_subscription</primary></indexterm></entry>
325       <entry>At least one row per subscription, showing information about
326        the subscription workers.
327        See <xref linkend="pg-stat-subscription"/> for details.
328       </entry>
329      </row>
330
331      <row>
332       <entry><structname>pg_stat_ssl</structname><indexterm><primary>pg_stat_ssl</primary></indexterm></entry>
333       <entry>One row per connection (regular and replication), showing information about
334        SSL used on this connection.
335        See <xref linkend="pg-stat-ssl-view"/> for details.
336       </entry>
337      </row>
338
339      <row>
340       <entry><structname>pg_stat_progress_vacuum</structname><indexterm><primary>pg_stat_progress_vacuum</primary></indexterm></entry>
341       <entry>One row for each backend (including autovacuum worker processes) running
342        <command>VACUUM</command>, showing current progress.
343        See <xref linkend='vacuum-progress-reporting'/>.
344       </entry>
345      </row>
346
347     </tbody>
348    </tgroup>
349   </table>
350
351   <table id="monitoring-stats-views-table">
352    <title>Collected Statistics Views</title>
353
354    <tgroup cols="2">
355     <thead>
356      <row>
357       <entry>View Name</entry>
358       <entry>Description</entry>
359      </row>
360     </thead>
361
362     <tbody>
363      <row>
364       <entry><structname>pg_stat_archiver</structname><indexterm><primary>pg_stat_archiver</primary></indexterm></entry>
365       <entry>One row only, showing statistics about the
366        WAL archiver process's activity. See
367        <xref linkend="pg-stat-archiver-view"/> for details.
368       </entry>
369      </row>
370
371      <row>
372       <entry><structname>pg_stat_bgwriter</structname><indexterm><primary>pg_stat_bgwriter</primary></indexterm></entry>
373       <entry>One row only, showing statistics about the
374        background writer process's activity. See
375        <xref linkend="pg-stat-bgwriter-view"/> for details.
376      </entry>
377      </row>
378
379      <row>
380       <entry><structname>pg_stat_database</structname><indexterm><primary>pg_stat_database</primary></indexterm></entry>
381       <entry>One row per database, showing database-wide statistics. See
382        <xref linkend="pg-stat-database-view"/> for details.
383       </entry>
384      </row>
385
386      <row>
387       <entry><structname>pg_stat_database_conflicts</structname><indexterm><primary>pg_stat_database_conflicts</primary></indexterm></entry>
388       <entry>
389        One row per database, showing database-wide statistics about
390        query cancels due to conflict with recovery on standby servers.
391        See <xref linkend="pg-stat-database-conflicts-view"/> for details.
392       </entry>
393      </row>
394
395      <row>
396       <entry><structname>pg_stat_all_tables</structname><indexterm><primary>pg_stat_all_tables</primary></indexterm></entry>
397       <entry>
398        One row for each table in the current database, showing statistics
399        about accesses to that specific table.
400        See <xref linkend="pg-stat-all-tables-view"/> for details.
401       </entry>
402      </row>
403
404      <row>
405       <entry><structname>pg_stat_sys_tables</structname><indexterm><primary>pg_stat_sys_tables</primary></indexterm></entry>
406       <entry>Same as <structname>pg_stat_all_tables</structname>, except that only
407       system tables are shown.</entry>
408      </row>
409
410      <row>
411       <entry><structname>pg_stat_user_tables</structname><indexterm><primary>pg_stat_user_tables</primary></indexterm></entry>
412       <entry>Same as <structname>pg_stat_all_tables</structname>, except that only user
413       tables are shown.</entry>
414      </row>
415
416      <row>
417       <entry><structname>pg_stat_xact_all_tables</structname><indexterm><primary>pg_stat_xact_all_tables</primary></indexterm></entry>
418       <entry>Similar to <structname>pg_stat_all_tables</structname>, but counts actions
419       taken so far within the current transaction (which are <emphasis>not</emphasis>
420       yet included in <structname>pg_stat_all_tables</structname> and related views).
421       The columns for numbers of live and dead rows and vacuum and
422       analyze actions are not present in this view.</entry>
423      </row>
424
425      <row>
426       <entry><structname>pg_stat_xact_sys_tables</structname><indexterm><primary>pg_stat_xact_sys_tables</primary></indexterm></entry>
427       <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
428       system tables are shown.</entry>
429      </row>
430
431      <row>
432       <entry><structname>pg_stat_xact_user_tables</structname><indexterm><primary>pg_stat_xact_user_tables</primary></indexterm></entry>
433       <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
434       user tables are shown.</entry>
435      </row>
436
437      <row>
438       <entry><structname>pg_stat_all_indexes</structname><indexterm><primary>pg_stat_all_indexes</primary></indexterm></entry>
439       <entry>
440        One row for each index in the current database, showing statistics
441        about accesses to that specific index.
442        See <xref linkend="pg-stat-all-indexes-view"/> for details.
443       </entry>
444      </row>
445
446      <row>
447       <entry><structname>pg_stat_sys_indexes</structname><indexterm><primary>pg_stat_sys_indexes</primary></indexterm></entry>
448       <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
449       indexes on system tables are shown.</entry>
450      </row>
451
452      <row>
453       <entry><structname>pg_stat_user_indexes</structname><indexterm><primary>pg_stat_user_indexes</primary></indexterm></entry>
454       <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
455       indexes on user tables are shown.</entry>
456      </row>
457
458      <row>
459       <entry><structname>pg_statio_all_tables</structname><indexterm><primary>pg_statio_all_tables</primary></indexterm></entry>
460       <entry>
461        One row for each table in the current database, showing statistics
462        about I/O on that specific table.
463        See <xref linkend="pg-statio-all-tables-view"/> for details.
464       </entry>
465      </row>
466
467      <row>
468       <entry><structname>pg_statio_sys_tables</structname><indexterm><primary>pg_statio_sys_tables</primary></indexterm></entry>
469       <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
470       system tables are shown.</entry>
471      </row>
472
473      <row>
474       <entry><structname>pg_statio_user_tables</structname><indexterm><primary>pg_statio_user_tables</primary></indexterm></entry>
475       <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
476       user tables are shown.</entry>
477      </row>
478
479      <row>
480       <entry><structname>pg_statio_all_indexes</structname><indexterm><primary>pg_statio_all_indexes</primary></indexterm></entry>
481       <entry>
482        One row for each index in the current database,
483        showing statistics about I/O on that specific index.
484        See <xref linkend="pg-statio-all-indexes-view"/> for details.
485       </entry>
486      </row>
487
488      <row>
489       <entry><structname>pg_statio_sys_indexes</structname><indexterm><primary>pg_statio_sys_indexes</primary></indexterm></entry>
490       <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
491       indexes on system tables are shown.</entry>
492      </row>
493
494      <row>
495       <entry><structname>pg_statio_user_indexes</structname><indexterm><primary>pg_statio_user_indexes</primary></indexterm></entry>
496       <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
497       indexes on user tables are shown.</entry>
498      </row>
499
500      <row>
501       <entry><structname>pg_statio_all_sequences</structname><indexterm><primary>pg_statio_all_sequences</primary></indexterm></entry>
502      <entry>
503        One row for each sequence in the current database,
504        showing statistics about I/O on that specific sequence.
505        See <xref linkend="pg-statio-all-sequences-view"/> for details.
506      </entry>
507      </row>
508
509      <row>
510       <entry><structname>pg_statio_sys_sequences</structname><indexterm><primary>pg_statio_sys_sequences</primary></indexterm></entry>
511       <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
512       system sequences are shown.  (Presently, no system sequences are defined,
513       so this view is always empty.)</entry>
514      </row>
515
516      <row>
517       <entry><structname>pg_statio_user_sequences</structname><indexterm><primary>pg_statio_user_sequences</primary></indexterm></entry>
518       <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
519       user sequences are shown.</entry>
520      </row>
521
522      <row>
523       <entry><structname>pg_stat_user_functions</structname><indexterm><primary>pg_stat_user_functions</primary></indexterm></entry>
524       <entry>
525        One row for each tracked function, showing statistics
526        about executions of that function. See
527        <xref linkend="pg-stat-user-functions-view"/> for details.
528       </entry>
529      </row>
530
531      <row>
532       <entry><structname>pg_stat_xact_user_functions</structname><indexterm><primary>pg_stat_xact_user_functions</primary></indexterm></entry>
533       <entry>Similar to <structname>pg_stat_user_functions</structname>, but counts only
534       calls during the current transaction (which are <emphasis>not</emphasis>
535       yet included in <structname>pg_stat_user_functions</structname>).</entry>
536      </row>
537
538     </tbody>
539    </tgroup>
540   </table>
541
542   <para>
543    The per-index statistics are particularly useful to determine which
544    indexes are being used and how effective they are.
545   </para>
546
547   <para>
548    The <structname>pg_statio_</structname> views are primarily useful to
549    determine the effectiveness of the buffer cache.  When the number
550    of actual disk reads is much smaller than the number of buffer
551    hits, then the cache is satisfying most read requests without
552    invoking a kernel call. However, these statistics do not give the
553    entire story: due to the way in which <productname>PostgreSQL</productname>
554    handles disk I/O, data that is not in the
555    <productname>PostgreSQL</productname> buffer cache might still reside in the
556    kernel's I/O cache, and might therefore still be fetched without
557    requiring a physical read. Users interested in obtaining more
558    detailed information on <productname>PostgreSQL</productname> I/O behavior are
559    advised to use the <productname>PostgreSQL</productname> statistics collector
560    in combination with operating system utilities that allow insight
561    into the kernel's handling of I/O.
562   </para>
563
564
565   <table id="pg-stat-activity-view" xreflabel="pg_stat_activity">
566    <title><structname>pg_stat_activity</structname> View</title>
567
568    <tgroup cols="3">
569     <thead>
570     <row>
571       <entry>Column</entry>
572       <entry>Type</entry>
573       <entry>Description</entry>
574      </row>
575     </thead>
576
577    <tbody>
578     <row>
579      <entry><structfield>datid</structfield></entry>
580      <entry><type>oid</type></entry>
581      <entry>OID of the database this backend is connected to</entry>
582     </row>
583     <row>
584      <entry><structfield>datname</structfield></entry>
585      <entry><type>name</type></entry>
586      <entry>Name of the database this backend is connected to</entry>
587     </row>
588     <row>
589      <entry><structfield>pid</structfield></entry>
590      <entry><type>integer</type></entry>
591      <entry>Process ID of this backend</entry>
592     </row>
593     <row>
594      <entry><structfield>usesysid</structfield></entry>
595      <entry><type>oid</type></entry>
596      <entry>OID of the user logged into this backend</entry>
597     </row>
598     <row>
599      <entry><structfield>usename</structfield></entry>
600      <entry><type>name</type></entry>
601      <entry>Name of the user logged into this backend</entry>
602     </row>
603     <row>
604      <entry><structfield>application_name</structfield></entry>
605      <entry><type>text</type></entry>
606      <entry>Name of the application that is connected
607       to this backend</entry>
608     </row>
609     <row>
610      <entry><structfield>client_addr</structfield></entry>
611      <entry><type>inet</type></entry>
612      <entry>IP address of the client connected to this backend.
613       If this field is null, it indicates either that the client is
614       connected via a Unix socket on the server machine or that this is an
615       internal process such as autovacuum.
616      </entry>
617     </row>
618     <row>
619      <entry><structfield>client_hostname</structfield></entry>
620      <entry><type>text</type></entry>
621      <entry>Host name of the connected client, as reported by a
622       reverse DNS lookup of <structfield>client_addr</structfield>. This field will
623       only be non-null for IP connections, and only when <xref
624       linkend="guc-log-hostname"/> is enabled.
625      </entry>
626     </row>
627     <row>
628      <entry><structfield>client_port</structfield></entry>
629      <entry><type>integer</type></entry>
630      <entry>TCP port number that the client is using for communication
631       with this backend, or <literal>-1</literal> if a Unix socket is used
632      </entry>
633     </row>
634     <row>
635      <entry><structfield>backend_start</structfield></entry>
636      <entry><type>timestamp with time zone</type></entry>
637      <entry>Time when this process was started.  For client backends,
638       this is the time the client connected to the server.
639      </entry>
640     </row>
641     <row>
642      <entry><structfield>xact_start</structfield></entry>
643      <entry><type>timestamp with time zone</type></entry>
644      <entry>Time when this process' current transaction was started, or null
645       if no transaction is active. If the current
646       query is the first of its transaction, this column is equal to the
647       <structfield>query_start</structfield> column.
648      </entry>
649     </row>
650     <row>
651      <entry><structfield>query_start</structfield></entry>
652      <entry><type>timestamp with time zone</type></entry>
653      <entry>Time when the currently active query was started, or if
654       <structfield>state</structfield> is not <literal>active</literal>, when the last query
655       was started
656      </entry>
657     </row>
658     <row>
659      <entry><structfield>state_change</structfield></entry>
660      <entry><type>timestamp with time zone</type></entry>
661      <entry>Time when the <structfield>state</structfield> was last changed</entry>
662     </row>
663      <row>
664       <entry><structfield>wait_event_type</structfield></entry>
665       <entry><type>text</type></entry>
666       <entry>The type of event for which the backend is waiting, if any;
667        otherwise NULL. Possible values are:
668        <itemizedlist>
669         <listitem>
670          <para>
671           <literal>LWLock</literal>: The backend is waiting for a lightweight lock.
672           Each such lock protects a particular data structure in shared memory.
673           <literal>wait_event</literal> will contain a name identifying the purpose
674           of the lightweight lock.  (Some locks have specific names; others
675           are part of a group of locks each with a similar purpose.)
676          </para>
677         </listitem>
678         <listitem>
679          <para>
680           <literal>Lock</literal>: The backend is waiting for a heavyweight lock.
681           Heavyweight locks, also known as lock manager locks or simply locks,
682           primarily protect SQL-visible objects such as tables.  However,
683           they are also used to ensure mutual exclusion for certain internal
684           operations such as relation extension.  <literal>wait_event</literal> will
685           identify the type of lock awaited.
686          </para>
687         </listitem>
688         <listitem>
689          <para>
690           <literal>BufferPin</literal>: The server process is waiting to access to
691           a data buffer during a period when no other process can be
692           examining that buffer.  Buffer pin waits can be protracted if
693           another process holds an open cursor which last read data from the
694           buffer in question.
695          </para>
696         </listitem>
697         <listitem>
698          <para>
699           <literal>Activity</literal>: The server process is idle.  This is used by
700           system processes waiting for activity in their main processing loop.
701           <literal>wait_event</literal> will identify the specific wait point.
702          </para>
703         </listitem>
704         <listitem>
705          <para>
706           <literal>Extension</literal>: The server process is waiting for activity
707           in an extension module.  This category is useful for modules to
708           track custom waiting points.
709          </para>
710         </listitem>
711         <listitem>
712          <para>
713           <literal>Client</literal>: The server process is waiting for some activity
714           on a socket from user applications, and that the server expects
715           something to happen that is independent from its internal processes.
716           <literal>wait_event</literal> will identify the specific wait point.
717          </para>
718         </listitem>
719         <listitem>
720          <para>
721           <literal>IPC</literal>: The server process is waiting for some activity
722           from another process in the server.  <literal>wait_event</literal> will
723           identify the specific wait point.
724          </para>
725         </listitem>
726         <listitem>
727          <para>
728           <literal>Timeout</literal>: The server process is waiting for a timeout
729           to expire.  <literal>wait_event</literal> will identify the specific wait
730           point.
731          </para>
732         </listitem>
733         <listitem>
734          <para>
735           <literal>IO</literal>: The server process is waiting for a IO to complete.
736           <literal>wait_event</literal> will identify the specific wait point.
737          </para>
738         </listitem>
739        </itemizedlist>
740       </entry>
741      </row>
742     <row>
743      <entry><structfield>wait_event</structfield></entry>
744      <entry><type>text</type></entry>
745      <entry>Wait event name if backend is currently waiting, otherwise NULL.
746      See <xref linkend="wait-event-table"/> for details.
747      </entry>
748     </row>
749     <row>
750      <entry><structfield>state</structfield></entry>
751      <entry><type>text</type></entry>
752      <entry>Current overall state of this backend.
753        Possible values are:
754        <itemizedlist>
755          <listitem>
756           <para>
757            <literal>active</literal>: The backend is executing a query.
758           </para>
759          </listitem>
760          <listitem>
761           <para>
762            <literal>idle</literal>: The backend is waiting for a new client command.
763           </para>
764          </listitem>
765          <listitem>
766           <para>
767            <literal>idle in transaction</literal>: The backend is in a transaction,
768            but is not currently executing a query.
769           </para>
770          </listitem>
771          <listitem>
772           <para>
773            <literal>idle in transaction (aborted)</literal>: This state is similar to
774            <literal>idle in transaction</literal>, except one of the statements in
775            the transaction caused an error.
776           </para>
777          </listitem>
778          <listitem>
779           <para>
780            <literal>fastpath function call</literal>: The backend is executing a
781            fast-path function.
782           </para>
783          </listitem>
784          <listitem>
785            <para>
786            <literal>disabled</literal>: This state is reported if <xref
787            linkend="guc-track-activities"/> is disabled in this backend.
788           </para>
789          </listitem>
790        </itemizedlist>
791      </entry>
792     </row>
793     <row>
794      <entry><structfield>backend_xid</structfield></entry>
795      <entry><type>xid</type></entry>
796      <entry>Top-level transaction identifier of this backend, if any.</entry>
797     </row>
798     <row>
799      <entry><structfield>backend_xmin</structfield></entry>
800      <entry><type>xid</type></entry>
801      <entry>The current backend's <literal>xmin</literal> horizon.</entry>
802     </row>
803     <row>
804      <entry><structfield>query</structfield></entry>
805      <entry><type>text</type></entry>
806      <entry>Text of this backend's most recent query. If
807       <structfield>state</structfield> is <literal>active</literal> this field shows the
808       currently executing query. In all other states, it shows the last query
809       that was executed. By default the query text is truncated at 1024
810       characters; this value can be changed via the parameter
811       <xref linkend="guc-track-activity-query-size"/>.
812      </entry>
813     </row>
814     <row>
815      <entry><structfield>backend_type</structfield></entry>
816      <entry><type>text</type></entry>
817      <entry>Type of current backend. Possible types are
818       <literal>autovacuum launcher</literal>, <literal>autovacuum worker</literal>,
819       <literal>logical replication launcher</literal>,
820       <literal>logical replication worker</literal>,
821       <literal>parallel worker</literal>, <literal>background writer</literal>,
822       <literal>client backend</literal>, <literal>checkpointer</literal>,
823       <literal>startup</literal>, <literal>walreceiver</literal>,
824       <literal>walsender</literal> and <literal>walwriter</literal>.
825       In addition, background workers registered by extensions may have
826       additional types.
827      </entry>
828     </row>
829    </tbody>
830    </tgroup>
831   </table>
832
833   <para>
834    The <structname>pg_stat_activity</structname> view will have one row
835    per server process, showing information related to
836    the current activity of that process.
837   </para>
838
839   <note>
840    <para>
841     The <structfield>wait_event</structfield> and <structfield>state</structfield> columns are
842     independent.  If a backend is in the <literal>active</literal> state,
843     it may or may not be <literal>waiting</literal> on some event.  If the state
844     is <literal>active</literal> and <structfield>wait_event</structfield> is non-null, it
845     means that a query is being executed, but is being blocked somewhere
846     in the system.
847    </para>
848   </note>
849
850   <table id="wait-event-table">
851    <title><structname>wait_event</structname> Description</title>
852
853     <tgroup cols="3">
854       <thead>
855        <row>
856         <entry>Wait Event Type</entry>
857         <entry>Wait Event Name</entry>
858         <entry>Description</entry>
859        </row>
860       </thead>
861
862       <tbody>
863        <row>
864         <entry morerows="63"><literal>LWLock</literal></entry>
865         <entry><literal>ShmemIndexLock</literal></entry>
866         <entry>Waiting to find or allocate space in shared memory.</entry>
867        </row>
868        <row>
869         <entry><literal>OidGenLock</literal></entry>
870         <entry>Waiting to allocate or assign an OID.</entry>
871        </row>
872         <row>
873          <entry><literal>XidGenLock</literal></entry>
874          <entry>Waiting to allocate or assign a transaction id.</entry>
875         </row>
876         <row>
877          <entry><literal>ProcArrayLock</literal></entry>
878          <entry>Waiting to get a snapshot or clearing a transaction id at
879          transaction end.</entry>
880         </row>
881         <row>
882          <entry><literal>SInvalReadLock</literal></entry>
883          <entry>Waiting to retrieve or remove messages from shared invalidation
884          queue.</entry>
885         </row>
886         <row>
887          <entry><literal>SInvalWriteLock</literal></entry>
888          <entry>Waiting to add a message in shared invalidation queue.</entry>
889         </row>
890         <row>
891          <entry><literal>WALBufMappingLock</literal></entry>
892          <entry>Waiting to replace a page in WAL buffers.</entry>
893         </row>
894         <row>
895          <entry><literal>WALWriteLock</literal></entry>
896          <entry>Waiting for WAL buffers to be written to disk.</entry>
897         </row>
898         <row>
899          <entry><literal>ControlFileLock</literal></entry>
900          <entry>Waiting to read or update the control file or creation of a
901          new WAL file.</entry>
902         </row>
903         <row>
904          <entry><literal>CheckpointLock</literal></entry>
905          <entry>Waiting to perform checkpoint.</entry>
906         </row>
907         <row>
908          <entry><literal>CLogControlLock</literal></entry>
909          <entry>Waiting to read or update transaction status.</entry>
910         </row>
911         <row>
912          <entry><literal>SubtransControlLock</literal></entry>
913          <entry>Waiting to read or update sub-transaction information.</entry>
914         </row>
915         <row>
916          <entry><literal>MultiXactGenLock</literal></entry>
917          <entry>Waiting to read or update shared multixact state.</entry>
918         </row>
919         <row>
920          <entry><literal>MultiXactOffsetControlLock</literal></entry>
921          <entry>Waiting to read or update multixact offset mappings.</entry>
922         </row>
923         <row>
924          <entry><literal>MultiXactMemberControlLock</literal></entry>
925          <entry>Waiting to read or update multixact member mappings.</entry>
926         </row>
927         <row>
928          <entry><literal>RelCacheInitLock</literal></entry>
929          <entry>Waiting to read or write relation cache initialization
930          file.</entry>
931         </row>
932         <row>
933          <entry><literal>CheckpointerCommLock</literal></entry>
934          <entry>Waiting to manage fsync requests.</entry>
935         </row>
936         <row>
937          <entry><literal>TwoPhaseStateLock</literal></entry>
938          <entry>Waiting to read or update the state of prepared transactions.</entry>
939         </row>
940         <row>
941          <entry><literal>TablespaceCreateLock</literal></entry>
942          <entry>Waiting to create or drop the tablespace.</entry>
943         </row>
944         <row>
945          <entry><literal>BtreeVacuumLock</literal></entry>
946           <entry>Waiting to read or update vacuum-related information for a
947           B-tree index.</entry>
948         </row>
949         <row>
950          <entry><literal>AddinShmemInitLock</literal></entry>
951          <entry>Waiting to manage space allocation in shared memory.</entry>
952         </row>
953         <row>
954          <entry><literal>AutovacuumLock</literal></entry>
955          <entry>Autovacuum worker or launcher waiting to update or
956          read the current state of autovacuum workers.</entry>
957         </row>
958         <row>
959          <entry><literal>AutovacuumScheduleLock</literal></entry>
960          <entry>Waiting to ensure that the table it has selected for a vacuum
961          still needs vacuuming.
962          </entry>
963         </row>
964         <row>
965          <entry><literal>SyncScanLock</literal></entry>
966          <entry>Waiting to get the start location of a scan on a table for
967          synchronized scans.</entry>
968         </row>
969         <row>
970          <entry><literal>RelationMappingLock</literal></entry>
971          <entry>Waiting to update the relation map file used to store catalog
972          to filenode mapping.
973          </entry>
974         </row>
975         <row>
976          <entry><literal>AsyncCtlLock</literal></entry>
977          <entry>Waiting to read or update shared notification state.</entry>
978         </row>
979         <row>
980          <entry><literal>AsyncQueueLock</literal></entry>
981           <entry>Waiting to read or update notification messages.</entry>
982         </row>
983         <row>
984          <entry><literal>SerializableXactHashLock</literal></entry>
985          <entry>Waiting to retrieve or store information about serializable
986          transactions.</entry>
987         </row>
988         <row>
989          <entry><literal>SerializableFinishedListLock</literal></entry>
990          <entry>Waiting to access the list of finished serializable
991          transactions.</entry>
992         </row>
993         <row>
994          <entry><literal>SerializablePredicateLockListLock</literal></entry>
995          <entry>Waiting to perform an operation on a list of locks held by
996          serializable transactions.</entry>
997         </row>
998         <row>
999          <entry><literal>OldSerXidLock</literal></entry>
1000          <entry>Waiting to read or record conflicting serializable
1001          transactions.</entry>
1002         </row>
1003         <row>
1004          <entry><literal>SyncRepLock</literal></entry>
1005          <entry>Waiting to read or update information about synchronous
1006          replicas.</entry>
1007         </row>
1008         <row>
1009          <entry><literal>BackgroundWorkerLock</literal></entry>
1010          <entry>Waiting to read or update background worker state.</entry>
1011         </row>
1012         <row>
1013          <entry><literal>DynamicSharedMemoryControlLock</literal></entry>
1014          <entry>Waiting to read or update dynamic shared memory state.</entry>
1015         </row>
1016         <row>
1017          <entry><literal>AutoFileLock</literal></entry>
1018          <entry>Waiting to update the <filename>postgresql.auto.conf</filename> file.</entry>
1019         </row>
1020         <row>
1021          <entry><literal>ReplicationSlotAllocationLock</literal></entry>
1022          <entry>Waiting to allocate or free a replication slot.</entry>
1023         </row>
1024         <row>
1025          <entry><literal>ReplicationSlotControlLock</literal></entry>
1026          <entry>Waiting to read or update replication slot state.</entry>
1027         </row>
1028         <row>
1029          <entry><literal>CommitTsControlLock</literal></entry>
1030          <entry>Waiting to read or update transaction commit timestamps.</entry>
1031         </row>
1032         <row>
1033          <entry><literal>CommitTsLock</literal></entry>
1034          <entry>Waiting to read or update the last value set for the
1035          transaction timestamp.</entry>
1036         </row>
1037         <row>
1038          <entry><literal>ReplicationOriginLock</literal></entry>
1039          <entry>Waiting to setup, drop or use replication origin.</entry>
1040         </row>
1041         <row>
1042          <entry><literal>MultiXactTruncationLock</literal></entry>
1043          <entry>Waiting to read or truncate multixact information.</entry>
1044         </row>
1045         <row>
1046          <entry><literal>OldSnapshotTimeMapLock</literal></entry>
1047          <entry>Waiting to read or update old snapshot control information.</entry>
1048         </row>
1049         <row>
1050          <entry><literal>LogicalRepWorkerLock</literal></entry>
1051          <entry>Waiting for action on logical replication worker to finish.</entry>
1052         </row>
1053         <row>
1054          <entry><literal>CLogTruncationLock</literal></entry>
1055          <entry>Waiting to execute <function>txid_status</function> or update
1056          the oldest transaction id available to it.</entry>
1057         </row>
1058         <row>
1059          <entry><literal>clog</literal></entry>
1060          <entry>Waiting for I/O on a clog (transaction status) buffer.</entry>
1061         </row>
1062         <row>
1063          <entry><literal>commit_timestamp</literal></entry>
1064          <entry>Waiting for I/O on commit timestamp buffer.</entry>
1065         </row>
1066         <row>
1067          <entry><literal>subtrans</literal></entry>
1068          <entry>Waiting for I/O a subtransaction buffer.</entry>
1069         </row>
1070         <row>
1071          <entry><literal>multixact_offset</literal></entry>
1072          <entry>Waiting for I/O on a multixact offset buffer.</entry>
1073         </row>
1074         <row>
1075          <entry><literal>multixact_member</literal></entry>
1076          <entry>Waiting for I/O on a multixact_member buffer.</entry>
1077         </row>
1078         <row>
1079          <entry><literal>async</literal></entry>
1080          <entry>Waiting for I/O on an async (notify) buffer.</entry>
1081         </row>
1082         <row>
1083          <entry><literal>oldserxid</literal></entry>
1084          <entry>Waiting for I/O on an oldserxid buffer.</entry>
1085         </row>
1086         <row>
1087          <entry><literal>wal_insert</literal></entry>
1088          <entry>Waiting to insert WAL into a memory buffer.</entry>
1089         </row>
1090         <row>
1091          <entry><literal>buffer_content</literal></entry>
1092          <entry>Waiting to read or write a data page in memory.</entry>
1093         </row>
1094         <row>
1095          <entry><literal>buffer_io</literal></entry>
1096          <entry>Waiting for I/O on a data page.</entry>
1097         </row>
1098         <row>
1099          <entry><literal>replication_origin</literal></entry>
1100          <entry>Waiting to read or update the replication progress.</entry>
1101         </row>
1102         <row>
1103          <entry><literal>replication_slot_io</literal></entry>
1104          <entry>Waiting for I/O on a replication slot.</entry>
1105         </row>
1106         <row>
1107          <entry><literal>proc</literal></entry>
1108          <entry>Waiting to read or update the fast-path lock information.</entry>
1109         </row>
1110         <row>
1111          <entry><literal>buffer_mapping</literal></entry>
1112          <entry>Waiting to associate a data block with a buffer in the buffer
1113          pool.</entry>
1114         </row>
1115         <row>
1116          <entry><literal>lock_manager</literal></entry>
1117          <entry>Waiting to add or examine locks for backends, or waiting to
1118          join or exit a locking group (used by parallel query).</entry>
1119         </row>
1120         <row>
1121          <entry><literal>predicate_lock_manager</literal></entry>
1122          <entry>Waiting to add or examine predicate lock information.</entry>
1123         </row>
1124         <row>
1125          <entry><literal>parallel_query_dsa</literal></entry>
1126          <entry>Waiting for parallel query dynamic shared memory allocation lock.</entry>
1127         </row>
1128         <row>
1129          <entry><literal>tbm</literal></entry>
1130          <entry>Waiting for TBM shared iterator lock.</entry>
1131         </row>
1132         <row>
1133          <entry><literal>parallel_append</literal></entry>
1134          <entry>Waiting to choose the next subplan during Parallel Append plan
1135          execution.</entry>
1136         </row>
1137         <row>
1138          <entry><literal>parallel_hash_join</literal></entry>
1139          <entry>Waiting to allocate or exchange a chunk of memory or update
1140          counters during Parallel Hash plan execution.</entry>
1141         </row>
1142         <row>
1143          <entry morerows="9"><literal>Lock</literal></entry>
1144          <entry><literal>relation</literal></entry>
1145          <entry>Waiting to acquire a lock on a relation.</entry>
1146         </row>
1147         <row>
1148          <entry><literal>extend</literal></entry>
1149          <entry>Waiting to extend a relation.</entry>
1150         </row>
1151         <row>
1152          <entry><literal>page</literal></entry>
1153          <entry>Waiting to acquire a lock on page of a relation.</entry>
1154         </row>
1155         <row>
1156          <entry><literal>tuple</literal></entry>
1157          <entry>Waiting to acquire a lock on a tuple.</entry>
1158         </row>
1159         <row>
1160          <entry><literal>transactionid</literal></entry>
1161          <entry>Waiting for a transaction to finish.</entry>
1162         </row>
1163         <row>
1164          <entry><literal>virtualxid</literal></entry>
1165          <entry>Waiting to acquire a virtual xid lock.</entry>
1166         </row>
1167         <row>
1168          <entry><literal>speculative token</literal></entry>
1169          <entry>Waiting to acquire a speculative insertion lock.</entry>
1170         </row>
1171         <row>
1172          <entry><literal>object</literal></entry>
1173          <entry>Waiting to acquire a lock on a non-relation database object.</entry>
1174         </row>
1175         <row>
1176          <entry><literal>userlock</literal></entry>
1177          <entry>Waiting to acquire a user lock.</entry>
1178         </row>
1179         <row>
1180          <entry><literal>advisory</literal></entry>
1181          <entry>Waiting to acquire an advisory user lock.</entry>
1182         </row>
1183         <row>
1184          <entry><literal>BufferPin</literal></entry>
1185          <entry><literal>BufferPin</literal></entry>
1186          <entry>Waiting to acquire a pin on a buffer.</entry>
1187         </row>
1188         <row>
1189          <entry morerows="13"><literal>Activity</literal></entry>
1190          <entry><literal>ArchiverMain</literal></entry>
1191          <entry>Waiting in main loop of the archiver process.</entry>
1192         </row>
1193         <row>
1194          <entry><literal>AutoVacuumMain</literal></entry>
1195          <entry>Waiting in main loop of autovacuum launcher process.</entry>
1196         </row>
1197         <row>
1198          <entry><literal>BgWriterHibernate</literal></entry>
1199          <entry>Waiting in background writer process, hibernating.</entry>
1200         </row>
1201         <row>
1202          <entry><literal>BgWriterMain</literal></entry>
1203          <entry>Waiting in main loop of background writer process background worker.</entry>
1204         </row>
1205         <row>
1206          <entry><literal>CheckpointerMain</literal></entry>
1207          <entry>Waiting in main loop of checkpointer process.</entry>
1208         </row>
1209         <row>
1210          <entry><literal>LogicalApplyMain</literal></entry>
1211          <entry>Waiting in main loop of logical apply process.</entry>
1212         </row>
1213         <row>
1214          <entry><literal>LogicalLauncherMain</literal></entry>
1215          <entry>Waiting in main loop of logical launcher process.</entry>
1216         </row>
1217         <row>
1218          <entry><literal>PgStatMain</literal></entry>
1219          <entry>Waiting in main loop of the statistics collector process.</entry>
1220         </row>
1221         <row>
1222          <entry><literal>RecoveryWalAll</literal></entry>
1223          <entry>Waiting for WAL from any kind of source (local, archive or stream) at recovery.</entry>
1224         </row>
1225         <row>
1226          <entry><literal>RecoveryWalStream</literal></entry>
1227          <entry>Waiting for WAL from a stream at recovery.</entry>
1228         </row>
1229         <row>
1230          <entry><literal>SysLoggerMain</literal></entry>
1231          <entry>Waiting in main loop of syslogger process.</entry>
1232         </row>
1233         <row>
1234          <entry><literal>WalReceiverMain</literal></entry>
1235          <entry>Waiting in main loop of WAL receiver process.</entry>
1236         </row>
1237         <row>
1238          <entry><literal>WalSenderMain</literal></entry>
1239          <entry>Waiting in main loop of WAL sender process.</entry>
1240         </row>
1241         <row>
1242          <entry><literal>WalWriterMain</literal></entry>
1243          <entry>Waiting in main loop of WAL writer process.</entry>
1244         </row>
1245         <row>
1246          <entry morerows="7"><literal>Client</literal></entry>
1247          <entry><literal>ClientRead</literal></entry>
1248          <entry>Waiting to read data from the client.</entry>
1249         </row>
1250         <row>
1251          <entry><literal>ClientWrite</literal></entry>
1252          <entry>Waiting to write data to the client.</entry>
1253         </row>
1254         <row>
1255          <entry><literal>LibPQWalReceiverConnect</literal></entry>
1256          <entry>Waiting in WAL receiver to establish connection to remote server.</entry>
1257         </row>
1258         <row>
1259          <entry><literal>LibPQWalReceiverReceive</literal></entry>
1260          <entry>Waiting in WAL receiver to receive data from remote server.</entry>
1261         </row>
1262         <row>
1263          <entry><literal>SSLOpenServer</literal></entry>
1264          <entry>Waiting for SSL while attempting connection.</entry>
1265         </row>
1266         <row>
1267          <entry><literal>WalReceiverWaitStart</literal></entry>
1268          <entry>Waiting for startup process to send initial data for streaming replication.</entry>
1269         </row>
1270         <row>
1271          <entry><literal>WalSenderWaitForWAL</literal></entry>
1272          <entry>Waiting for WAL to be flushed in WAL sender process.</entry>
1273         </row>
1274         <row>
1275          <entry><literal>WalSenderWriteData</literal></entry>
1276          <entry>Waiting for any activity when processing replies from WAL receiver in WAL sender process.</entry>
1277         </row>
1278         <row>
1279          <entry><literal>Extension</literal></entry>
1280          <entry><literal>Extension</literal></entry>
1281          <entry>Waiting in an extension.</entry>
1282         </row>
1283         <row>
1284          <entry morerows="34"><literal>IPC</literal></entry>
1285          <entry><literal>BgWorkerShutdown</literal></entry>
1286          <entry>Waiting for background worker to shut down.</entry>
1287         </row>
1288         <row>
1289          <entry><literal>BgWorkerStartup</literal></entry>
1290          <entry>Waiting for background worker to start up.</entry>
1291         </row>
1292         <row>
1293          <entry><literal>BtreePage</literal></entry>
1294          <entry>Waiting for the page number needed to continue a parallel B-tree scan to become available.</entry>
1295         </row>
1296         <row>
1297          <entry><literal>ClogGroupUpdate</literal></entry>
1298          <entry>Waiting for group leader to update transaction status at transaction end.</entry>
1299         </row>
1300         <row>
1301          <entry><literal>ExecuteGather</literal></entry>
1302          <entry>Waiting for activity from child process when executing <literal>Gather</literal> node.</entry>
1303         </row>
1304         <row>
1305           <entry><literal>Hash/Batch/Allocating</literal></entry>
1306           <entry>Waiting for an elected Parallel Hash participant to allocate a hash table.</entry>
1307         </row>
1308         <row>
1309           <entry><literal>Hash/Batch/Electing</literal></entry>
1310           <entry>Electing a Parallel Hash participant to allocate a hash table.</entry>
1311         </row>
1312         <row>
1313           <entry><literal>Hash/Batch/Loading</literal></entry>
1314           <entry>Waiting for other Parallel Hash participants to finish loading a hash table.</entry>
1315         </row>
1316         <row>
1317           <entry><literal>Hash/Build/Allocating</literal></entry>
1318           <entry>Waiting for an elected Parallel Hash participant to allocate the initial hash table.</entry>
1319         </row>
1320         <row>
1321           <entry><literal>Hash/Build/Electing</literal></entry>
1322           <entry>Electing a Parallel Hash participant to allocate the initial hash table.</entry>
1323         </row>
1324         <row>
1325           <entry><literal>Hash/Build/HashingInner</literal></entry>
1326           <entry>Waiting for other Parallel Hash participants to finish hashing the inner relation.</entry>
1327         </row>
1328         <row>
1329           <entry><literal>Hash/Build/HashingOuter</literal></entry>
1330           <entry>Waiting for other Parallel Hash participants to finish partitioning the outer relation.</entry>
1331         </row>
1332         <row>
1333           <entry><literal>Hash/GrowBatches/Allocating</literal></entry>
1334           <entry>Waiting for an elected Parallel Hash participant to allocate more batches.</entry>
1335         </row>
1336         <row>
1337           <entry><literal>Hash/GrowBatches/Deciding</literal></entry>
1338           <entry>Electing a Parallel Hash participant to decide on future batch growth.</entry>
1339         </row>
1340         <row>
1341           <entry><literal>Hash/GrowBatches/Electing</literal></entry>
1342           <entry>Electing a Parallel Hash participant to allocate more batches.</entry>
1343         </row>
1344         <row>
1345           <entry><literal>Hash/GrowBatches/Finishing</literal></entry>
1346           <entry>Waiting for an elected Parallel Hash participant to decide on future batch growth.</entry>
1347         </row>
1348         <row>
1349           <entry><literal>Hash/GrowBatches/Repartitioning</literal></entry>
1350           <entry>Waiting for other Parallel Hash participants to finishing repartitioning.</entry>
1351         </row>
1352         <row>
1353           <entry><literal>Hash/GrowBuckets/Allocating</literal></entry>
1354           <entry>Waiting for an elected Parallel Hash participant to finish allocating more buckets.</entry>
1355         </row>
1356         <row>
1357           <entry><literal>Hash/GrowBuckets/Electing</literal></entry>
1358           <entry>Electing a Parallel Hash participant to allocate more buckets.</entry>
1359         </row>
1360         <row>
1361           <entry><literal>Hash/GrowBuckets/Reinserting</literal></entry>
1362           <entry>Waiting for other Parallel Hash participants to finish inserting tuples into new buckets.</entry>
1363         </row>
1364         <row>
1365          <entry><literal>LogicalSyncData</literal></entry>
1366          <entry>Waiting for logical replication remote server to send data for initial table synchronization.</entry>
1367         </row>
1368         <row>
1369          <entry><literal>LogicalSyncStateChange</literal></entry>
1370          <entry>Waiting for logical replication remote server to change state.</entry>
1371         </row>
1372         <row>
1373          <entry><literal>MessageQueueInternal</literal></entry>
1374          <entry>Waiting for other process to be attached in shared message queue.</entry>
1375         </row>
1376         <row>
1377          <entry><literal>MessageQueuePutMessage</literal></entry>
1378          <entry>Waiting to write a protocol message to a shared message queue.</entry>
1379         </row>
1380         <row>
1381          <entry><literal>MessageQueueReceive</literal></entry>
1382          <entry>Waiting to receive bytes from a shared message queue.</entry>
1383         </row>
1384         <row>
1385          <entry><literal>MessageQueueSend</literal></entry>
1386          <entry>Waiting to send bytes to a shared message queue.</entry>
1387         </row>
1388         <row>
1389          <entry><literal>ParallelBitmapScan</literal></entry>
1390          <entry>Waiting for parallel bitmap scan to become initialized.</entry>
1391         </row>
1392         <row>
1393          <entry><literal>ParallelCreateIndexScan</literal></entry>
1394          <entry>Waiting for parallel <command>CREATE INDEX</command> workers to finish heap scan.</entry>
1395         </row>
1396         <row>
1397          <entry><literal>ParallelFinish</literal></entry>
1398          <entry>Waiting for parallel workers to finish computing.</entry>
1399         </row>
1400         <row>
1401          <entry><literal>ProcArrayGroupUpdate</literal></entry>
1402          <entry>Waiting for group leader to clear transaction id at transaction end.</entry>
1403         </row>
1404         <row>
1405          <entry><literal>Promote</literal></entry>
1406          <entry>Waiting for standby promotion.</entry>
1407         </row>
1408         <row>
1409          <entry><literal>ReplicationOriginDrop</literal></entry>
1410          <entry>Waiting for a replication origin to become inactive to be dropped.</entry>
1411         </row>
1412         <row>
1413          <entry><literal>ReplicationSlotDrop</literal></entry>
1414          <entry>Waiting for a replication slot to become inactive to be dropped.</entry>
1415         </row>
1416         <row>
1417          <entry><literal>SafeSnapshot</literal></entry>
1418          <entry>Waiting for a snapshot for a <literal>READ ONLY DEFERRABLE</literal> transaction.</entry>
1419         </row>
1420         <row>
1421          <entry><literal>SyncRep</literal></entry>
1422          <entry>Waiting for confirmation from remote server during synchronous replication.</entry>
1423         </row>
1424         <row>
1425          <entry morerows="2"><literal>Timeout</literal></entry>
1426          <entry><literal>BaseBackupThrottle</literal></entry>
1427          <entry>Waiting during base backup when throttling activity.</entry>
1428         </row>
1429         <row>
1430          <entry><literal>PgSleep</literal></entry>
1431          <entry>Waiting in process that called <function>pg_sleep</function>.</entry>
1432         </row>
1433         <row>
1434          <entry><literal>RecoveryApplyDelay</literal></entry>
1435          <entry>Waiting to apply WAL at recovery because it is delayed.</entry>
1436         </row>
1437         <row>
1438          <entry morerows="66"><literal>IO</literal></entry>
1439          <entry><literal>BufFileRead</literal></entry>
1440          <entry>Waiting for a read from a buffered file.</entry>
1441         </row>
1442         <row>
1443          <entry><literal>BufFileWrite</literal></entry>
1444          <entry>Waiting for a write to a buffered file.</entry>
1445         </row>
1446         <row>
1447          <entry><literal>ControlFileRead</literal></entry>
1448          <entry>Waiting for a read from the control file.</entry>
1449         </row>
1450         <row>
1451          <entry><literal>ControlFileSync</literal></entry>
1452          <entry>Waiting for the control file to reach stable storage.</entry>
1453         </row>
1454         <row>
1455          <entry><literal>ControlFileSyncUpdate</literal></entry>
1456          <entry>Waiting for an update to the control file to reach stable storage.</entry>
1457         </row>
1458         <row>
1459          <entry><literal>ControlFileWrite</literal></entry>
1460          <entry>Waiting for a write to the control file.</entry>
1461         </row>
1462         <row>
1463          <entry><literal>ControlFileWriteUpdate</literal></entry>
1464          <entry>Waiting for a write to update the control file.</entry>
1465         </row>
1466         <row>
1467          <entry><literal>CopyFileRead</literal></entry>
1468          <entry>Waiting for a read during a file copy operation.</entry>
1469         </row>
1470         <row>
1471          <entry><literal>CopyFileWrite</literal></entry>
1472          <entry>Waiting for a write during a file copy operation.</entry>
1473         </row>
1474         <row>
1475          <entry><literal>DataFileExtend</literal></entry>
1476          <entry>Waiting for a relation data file to be extended.</entry>
1477         </row>
1478         <row>
1479          <entry><literal>DataFileFlush</literal></entry>
1480          <entry>Waiting for a relation data file to reach stable storage.</entry>
1481         </row>
1482         <row>
1483          <entry><literal>DataFileImmediateSync</literal></entry>
1484          <entry>Waiting for an immediate synchronization of a relation data file to stable storage.</entry>
1485         </row>
1486         <row>
1487          <entry><literal>DataFilePrefetch</literal></entry>
1488          <entry>Waiting for an asynchronous prefetch from a relation data file.</entry>
1489         </row>
1490         <row>
1491          <entry><literal>DataFileRead</literal></entry>
1492          <entry>Waiting for a read from a relation data file.</entry>
1493         </row>
1494         <row>
1495          <entry><literal>DataFileSync</literal></entry>
1496          <entry>Waiting for changes to a relation data file to reach stable storage.</entry>
1497         </row>
1498         <row>
1499          <entry><literal>DataFileTruncate</literal></entry>
1500          <entry>Waiting for a relation data file to be truncated.</entry>
1501         </row>
1502         <row>
1503          <entry><literal>DataFileWrite</literal></entry>
1504          <entry>Waiting for a write to a relation data file.</entry>
1505         </row>
1506         <row>
1507          <entry><literal>DSMFillZeroWrite</literal></entry>
1508          <entry>Waiting to write zero bytes to a dynamic shared memory backing file.</entry>
1509         </row>
1510         <row>
1511          <entry><literal>LockFileAddToDataDirRead</literal></entry>
1512          <entry>Waiting for a read while adding a line to the data directory lock file.</entry>
1513         </row>
1514         <row>
1515          <entry><literal>LockFileAddToDataDirSync</literal></entry>
1516          <entry>Waiting for data to reach stable storage while adding a line to the data directory lock file.</entry>
1517         </row>
1518         <row>
1519          <entry><literal>LockFileAddToDataDirWrite</literal></entry>
1520          <entry>Waiting for a write while adding a line to the data directory lock file.</entry>
1521         </row>
1522         <row>
1523          <entry><literal>LockFileCreateRead</literal></entry>
1524          <entry>Waiting to read while creating the data directory lock file.</entry>
1525         </row>
1526         <row>
1527          <entry><literal>LockFileCreateSync</literal></entry>
1528          <entry>Waiting for data to reach stable storage while creating the data directory lock file.</entry>
1529         </row>
1530         <row>
1531          <entry><literal>LockFileCreateWrite</literal></entry>
1532          <entry>Waiting for a write while creating the data directory lock file.</entry>
1533         </row>
1534         <row>
1535          <entry><literal>LockFileReCheckDataDirRead</literal></entry>
1536          <entry>Waiting for a read during recheck of the data directory lock file.</entry>
1537         </row>
1538         <row>
1539          <entry><literal>LogicalRewriteCheckpointSync</literal></entry>
1540          <entry>Waiting for logical rewrite mappings to reach stable storage during a checkpoint.</entry>
1541         </row>
1542         <row>
1543          <entry><literal>LogicalRewriteMappingSync</literal></entry>
1544          <entry>Waiting for mapping data to reach stable storage during a logical rewrite.</entry>
1545         </row>
1546         <row>
1547          <entry><literal>LogicalRewriteMappingWrite</literal></entry>
1548          <entry>Waiting for a write of mapping data during a logical rewrite.</entry>
1549         </row>
1550         <row>
1551          <entry><literal>LogicalRewriteSync</literal></entry>
1552          <entry>Waiting for logical rewrite mappings to reach stable storage.</entry>
1553         </row>
1554         <row>
1555          <entry><literal>LogicalRewriteWrite</literal></entry>
1556          <entry>Waiting for a write of logical rewrite mappings.</entry>
1557         </row>
1558         <row>
1559          <entry><literal>RelationMapRead</literal></entry>
1560          <entry>Waiting for a read of the relation map file.</entry>
1561         </row>
1562         <row>
1563          <entry><literal>RelationMapSync</literal></entry>
1564          <entry>Waiting for the relation map file to reach stable storage.</entry>
1565         </row>
1566         <row>
1567          <entry><literal>RelationMapWrite</literal></entry>
1568          <entry>Waiting for a write to the relation map file.</entry>
1569         </row>
1570         <row>
1571          <entry><literal>ReorderBufferRead</literal></entry>
1572          <entry>Waiting for a read during reorder buffer management.</entry>
1573         </row>
1574         <row>
1575          <entry><literal>ReorderBufferWrite</literal></entry>
1576          <entry>Waiting for a write during reorder buffer management.</entry>
1577         </row>
1578         <row>
1579          <entry><literal>ReorderLogicalMappingRead</literal></entry>
1580          <entry>Waiting for a read of a logical mapping during reorder buffer management.</entry>
1581         </row>
1582         <row>
1583          <entry><literal>ReplicationSlotRead</literal></entry>
1584          <entry>Waiting for a read from a replication slot control file.</entry>
1585         </row>
1586         <row>
1587          <entry><literal>ReplicationSlotRestoreSync</literal></entry>
1588          <entry>Waiting for a replication slot control file to reach stable storage while restoring it to memory.</entry>
1589         </row>
1590         <row>
1591          <entry><literal>ReplicationSlotSync</literal></entry>
1592          <entry>Waiting for a replication slot control file to reach stable storage.</entry>
1593         </row>
1594         <row>
1595          <entry><literal>ReplicationSlotWrite</literal></entry>
1596          <entry>Waiting for a write to a replication slot control file.</entry>
1597         </row>
1598         <row>
1599          <entry><literal>SLRUFlushSync</literal></entry>
1600          <entry>Waiting for SLRU data to reach stable storage during a checkpoint or database shutdown.</entry>
1601         </row>
1602         <row>
1603          <entry><literal>SLRURead</literal></entry>
1604          <entry>Waiting for a read of an SLRU page.</entry>
1605         </row>
1606         <row>
1607          <entry><literal>SLRUSync</literal></entry>
1608          <entry>Waiting for SLRU data to reach stable storage following a page write.</entry>
1609         </row>
1610         <row>
1611          <entry><literal>SLRUWrite</literal></entry>
1612          <entry>Waiting for a write of an SLRU page.</entry>
1613         </row>
1614         <row>
1615          <entry><literal>SnapbuildRead</literal></entry>
1616          <entry>Waiting for a read of a serialized historical catalog snapshot.</entry>
1617         </row>
1618         <row>
1619          <entry><literal>SnapbuildSync</literal></entry>
1620          <entry>Waiting for a serialized historical catalog snapshot to reach stable storage.</entry>
1621         </row>
1622         <row>
1623          <entry><literal>SnapbuildWrite</literal></entry>
1624          <entry>Waiting for a write of a serialized historical catalog snapshot.</entry>
1625         </row>
1626         <row>
1627          <entry><literal>TimelineHistoryFileSync</literal></entry>
1628          <entry>Waiting for a timeline history file received via streaming replication to reach stable storage.</entry>
1629         </row>
1630         <row>
1631          <entry><literal>TimelineHistoryFileWrite</literal></entry>
1632          <entry>Waiting for a write of a timeline history file received via streaming replication.</entry>
1633         </row>
1634         <row>
1635          <entry><literal>TimelineHistoryRead</literal></entry>
1636          <entry>Waiting for a read of a timeline history file.</entry>
1637         </row>
1638         <row>
1639          <entry><literal>TimelineHistorySync</literal></entry>
1640          <entry>Waiting for a newly created timeline history file to reach stable storage.</entry>
1641         </row>
1642         <row>
1643          <entry><literal>TimelineHistoryWrite</literal></entry>
1644          <entry>Waiting for a write of a newly created timeline history file.</entry>
1645         </row>
1646         <row>
1647          <entry><literal>TwophaseFileRead</literal></entry>
1648          <entry>Waiting for a read of a two phase state file.</entry>
1649         </row>
1650         <row>
1651          <entry><literal>TwophaseFileSync</literal></entry>
1652          <entry>Waiting for a two phase state file to reach stable storage.</entry>
1653         </row>
1654         <row>
1655          <entry><literal>TwophaseFileWrite</literal></entry>
1656          <entry>Waiting for a write of a two phase state file.</entry>
1657         </row>
1658         <row>
1659          <entry><literal>WALBootstrapSync</literal></entry>
1660          <entry>Waiting for WAL to reach stable storage during bootstrapping.</entry>
1661         </row>
1662         <row>
1663          <entry><literal>WALBootstrapWrite</literal></entry>
1664          <entry>Waiting for a write of a WAL page during bootstrapping.</entry>
1665         </row>
1666         <row>
1667          <entry><literal>WALCopyRead</literal></entry>
1668          <entry>Waiting for a read when creating a new WAL segment by copying an existing one.</entry>
1669         </row>
1670         <row>
1671          <entry><literal>WALCopySync</literal></entry>
1672          <entry>Waiting a new WAL segment created by copying an existing one to reach stable storage.</entry>
1673         </row>
1674         <row>
1675          <entry><literal>WALCopyWrite</literal></entry>
1676          <entry>Waiting for a write when creating a new WAL segment by copying an existing one.</entry>
1677         </row>
1678         <row>
1679          <entry><literal>WALInitSync</literal></entry>
1680          <entry>Waiting for a newly initialized WAL file to reach stable storage.</entry>
1681         </row>
1682         <row>
1683          <entry><literal>WALInitWrite</literal></entry>
1684          <entry>Waiting for a write while initializing a new WAL file.</entry>
1685         </row>
1686         <row>
1687          <entry><literal>WALRead</literal></entry>
1688          <entry>Waiting for a read from a WAL file.</entry>
1689         </row>
1690         <row>
1691          <entry><literal>WALSenderTimelineHistoryRead</literal></entry>
1692          <entry>Waiting for a read from a timeline history file during walsender timeline command.</entry>
1693         </row>
1694         <row>
1695          <entry><literal>WALSync</literal></entry>
1696          <entry>Waiting for a WAL file to reach stable storage.</entry>
1697         </row>
1698         <row>
1699          <entry><literal>WALSyncMethodAssign</literal></entry>
1700          <entry>Waiting for data to reach stable storage while assigning WAL sync method.</entry>
1701         </row>
1702         <row>
1703          <entry><literal>WALWrite</literal></entry>
1704          <entry>Waiting for a write to a WAL file.</entry>
1705         </row>
1706       </tbody>
1707      </tgroup>
1708     </table>
1709
1710    <note>
1711     <para>
1712      For tranches registered by extensions, the name is specified by extension
1713      and this will be displayed as <structfield>wait_event</structfield>.  It is quite
1714      possible that user has registered the tranche in one of the backends (by
1715      having allocation in dynamic shared memory) in which case other backends
1716      won't have that information, so we display <literal>extension</literal> for such
1717      cases.
1718     </para>
1719    </note>
1720
1721    <para>
1722      Here is an example of how wait events can be viewed
1723
1724 <programlisting>
1725 SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
1726  pid  | wait_event_type |  wait_event
1727 ------+-----------------+---------------
1728  2540 | Lock            | relation
1729  6644 | LWLock          | ProcArrayLock
1730 (2 rows)
1731 </programlisting>
1732    </para>
1733
1734   <table id="pg-stat-replication-view" xreflabel="pg_stat_replication">
1735    <title><structname>pg_stat_replication</structname> View</title>
1736    <tgroup cols="3">
1737     <thead>
1738     <row>
1739       <entry>Column</entry>
1740       <entry>Type</entry>
1741       <entry>Description</entry>
1742      </row>
1743     </thead>
1744
1745    <tbody>
1746     <row>
1747      <entry><structfield>pid</structfield></entry>
1748      <entry><type>integer</type></entry>
1749      <entry>Process ID of a WAL sender process</entry>
1750     </row>
1751     <row>
1752      <entry><structfield>usesysid</structfield></entry>
1753      <entry><type>oid</type></entry>
1754      <entry>OID of the user logged into this WAL sender process</entry>
1755     </row>
1756     <row>
1757      <entry><structfield>usename</structfield></entry>
1758      <entry><type>name</type></entry>
1759      <entry>Name of the user logged into this WAL sender process</entry>
1760     </row>
1761     <row>
1762      <entry><structfield>application_name</structfield></entry>
1763      <entry><type>text</type></entry>
1764      <entry>Name of the application that is connected
1765       to this WAL sender</entry>
1766     </row>
1767     <row>
1768      <entry><structfield>client_addr</structfield></entry>
1769      <entry><type>inet</type></entry>
1770      <entry>IP address of the client connected to this WAL sender.
1771       If this field is null, it indicates that the client is
1772       connected via a Unix socket on the server machine.
1773      </entry>
1774     </row>
1775     <row>
1776      <entry><structfield>client_hostname</structfield></entry>
1777      <entry><type>text</type></entry>
1778      <entry>Host name of the connected client, as reported by a
1779       reverse DNS lookup of <structfield>client_addr</structfield>. This field will
1780       only be non-null for IP connections, and only when <xref
1781       linkend="guc-log-hostname"/> is enabled.
1782      </entry>
1783     </row>
1784     <row>
1785      <entry><structfield>client_port</structfield></entry>
1786      <entry><type>integer</type></entry>
1787      <entry>TCP port number that the client is using for communication
1788       with this WAL sender, or <literal>-1</literal> if a Unix socket is used
1789      </entry>
1790     </row>
1791     <row>
1792      <entry><structfield>backend_start</structfield></entry>
1793      <entry><type>timestamp with time zone</type></entry>
1794      <entry>Time when this process was started, i.e., when the
1795       client connected to this WAL sender
1796      </entry>
1797     </row>
1798     <row>
1799      <entry><structfield>backend_xmin</structfield></entry>
1800      <entry><type>xid</type></entry>
1801      <entry>This standby's <literal>xmin</literal> horizon reported
1802      by <xref linkend="guc-hot-standby-feedback"/>.</entry>
1803     </row>
1804     <row>
1805      <entry><structfield>state</structfield></entry>
1806      <entry><type>text</type></entry>
1807      <entry>Current WAL sender state.
1808        Possible values are:
1809        <itemizedlist>
1810          <listitem>
1811           <para>
1812            <literal>startup</literal>: This WAL sender is starting up.
1813           </para>
1814          </listitem>
1815          <listitem>
1816           <para>
1817            <literal>catchup</literal>: This WAL sender's connected standby is
1818            catching up with the primary.
1819           </para>
1820          </listitem>
1821          <listitem>
1822           <para>
1823            <literal>streaming</literal>: This WAL sender is streaming changes
1824            after its connected standby server has caught up with the primary.
1825           </para>
1826          </listitem>
1827          <listitem>
1828           <para>
1829            <literal>backup</literal>: This WAL sender is sending a backup.
1830           </para>
1831          </listitem>
1832          <listitem>
1833           <para>
1834            <literal>stopping</literal>: This WAL sender is stopping.
1835           </para>
1836          </listitem>
1837        </itemizedlist>
1838      </entry>
1839     </row>
1840     <row>
1841      <entry><structfield>sent_lsn</structfield></entry>
1842      <entry><type>pg_lsn</type></entry>
1843      <entry>Last write-ahead log location sent on this connection</entry>
1844     </row>
1845     <row>
1846      <entry><structfield>write_lsn</structfield></entry>
1847      <entry><type>pg_lsn</type></entry>
1848      <entry>Last write-ahead log location written to disk by this standby
1849       server</entry>
1850     </row>
1851     <row>
1852      <entry><structfield>flush_lsn</structfield></entry>
1853      <entry><type>pg_lsn</type></entry>
1854      <entry>Last write-ahead log location flushed to disk by this standby
1855       server</entry>
1856     </row>
1857     <row>
1858      <entry><structfield>replay_lsn</structfield></entry>
1859      <entry><type>pg_lsn</type></entry>
1860      <entry>Last write-ahead log location replayed into the database on this
1861       standby server</entry>
1862     </row>
1863     <row>
1864      <entry><structfield>write_lag</structfield></entry>
1865      <entry><type>interval</type></entry>
1866      <entry>Time elapsed between flushing recent WAL locally and receiving
1867       notification that this standby server has written it (but not yet
1868       flushed it or applied it).  This can be used to gauge the delay that
1869       <literal>synchronous_commit</literal> level
1870       <literal>remote_write</literal> incurred while committing if this
1871       server was configured as a synchronous standby.</entry>
1872     </row>
1873     <row>
1874      <entry><structfield>flush_lag</structfield></entry>
1875      <entry><type>interval</type></entry>
1876      <entry>Time elapsed between flushing recent WAL locally and receiving
1877       notification that this standby server has written and flushed it
1878       (but not yet applied it).  This can be used to gauge the delay that
1879       <literal>synchronous_commit</literal> level
1880       <literal>on</literal> incurred while committing if this
1881       server was configured as a synchronous standby.</entry>
1882     </row>
1883     <row>
1884      <entry><structfield>replay_lag</structfield></entry>
1885      <entry><type>interval</type></entry>
1886      <entry>Time elapsed between flushing recent WAL locally and receiving
1887       notification that this standby server has written, flushed and
1888       applied it.  This can be used to gauge the delay that
1889       <literal>synchronous_commit</literal> level
1890       <literal>remote_apply</literal> incurred while committing if this
1891       server was configured as a synchronous standby.</entry>
1892     </row>
1893     <row>
1894      <entry><structfield>sync_priority</structfield></entry>
1895      <entry><type>integer</type></entry>
1896      <entry>Priority of this standby server for being chosen as the
1897       synchronous standby in a priority-based synchronous replication.
1898       This has no effect in a quorum-based synchronous replication.</entry>
1899     </row>
1900     <row>
1901      <entry><structfield>sync_state</structfield></entry>
1902      <entry><type>text</type></entry>
1903      <entry>Synchronous state of this standby server.
1904        Possible values are:
1905        <itemizedlist>
1906          <listitem>
1907           <para>
1908            <literal>async</literal>: This standby server is asynchronous.
1909           </para>
1910          </listitem>
1911          <listitem>
1912           <para>
1913            <literal>potential</literal>: This standby server is now asynchronous,
1914            but can potentially become synchronous if one of current
1915            synchronous ones fails.
1916           </para>
1917          </listitem>
1918          <listitem>
1919           <para>
1920            <literal>sync</literal>: This standby server is synchronous.
1921           </para>
1922          </listitem>
1923          <listitem>
1924           <para>
1925            <literal>quorum</literal>: This standby server is considered as a candidate
1926            for quorum standbys.
1927           </para>
1928          </listitem>
1929        </itemizedlist>
1930      </entry>
1931     </row>
1932     <row>
1933      <entry><structfield>reply_time</structfield></entry>
1934      <entry><type>timestamp with time zone</type></entry>
1935      <entry>Send time of last reply message received from standby server</entry>
1936     </row>
1937    </tbody>
1938    </tgroup>
1939   </table>
1940
1941   <para>
1942    The <structname>pg_stat_replication</structname> view will contain one row
1943    per WAL sender process, showing statistics about replication to that
1944    sender's connected standby server.  Only directly connected standbys are
1945    listed; no information is available about downstream standby servers.
1946   </para>
1947
1948   <para>
1949    The lag times reported in the <structname>pg_stat_replication</structname>
1950    view are measurements of the time taken for recent WAL to be written,
1951    flushed and replayed and for the sender to know about it.  These times
1952    represent the commit delay that was (or would have been) introduced by each
1953    synchronous commit level, if the remote server was configured as a
1954    synchronous standby.  For an asynchronous standby, the
1955    <structfield>replay_lag</structfield> column approximates the delay
1956    before recent transactions became visible to queries.  If the standby
1957    server has entirely caught up with the sending server and there is no more
1958    WAL activity, the most recently measured lag times will continue to be
1959    displayed for a short time and then show NULL.
1960   </para>
1961
1962   <para>
1963    Lag times work automatically for physical replication. Logical decoding
1964    plugins may optionally emit tracking messages; if they do not, the tracking
1965    mechanism will simply display NULL lag.
1966   </para>
1967
1968   <note>
1969    <para>
1970     The reported lag times are not predictions of how long it will take for
1971     the standby to catch up with the sending server assuming the current
1972     rate of replay.  Such a system would show similar times while new WAL is
1973     being generated, but would differ when the sender becomes idle.  In
1974     particular, when the standby has caught up completely,
1975     <structname>pg_stat_replication</structname> shows the time taken to
1976     write, flush and replay the most recent reported WAL location rather than
1977     zero as some users might expect.  This is consistent with the goal of
1978     measuring synchronous commit and transaction visibility delays for
1979     recent write transactions.
1980     To reduce confusion for users expecting a different model of lag, the
1981     lag columns revert to NULL after a short time on a fully replayed idle
1982     system. Monitoring systems should choose whether to represent this
1983     as missing data, zero or continue to display the last known value.
1984    </para>
1985   </note>
1986
1987   <table id="pg-stat-wal-receiver-view" xreflabel="pg_stat_wal_receiver">
1988    <title><structname>pg_stat_wal_receiver</structname> View</title>
1989    <tgroup cols="3">
1990     <thead>
1991     <row>
1992       <entry>Column</entry>
1993       <entry>Type</entry>
1994       <entry>Description</entry>
1995      </row>
1996     </thead>
1997
1998    <tbody>
1999     <row>
2000      <entry><structfield>pid</structfield></entry>
2001      <entry><type>integer</type></entry>
2002      <entry>Process ID of the WAL receiver process</entry>
2003     </row>
2004     <row>
2005      <entry><structfield>status</structfield></entry>
2006      <entry><type>text</type></entry>
2007      <entry>Activity status of the WAL receiver process</entry>
2008     </row>
2009     <row>
2010      <entry><structfield>receive_start_lsn</structfield></entry>
2011      <entry><type>pg_lsn</type></entry>
2012      <entry>First write-ahead log location used when WAL receiver is
2013       started</entry>
2014     </row>
2015     <row>
2016      <entry><structfield>receive_start_tli</structfield></entry>
2017      <entry><type>integer</type></entry>
2018      <entry>First timeline number used when WAL receiver is started</entry>
2019     </row>
2020     <row>
2021      <entry><structfield>received_lsn</structfield></entry>
2022      <entry><type>pg_lsn</type></entry>
2023      <entry>Last write-ahead log location already received and flushed to
2024       disk, the initial value of this field being the first log location used
2025       when WAL receiver is started</entry>
2026     </row>
2027     <row>
2028      <entry><structfield>received_tli</structfield></entry>
2029      <entry><type>integer</type></entry>
2030      <entry>Timeline number of last write-ahead log location received and
2031       flushed to disk, the initial value of this field being the timeline
2032       number of the first log location used when WAL receiver is started
2033      </entry>
2034     </row>
2035     <row>
2036      <entry><structfield>last_msg_send_time</structfield></entry>
2037      <entry><type>timestamp with time zone</type></entry>
2038      <entry>Send time of last message received from origin WAL sender</entry>
2039     </row>
2040     <row>
2041      <entry><structfield>last_msg_receipt_time</structfield></entry>
2042      <entry><type>timestamp with time zone</type></entry>
2043      <entry>Receipt time of last message received from origin WAL sender</entry>
2044     </row>
2045     <row>
2046      <entry><structfield>latest_end_lsn</structfield></entry>
2047      <entry><type>pg_lsn</type></entry>
2048      <entry>Last write-ahead log location reported to origin WAL sender</entry>
2049     </row>
2050     <row>
2051      <entry><structfield>latest_end_time</structfield></entry>
2052      <entry><type>timestamp with time zone</type></entry>
2053      <entry>Time of last write-ahead log location reported to origin WAL sender</entry>
2054     </row>
2055     <row>
2056      <entry><structfield>slot_name</structfield></entry>
2057      <entry><type>text</type></entry>
2058      <entry>Replication slot name used by this WAL receiver</entry>
2059     </row>
2060     <row>
2061      <entry><structfield>sender_host</structfield></entry>
2062      <entry><type>text</type></entry>
2063      <entry>
2064       Host of the <productname>PostgreSQL</productname> instance
2065       this WAL receiver is connected to. This can be a host name,
2066       an IP address, or a directory path if the connection is via
2067       Unix socket.  (The path case can be distinguished because it
2068       will always be an absolute path, beginning with <literal>/</literal>.)
2069      </entry>
2070     </row>
2071     <row>
2072      <entry><structfield>sender_port</structfield></entry>
2073      <entry><type>integer</type></entry>
2074      <entry>
2075       Port number of the <productname>PostgreSQL</productname> instance
2076       this WAL receiver is connected to.
2077      </entry>
2078     </row>
2079     <row>
2080      <entry><structfield>conninfo</structfield></entry>
2081      <entry><type>text</type></entry>
2082      <entry>
2083       Connection string used by this WAL receiver,
2084       with security-sensitive fields obfuscated.
2085      </entry>
2086     </row>
2087    </tbody>
2088    </tgroup>
2089   </table>
2090
2091   <para>
2092    The <structname>pg_stat_wal_receiver</structname> view will contain only
2093    one row, showing statistics about the WAL receiver from that receiver's
2094    connected server.
2095   </para>
2096
2097   <table id="pg-stat-subscription" xreflabel="pg_stat_subscription">
2098    <title><structname>pg_stat_subscription</structname> View</title>
2099    <tgroup cols="3">
2100     <thead>
2101     <row>
2102       <entry>Column</entry>
2103       <entry>Type</entry>
2104       <entry>Description</entry>
2105      </row>
2106     </thead>
2107
2108    <tbody>
2109     <row>
2110      <entry><structfield>subid</structfield></entry>
2111      <entry><type>oid</type></entry>
2112      <entry>OID of the subscription</entry>
2113     </row>
2114     <row>
2115      <entry><structfield>subname</structfield></entry>
2116      <entry><type>text</type></entry>
2117      <entry>Name of the subscription</entry>
2118     </row>
2119     <row>
2120      <entry><structfield>pid</structfield></entry>
2121      <entry><type>integer</type></entry>
2122      <entry>Process ID of the subscription worker process</entry>
2123     </row>
2124     <row>
2125      <entry><structfield>relid</structfield></entry>
2126      <entry><type>Oid</type></entry>
2127      <entry>OID of the relation that the worker is synchronizing; null for the
2128      main apply worker</entry>
2129     </row>
2130     <row>
2131      <entry><structfield>received_lsn</structfield></entry>
2132      <entry><type>pg_lsn</type></entry>
2133      <entry>Last write-ahead log location received, the initial value of
2134       this field being 0</entry>
2135     </row>
2136     <row>
2137      <entry><structfield>last_msg_send_time</structfield></entry>
2138      <entry><type>timestamp with time zone</type></entry>
2139      <entry>Send time of last message received from origin WAL sender</entry>
2140     </row>
2141     <row>
2142      <entry><structfield>last_msg_receipt_time</structfield></entry>
2143      <entry><type>timestamp with time zone</type></entry>
2144      <entry>Receipt time of last message received from origin WAL sender
2145      </entry>
2146     </row>
2147     <row>
2148      <entry><structfield>latest_end_lsn</structfield></entry>
2149      <entry><type>pg_lsn</type></entry>
2150      <entry>Last write-ahead log location reported to origin WAL sender
2151      </entry>
2152     </row>
2153     <row>
2154      <entry><structfield>latest_end_time</structfield></entry>
2155      <entry><type>timestamp with time zone</type></entry>
2156      <entry>Time of last write-ahead log location reported to origin WAL
2157       sender</entry>
2158     </row>
2159    </tbody>
2160    </tgroup>
2161   </table>
2162
2163   <para>
2164    The <structname>pg_stat_subscription</structname> view will contain one
2165    row per subscription for main worker (with null PID if the worker is
2166    not running), and additional rows for workers handling the initial data
2167    copy of the subscribed tables.
2168   </para>
2169
2170   <table id="pg-stat-ssl-view" xreflabel="pg_stat_ssl">
2171    <title><structname>pg_stat_ssl</structname> View</title>
2172    <tgroup cols="3">
2173     <thead>
2174     <row>
2175       <entry>Column</entry>
2176       <entry>Type</entry>
2177       <entry>Description</entry>
2178      </row>
2179     </thead>
2180
2181    <tbody>
2182     <row>
2183      <entry><structfield>pid</structfield></entry>
2184      <entry><type>integer</type></entry>
2185      <entry>Process ID of a backend or WAL sender process</entry>
2186     </row>
2187     <row>
2188      <entry><structfield>ssl</structfield></entry>
2189      <entry><type>boolean</type></entry>
2190      <entry>True if SSL is used on this connection</entry>
2191     </row>
2192     <row>
2193      <entry><structfield>version</structfield></entry>
2194      <entry><type>text</type></entry>
2195      <entry>Version of SSL in use, or NULL if SSL is not in use
2196       on this connection</entry>
2197     </row>
2198     <row>
2199      <entry><structfield>cipher</structfield></entry>
2200      <entry><type>text</type></entry>
2201      <entry>Name of SSL cipher in use, or NULL if SSL is not in use
2202       on this connection</entry>
2203     </row>
2204     <row>
2205      <entry><structfield>bits</structfield></entry>
2206      <entry><type>integer</type></entry>
2207      <entry>Number of bits in the encryption algorithm used, or NULL
2208      if SSL is not used on this connection</entry>
2209     </row>
2210     <row>
2211      <entry><structfield>compression</structfield></entry>
2212      <entry><type>boolean</type></entry>
2213      <entry>True if SSL compression is in use, false if not,
2214       or NULL if SSL is not in use on this connection</entry>
2215     </row>
2216     <row>
2217      <entry><structfield>client_dn</structfield></entry>
2218      <entry><type>text</type></entry>
2219      <entry>Distinguished Name (DN) field from the client certificate
2220       used, or NULL if no client certificate was supplied or if SSL
2221       is not in use on this connection. This field is truncated if the
2222       DN field is longer than <symbol>NAMEDATALEN</symbol> (64 characters
2223       in a standard build).
2224      </entry>
2225     </row>
2226     <row>
2227      <entry><structfield>client_serial</structfield></entry>
2228      <entry><type>numeric</type></entry>
2229      <entry>Serial number of the client certificate, or NULL if no client
2230      certificate was supplied or if SSL is not in use on this connection.  The
2231      combination of certificate serial number and certificate issuer uniquely
2232      identifies a certificate (unless the issuer erroneously reuses serial
2233      numbers).</entry>
2234     </row>
2235     <row>
2236      <entry><structfield>issuer_dn</structfield></entry>
2237      <entry><type>text</type></entry>
2238      <entry>DN of the issuer of the client certificate, or NULL if no client
2239      certificate was supplied or if SSL is not in use on this connection.
2240      This field is truncated like <structfield>client_dn</structfield>.</entry>
2241     </row>
2242    </tbody>
2243    </tgroup>
2244   </table>
2245
2246   <para>
2247    The <structname>pg_stat_ssl</structname> view will contain one row per
2248    backend or WAL sender process, showing statistics about SSL usage on
2249    this connection. It can be joined to <structname>pg_stat_activity</structname>
2250    or <structname>pg_stat_replication</structname> on the
2251    <structfield>pid</structfield> column to get more details about the
2252    connection.
2253   </para>
2254
2255
2256   <table id="pg-stat-archiver-view" xreflabel="pg_stat_archiver">
2257    <title><structname>pg_stat_archiver</structname> View</title>
2258
2259    <tgroup cols="3">
2260     <thead>
2261      <row>
2262       <entry>Column</entry>
2263       <entry>Type</entry>
2264       <entry>Description</entry>
2265      </row>
2266     </thead>
2267
2268     <tbody>
2269      <row>
2270       <entry><structfield>archived_count</structfield></entry>
2271       <entry><type>bigint</type></entry>
2272       <entry>Number of WAL files that have been successfully archived</entry>
2273      </row>
2274      <row>
2275       <entry><structfield>last_archived_wal</structfield></entry>
2276       <entry><type>text</type></entry>
2277       <entry>Name of the last WAL file successfully archived</entry>
2278      </row>
2279      <row>
2280       <entry><structfield>last_archived_time</structfield></entry>
2281       <entry><type>timestamp with time zone</type></entry>
2282       <entry>Time of the last successful archive operation</entry>
2283      </row>
2284      <row>
2285       <entry><structfield>failed_count</structfield></entry>
2286       <entry><type>bigint</type></entry>
2287       <entry>Number of failed attempts for archiving WAL files</entry>
2288      </row>
2289      <row>
2290       <entry><structfield>last_failed_wal</structfield></entry>
2291       <entry><type>text</type></entry>
2292       <entry>Name of the WAL file of the last failed archival operation</entry>
2293      </row>
2294      <row>
2295       <entry><structfield>last_failed_time</structfield></entry>
2296       <entry><type>timestamp with time zone</type></entry>
2297       <entry>Time of the last failed archival operation</entry>
2298      </row>
2299      <row>
2300       <entry><structfield>stats_reset</structfield></entry>
2301       <entry><type>timestamp with time zone</type></entry>
2302       <entry>Time at which these statistics were last reset</entry>
2303      </row>
2304     </tbody>
2305    </tgroup>
2306   </table>
2307
2308   <para>
2309    The <structname>pg_stat_archiver</structname> view will always have a
2310    single row, containing data about the archiver process of the cluster.
2311   </para>
2312
2313   <table id="pg-stat-bgwriter-view" xreflabel="pg_stat_bgwriter">
2314    <title><structname>pg_stat_bgwriter</structname> View</title>
2315
2316    <tgroup cols="3">
2317     <thead>
2318     <row>
2319       <entry>Column</entry>
2320       <entry>Type</entry>
2321       <entry>Description</entry>
2322      </row>
2323     </thead>
2324
2325     <tbody>
2326      <row>
2327       <entry><structfield>checkpoints_timed</structfield></entry>
2328       <entry><type>bigint</type></entry>
2329       <entry>Number of scheduled checkpoints that have been performed</entry>
2330      </row>
2331      <row>
2332       <entry><structfield>checkpoints_req</structfield></entry>
2333       <entry><type>bigint</type></entry>
2334       <entry>Number of requested checkpoints that have been performed</entry>
2335      </row>
2336      <row>
2337       <entry><structfield>checkpoint_write_time</structfield></entry>
2338       <entry><type>double precision</type></entry>
2339       <entry>
2340         Total amount of time that has been spent in the portion of
2341         checkpoint processing where files are written to disk, in milliseconds
2342       </entry>
2343      </row>
2344      <row>
2345       <entry><structfield>checkpoint_sync_time</structfield></entry>
2346       <entry><type>double precision</type></entry>
2347       <entry>
2348         Total amount of time that has been spent in the portion of
2349         checkpoint processing where files are synchronized to disk, in
2350         milliseconds
2351       </entry>
2352      </row>
2353      <row>
2354       <entry><structfield>buffers_checkpoint</structfield></entry>
2355       <entry><type>bigint</type></entry>
2356       <entry>Number of buffers written during checkpoints</entry>
2357      </row>
2358      <row>
2359       <entry><structfield>buffers_clean</structfield></entry>
2360       <entry><type>bigint</type></entry>
2361       <entry>Number of buffers written by the background writer</entry>
2362      </row>
2363      <row>
2364       <entry><structfield>maxwritten_clean</structfield></entry>
2365       <entry><type>bigint</type></entry>
2366       <entry>Number of times the background writer stopped a cleaning
2367        scan because it had written too many buffers</entry>
2368      </row>
2369      <row>
2370       <entry><structfield>buffers_backend</structfield></entry>
2371       <entry><type>bigint</type></entry>
2372       <entry>Number of buffers written directly by a backend</entry>
2373      </row>
2374      <row>
2375       <entry><structfield>buffers_backend_fsync</structfield></entry>
2376       <entry><type>bigint</type></entry>
2377       <entry>Number of times a backend had to execute its own
2378        <function>fsync</function> call (normally the background writer handles those
2379        even when the backend does its own write)</entry>
2380      </row>
2381      <row>
2382       <entry><structfield>buffers_alloc</structfield></entry>
2383       <entry><type>bigint</type></entry>
2384       <entry>Number of buffers allocated</entry>
2385      </row>
2386      <row>
2387       <entry><structfield>stats_reset</structfield></entry>
2388       <entry><type>timestamp with time zone</type></entry>
2389       <entry>Time at which these statistics were last reset</entry>
2390      </row>
2391     </tbody>
2392     </tgroup>
2393   </table>
2394
2395   <para>
2396    The <structname>pg_stat_bgwriter</structname> view will always have a
2397    single row, containing global data for the cluster.
2398   </para>
2399
2400   <table id="pg-stat-database-view" xreflabel="pg_stat_database">
2401    <title><structname>pg_stat_database</structname> View</title>
2402    <tgroup cols="3">
2403     <thead>
2404     <row>
2405       <entry>Column</entry>
2406       <entry>Type</entry>
2407       <entry>Description</entry>
2408      </row>
2409     </thead>
2410
2411    <tbody>
2412     <row>
2413      <entry><structfield>datid</structfield></entry>
2414      <entry><type>oid</type></entry>
2415      <entry>OID of a database</entry>
2416     </row>
2417     <row>
2418      <entry><structfield>datname</structfield></entry>
2419      <entry><type>name</type></entry>
2420      <entry>Name of this database</entry>
2421     </row>
2422     <row>
2423      <entry><structfield>numbackends</structfield></entry>
2424      <entry><type>integer</type></entry>
2425      <entry>Number of backends currently connected to this database.
2426      This is the only column in this view that returns a value reflecting
2427      current state; all other columns return the accumulated values since
2428      the last reset.</entry>
2429     </row>
2430     <row>
2431      <entry><structfield>xact_commit</structfield></entry>
2432      <entry><type>bigint</type></entry>
2433      <entry>Number of transactions in this database that have been
2434       committed</entry>
2435     </row>
2436     <row>
2437      <entry><structfield>xact_rollback</structfield></entry>
2438      <entry><type>bigint</type></entry>
2439      <entry>Number of transactions in this database that have been
2440       rolled back</entry>
2441     </row>
2442     <row>
2443      <entry><structfield>blks_read</structfield></entry>
2444      <entry><type>bigint</type></entry>
2445      <entry>Number of disk blocks read in this database</entry>
2446     </row>
2447     <row>
2448      <entry><structfield>blks_hit</structfield></entry>
2449      <entry><type>bigint</type></entry>
2450      <entry>Number of times disk blocks were found already in the buffer
2451       cache, so that a read was not necessary (this only includes hits in the
2452       PostgreSQL buffer cache, not the operating system's file system cache)
2453      </entry>
2454     </row>
2455     <row>
2456      <entry><structfield>tup_returned</structfield></entry>
2457      <entry><type>bigint</type></entry>
2458      <entry>Number of rows returned by queries in this database</entry>
2459     </row>
2460     <row>
2461      <entry><structfield>tup_fetched</structfield></entry>
2462      <entry><type>bigint</type></entry>
2463      <entry>Number of rows fetched by queries in this database</entry>
2464     </row>
2465     <row>
2466      <entry><structfield>tup_inserted</structfield></entry>
2467      <entry><type>bigint</type></entry>
2468      <entry>Number of rows inserted by queries in this database</entry>
2469     </row>
2470     <row>
2471      <entry><structfield>tup_updated</structfield></entry>
2472      <entry><type>bigint</type></entry>
2473      <entry>Number of rows updated by queries in this database</entry>
2474     </row>
2475     <row>
2476      <entry><structfield>tup_deleted</structfield></entry>
2477      <entry><type>bigint</type></entry>
2478      <entry>Number of rows deleted by queries in this database</entry>
2479     </row>
2480     <row>
2481      <entry><structfield>conflicts</structfield></entry>
2482      <entry><type>bigint</type></entry>
2483      <entry>Number of queries canceled due to conflicts with recovery
2484       in this database. (Conflicts occur only on standby servers; see
2485       <xref linkend="pg-stat-database-conflicts-view"/> for details.)
2486      </entry>
2487     </row>
2488     <row>
2489      <entry><structfield>temp_files</structfield></entry>
2490      <entry><type>bigint</type></entry>
2491      <entry>Number of temporary files created by queries in this database.
2492       All temporary files are counted, regardless of why the temporary file
2493       was created (e.g., sorting or hashing), and regardless of the
2494       <xref linkend="guc-log-temp-files"/> setting.
2495      </entry>
2496     </row>
2497     <row>
2498      <entry><structfield>temp_bytes</structfield></entry>
2499      <entry><type>bigint</type></entry>
2500      <entry>Total amount of data written to temporary files by queries in
2501       this database. All temporary files are counted, regardless of why
2502       the temporary file was created, and
2503       regardless of the <xref linkend="guc-log-temp-files"/> setting.
2504      </entry>
2505     </row>
2506     <row>
2507      <entry><structfield>deadlocks</structfield></entry>
2508      <entry><type>bigint</type></entry>
2509      <entry>Number of deadlocks detected in this database</entry>
2510     </row>
2511     <row>
2512      <entry><structfield>blk_read_time</structfield></entry>
2513      <entry><type>double precision</type></entry>
2514      <entry>Time spent reading data file blocks by backends in this database,
2515       in milliseconds</entry>
2516     </row>
2517     <row>
2518      <entry><structfield>blk_write_time</structfield></entry>
2519      <entry><type>double precision</type></entry>
2520      <entry>Time spent writing data file blocks by backends in this database,
2521       in milliseconds</entry>
2522     </row>
2523     <row>
2524      <entry><structfield>stats_reset</structfield></entry>
2525      <entry><type>timestamp with time zone</type></entry>
2526      <entry>Time at which these statistics were last reset</entry>
2527     </row>
2528    </tbody>
2529    </tgroup>
2530   </table>
2531
2532   <para>
2533    The <structname>pg_stat_database</structname> view will contain one row
2534    for each database in the cluster, showing database-wide statistics.
2535   </para>
2536
2537   <table id="pg-stat-database-conflicts-view" xreflabel="pg_stat_database_conflicts">
2538    <title><structname>pg_stat_database_conflicts</structname> View</title>
2539    <tgroup cols="3">
2540     <thead>
2541     <row>
2542       <entry>Column</entry>
2543       <entry>Type</entry>
2544       <entry>Description</entry>
2545      </row>
2546     </thead>
2547
2548    <tbody>
2549     <row>
2550      <entry><structfield>datid</structfield></entry>
2551      <entry><type>oid</type></entry>
2552      <entry>OID of a database</entry>
2553     </row>
2554     <row>
2555      <entry><structfield>datname</structfield></entry>
2556      <entry><type>name</type></entry>
2557      <entry>Name of this database</entry>
2558     </row>
2559     <row>
2560      <entry><structfield>confl_tablespace</structfield></entry>
2561      <entry><type>bigint</type></entry>
2562      <entry>Number of queries in this database that have been canceled due to
2563       dropped tablespaces</entry>
2564     </row>
2565     <row>
2566      <entry><structfield>confl_lock</structfield></entry>
2567      <entry><type>bigint</type></entry>
2568      <entry>Number of queries in this database that have been canceled due to
2569       lock timeouts</entry>
2570     </row>
2571     <row>
2572      <entry><structfield>confl_snapshot</structfield></entry>
2573      <entry><type>bigint</type></entry>
2574      <entry>Number of queries in this database that have been canceled due to
2575       old snapshots</entry>
2576     </row>
2577     <row>
2578      <entry><structfield>confl_bufferpin</structfield></entry>
2579      <entry><type>bigint</type></entry>
2580      <entry>Number of queries in this database that have been canceled due to
2581       pinned buffers</entry>
2582     </row>
2583     <row>
2584      <entry><structfield>confl_deadlock</structfield></entry>
2585      <entry><type>bigint</type></entry>
2586      <entry>Number of queries in this database that have been canceled due to
2587       deadlocks</entry>
2588     </row>
2589    </tbody>
2590    </tgroup>
2591   </table>
2592
2593   <para>
2594    The <structname>pg_stat_database_conflicts</structname> view will contain
2595    one row per database, showing database-wide statistics about
2596    query cancels occurring due to conflicts with recovery on standby servers.
2597    This view will only contain information on standby servers, since
2598    conflicts do not occur on master servers.
2599   </para>
2600
2601   <table id="pg-stat-all-tables-view" xreflabel="pg_stat_all_tables">
2602    <title><structname>pg_stat_all_tables</structname> View</title>
2603    <tgroup cols="3">
2604     <thead>
2605     <row>
2606       <entry>Column</entry>
2607       <entry>Type</entry>
2608       <entry>Description</entry>
2609      </row>
2610     </thead>
2611
2612    <tbody>
2613     <row>
2614      <entry><structfield>relid</structfield></entry>
2615      <entry><type>oid</type></entry>
2616      <entry>OID of a table</entry>
2617     </row>
2618     <row>
2619      <entry><structfield>schemaname</structfield></entry>
2620      <entry><type>name</type></entry>
2621      <entry>Name of the schema that this table is in</entry>
2622     </row>
2623     <row>
2624      <entry><structfield>relname</structfield></entry>
2625      <entry><type>name</type></entry>
2626      <entry>Name of this table</entry>
2627     </row>
2628     <row>
2629      <entry><structfield>seq_scan</structfield></entry>
2630      <entry><type>bigint</type></entry>
2631      <entry>Number of sequential scans initiated on this table</entry>
2632     </row>
2633     <row>
2634      <entry><structfield>seq_tup_read</structfield></entry>
2635      <entry><type>bigint</type></entry>
2636      <entry>Number of live rows fetched by sequential scans</entry>
2637     </row>
2638     <row>
2639      <entry><structfield>idx_scan</structfield></entry>
2640      <entry><type>bigint</type></entry>
2641      <entry>Number of index scans initiated on this table</entry>
2642     </row>
2643     <row>
2644      <entry><structfield>idx_tup_fetch</structfield></entry>
2645      <entry><type>bigint</type></entry>
2646      <entry>Number of live rows fetched by index scans</entry>
2647     </row>
2648     <row>
2649      <entry><structfield>n_tup_ins</structfield></entry>
2650      <entry><type>bigint</type></entry>
2651      <entry>Number of rows inserted</entry>
2652     </row>
2653     <row>
2654      <entry><structfield>n_tup_upd</structfield></entry>
2655      <entry><type>bigint</type></entry>
2656      <entry>Number of rows updated (includes HOT updated rows)</entry>
2657     </row>
2658     <row>
2659      <entry><structfield>n_tup_del</structfield></entry>
2660      <entry><type>bigint</type></entry>
2661      <entry>Number of rows deleted</entry>
2662     </row>
2663     <row>
2664      <entry><structfield>n_tup_hot_upd</structfield></entry>
2665      <entry><type>bigint</type></entry>
2666      <entry>Number of rows HOT updated (i.e., with no separate index
2667       update required)</entry>
2668     </row>
2669     <row>
2670      <entry><structfield>n_live_tup</structfield></entry>
2671      <entry><type>bigint</type></entry>
2672      <entry>Estimated number of live rows</entry>
2673     </row>
2674     <row>
2675      <entry><structfield>n_dead_tup</structfield></entry>
2676      <entry><type>bigint</type></entry>
2677      <entry>Estimated number of dead rows</entry>
2678     </row>
2679     <row>
2680      <entry><structfield>n_mod_since_analyze</structfield></entry>
2681      <entry><type>bigint</type></entry>
2682      <entry>Estimated number of rows modified since this table was last analyzed</entry>
2683     </row>
2684     <row>
2685      <entry><structfield>last_vacuum</structfield></entry>
2686      <entry><type>timestamp with time zone</type></entry>
2687      <entry>Last time at which this table was manually vacuumed
2688       (not counting <command>VACUUM FULL</command>)</entry>
2689     </row>
2690     <row>
2691      <entry><structfield>last_autovacuum</structfield></entry>
2692      <entry><type>timestamp with time zone</type></entry>
2693      <entry>Last time at which this table was vacuumed by the autovacuum
2694       daemon</entry>
2695     </row>
2696     <row>
2697      <entry><structfield>last_analyze</structfield></entry>
2698      <entry><type>timestamp with time zone</type></entry>
2699      <entry>Last time at which this table was manually analyzed</entry>
2700     </row>
2701     <row>
2702      <entry><structfield>last_autoanalyze</structfield></entry>
2703      <entry><type>timestamp with time zone</type></entry>
2704      <entry>Last time at which this table was analyzed by the autovacuum
2705       daemon</entry>
2706     </row>
2707     <row>
2708      <entry><structfield>vacuum_count</structfield></entry>
2709      <entry><type>bigint</type></entry>
2710      <entry>Number of times this table has been manually vacuumed
2711       (not counting <command>VACUUM FULL</command>)</entry>
2712     </row>
2713     <row>
2714      <entry><structfield>autovacuum_count</structfield></entry>
2715      <entry><type>bigint</type></entry>
2716      <entry>Number of times this table has been vacuumed by the autovacuum
2717       daemon</entry>
2718     </row>
2719     <row>
2720      <entry><structfield>analyze_count</structfield></entry>
2721      <entry><type>bigint</type></entry>
2722      <entry>Number of times this table has been manually analyzed</entry>
2723     </row>
2724     <row>
2725      <entry><structfield>autoanalyze_count</structfield></entry>
2726      <entry><type>bigint</type></entry>
2727      <entry>Number of times this table has been analyzed by the autovacuum
2728       daemon</entry>
2729     </row>
2730    </tbody>
2731    </tgroup>
2732   </table>
2733
2734   <para>
2735    The <structname>pg_stat_all_tables</structname> view will contain
2736    one row for each table in the current database (including TOAST
2737    tables), showing statistics about accesses to that specific table. The
2738    <structname>pg_stat_user_tables</structname> and
2739    <structname>pg_stat_sys_tables</structname> views
2740    contain the same information,
2741    but filtered to only show user and system tables respectively.
2742   </para>
2743
2744   <table id="pg-stat-all-indexes-view" xreflabel="pg_stat_all_indexes">
2745    <title><structname>pg_stat_all_indexes</structname> View</title>
2746    <tgroup cols="3">
2747     <thead>
2748     <row>
2749       <entry>Column</entry>
2750       <entry>Type</entry>
2751       <entry>Description</entry>
2752      </row>
2753     </thead>
2754
2755    <tbody>
2756     <row>
2757      <entry><structfield>relid</structfield></entry>
2758      <entry><type>oid</type></entry>
2759      <entry>OID of the table for this index</entry>
2760     </row>
2761     <row>
2762      <entry><structfield>indexrelid</structfield></entry>
2763      <entry><type>oid</type></entry>
2764      <entry>OID of this index</entry>
2765     </row>
2766     <row>
2767      <entry><structfield>schemaname</structfield></entry>
2768      <entry><type>name</type></entry>
2769      <entry>Name of the schema this index is in</entry>
2770     </row>
2771     <row>
2772      <entry><structfield>relname</structfield></entry>
2773      <entry><type>name</type></entry>
2774      <entry>Name of the table for this index</entry>
2775     </row>
2776     <row>
2777      <entry><structfield>indexrelname</structfield></entry>
2778      <entry><type>name</type></entry>
2779      <entry>Name of this index</entry>
2780     </row>
2781     <row>
2782      <entry><structfield>idx_scan</structfield></entry>
2783      <entry><type>bigint</type></entry>
2784      <entry>Number of index scans initiated on this index</entry>
2785     </row>
2786     <row>
2787      <entry><structfield>idx_tup_read</structfield></entry>
2788      <entry><type>bigint</type></entry>
2789      <entry>Number of index entries returned by scans on this index</entry>
2790     </row>
2791     <row>
2792      <entry><structfield>idx_tup_fetch</structfield></entry>
2793      <entry><type>bigint</type></entry>
2794      <entry>Number of live table rows fetched by simple index scans using this
2795       index</entry>
2796     </row>
2797    </tbody>
2798    </tgroup>
2799   </table>
2800
2801   <para>
2802    The <structname>pg_stat_all_indexes</structname> view will contain
2803    one row for each index in the current database,
2804    showing statistics about accesses to that specific index. The
2805    <structname>pg_stat_user_indexes</structname> and
2806    <structname>pg_stat_sys_indexes</structname> views
2807    contain the same information,
2808    but filtered to only show user and system indexes respectively.
2809   </para>
2810
2811   <para>
2812    Indexes can be used by simple index scans, <quote>bitmap</quote> index scans,
2813    and the optimizer.  In a bitmap scan
2814    the output of several indexes can be combined via AND or OR rules,
2815    so it is difficult to associate individual heap row fetches
2816    with specific indexes when a bitmap scan is used.  Therefore, a bitmap
2817    scan increments the
2818    <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_read</structfield>
2819    count(s) for the index(es) it uses, and it increments the
2820    <structname>pg_stat_all_tables</structname>.<structfield>idx_tup_fetch</structfield>
2821    count for the table, but it does not affect
2822    <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_fetch</structfield>.
2823    The optimizer also accesses indexes to check for supplied constants
2824    whose values are outside the recorded range of the optimizer statistics
2825    because the optimizer statistics might be stale.
2826   </para>
2827
2828   <note>
2829    <para>
2830     The <structfield>idx_tup_read</structfield> and <structfield>idx_tup_fetch</structfield> counts
2831     can be different even without any use of bitmap scans,
2832     because <structfield>idx_tup_read</structfield> counts
2833     index entries retrieved from the index while <structfield>idx_tup_fetch</structfield>
2834     counts live rows fetched from the table.  The latter will be less if any
2835     dead or not-yet-committed rows are fetched using the index, or if any
2836     heap fetches are avoided by means of an index-only scan.
2837    </para>
2838   </note>
2839
2840   <table id="pg-statio-all-tables-view" xreflabel="pg_statio_all_tables">
2841    <title><structname>pg_statio_all_tables</structname> View</title>
2842    <tgroup cols="3">
2843     <thead>
2844     <row>
2845       <entry>Column</entry>
2846       <entry>Type</entry>
2847       <entry>Description</entry>
2848      </row>
2849     </thead>
2850
2851    <tbody>
2852     <row>
2853      <entry><structfield>relid</structfield></entry>
2854      <entry><type>oid</type></entry>
2855      <entry>OID of a table</entry>
2856     </row>
2857     <row>
2858      <entry><structfield>schemaname</structfield></entry>
2859      <entry><type>name</type></entry>
2860      <entry>Name of the schema that this table is in</entry>
2861     </row>
2862     <row>
2863      <entry><structfield>relname</structfield></entry>
2864      <entry><type>name</type></entry>
2865      <entry>Name of this table</entry>
2866     </row>
2867     <row>
2868      <entry><structfield>heap_blks_read</structfield></entry>
2869      <entry><type>bigint</type></entry>
2870      <entry>Number of disk blocks read from this table</entry>
2871     </row>
2872     <row>
2873      <entry><structfield>heap_blks_hit</structfield></entry>
2874      <entry><type>bigint</type></entry>
2875      <entry>Number of buffer hits in this table</entry>
2876     </row>
2877     <row>
2878      <entry><structfield>idx_blks_read</structfield></entry>
2879      <entry><type>bigint</type></entry>
2880      <entry>Number of disk blocks read from all indexes on this table</entry>
2881     </row>
2882     <row>
2883      <entry><structfield>idx_blks_hit</structfield></entry>
2884      <entry><type>bigint</type></entry>
2885      <entry>Number of buffer hits in all indexes on this table</entry>
2886     </row>
2887     <row>
2888      <entry><structfield>toast_blks_read</structfield></entry>
2889      <entry><type>bigint</type></entry>
2890      <entry>Number of disk blocks read from this table's TOAST table (if any)</entry>
2891     </row>
2892     <row>
2893      <entry><structfield>toast_blks_hit</structfield></entry>
2894      <entry><type>bigint</type></entry>
2895      <entry>Number of buffer hits in this table's TOAST table (if any)</entry>
2896     </row>
2897     <row>
2898      <entry><structfield>tidx_blks_read</structfield></entry>
2899      <entry><type>bigint</type></entry>
2900      <entry>Number of disk blocks read from this table's TOAST table indexes (if any)</entry>
2901     </row>
2902     <row>
2903      <entry><structfield>tidx_blks_hit</structfield></entry>
2904      <entry><type>bigint</type></entry>
2905      <entry>Number of buffer hits in this table's TOAST table indexes (if any)</entry>
2906     </row>
2907    </tbody>
2908    </tgroup>
2909   </table>
2910
2911   <para>
2912    The <structname>pg_statio_all_tables</structname> view will contain
2913    one row for each table in the current database (including TOAST
2914    tables), showing statistics about I/O on that specific table. The
2915    <structname>pg_statio_user_tables</structname> and
2916    <structname>pg_statio_sys_tables</structname> views
2917    contain the same information,
2918    but filtered to only show user and system tables respectively.
2919   </para>
2920
2921   <table id="pg-statio-all-indexes-view" xreflabel="pg_statio_all_indexes">
2922    <title><structname>pg_statio_all_indexes</structname> View</title>
2923    <tgroup cols="3">
2924     <thead>
2925     <row>
2926       <entry>Column</entry>
2927       <entry>Type</entry>
2928       <entry>Description</entry>
2929      </row>
2930     </thead>
2931
2932    <tbody>
2933     <row>
2934      <entry><structfield>relid</structfield></entry>
2935      <entry><type>oid</type></entry>
2936      <entry>OID of the table for this index</entry>
2937     </row>
2938     <row>
2939      <entry><structfield>indexrelid</structfield></entry>
2940      <entry><type>oid</type></entry>
2941      <entry>OID of this index</entry>
2942     </row>
2943     <row>
2944      <entry><structfield>schemaname</structfield></entry>
2945      <entry><type>name</type></entry>
2946      <entry>Name of the schema this index is in</entry>
2947     </row>
2948     <row>
2949      <entry><structfield>relname</structfield></entry>
2950      <entry><type>name</type></entry>
2951      <entry>Name of the table for this index</entry>
2952     </row>
2953     <row>
2954      <entry><structfield>indexrelname</structfield></entry>
2955      <entry><type>name</type></entry>
2956      <entry>Name of this index</entry>
2957     </row>
2958     <row>
2959      <entry><structfield>idx_blks_read</structfield></entry>
2960      <entry><type>bigint</type></entry>
2961      <entry>Number of disk blocks read from this index</entry>
2962     </row>
2963     <row>
2964      <entry><structfield>idx_blks_hit</structfield></entry>
2965      <entry><type>bigint</type></entry>
2966      <entry>Number of buffer hits in this index</entry>
2967     </row>
2968    </tbody>
2969    </tgroup>
2970   </table>
2971
2972   <para>
2973    The <structname>pg_statio_all_indexes</structname> view will contain
2974    one row for each index in the current database,
2975    showing statistics about I/O on that specific index. The
2976    <structname>pg_statio_user_indexes</structname> and
2977    <structname>pg_statio_sys_indexes</structname> views
2978    contain the same information,
2979    but filtered to only show user and system indexes respectively.
2980   </para>
2981
2982   <table id="pg-statio-all-sequences-view" xreflabel="pg_statio_all_sequences">
2983    <title><structname>pg_statio_all_sequences</structname> View</title>
2984    <tgroup cols="3">
2985     <thead>
2986     <row>
2987       <entry>Column</entry>
2988       <entry>Type</entry>
2989       <entry>Description</entry>
2990      </row>
2991     </thead>
2992
2993    <tbody>
2994     <row>
2995      <entry><structfield>relid</structfield></entry>
2996      <entry><type>oid</type></entry>
2997      <entry>OID of a sequence</entry>
2998     </row>
2999     <row>
3000      <entry><structfield>schemaname</structfield></entry>
3001      <entry><type>name</type></entry>
3002      <entry>Name of the schema this sequence is in</entry>
3003     </row>
3004     <row>
3005      <entry><structfield>relname</structfield></entry>
3006      <entry><type>name</type></entry>
3007      <entry>Name of this sequence</entry>
3008     </row>
3009     <row>
3010      <entry><structfield>blks_read</structfield></entry>
3011      <entry><type>bigint</type></entry>
3012      <entry>Number of disk blocks read from this sequence</entry>
3013     </row>
3014     <row>
3015      <entry><structfield>blks_hit</structfield></entry>
3016      <entry><type>bigint</type></entry>
3017      <entry>Number of buffer hits in this sequence</entry>
3018     </row>
3019    </tbody>
3020    </tgroup>
3021   </table>
3022
3023   <para>
3024    The <structname>pg_statio_all_sequences</structname> view will contain
3025    one row for each sequence in the current database,
3026    showing statistics about I/O on that specific sequence.
3027   </para>
3028
3029   <table id="pg-stat-user-functions-view" xreflabel="pg_stat_user_functions">
3030    <title><structname>pg_stat_user_functions</structname> View</title>
3031    <tgroup cols="3">
3032     <thead>
3033     <row>
3034       <entry>Column</entry>
3035       <entry>Type</entry>
3036       <entry>Description</entry>
3037      </row>
3038     </thead>
3039
3040    <tbody>
3041     <row>
3042      <entry><structfield>funcid</structfield></entry>
3043      <entry><type>oid</type></entry>
3044      <entry>OID of a function</entry>
3045     </row>
3046     <row>
3047      <entry><structfield>schemaname</structfield></entry>
3048      <entry><type>name</type></entry>
3049      <entry>Name of the schema this function is in</entry>
3050     </row>
3051     <row>
3052      <entry><structfield>funcname</structfield></entry>
3053      <entry><type>name</type></entry>
3054      <entry>Name of this function</entry>
3055     </row>
3056     <row>
3057      <entry><structfield>calls</structfield></entry>
3058      <entry><type>bigint</type></entry>
3059      <entry>Number of times this function has been called</entry>
3060     </row>
3061     <row>
3062      <entry><structfield>total_time</structfield></entry>
3063      <entry><type>double precision</type></entry>
3064      <entry>Total time spent in this function and all other functions
3065      called by it, in milliseconds</entry>
3066     </row>
3067     <row>
3068      <entry><structfield>self_time</structfield></entry>
3069      <entry><type>double precision</type></entry>
3070      <entry>Total time spent in this function itself, not including
3071      other functions called by it, in milliseconds</entry>
3072     </row>
3073    </tbody>
3074    </tgroup>
3075   </table>
3076
3077   <para>
3078    The <structname>pg_stat_user_functions</structname> view will contain
3079    one row for each tracked function, showing statistics about executions of
3080    that function.  The <xref linkend="guc-track-functions"/> parameter
3081    controls exactly which functions are tracked.
3082   </para>
3083
3084  </sect2>
3085
3086  <sect2 id="monitoring-stats-functions">
3087   <title>Statistics Functions</title>
3088
3089   <para>
3090    Other ways of looking at the statistics can be set up by writing
3091    queries that use the same underlying statistics access functions used by
3092    the standard views shown above.  For details such as the functions' names,
3093    consult the definitions of the standard views.  (For example, in
3094    <application>psql</application> you could issue <literal>\d+ pg_stat_activity</literal>.)
3095    The access functions for per-database statistics take a database OID as an
3096    argument to identify which database to report on.
3097    The per-table and per-index functions take a table or index OID.
3098    The functions for per-function statistics take a function OID.
3099    Note that only tables, indexes, and functions in the current database
3100    can be seen with these functions.
3101   </para>
3102
3103   <para>
3104    Additional functions related to statistics collection are listed in <xref
3105    linkend="monitoring-stats-funcs-table"/>.
3106   </para>
3107
3108   <table id="monitoring-stats-funcs-table">
3109    <title>Additional Statistics Functions</title>
3110
3111    <tgroup cols="3">
3112     <thead>
3113      <row>
3114       <entry>Function</entry>
3115       <entry>Return Type</entry>
3116       <entry>Description</entry>
3117      </row>
3118     </thead>
3119
3120     <tbody>
3121
3122      <row>
3123        <!-- See also the entry for this in func.sgml -->
3124       <entry><literal><function>pg_backend_pid()</function></literal></entry>
3125       <entry><type>integer</type></entry>
3126       <entry>
3127        Process ID of the server process handling the current session
3128       </entry>
3129      </row>
3130
3131      <row>
3132       <entry><literal><function>pg_stat_get_activity</function>(<type>integer</type>)</literal><indexterm><primary>pg_stat_get_activity</primary></indexterm></entry>
3133       <entry><type>setof record</type></entry>
3134       <entry>
3135        Returns a record of information about the backend with the specified PID, or
3136        one record for each active backend in the system if <symbol>NULL</symbol> is
3137        specified. The fields returned are a subset of those in the
3138        <structname>pg_stat_activity</structname> view.
3139       </entry>
3140      </row>
3141
3142      <row>
3143       <entry><literal><function>pg_stat_get_snapshot_timestamp()</function></literal><indexterm><primary>pg_stat_get_snapshot_timestamp</primary></indexterm></entry>
3144       <entry><type>timestamp with time zone</type></entry>
3145       <entry>
3146        Returns the timestamp of the current statistics snapshot
3147       </entry>
3148      </row>
3149
3150      <row>
3151       <entry><literal><function>pg_stat_clear_snapshot()</function></literal><indexterm><primary>pg_stat_clear_snapshot</primary></indexterm></entry>
3152       <entry><type>void</type></entry>
3153       <entry>
3154        Discard the current statistics snapshot
3155       </entry>
3156      </row>
3157
3158      <row>
3159       <entry><literal><function>pg_stat_reset()</function></literal><indexterm><primary>pg_stat_reset</primary></indexterm></entry>
3160       <entry><type>void</type></entry>
3161       <entry>
3162        Reset all statistics counters for the current database to zero
3163        (requires superuser privileges by default, but EXECUTE for this
3164        function can be granted to others.)
3165       </entry>
3166      </row>
3167
3168      <row>
3169       <entry><literal><function>pg_stat_reset_shared</function>(text)</literal><indexterm><primary>pg_stat_reset_shared</primary></indexterm></entry>
3170       <entry><type>void</type></entry>
3171       <entry>
3172        Reset some cluster-wide statistics counters to zero, depending on the
3173        argument (requires superuser privileges by default, but EXECUTE for
3174        this function can be granted to others).
3175        Calling <literal>pg_stat_reset_shared('bgwriter')</literal> will zero all the
3176        counters shown in the <structname>pg_stat_bgwriter</structname> view.
3177        Calling <literal>pg_stat_reset_shared('archiver')</literal> will zero all the
3178        counters shown in the <structname>pg_stat_archiver</structname> view.
3179       </entry>
3180      </row>
3181
3182      <row>
3183       <entry><literal><function>pg_stat_reset_single_table_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_table_counters</primary></indexterm></entry>
3184       <entry><type>void</type></entry>
3185       <entry>
3186        Reset statistics for a single table or index in the current database to
3187        zero (requires superuser privileges by default, but EXECUTE for this
3188        function can be granted to others)
3189       </entry>
3190      </row>
3191
3192      <row>
3193       <entry><literal><function>pg_stat_reset_single_function_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_function_counters</primary></indexterm></entry>
3194       <entry><type>void</type></entry>
3195       <entry>
3196        Reset statistics for a single function in the current database to
3197        zero (requires superuser privileges by default, but EXECUTE for this
3198        function can be granted to others)
3199       </entry>
3200      </row>
3201     </tbody>
3202    </tgroup>
3203   </table>
3204
3205   <para>
3206    <function>pg_stat_get_activity</function>, the underlying function of
3207    the <structname>pg_stat_activity</structname> view, returns a set of records
3208    containing all the available information about each backend process.
3209    Sometimes it may be more convenient to obtain just a subset of this
3210    information.  In such cases, an older set of per-backend statistics
3211    access functions can be used; these are shown in <xref
3212    linkend="monitoring-stats-backend-funcs-table"/>.
3213    These access functions use a backend ID number, which ranges from one
3214    to the number of currently active backends.
3215    The function <function>pg_stat_get_backend_idset</function> provides a
3216    convenient way to generate one row for each active backend for
3217    invoking these functions.  For example, to show the <acronym>PID</acronym>s and
3218    current queries of all backends:
3219
3220 <programlisting>
3221 SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
3222        pg_stat_get_backend_activity(s.backendid) AS query
3223     FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
3224 </programlisting>
3225   </para>
3226
3227   <table id="monitoring-stats-backend-funcs-table">
3228    <title>Per-Backend Statistics Functions</title>
3229
3230    <tgroup cols="3">
3231     <thead>
3232      <row>
3233       <entry>Function</entry>
3234       <entry>Return Type</entry>
3235       <entry>Description</entry>
3236      </row>
3237     </thead>
3238
3239     <tbody>
3240
3241      <row>
3242       <entry><literal><function>pg_stat_get_backend_idset()</function></literal></entry>
3243       <entry><type>setof integer</type></entry>
3244       <entry>Set of currently active backend ID numbers (from 1 to the
3245        number of active backends)</entry>
3246      </row>
3247
3248      <row>
3249       <entry><literal><function>pg_stat_get_backend_activity(integer)</function></literal></entry>
3250       <entry><type>text</type></entry>
3251       <entry>Text of this backend's most recent query</entry>
3252      </row>
3253
3254      <row>
3255       <entry><literal><function>pg_stat_get_backend_activity_start(integer)</function></literal></entry>
3256       <entry><type>timestamp with time zone</type></entry>
3257       <entry>Time when the most recent query was started</entry>
3258      </row>
3259
3260      <row>
3261       <entry><literal><function>pg_stat_get_backend_client_addr(integer)</function></literal></entry>
3262       <entry><type>inet</type></entry>
3263       <entry>IP address of the client connected to this backend</entry>
3264      </row>
3265
3266      <row>
3267       <entry><literal><function>pg_stat_get_backend_client_port(integer)</function></literal></entry>
3268       <entry><type>integer</type></entry>
3269       <entry>TCP port number that the client is using for communication</entry>
3270      </row>
3271
3272      <row>
3273       <entry><literal><function>pg_stat_get_backend_dbid(integer)</function></literal></entry>
3274       <entry><type>oid</type></entry>
3275       <entry>OID of the database this backend is connected to</entry>
3276      </row>
3277
3278      <row>
3279       <entry><literal><function>pg_stat_get_backend_pid(integer)</function></literal></entry>
3280       <entry><type>integer</type></entry>
3281       <entry>Process ID of this backend</entry>
3282      </row>
3283
3284      <row>
3285       <entry><literal><function>pg_stat_get_backend_start(integer)</function></literal></entry>
3286       <entry><type>timestamp with time zone</type></entry>
3287       <entry>Time when this process was started</entry>
3288      </row>
3289
3290      <row>
3291       <entry><literal><function>pg_stat_get_backend_userid(integer)</function></literal></entry>
3292       <entry><type>oid</type></entry>
3293       <entry>OID of the user logged into this backend</entry>
3294      </row>
3295
3296       <row>
3297        <entry><literal><function>pg_stat_get_backend_wait_event_type(integer)</function></literal></entry>
3298        <entry><type>text</type></entry>
3299         <entry>Wait event type name if backend is currently waiting, otherwise NULL.
3300         See <xref linkend="wait-event-table"/> for details.
3301         </entry>
3302       </row>
3303
3304      <row>
3305       <entry><literal><function>pg_stat_get_backend_wait_event(integer)</function></literal></entry>
3306       <entry><type>text</type></entry>
3307        <entry>Wait event name if backend is currently waiting, otherwise NULL.
3308        See <xref linkend="wait-event-table"/> for details.
3309        </entry>
3310      </row>
3311
3312      <row>
3313       <entry><literal><function>pg_stat_get_backend_xact_start(integer)</function></literal></entry>
3314       <entry><type>timestamp with time zone</type></entry>
3315       <entry>Time when the current transaction was started</entry>
3316      </row>
3317
3318     </tbody>
3319    </tgroup>
3320   </table>
3321
3322  </sect2>
3323  </sect1>
3324
3325  <sect1 id="monitoring-locks">
3326   <title>Viewing Locks</title>
3327
3328   <indexterm zone="monitoring-locks">
3329    <primary>lock</primary>
3330    <secondary>monitoring</secondary>
3331   </indexterm>
3332
3333   <para>
3334    Another useful tool for monitoring database activity is the
3335    <structname>pg_locks</structname> system table.  It allows the
3336    database administrator to view information about the outstanding
3337    locks in the lock manager. For example, this capability can be used
3338    to:
3339
3340    <itemizedlist>
3341     <listitem>
3342      <para>
3343       View all the locks currently outstanding, all the locks on
3344       relations in a particular database, all the locks on a
3345       particular relation, or all the locks held by a particular
3346       <productname>PostgreSQL</productname> session.
3347      </para>
3348     </listitem>
3349
3350     <listitem>
3351      <para>
3352       Determine the relation in the current database with the most
3353       ungranted locks (which might be a source of contention among
3354       database clients).
3355      </para>
3356     </listitem>
3357
3358     <listitem>
3359      <para>
3360       Determine the effect of lock contention on overall database
3361       performance, as well as the extent to which contention varies
3362       with overall database traffic.
3363      </para>
3364     </listitem>
3365    </itemizedlist>
3366
3367    Details of the <structname>pg_locks</structname> view appear in
3368    <xref linkend="view-pg-locks"/>.
3369    For more information on locking and managing concurrency with
3370    <productname>PostgreSQL</productname>, refer to <xref linkend="mvcc"/>.
3371   </para>
3372  </sect1>
3373
3374  <sect1 id="progress-reporting">
3375   <title>Progress Reporting</title>
3376
3377   <para>
3378    <productname>PostgreSQL</productname> has the ability to report the progress of
3379    certain commands during command execution.  Currently, the only command
3380    which supports progress reporting is <command>VACUUM</command>.  This may be
3381    expanded in the future.
3382   </para>
3383
3384  <sect2 id="vacuum-progress-reporting">
3385   <title>VACUUM Progress Reporting</title>
3386
3387   <para>
3388    Whenever <command>VACUUM</command> is running, the
3389    <structname>pg_stat_progress_vacuum</structname> view will contain
3390    one row for each backend (including autovacuum worker processes) that is
3391    currently vacuuming.  The tables below describe the information
3392    that will be reported and provide information about how to interpret it.
3393    Progress reporting is not currently supported for <command>VACUUM FULL</command>
3394    and backends running <command>VACUUM FULL</command> will not be listed in this
3395    view.
3396   </para>
3397
3398   <table id="pg-stat-progress-vacuum-view" xreflabel="pg_stat_progress_vacuum">
3399    <title><structname>pg_stat_progress_vacuum</structname> View</title>
3400    <tgroup cols="3">
3401     <thead>
3402     <row>
3403       <entry>Column</entry>
3404       <entry>Type</entry>
3405       <entry>Description</entry>
3406      </row>
3407     </thead>
3408
3409    <tbody>
3410     <row>
3411      <entry><structfield>pid</structfield></entry>
3412      <entry><type>integer</type></entry>
3413      <entry>Process ID of backend.</entry>
3414     </row>
3415     <row>
3416      <entry><structfield>datid</structfield></entry>
3417      <entry><type>oid</type></entry>
3418      <entry>OID of the database to which this backend is connected.</entry>
3419     </row>
3420     <row>
3421      <entry><structfield>datname</structfield></entry>
3422      <entry><type>name</type></entry>
3423      <entry>Name of the database to which this backend is connected.</entry>
3424     </row>
3425     <row>
3426      <entry><structfield>relid</structfield></entry>
3427      <entry><type>oid</type></entry>
3428      <entry>OID of the table being vacuumed.</entry>
3429     </row>
3430     <row>
3431      <entry><structfield>phase</structfield></entry>
3432      <entry><type>text</type></entry>
3433      <entry>
3434        Current processing phase of vacuum.  See <xref linkend='vacuum-phases'/>.
3435      </entry>
3436     </row>
3437     <row>
3438      <entry><structfield>heap_blks_total</structfield></entry>
3439      <entry><type>bigint</type></entry>
3440      <entry>
3441        Total number of heap blocks in the table.  This number is reported
3442        as of the beginning of the scan; blocks added later will not be (and
3443        need not be) visited by this <command>VACUUM</command>.
3444      </entry>
3445     </row>
3446     <row>
3447      <entry><structfield>heap_blks_scanned</structfield></entry>
3448      <entry><type>bigint</type></entry>
3449      <entry>
3450        Number of heap blocks scanned.  Because the
3451        <link linkend="storage-vm">visibility map</link> is used to optimize scans,
3452        some blocks will be skipped without inspection; skipped blocks are
3453        included in this total, so that this number will eventually become
3454        equal to <structfield>heap_blks_total</structfield> when the vacuum is complete.
3455        This counter only advances when the phase is <literal>scanning heap</literal>.
3456      </entry>
3457     </row>
3458     <row>
3459      <entry><structfield>heap_blks_vacuumed</structfield></entry>
3460      <entry><type>bigint</type></entry>
3461      <entry>
3462        Number of heap blocks vacuumed.  Unless the table has no indexes, this
3463        counter only advances when the phase is <literal>vacuuming heap</literal>.
3464        Blocks that contain no dead tuples are skipped, so the counter may
3465        sometimes skip forward in large increments.
3466      </entry>
3467     </row>
3468     <row>
3469      <entry><structfield>index_vacuum_count</structfield></entry>
3470      <entry><type>bigint</type></entry>
3471      <entry>
3472        Number of completed index vacuum cycles.
3473      </entry>
3474     </row>
3475     <row>
3476      <entry><structfield>max_dead_tuples</structfield></entry>
3477      <entry><type>bigint</type></entry>
3478      <entry>
3479       Number of dead tuples that we can store before needing to perform
3480       an index vacuum cycle, based on
3481       <xref linkend="guc-maintenance-work-mem"/>.
3482      </entry>
3483     </row>
3484     <row>
3485      <entry><structfield>num_dead_tuples</structfield></entry>
3486      <entry><type>bigint</type></entry>
3487      <entry>
3488        Number of dead tuples collected since the last index vacuum cycle.
3489      </entry>
3490     </row>
3491    </tbody>
3492    </tgroup>
3493   </table>
3494
3495   <table id="vacuum-phases">
3496    <title>VACUUM phases</title>
3497    <tgroup cols="2">
3498     <thead>
3499     <row>
3500       <entry>Phase</entry>
3501       <entry>Description</entry>
3502      </row>
3503     </thead>
3504
3505    <tbody>
3506     <row>
3507      <entry><literal>initializing</literal></entry>
3508      <entry>
3509        <command>VACUUM</command> is preparing to begin scanning the heap.  This
3510        phase is expected to be very brief.
3511      </entry>
3512     </row>
3513     <row>
3514      <entry><literal>scanning heap</literal></entry>
3515      <entry>
3516        <command>VACUUM</command> is currently scanning the heap.  It will prune and
3517        defragment each page if required, and possibly perform freezing
3518        activity.  The <structfield>heap_blks_scanned</structfield> column can be used
3519        to monitor the progress of the scan.
3520      </entry>
3521     </row>
3522     <row>
3523      <entry><literal>vacuuming indexes</literal></entry>
3524      <entry>
3525        <command>VACUUM</command> is currently vacuuming the indexes.  If a table has
3526        any indexes, this will happen at least once per vacuum, after the heap
3527        has been completely scanned.  It may happen multiple times per vacuum
3528        if <xref linkend="guc-maintenance-work-mem"/> is insufficient to
3529        store the number of dead tuples found.
3530      </entry>
3531     </row>
3532     <row>
3533      <entry><literal>vacuuming heap</literal></entry>
3534      <entry>
3535        <command>VACUUM</command> is currently vacuuming the heap.  Vacuuming the heap
3536        is distinct from scanning the heap, and occurs after each instance of
3537        vacuuming indexes.  If <structfield>heap_blks_scanned</structfield> is less than
3538        <structfield>heap_blks_total</structfield>, the system will return to scanning
3539        the heap after this phase is completed; otherwise, it will begin
3540        cleaning up indexes after this phase is completed.
3541      </entry>
3542     </row>
3543     <row>
3544      <entry><literal>cleaning up indexes</literal></entry>
3545      <entry>
3546        <command>VACUUM</command> is currently cleaning up indexes.  This occurs after
3547        the heap has been completely scanned and all vacuuming of the indexes
3548        and the heap has been completed.
3549      </entry>
3550     </row>
3551     <row>
3552      <entry><literal>truncating heap</literal></entry>
3553      <entry>
3554        <command>VACUUM</command> is currently truncating the heap so as to return
3555        empty pages at the end of the relation to the operating system.  This
3556        occurs after cleaning up indexes.
3557      </entry>
3558     </row>
3559     <row>
3560      <entry><literal>performing final cleanup</literal></entry>
3561      <entry>
3562        <command>VACUUM</command> is performing final cleanup.  During this phase,
3563        <command>VACUUM</command> will vacuum the free space map, update statistics
3564        in <literal>pg_class</literal>, and report statistics to the statistics
3565        collector.  When this phase is completed, <command>VACUUM</command> will end.
3566      </entry>
3567     </row>
3568    </tbody>
3569    </tgroup>
3570   </table>
3571
3572  </sect2>
3573  </sect1>
3574
3575  <sect1 id="dynamic-trace">
3576   <title>Dynamic Tracing</title>
3577
3578  <indexterm zone="dynamic-trace">
3579   <primary>DTrace</primary>
3580  </indexterm>
3581
3582   <para>
3583    <productname>PostgreSQL</productname> provides facilities to support
3584    dynamic tracing of the database server. This allows an external
3585    utility to be called at specific points in the code and thereby trace
3586    execution.
3587   </para>
3588
3589   <para>
3590    A number of probes or trace points are already inserted into the source
3591    code. These probes are intended to be used by database developers and
3592    administrators. By default the probes are not compiled into
3593    <productname>PostgreSQL</productname>; the user needs to explicitly tell
3594    the configure script to make the probes available.
3595   </para>
3596
3597   <para>
3598    Currently, the
3599    <ulink url="https://en.wikipedia.org/wiki/DTrace">DTrace</ulink>
3600    utility is supported, which, at the time of this writing, is available
3601    on Solaris, macOS, FreeBSD, NetBSD, and Oracle Linux.  The
3602    <ulink url="http://sourceware.org/systemtap/">SystemTap</ulink> project
3603    for Linux provides a DTrace equivalent and can also be used.  Supporting other dynamic
3604    tracing utilities is theoretically possible by changing the definitions for
3605    the macros in <filename>src/include/utils/probes.h</filename>.
3606   </para>
3607
3608   <sect2 id="compiling-for-trace">
3609    <title>Compiling for Dynamic Tracing</title>
3610
3611   <para>
3612    By default, probes are not available, so you will need to
3613    explicitly tell the configure script to make the probes available
3614    in <productname>PostgreSQL</productname>. To include DTrace support
3615    specify <option>--enable-dtrace</option> to configure.  See <xref
3616    linkend="install-procedure"/> for further information.
3617   </para>
3618   </sect2>
3619
3620   <sect2 id="trace-points">
3621    <title>Built-in Probes</title>
3622
3623   <para>
3624    A number of standard probes are provided in the source code,
3625    as shown in <xref linkend="dtrace-probe-point-table"/>;
3626    <xref linkend="typedefs-table"/>
3627    shows the types used in the probes.  More probes can certainly be
3628    added to enhance <productname>PostgreSQL</productname>'s observability.
3629   </para>
3630
3631  <table id="dtrace-probe-point-table">
3632   <title>Built-in DTrace Probes</title>
3633   <tgroup cols="3">
3634    <thead>
3635     <row>
3636      <entry>Name</entry>
3637      <entry>Parameters</entry>
3638      <entry>Description</entry>
3639     </row>
3640    </thead>
3641
3642    <tbody>
3643
3644     <row>
3645      <entry><literal>transaction-start</literal></entry>
3646      <entry><literal>(LocalTransactionId)</literal></entry>
3647      <entry>Probe that fires at the start of a new transaction.
3648       arg0 is the transaction ID.</entry>
3649     </row>
3650     <row>
3651      <entry><literal>transaction-commit</literal></entry>
3652      <entry><literal>(LocalTransactionId)</literal></entry>
3653      <entry>Probe that fires when a transaction completes successfully.
3654       arg0 is the transaction ID.</entry>
3655     </row>
3656     <row>
3657      <entry><literal>transaction-abort</literal></entry>
3658      <entry><literal>(LocalTransactionId)</literal></entry>
3659      <entry>Probe that fires when a transaction completes unsuccessfully.
3660       arg0 is the transaction ID.</entry>
3661     </row>
3662     <row>
3663      <entry><literal>query-start</literal></entry>
3664      <entry><literal>(const char *)</literal></entry>
3665      <entry>Probe that fires when the processing of a query is started.
3666       arg0 is the query string.</entry>
3667     </row>
3668     <row>
3669      <entry><literal>query-done</literal></entry>
3670      <entry><literal>(const char *)</literal></entry>
3671      <entry>Probe that fires when the processing of a query is complete.
3672       arg0 is the query string.</entry>
3673     </row>
3674     <row>
3675      <entry><literal>query-parse-start</literal></entry>
3676      <entry><literal>(const char *)</literal></entry>
3677      <entry>Probe that fires when the parsing of a query is started.
3678       arg0 is the query string.</entry>
3679     </row>
3680     <row>
3681      <entry><literal>query-parse-done</literal></entry>
3682      <entry><literal>(const char *)</literal></entry>
3683      <entry>Probe that fires when the parsing of a query is complete.
3684       arg0 is the query string.</entry>
3685     </row>
3686     <row>
3687      <entry><literal>query-rewrite-start</literal></entry>
3688      <entry><literal>(const char *)</literal></entry>
3689      <entry>Probe that fires when the rewriting of a query is started.
3690       arg0 is the query string.</entry>
3691     </row>
3692     <row>
3693      <entry><literal>query-rewrite-done</literal></entry>
3694      <entry><literal>(const char *)</literal></entry>
3695      <entry>Probe that fires when the rewriting of a query is complete.
3696       arg0 is the query string.</entry>
3697     </row>
3698     <row>
3699      <entry><literal>query-plan-start</literal></entry>
3700      <entry><literal>()</literal></entry>
3701      <entry>Probe that fires when the planning of a query is started.</entry>
3702     </row>
3703     <row>
3704      <entry><literal>query-plan-done</literal></entry>
3705      <entry><literal>()</literal></entry>
3706      <entry>Probe that fires when the planning of a query is complete.</entry>
3707     </row>
3708     <row>
3709      <entry><literal>query-execute-start</literal></entry>
3710      <entry><literal>()</literal></entry>
3711      <entry>Probe that fires when the execution of a query is started.</entry>
3712     </row>
3713     <row>
3714      <entry><literal>query-execute-done</literal></entry>
3715      <entry><literal>()</literal></entry>
3716      <entry>Probe that fires when the execution of a query is complete.</entry>
3717     </row>
3718     <row>
3719      <entry><literal>statement-status</literal></entry>
3720      <entry><literal>(const char *)</literal></entry>
3721      <entry>Probe that fires anytime the server process updates its
3722       <structname>pg_stat_activity</structname>.<structfield>status</structfield>.
3723       arg0 is the new status string.</entry>
3724     </row>
3725     <row>
3726      <entry><literal>checkpoint-start</literal></entry>
3727      <entry><literal>(int)</literal></entry>
3728      <entry>Probe that fires when a checkpoint is started.
3729       arg0 holds the bitwise flags used to distinguish different checkpoint
3730       types, such as shutdown, immediate or force.</entry>
3731     </row>
3732     <row>
3733      <entry><literal>checkpoint-done</literal></entry>
3734      <entry><literal>(int, int, int, int, int)</literal></entry>
3735      <entry>Probe that fires when a checkpoint is complete.
3736       (The probes listed next fire in sequence during checkpoint processing.)
3737       arg0 is the number of buffers written. arg1 is the total number of
3738       buffers. arg2, arg3 and arg4 contain the number of WAL files added,
3739       removed and recycled respectively.</entry>
3740     </row>
3741     <row>
3742      <entry><literal>clog-checkpoint-start</literal></entry>
3743      <entry><literal>(bool)</literal></entry>
3744      <entry>Probe that fires when the CLOG portion of a checkpoint is started.
3745       arg0 is true for normal checkpoint, false for shutdown
3746       checkpoint.</entry>
3747     </row>
3748     <row>
3749      <entry><literal>clog-checkpoint-done</literal></entry>
3750      <entry><literal>(bool)</literal></entry>
3751      <entry>Probe that fires when the CLOG portion of a checkpoint is
3752       complete. arg0 has the same meaning as for <literal>clog-checkpoint-start</literal>.</entry>
3753     </row>
3754     <row>
3755      <entry><literal>subtrans-checkpoint-start</literal></entry>
3756      <entry><literal>(bool)</literal></entry>
3757      <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
3758       started.
3759       arg0 is true for normal checkpoint, false for shutdown
3760       checkpoint.</entry>
3761     </row>
3762     <row>
3763      <entry><literal>subtrans-checkpoint-done</literal></entry>
3764      <entry><literal>(bool)</literal></entry>
3765      <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
3766       complete. arg0 has the same meaning as for
3767       <literal>subtrans-checkpoint-start</literal>.</entry>
3768     </row>
3769     <row>
3770      <entry><literal>multixact-checkpoint-start</literal></entry>
3771      <entry><literal>(bool)</literal></entry>
3772      <entry>Probe that fires when the MultiXact portion of a checkpoint is
3773       started.
3774       arg0 is true for normal checkpoint, false for shutdown
3775       checkpoint.</entry>
3776     </row>
3777     <row>
3778      <entry><literal>multixact-checkpoint-done</literal></entry>
3779      <entry><literal>(bool)</literal></entry>
3780      <entry>Probe that fires when the MultiXact portion of a checkpoint is
3781       complete. arg0 has the same meaning as for
3782       <literal>multixact-checkpoint-start</literal>.</entry>
3783     </row>
3784     <row>
3785      <entry><literal>buffer-checkpoint-start</literal></entry>
3786      <entry><literal>(int)</literal></entry>
3787      <entry>Probe that fires when the buffer-writing portion of a checkpoint
3788       is started.
3789       arg0 holds the bitwise flags used to distinguish different checkpoint
3790       types, such as shutdown, immediate or force.</entry>
3791     </row>
3792     <row>
3793      <entry><literal>buffer-sync-start</literal></entry>
3794      <entry><literal>(int, int)</literal></entry>
3795      <entry>Probe that fires when we begin to write dirty buffers during
3796       checkpoint (after identifying which buffers must be written).
3797       arg0 is the total number of buffers.
3798       arg1 is the number that are currently dirty and need to be written.</entry>
3799     </row>
3800     <row>
3801      <entry><literal>buffer-sync-written</literal></entry>
3802      <entry><literal>(int)</literal></entry>
3803      <entry>Probe that fires after each buffer is written during checkpoint.
3804       arg0 is the ID number of the buffer.</entry>
3805     </row>
3806     <row>
3807      <entry><literal>buffer-sync-done</literal></entry>
3808      <entry><literal>(int, int, int)</literal></entry>
3809      <entry>Probe that fires when all dirty buffers have been written.
3810       arg0 is the total number of buffers.
3811       arg1 is the number of buffers actually written by the checkpoint process.
3812       arg2 is the number that were expected to be written (arg1 of
3813       <literal>buffer-sync-start</literal>); any difference reflects other processes flushing
3814       buffers during the checkpoint.</entry>
3815     </row>
3816     <row>
3817      <entry><literal>buffer-checkpoint-sync-start</literal></entry>
3818      <entry><literal>()</literal></entry>
3819      <entry>Probe that fires after dirty buffers have been written to the
3820       kernel, and before starting to issue fsync requests.</entry>
3821     </row>
3822     <row>
3823      <entry><literal>buffer-checkpoint-done</literal></entry>
3824      <entry><literal>()</literal></entry>
3825      <entry>Probe that fires when syncing of buffers to disk is
3826       complete.</entry>
3827     </row>
3828     <row>
3829      <entry><literal>twophase-checkpoint-start</literal></entry>
3830      <entry><literal>()</literal></entry>
3831      <entry>Probe that fires when the two-phase portion of a checkpoint is
3832       started.</entry>
3833     </row>
3834     <row>
3835      <entry><literal>twophase-checkpoint-done</literal></entry>
3836      <entry><literal>()</literal></entry>
3837      <entry>Probe that fires when the two-phase portion of a checkpoint is
3838       complete.</entry>
3839     </row>
3840     <row>
3841      <entry><literal>buffer-read-start</literal></entry>
3842      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool)</literal></entry>
3843      <entry>Probe that fires when a buffer read is started.
3844       arg0 and arg1 contain the fork and block numbers of the page (but
3845       arg1 will be -1 if this is a relation extension request).
3846       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3847       identifying the relation.
3848       arg5 is the ID of the backend which created the temporary relation for a
3849       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3850       arg6 is true for a relation extension request, false for normal
3851       read.</entry>
3852     </row>
3853     <row>
3854      <entry><literal>buffer-read-done</literal></entry>
3855      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool, bool)</literal></entry>
3856      <entry>Probe that fires when a buffer read is complete.
3857       arg0 and arg1 contain the fork and block numbers of the page (if this
3858       is a relation extension request, arg1 now contains the block number
3859       of the newly added block).
3860       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3861       identifying the relation.
3862       arg5 is the ID of the backend which created the temporary relation for a
3863       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3864       arg6 is true for a relation extension request, false for normal
3865       read.
3866       arg7 is true if the buffer was found in the pool, false if not.</entry>
3867     </row>
3868     <row>
3869      <entry><literal>buffer-flush-start</literal></entry>
3870      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3871      <entry>Probe that fires before issuing any write request for a shared
3872       buffer.
3873       arg0 and arg1 contain the fork and block numbers of the page.
3874       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3875       identifying the relation.</entry>
3876     </row>
3877     <row>
3878      <entry><literal>buffer-flush-done</literal></entry>
3879      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3880      <entry>Probe that fires when a write request is complete.  (Note
3881       that this just reflects the time to pass the data to the kernel;
3882       it's typically not actually been written to disk yet.)
3883       The arguments are the same as for <literal>buffer-flush-start</literal>.</entry>
3884     </row>
3885     <row>
3886      <entry><literal>buffer-write-dirty-start</literal></entry>
3887      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3888      <entry>Probe that fires when a server process begins to write a dirty
3889       buffer.  (If this happens often, it implies that
3890       <xref linkend="guc-shared-buffers"/> is too
3891       small or the background writer control parameters need adjustment.)
3892       arg0 and arg1 contain the fork and block numbers of the page.
3893       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3894       identifying the relation.</entry>
3895     </row>
3896     <row>
3897      <entry><literal>buffer-write-dirty-done</literal></entry>
3898      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3899      <entry>Probe that fires when a dirty-buffer write is complete.
3900       The arguments are the same as for <literal>buffer-write-dirty-start</literal>.</entry>
3901     </row>
3902     <row>
3903      <entry><literal>wal-buffer-write-dirty-start</literal></entry>
3904      <entry><literal>()</literal></entry>
3905      <entry>Probe that fires when a server process begins to write a
3906       dirty WAL buffer because no more WAL buffer space is available.
3907       (If this happens often, it implies that
3908       <xref linkend="guc-wal-buffers"/> is too small.)</entry>
3909     </row>
3910     <row>
3911      <entry><literal>wal-buffer-write-dirty-done</literal></entry>
3912      <entry><literal>()</literal></entry>
3913      <entry>Probe that fires when a dirty WAL buffer write is complete.</entry>
3914     </row>
3915     <row>
3916      <entry><literal>wal-insert</literal></entry>
3917      <entry><literal>(unsigned char, unsigned char)</literal></entry>
3918      <entry>Probe that fires when a WAL record is inserted.
3919       arg0 is the resource manager (rmid) for the record.
3920       arg1 contains the info flags.</entry>
3921     </row>
3922     <row>
3923      <entry><literal>wal-switch</literal></entry>
3924      <entry><literal>()</literal></entry>
3925      <entry>Probe that fires when a WAL segment switch is requested.</entry>
3926     </row>
3927     <row>
3928      <entry><literal>smgr-md-read-start</literal></entry>
3929      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
3930      <entry>Probe that fires when beginning to read a block from a relation.
3931       arg0 and arg1 contain the fork and block numbers of the page.
3932       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3933       identifying the relation.
3934       arg5 is the ID of the backend which created the temporary relation for a
3935       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
3936     </row>
3937     <row>
3938      <entry><literal>smgr-md-read-done</literal></entry>
3939      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
3940      <entry>Probe that fires when a block read is complete.
3941       arg0 and arg1 contain the fork and block numbers of the page.
3942       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3943       identifying the relation.
3944       arg5 is the ID of the backend which created the temporary relation for a
3945       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3946       arg6 is the number of bytes actually read, while arg7 is the number
3947       requested (if these are different it indicates trouble).</entry>
3948     </row>
3949     <row>
3950      <entry><literal>smgr-md-write-start</literal></entry>
3951      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
3952      <entry>Probe that fires when beginning to write a block to a relation.
3953       arg0 and arg1 contain the fork and block numbers of the page.
3954       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3955       identifying the relation.
3956       arg5 is the ID of the backend which created the temporary relation for a
3957       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
3958     </row>
3959     <row>
3960      <entry><literal>smgr-md-write-done</literal></entry>
3961      <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
3962      <entry>Probe that fires when a block write is complete.
3963       arg0 and arg1 contain the fork and block numbers of the page.
3964       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3965       identifying the relation.
3966       arg5 is the ID of the backend which created the temporary relation for a
3967       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3968       arg6 is the number of bytes actually written, while arg7 is the number
3969       requested (if these are different it indicates trouble).</entry>
3970     </row>
3971     <row>
3972      <entry><literal>sort-start</literal></entry>
3973      <entry><literal>(int, bool, int, int, bool, int)</literal></entry>
3974      <entry>Probe that fires when a sort operation is started.
3975       arg0 indicates heap, index or datum sort.
3976       arg1 is true for unique-value enforcement.
3977       arg2 is the number of key columns.
3978       arg3 is the number of kilobytes of work memory allowed.
3979       arg4 is true if random access to the sort result is required.
3980       arg5 indicates serial when <literal>0</literal>, parallel worker when
3981       <literal>1</literal>, or parallel leader when <literal>2</literal>.</entry>
3982     </row>
3983     <row>
3984      <entry><literal>sort-done</literal></entry>
3985      <entry><literal>(bool, long)</literal></entry>
3986      <entry>Probe that fires when a sort is complete.
3987       arg0 is true for external sort, false for internal sort.
3988       arg1 is the number of disk blocks used for an external sort,
3989       or kilobytes of memory used for an internal sort.</entry>
3990     </row>
3991     <row>
3992      <entry><literal>lwlock-acquire</literal></entry>
3993      <entry><literal>(char *, LWLockMode)</literal></entry>
3994      <entry>Probe that fires when an LWLock has been acquired.
3995       arg0 is the LWLock's tranche.
3996       arg1 is the requested lock mode, either exclusive or shared.</entry>
3997     </row>
3998     <row>
3999      <entry><literal>lwlock-release</literal></entry>
4000      <entry><literal>(char *)</literal></entry>
4001      <entry>Probe that fires when an LWLock has been released (but note
4002       that any released waiters have not yet been awakened).
4003       arg0 is the LWLock's tranche.</entry>
4004     </row>
4005     <row>
4006      <entry><literal>lwlock-wait-start</literal></entry>
4007      <entry><literal>(char *, LWLockMode)</literal></entry>
4008      <entry>Probe that fires when an LWLock was not immediately available and
4009       a server process has begun to wait for the lock to become available.
4010       arg0 is the LWLock's tranche.
4011       arg1 is the requested lock mode, either exclusive or shared.</entry>
4012     </row>
4013     <row>
4014      <entry><literal>lwlock-wait-done</literal></entry>
4015      <entry><literal>(char *, LWLockMode)</literal></entry>
4016      <entry>Probe that fires when a server process has been released from its
4017       wait for an LWLock (it does not actually have the lock yet).
4018       arg0 is the LWLock's tranche.
4019       arg1 is the requested lock mode, either exclusive or shared.</entry>
4020     </row>
4021     <row>
4022      <entry><literal>lwlock-condacquire</literal></entry>
4023      <entry><literal>(char *, LWLockMode)</literal></entry>
4024      <entry>Probe that fires when an LWLock was successfully acquired when the
4025       caller specified no waiting.
4026       arg0 is the LWLock's tranche.
4027       arg1 is the requested lock mode, either exclusive or shared.</entry>
4028     </row>
4029     <row>
4030      <entry><literal>lwlock-condacquire-fail</literal></entry>
4031      <entry><literal>(char *, LWLockMode)</literal></entry>
4032      <entry>Probe that fires when an LWLock was not successfully acquired when
4033       the caller specified no waiting.
4034       arg0 is the LWLock's tranche.
4035       arg1 is the requested lock mode, either exclusive or shared.</entry>
4036     </row>
4037     <row>
4038      <entry><literal>lock-wait-start</literal></entry>
4039      <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4040      <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4041       has begun to wait because the lock is not available.
4042       arg0 through arg3 are the tag fields identifying the object being
4043       locked.  arg4 indicates the type of object being locked.
4044       arg5 indicates the lock type being requested.</entry>
4045     </row>
4046     <row>
4047      <entry><literal>lock-wait-done</literal></entry>
4048      <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4049      <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4050       has finished waiting (i.e., has acquired the lock).
4051       The arguments are the same as for <literal>lock-wait-start</literal>.</entry>
4052     </row>
4053     <row>
4054      <entry><literal>deadlock-found</literal></entry>
4055      <entry><literal>()</literal></entry>
4056      <entry>Probe that fires when a deadlock is found by the deadlock
4057       detector.</entry>
4058     </row>
4059
4060    </tbody>
4061    </tgroup>
4062   </table>
4063
4064  <table id="typedefs-table">
4065   <title>Defined Types Used in Probe Parameters</title>
4066   <tgroup cols="2">
4067    <thead>
4068     <row>
4069      <entry>Type</entry>
4070      <entry>Definition</entry>
4071     </row>
4072    </thead>
4073
4074    <tbody>
4075
4076     <row>
4077      <entry><type>LocalTransactionId</type></entry>
4078      <entry><type>unsigned int</type></entry>
4079     </row>
4080     <row>
4081      <entry><type>LWLockMode</type></entry>
4082      <entry><type>int</type></entry>
4083     </row>
4084     <row>
4085      <entry><type>LOCKMODE</type></entry>
4086      <entry><type>int</type></entry>
4087     </row>
4088     <row>
4089      <entry><type>BlockNumber</type></entry>
4090      <entry><type>unsigned int</type></entry>
4091     </row>
4092     <row>
4093      <entry><type>Oid</type></entry>
4094      <entry><type>unsigned int</type></entry>
4095     </row>
4096     <row>
4097      <entry><type>ForkNumber</type></entry>
4098      <entry><type>int</type></entry>
4099     </row>
4100     <row>
4101      <entry><type>bool</type></entry>
4102      <entry><type>char</type></entry>
4103     </row>
4104
4105    </tbody>
4106    </tgroup>
4107   </table>
4108
4109
4110   </sect2>
4111
4112   <sect2 id="using-trace-points">
4113    <title>Using Probes</title>
4114
4115   <para>
4116    The example below shows a DTrace script for analyzing transaction
4117    counts in the system, as an alternative to snapshotting
4118    <structname>pg_stat_database</structname> before and after a performance test:
4119 <programlisting>
4120 #!/usr/sbin/dtrace -qs
4121
4122 postgresql$1:::transaction-start
4123 {
4124       @start["Start"] = count();
4125       self->ts  = timestamp;
4126 }
4127
4128 postgresql$1:::transaction-abort
4129 {
4130       @abort["Abort"] = count();
4131 }
4132
4133 postgresql$1:::transaction-commit
4134 /self->ts/
4135 {
4136       @commit["Commit"] = count();
4137       @time["Total time (ns)"] = sum(timestamp - self->ts);
4138       self->ts=0;
4139 }
4140 </programlisting>
4141    When executed, the example D script gives output such as:
4142 <screen>
4143 # ./txn_count.d `pgrep -n postgres` or ./txn_count.d &lt;PID&gt;
4144 ^C
4145
4146 Start                                          71
4147 Commit                                         70
4148 Total time (ns)                        2312105013
4149 </screen>
4150   </para>
4151
4152   <note>
4153    <para>
4154     SystemTap uses a different notation for trace scripts than DTrace does,
4155     even though the underlying trace points are compatible.  One point worth
4156     noting is that at this writing, SystemTap scripts must reference probe
4157     names using double underscores in place of hyphens.  This is expected to
4158     be fixed in future SystemTap releases.
4159    </para>
4160   </note>
4161
4162   <para>
4163    You should remember that DTrace scripts need to be carefully written and
4164    debugged, otherwise the trace information collected might
4165    be meaningless. In most cases where problems are found it is the
4166    instrumentation that is at fault, not the underlying system. When
4167    discussing information found using dynamic tracing, be sure to enclose
4168    the script used to allow that too to be checked and discussed.
4169   </para>
4170   </sect2>
4171
4172   <sect2 id="defining-trace-points">
4173    <title>Defining New Probes</title>
4174
4175   <para>
4176    New probes can be defined within the code wherever the developer
4177    desires, though this will require a recompilation. Below are the steps
4178    for inserting new probes:
4179   </para>
4180
4181   <procedure>
4182    <step>
4183     <para>
4184      Decide on probe names and data to be made available through the probes
4185     </para>
4186    </step>
4187
4188    <step>
4189     <para>
4190      Add the probe definitions to <filename>src/backend/utils/probes.d</filename>
4191     </para>
4192    </step>
4193
4194    <step>
4195     <para>
4196      Include <filename>pg_trace.h</filename> if it is not already present in the
4197      module(s) containing the probe points, and insert
4198      <literal>TRACE_POSTGRESQL</literal> probe macros at the desired locations
4199      in the source code
4200     </para>
4201    </step>
4202
4203    <step>
4204     <para>
4205      Recompile and verify that the new probes are available
4206     </para>
4207    </step>
4208   </procedure>
4209
4210   <formalpara>
4211    <title>Example:</title>
4212    <para>
4213     Here is an example of how you would add a probe to trace all new
4214     transactions by transaction ID.
4215    </para>
4216   </formalpara>
4217
4218   <procedure>
4219    <step>
4220     <para>
4221      Decide that the probe will be named <literal>transaction-start</literal> and
4222      requires a parameter of type <type>LocalTransactionId</type>
4223     </para>
4224    </step>
4225
4226    <step>
4227     <para>
4228      Add the probe definition to <filename>src/backend/utils/probes.d</filename>:
4229 <programlisting>
4230 probe transaction__start(LocalTransactionId);
4231 </programlisting>
4232      Note the use of the double underline in the probe name. In a DTrace
4233      script using the probe, the double underline needs to be replaced with a
4234      hyphen, so <literal>transaction-start</literal> is the name to document for
4235      users.
4236     </para>
4237    </step>
4238
4239    <step>
4240     <para>
4241      At compile time, <literal>transaction__start</literal> is converted to a macro
4242      called <literal>TRACE_POSTGRESQL_TRANSACTION_START</literal> (notice the
4243      underscores are single here), which is available by including
4244      <filename>pg_trace.h</filename>.  Add the macro call to the appropriate location
4245      in the source code.  In this case, it looks like the following:
4246
4247 <programlisting>
4248 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
4249 </programlisting>
4250     </para>
4251    </step>
4252
4253    <step>
4254     <para>
4255      After recompiling and running the new binary, check that your newly added
4256      probe is available by executing the following DTrace command.  You
4257      should see similar output:
4258 <screen>
4259 # dtrace -ln transaction-start
4260    ID    PROVIDER          MODULE           FUNCTION NAME
4261 18705 postgresql49878     postgres     StartTransactionCommand transaction-start
4262 18755 postgresql49877     postgres     StartTransactionCommand transaction-start
4263 18805 postgresql49876     postgres     StartTransactionCommand transaction-start
4264 18855 postgresql49875     postgres     StartTransactionCommand transaction-start
4265 18986 postgresql49873     postgres     StartTransactionCommand transaction-start
4266 </screen>
4267     </para>
4268    </step>
4269   </procedure>
4270
4271   <para>
4272    There are a few things to be careful about when adding trace macros
4273    to the C code:
4274
4275    <itemizedlist>
4276     <listitem>
4277      <para>
4278       You should take care that the data types specified for a probe's
4279       parameters match the data types of the variables used in the macro.
4280       Otherwise, you will get compilation errors.
4281      </para>
4282     </listitem>
4283
4284
4285     <listitem>
4286      <para>
4287       On most platforms, if <productname>PostgreSQL</productname> is
4288       built with <option>--enable-dtrace</option>, the arguments to a trace
4289       macro will be evaluated whenever control passes through the
4290       macro, <emphasis>even if no tracing is being done</emphasis>.  This is
4291       usually not worth worrying about if you are just reporting the
4292       values of a few local variables.  But beware of putting expensive
4293       function calls into the arguments.  If you need to do that,
4294       consider protecting the macro with a check to see if the trace
4295       is actually enabled:
4296
4297 <programlisting>
4298 if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
4299     TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
4300 </programlisting>
4301
4302       Each trace macro has a corresponding <literal>ENABLED</literal> macro.
4303      </para>
4304     </listitem>
4305    </itemizedlist>
4306
4307   </para>
4308
4309   </sect2>
4310
4311  </sect1>
4312
4313 </chapter>