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