gooderp18绿色标准版
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

730 líneas
120KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>27.2. The Statistics Collector</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="monitoring-ps.html" title="27.1. Standard Unix Tools" /><link rel="next" href="monitoring-locks.html" title="27.3. Viewing Locks" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">27.2. The Statistics Collector</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="monitoring-ps.html" title="27.1. Standard Unix Tools">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="monitoring.html" title="Chapter 27. Monitoring Database Activity">Up</a></td><th width="60%" align="center">Chapter 27. Monitoring Database Activity</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="monitoring-locks.html" title="27.3. Viewing Locks">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="MONITORING-STATS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">27.2. The Statistics Collector</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="monitoring-stats.html#MONITORING-STATS-SETUP">27.2.1. Statistics Collection Configuration</a></span></dt><dt><span class="sect2"><a href="monitoring-stats.html#MONITORING-STATS-VIEWS">27.2.2. Viewing Statistics</a></span></dt><dt><span class="sect2"><a href="monitoring-stats.html#MONITORING-STATS-FUNCTIONS">27.2.3. Statistics Functions</a></span></dt></dl></div><a id="id-1.6.14.7.2" class="indexterm"></a><p>
  3. <span class="productname">PostgreSQL</span>'s <em class="firstterm">statistics collector</em>
  4. is a subsystem that supports collection and reporting of information about
  5. server activity. Presently, the collector can count accesses to tables
  6. and indexes in both disk-block and individual-row terms. It also tracks
  7. the total number of rows in each table, and information about vacuum and
  8. analyze actions for each table. It can also count calls to user-defined
  9. functions and the total time spent in each one.
  10. </p><p>
  11. <span class="productname">PostgreSQL</span> also supports reporting dynamic
  12. information about exactly what is going on in the system right now, such as
  13. the exact command currently being executed by other server processes, and
  14. which other connections exist in the system. This facility is independent
  15. of the collector process.
  16. </p><div class="sect2" id="MONITORING-STATS-SETUP"><div class="titlepage"><div><div><h3 class="title">27.2.1. Statistics Collection Configuration</h3></div></div></div><p>
  17. Since collection of statistics adds some overhead to query execution,
  18. the system can be configured to collect or not collect information.
  19. This is controlled by configuration parameters that are normally set in
  20. <code class="filename">postgresql.conf</code>. (See <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a> for
  21. details about setting configuration parameters.)
  22. </p><p>
  23. The parameter <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-ACTIVITIES">track_activities</a> enables monitoring
  24. of the current command being executed by any server process.
  25. </p><p>
  26. The parameter <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-COUNTS">track_counts</a> controls whether
  27. statistics are collected about table and index accesses.
  28. </p><p>
  29. The parameter <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-FUNCTIONS">track_functions</a> enables tracking of
  30. usage of user-defined functions.
  31. </p><p>
  32. The parameter <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-IO-TIMING">track_io_timing</a> enables monitoring
  33. of block read and write times.
  34. </p><p>
  35. Normally these parameters are set in <code class="filename">postgresql.conf</code> so
  36. that they apply to all server processes, but it is possible to turn
  37. them on or off in individual sessions using the <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> command. (To prevent
  38. ordinary users from hiding their activity from the administrator,
  39. only superusers are allowed to change these parameters with
  40. <code class="command">SET</code>.)
  41. </p><p>
  42. The statistics collector transmits the collected information to other
  43. <span class="productname">PostgreSQL</span> processes through temporary files.
  44. These files are stored in the directory named by the
  45. <a class="xref" href="runtime-config-statistics.html#GUC-STATS-TEMP-DIRECTORY">stats_temp_directory</a> parameter,
  46. <code class="filename">pg_stat_tmp</code> by default.
  47. For better performance, <code class="varname">stats_temp_directory</code> can be
  48. pointed at a RAM-based file system, decreasing physical I/O requirements.
  49. When the server shuts down cleanly, a permanent copy of the statistics
  50. data is stored in the <code class="filename">pg_stat</code> subdirectory, so that
  51. statistics can be retained across server restarts. When recovery is
  52. performed at server start (e.g. after immediate shutdown, server crash,
  53. and point-in-time recovery), all statistics counters are reset.
  54. </p></div><div class="sect2" id="MONITORING-STATS-VIEWS"><div class="titlepage"><div><div><h3 class="title">27.2.2. Viewing Statistics</h3></div></div></div><p>
  55. Several predefined views, listed in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-DYNAMIC-VIEWS-TABLE" title="Table 27.1. Dynamic Statistics Views">Table 27.1</a>, are available to show
  56. the current state of the system. There are also several other
  57. views, listed in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-VIEWS-TABLE" title="Table 27.2. Collected Statistics Views">Table 27.2</a>, available to show the results
  58. of statistics collection. Alternatively, one can
  59. build custom views using the underlying statistics functions, as discussed
  60. in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-FUNCTIONS" title="27.2.3. Statistics Functions">Section 27.2.3</a>.
  61. </p><p>
  62. When using the statistics to monitor collected data, it is important
  63. to realize that the information does not update instantaneously.
  64. Each individual server process transmits new statistical counts to
  65. the collector just before going idle; so a query or transaction still in
  66. progress does not affect the displayed totals. Also, the collector itself
  67. emits a new report at most once per <code class="varname">PGSTAT_STAT_INTERVAL</code>
  68. milliseconds (500 ms unless altered while building the server). So the
  69. displayed information lags behind actual activity. However, current-query
  70. information collected by <code class="varname">track_activities</code> is
  71. always up-to-date.
  72. </p><p>
  73. Another important point is that when a server process is asked to display
  74. any of these statistics, it first fetches the most recent report emitted by
  75. the collector process and then continues to use this snapshot for all
  76. statistical views and functions until the end of its current transaction.
  77. So the statistics will show static information as long as you continue the
  78. current transaction. Similarly, information about the current queries of
  79. all sessions is collected when any such information is first requested
  80. within a transaction, and the same information will be displayed throughout
  81. the transaction.
  82. This is a feature, not a bug, because it allows you to perform several
  83. queries on the statistics and correlate the results without worrying that
  84. the numbers are changing underneath you. But if you want to see new
  85. results with each query, be sure to do the queries outside any transaction
  86. block. Alternatively, you can invoke
  87. <code class="function">pg_stat_clear_snapshot</code>(), which will discard the
  88. current transaction's statistics snapshot (if any). The next use of
  89. statistical information will cause a new snapshot to be fetched.
  90. </p><p>
  91. A transaction can also see its own statistics (as yet untransmitted to the
  92. collector) in the views <code class="structname">pg_stat_xact_all_tables</code>,
  93. <code class="structname">pg_stat_xact_sys_tables</code>,
  94. <code class="structname">pg_stat_xact_user_tables</code>, and
  95. <code class="structname">pg_stat_xact_user_functions</code>. These numbers do not act as
  96. stated above; instead they update continuously throughout the transaction.
  97. </p><p>
  98. Some of the information in the dynamic statistics views shown in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-DYNAMIC-VIEWS-TABLE" title="Table 27.1. Dynamic Statistics Views">Table 27.1</a> is security restricted.
  99. Ordinary users can only see all the information about their own sessions
  100. (sessions belonging to a role that they are a member of). In rows about
  101. other sessions, many columns will be null. Note, however, that the
  102. existence of a session and its general properties such as its sessions user
  103. and database are visible to all users. Superusers and members of the
  104. built-in role <code class="literal">pg_read_all_stats</code> (see also <a class="xref" href="default-roles.html" title="21.5. Default Roles">Section 21.5</a>) can see all the information about all sessions.
  105. </p><div class="table" id="MONITORING-STATS-DYNAMIC-VIEWS-TABLE"><p class="title"><strong>Table 27.1. Dynamic Statistics Views</strong></p><div class="table-contents"><table class="table" summary="Dynamic Statistics Views" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>View Name</th><th>Description</th></tr></thead><tbody><tr><td>
  106. <code class="structname">pg_stat_activity</code>
  107. <a id="id-1.6.14.7.6.7.2.2.1.1.2" class="indexterm"></a>
  108. </td><td>
  109. One row per server process, showing information related to
  110. the current activity of that process, such as state and current query.
  111. See <a class="xref" href="monitoring-stats.html#PG-STAT-ACTIVITY-VIEW" title="Table 27.3. pg_stat_activity View">pg_stat_activity</a> for details.
  112. </td></tr><tr><td><code class="structname">pg_stat_replication</code><a id="id-1.6.14.7.6.7.2.2.2.1.2" class="indexterm"></a></td><td>One row per WAL sender process, showing statistics about
  113. replication to that sender's connected standby server.
  114. See <a class="xref" href="monitoring-stats.html#PG-STAT-REPLICATION-VIEW" title="Table 27.5. pg_stat_replication View">pg_stat_replication</a> for details.
  115. </td></tr><tr><td><code class="structname">pg_stat_wal_receiver</code><a id="id-1.6.14.7.6.7.2.2.3.1.2" class="indexterm"></a></td><td>Only one row, showing statistics about the WAL receiver from
  116. that receiver's connected server.
  117. See <a class="xref" href="monitoring-stats.html#PG-STAT-WAL-RECEIVER-VIEW" title="Table 27.6. pg_stat_wal_receiver View">pg_stat_wal_receiver</a> for details.
  118. </td></tr><tr><td><code class="structname">pg_stat_subscription</code><a id="id-1.6.14.7.6.7.2.2.4.1.2" class="indexterm"></a></td><td>At least one row per subscription, showing information about
  119. the subscription workers.
  120. See <a class="xref" href="monitoring-stats.html#PG-STAT-SUBSCRIPTION" title="Table 27.7. pg_stat_subscription View">pg_stat_subscription</a> for details.
  121. </td></tr><tr><td><code class="structname">pg_stat_ssl</code><a id="id-1.6.14.7.6.7.2.2.5.1.2" class="indexterm"></a></td><td>One row per connection (regular and replication), showing information about
  122. SSL used on this connection.
  123. See <a class="xref" href="monitoring-stats.html#PG-STAT-SSL-VIEW" title="Table 27.8. pg_stat_ssl View">pg_stat_ssl</a> for details.
  124. </td></tr><tr><td><code class="structname">pg_stat_gssapi</code><a id="id-1.6.14.7.6.7.2.2.6.1.2" class="indexterm"></a></td><td>One row per connection (regular and replication), showing information about
  125. GSSAPI authentication and encryption used on this connection.
  126. See <a class="xref" href="monitoring-stats.html#PG-STAT-GSSAPI-VIEW" title="Table 27.9. pg_stat_gssapi View">pg_stat_gssapi</a> for details.
  127. </td></tr><tr><td><code class="structname">pg_stat_progress_create_index</code><a id="id-1.6.14.7.6.7.2.2.7.1.2" class="indexterm"></a></td><td>One row for each backend running <code class="command">CREATE INDEX</code> or <code class="command">REINDEX</code>, showing
  128. current progress.
  129. See <a class="xref" href="progress-reporting.html#CREATE-INDEX-PROGRESS-REPORTING" title="27.4.1. CREATE INDEX Progress Reporting">Section 27.4.1</a>.
  130. </td></tr><tr><td><code class="structname">pg_stat_progress_vacuum</code><a id="id-1.6.14.7.6.7.2.2.8.1.2" class="indexterm"></a></td><td>One row for each backend (including autovacuum worker processes) running
  131. <code class="command">VACUUM</code>, showing current progress.
  132. See <a class="xref" href="progress-reporting.html#VACUUM-PROGRESS-REPORTING" title="27.4.2. VACUUM Progress Reporting">Section 27.4.2</a>.
  133. </td></tr><tr><td><code class="structname">pg_stat_progress_cluster</code><a id="id-1.6.14.7.6.7.2.2.9.1.2" class="indexterm"></a></td><td>One row for each backend running
  134. <code class="command">CLUSTER</code> or <code class="command">VACUUM FULL</code>, showing current progress.
  135. See <a class="xref" href="progress-reporting.html#CLUSTER-PROGRESS-REPORTING" title="27.4.3. CLUSTER Progress Reporting">Section 27.4.3</a>.
  136. </td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="MONITORING-STATS-VIEWS-TABLE"><p class="title"><strong>Table 27.2. Collected Statistics Views</strong></p><div class="table-contents"><table class="table" summary="Collected Statistics Views" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>View Name</th><th>Description</th></tr></thead><tbody><tr><td><code class="structname">pg_stat_archiver</code><a id="id-1.6.14.7.6.8.2.2.1.1.2" class="indexterm"></a></td><td>One row only, showing statistics about the
  137. WAL archiver process's activity. See
  138. <a class="xref" href="monitoring-stats.html#PG-STAT-ARCHIVER-VIEW" title="Table 27.10. pg_stat_archiver View">pg_stat_archiver</a> for details.
  139. </td></tr><tr><td><code class="structname">pg_stat_bgwriter</code><a id="id-1.6.14.7.6.8.2.2.2.1.2" class="indexterm"></a></td><td>One row only, showing statistics about the
  140. background writer process's activity. See
  141. <a class="xref" href="monitoring-stats.html#PG-STAT-BGWRITER-VIEW" title="Table 27.11. pg_stat_bgwriter View">pg_stat_bgwriter</a> for details.
  142. </td></tr><tr><td><code class="structname">pg_stat_database</code><a id="id-1.6.14.7.6.8.2.2.3.1.2" class="indexterm"></a></td><td>One row per database, showing database-wide statistics. See
  143. <a class="xref" href="monitoring-stats.html#PG-STAT-DATABASE-VIEW" title="Table 27.12. pg_stat_database View">pg_stat_database</a> for details.
  144. </td></tr><tr><td><code class="structname">pg_stat_database_conflicts</code><a id="id-1.6.14.7.6.8.2.2.4.1.2" class="indexterm"></a></td><td>
  145. One row per database, showing database-wide statistics about
  146. query cancels due to conflict with recovery on standby servers.
  147. See <a class="xref" href="monitoring-stats.html#PG-STAT-DATABASE-CONFLICTS-VIEW" title="Table 27.13. pg_stat_database_conflicts View">pg_stat_database_conflicts</a> for details.
  148. </td></tr><tr><td><code class="structname">pg_stat_all_tables</code><a id="id-1.6.14.7.6.8.2.2.5.1.2" class="indexterm"></a></td><td>
  149. One row for each table in the current database, showing statistics
  150. about accesses to that specific table.
  151. See <a class="xref" href="monitoring-stats.html#PG-STAT-ALL-TABLES-VIEW" title="Table 27.14. pg_stat_all_tables View">pg_stat_all_tables</a> for details.
  152. </td></tr><tr><td><code class="structname">pg_stat_sys_tables</code><a id="id-1.6.14.7.6.8.2.2.6.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_all_tables</code>, except that only
  153. system tables are shown.</td></tr><tr><td><code class="structname">pg_stat_user_tables</code><a id="id-1.6.14.7.6.8.2.2.7.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_all_tables</code>, except that only user
  154. tables are shown.</td></tr><tr><td><code class="structname">pg_stat_xact_all_tables</code><a id="id-1.6.14.7.6.8.2.2.8.1.2" class="indexterm"></a></td><td>Similar to <code class="structname">pg_stat_all_tables</code>, but counts actions
  155. taken so far within the current transaction (which are <span class="emphasis"><em>not</em></span>
  156. yet included in <code class="structname">pg_stat_all_tables</code> and related views).
  157. The columns for numbers of live and dead rows and vacuum and
  158. analyze actions are not present in this view.</td></tr><tr><td><code class="structname">pg_stat_xact_sys_tables</code><a id="id-1.6.14.7.6.8.2.2.9.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_xact_all_tables</code>, except that only
  159. system tables are shown.</td></tr><tr><td><code class="structname">pg_stat_xact_user_tables</code><a id="id-1.6.14.7.6.8.2.2.10.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_xact_all_tables</code>, except that only
  160. user tables are shown.</td></tr><tr><td><code class="structname">pg_stat_all_indexes</code><a id="id-1.6.14.7.6.8.2.2.11.1.2" class="indexterm"></a></td><td>
  161. One row for each index in the current database, showing statistics
  162. about accesses to that specific index.
  163. See <a class="xref" href="monitoring-stats.html#PG-STAT-ALL-INDEXES-VIEW" title="Table 27.15. pg_stat_all_indexes View">pg_stat_all_indexes</a> for details.
  164. </td></tr><tr><td><code class="structname">pg_stat_sys_indexes</code><a id="id-1.6.14.7.6.8.2.2.12.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_all_indexes</code>, except that only
  165. indexes on system tables are shown.</td></tr><tr><td><code class="structname">pg_stat_user_indexes</code><a id="id-1.6.14.7.6.8.2.2.13.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_stat_all_indexes</code>, except that only
  166. indexes on user tables are shown.</td></tr><tr><td><code class="structname">pg_statio_all_tables</code><a id="id-1.6.14.7.6.8.2.2.14.1.2" class="indexterm"></a></td><td>
  167. One row for each table in the current database, showing statistics
  168. about I/O on that specific table.
  169. See <a class="xref" href="monitoring-stats.html#PG-STATIO-ALL-TABLES-VIEW" title="Table 27.16. pg_statio_all_tables View">pg_statio_all_tables</a> for details.
  170. </td></tr><tr><td><code class="structname">pg_statio_sys_tables</code><a id="id-1.6.14.7.6.8.2.2.15.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_tables</code>, except that only
  171. system tables are shown.</td></tr><tr><td><code class="structname">pg_statio_user_tables</code><a id="id-1.6.14.7.6.8.2.2.16.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_tables</code>, except that only
  172. user tables are shown.</td></tr><tr><td><code class="structname">pg_statio_all_indexes</code><a id="id-1.6.14.7.6.8.2.2.17.1.2" class="indexterm"></a></td><td>
  173. One row for each index in the current database,
  174. showing statistics about I/O on that specific index.
  175. See <a class="xref" href="monitoring-stats.html#PG-STATIO-ALL-INDEXES-VIEW" title="Table 27.17. pg_statio_all_indexes View">pg_statio_all_indexes</a> for details.
  176. </td></tr><tr><td><code class="structname">pg_statio_sys_indexes</code><a id="id-1.6.14.7.6.8.2.2.18.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_indexes</code>, except that only
  177. indexes on system tables are shown.</td></tr><tr><td><code class="structname">pg_statio_user_indexes</code><a id="id-1.6.14.7.6.8.2.2.19.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_indexes</code>, except that only
  178. indexes on user tables are shown.</td></tr><tr><td><code class="structname">pg_statio_all_sequences</code><a id="id-1.6.14.7.6.8.2.2.20.1.2" class="indexterm"></a></td><td>
  179. One row for each sequence in the current database,
  180. showing statistics about I/O on that specific sequence.
  181. See <a class="xref" href="monitoring-stats.html#PG-STATIO-ALL-SEQUENCES-VIEW" title="Table 27.18. pg_statio_all_sequences View">pg_statio_all_sequences</a> for details.
  182. </td></tr><tr><td><code class="structname">pg_statio_sys_sequences</code><a id="id-1.6.14.7.6.8.2.2.21.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_sequences</code>, except that only
  183. system sequences are shown. (Presently, no system sequences are defined,
  184. so this view is always empty.)</td></tr><tr><td><code class="structname">pg_statio_user_sequences</code><a id="id-1.6.14.7.6.8.2.2.22.1.2" class="indexterm"></a></td><td>Same as <code class="structname">pg_statio_all_sequences</code>, except that only
  185. user sequences are shown.</td></tr><tr><td><code class="structname">pg_stat_user_functions</code><a id="id-1.6.14.7.6.8.2.2.23.1.2" class="indexterm"></a></td><td>
  186. One row for each tracked function, showing statistics
  187. about executions of that function. See
  188. <a class="xref" href="monitoring-stats.html#PG-STAT-USER-FUNCTIONS-VIEW" title="Table 27.19. pg_stat_user_functions View">pg_stat_user_functions</a> for details.
  189. </td></tr><tr><td><code class="structname">pg_stat_xact_user_functions</code><a id="id-1.6.14.7.6.8.2.2.24.1.2" class="indexterm"></a></td><td>Similar to <code class="structname">pg_stat_user_functions</code>, but counts only
  190. calls during the current transaction (which are <span class="emphasis"><em>not</em></span>
  191. yet included in <code class="structname">pg_stat_user_functions</code>).</td></tr></tbody></table></div></div><br class="table-break" /><p>
  192. The per-index statistics are particularly useful to determine which
  193. indexes are being used and how effective they are.
  194. </p><p>
  195. The <code class="structname">pg_statio_</code> views are primarily useful to
  196. determine the effectiveness of the buffer cache. When the number
  197. of actual disk reads is much smaller than the number of buffer
  198. hits, then the cache is satisfying most read requests without
  199. invoking a kernel call. However, these statistics do not give the
  200. entire story: due to the way in which <span class="productname">PostgreSQL</span>
  201. handles disk I/O, data that is not in the
  202. <span class="productname">PostgreSQL</span> buffer cache might still reside in the
  203. kernel's I/O cache, and might therefore still be fetched without
  204. requiring a physical read. Users interested in obtaining more
  205. detailed information on <span class="productname">PostgreSQL</span> I/O behavior are
  206. advised to use the <span class="productname">PostgreSQL</span> statistics collector
  207. in combination with operating system utilities that allow insight
  208. into the kernel's handling of I/O.
  209. </p><div class="table" id="PG-STAT-ACTIVITY-VIEW"><p class="title"><strong>Table 27.3. <code class="structname">pg_stat_activity</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_activity View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">datid</code></td><td><code class="type">oid</code></td><td>OID of the database this backend is connected to</td></tr><tr><td><code class="structfield">datname</code></td><td><code class="type">name</code></td><td>Name of the database this backend is connected to</td></tr><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of this backend</td></tr><tr><td><code class="structfield">usesysid</code></td><td><code class="type">oid</code></td><td>OID of the user logged into this backend</td></tr><tr><td><code class="structfield">usename</code></td><td><code class="type">name</code></td><td>Name of the user logged into this backend</td></tr><tr><td><code class="structfield">application_name</code></td><td><code class="type">text</code></td><td>Name of the application that is connected
  210. to this backend</td></tr><tr><td><code class="structfield">client_addr</code></td><td><code class="type">inet</code></td><td>IP address of the client connected to this backend.
  211. If this field is null, it indicates either that the client is
  212. connected via a Unix socket on the server machine or that this is an
  213. internal process such as autovacuum.
  214. </td></tr><tr><td><code class="structfield">client_hostname</code></td><td><code class="type">text</code></td><td>Host name of the connected client, as reported by a
  215. reverse DNS lookup of <code class="structfield">client_addr</code>. This field will
  216. only be non-null for IP connections, and only when <a class="xref" href="runtime-config-logging.html#GUC-LOG-HOSTNAME">log_hostname</a> is enabled.
  217. </td></tr><tr><td><code class="structfield">client_port</code></td><td><code class="type">integer</code></td><td>TCP port number that the client is using for communication
  218. with this backend, or <code class="literal">-1</code> if a Unix socket is used
  219. </td></tr><tr><td><code class="structfield">backend_start</code></td><td><code class="type">timestamp with time zone</code></td><td>Time when this process was started. For client backends,
  220. this is the time the client connected to the server.
  221. </td></tr><tr><td><code class="structfield">xact_start</code></td><td><code class="type">timestamp with time zone</code></td><td>Time when this process' current transaction was started, or null
  222. if no transaction is active. If the current
  223. query is the first of its transaction, this column is equal to the
  224. <code class="structfield">query_start</code> column.
  225. </td></tr><tr><td><code class="structfield">query_start</code></td><td><code class="type">timestamp with time zone</code></td><td>Time when the currently active query was started, or if
  226. <code class="structfield">state</code> is not <code class="literal">active</code>, when the last query
  227. was started
  228. </td></tr><tr><td><code class="structfield">state_change</code></td><td><code class="type">timestamp with time zone</code></td><td>Time when the <code class="structfield">state</code> was last changed</td></tr><tr><td><code class="structfield">wait_event_type</code></td><td><code class="type">text</code></td><td>The type of event for which the backend is waiting, if any;
  229. otherwise NULL. Possible values are:
  230. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  231. <code class="literal">LWLock</code>: The backend is waiting for a lightweight lock.
  232. Each such lock protects a particular data structure in shared memory.
  233. <code class="literal">wait_event</code> will contain a name identifying the purpose
  234. of the lightweight lock. (Some locks have specific names; others
  235. are part of a group of locks each with a similar purpose.)
  236. </p></li><li class="listitem"><p>
  237. <code class="literal">Lock</code>: The backend is waiting for a heavyweight lock.
  238. Heavyweight locks, also known as lock manager locks or simply locks,
  239. primarily protect SQL-visible objects such as tables. However,
  240. they are also used to ensure mutual exclusion for certain internal
  241. operations such as relation extension. <code class="literal">wait_event</code> will
  242. identify the type of lock awaited.
  243. </p></li><li class="listitem"><p>
  244. <code class="literal">BufferPin</code>: The server process is waiting to access to
  245. a data buffer during a period when no other process can be
  246. examining that buffer. Buffer pin waits can be protracted if
  247. another process holds an open cursor which last read data from the
  248. buffer in question.
  249. </p></li><li class="listitem"><p>
  250. <code class="literal">Activity</code>: The server process is idle. This is used by
  251. system processes waiting for activity in their main processing loop.
  252. <code class="literal">wait_event</code> will identify the specific wait point.
  253. </p></li><li class="listitem"><p>
  254. <code class="literal">Extension</code>: The server process is waiting for activity
  255. in an extension module. This category is useful for modules to
  256. track custom waiting points.
  257. </p></li><li class="listitem"><p>
  258. <code class="literal">Client</code>: The server process is waiting for some activity
  259. on a socket from user applications, and that the server expects
  260. something to happen that is independent from its internal processes.
  261. <code class="literal">wait_event</code> will identify the specific wait point.
  262. </p></li><li class="listitem"><p>
  263. <code class="literal">IPC</code>: The server process is waiting for some activity
  264. from another process in the server. <code class="literal">wait_event</code> will
  265. identify the specific wait point.
  266. </p></li><li class="listitem"><p>
  267. <code class="literal">Timeout</code>: The server process is waiting for a timeout
  268. to expire. <code class="literal">wait_event</code> will identify the specific wait
  269. point.
  270. </p></li><li class="listitem"><p>
  271. <code class="literal">IO</code>: The server process is waiting for a IO to complete.
  272. <code class="literal">wait_event</code> will identify the specific wait point.
  273. </p></li></ul></div>
  274. </td></tr><tr><td><code class="structfield">wait_event</code></td><td><code class="type">text</code></td><td>Wait event name if backend is currently waiting, otherwise NULL.
  275. See <a class="xref" href="monitoring-stats.html#WAIT-EVENT-TABLE" title="Table 27.4. wait_event Description">Table 27.4</a> for details.
  276. </td></tr><tr><td><code class="structfield">state</code></td><td><code class="type">text</code></td><td>Current overall state of this backend.
  277. Possible values are:
  278. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  279. <code class="literal">active</code>: The backend is executing a query.
  280. </p></li><li class="listitem"><p>
  281. <code class="literal">idle</code>: The backend is waiting for a new client command.
  282. </p></li><li class="listitem"><p>
  283. <code class="literal">idle in transaction</code>: The backend is in a transaction,
  284. but is not currently executing a query.
  285. </p></li><li class="listitem"><p>
  286. <code class="literal">idle in transaction (aborted)</code>: This state is similar to
  287. <code class="literal">idle in transaction</code>, except one of the statements in
  288. the transaction caused an error.
  289. </p></li><li class="listitem"><p>
  290. <code class="literal">fastpath function call</code>: The backend is executing a
  291. fast-path function.
  292. </p></li><li class="listitem"><p>
  293. <code class="literal">disabled</code>: This state is reported if <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-ACTIVITIES">track_activities</a> is disabled in this backend.
  294. </p></li></ul></div>
  295. </td></tr><tr><td><code class="structfield">backend_xid</code></td><td><code class="type">xid</code></td><td>Top-level transaction identifier of this backend, if any.</td></tr><tr><td><code class="structfield">backend_xmin</code></td><td><code class="type">xid</code></td><td>The current backend's <code class="literal">xmin</code> horizon.</td></tr><tr><td><code class="structfield">query</code></td><td><code class="type">text</code></td><td>Text of this backend's most recent query. If
  296. <code class="structfield">state</code> is <code class="literal">active</code> this field shows the
  297. currently executing query. In all other states, it shows the last query
  298. that was executed. By default the query text is truncated at 1024
  299. bytes; this value can be changed via the parameter
  300. <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-ACTIVITY-QUERY-SIZE">track_activity_query_size</a>.
  301. </td></tr><tr><td><code class="structfield">backend_type</code></td><td><code class="type">text</code></td><td>Type of current backend. Possible types are
  302. <code class="literal">autovacuum launcher</code>, <code class="literal">autovacuum worker</code>,
  303. <code class="literal">logical replication launcher</code>,
  304. <code class="literal">logical replication worker</code>,
  305. <code class="literal">parallel worker</code>, <code class="literal">background writer</code>,
  306. <code class="literal">client backend</code>, <code class="literal">checkpointer</code>,
  307. <code class="literal">startup</code>, <code class="literal">walreceiver</code>,
  308. <code class="literal">walsender</code> and <code class="literal">walwriter</code>.
  309. In addition, background workers registered by extensions may have
  310. additional types.
  311. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  312. The <code class="structname">pg_stat_activity</code> view will have one row
  313. per server process, showing information related to
  314. the current activity of that process.
  315. </p><div class="note"><h3 class="title">Note</h3><p>
  316. The <code class="structfield">wait_event</code> and <code class="structfield">state</code> columns are
  317. independent. If a backend is in the <code class="literal">active</code> state,
  318. it may or may not be <code class="literal">waiting</code> on some event. If the state
  319. is <code class="literal">active</code> and <code class="structfield">wait_event</code> is non-null, it
  320. means that a query is being executed, but is being blocked somewhere
  321. in the system.
  322. </p></div><div class="table" id="WAIT-EVENT-TABLE"><p class="title"><strong>Table 27.4. <code class="structname">wait_event</code> Description</strong></p><div class="table-contents"><table class="table" summary="wait_event Description" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Wait Event Type</th><th>Wait Event Name</th><th>Description</th></tr></thead><tbody><tr><td rowspan="65"><code class="literal">LWLock</code></td><td><code class="literal">ShmemIndexLock</code></td><td>Waiting to find or allocate space in shared memory.</td></tr><tr><td><code class="literal">OidGenLock</code></td><td>Waiting to allocate or assign an OID.</td></tr><tr><td><code class="literal">XidGenLock</code></td><td>Waiting to allocate or assign a transaction id.</td></tr><tr><td><code class="literal">ProcArrayLock</code></td><td>Waiting to get a snapshot or clearing a transaction id at
  323. transaction end.</td></tr><tr><td><code class="literal">SInvalReadLock</code></td><td>Waiting to retrieve or remove messages from shared invalidation
  324. queue.</td></tr><tr><td><code class="literal">SInvalWriteLock</code></td><td>Waiting to add a message in shared invalidation queue.</td></tr><tr><td><code class="literal">WALBufMappingLock</code></td><td>Waiting to replace a page in WAL buffers.</td></tr><tr><td><code class="literal">WALWriteLock</code></td><td>Waiting for WAL buffers to be written to disk.</td></tr><tr><td><code class="literal">ControlFileLock</code></td><td>Waiting to read or update the control file or creation of a
  325. new WAL file.</td></tr><tr><td><code class="literal">CheckpointLock</code></td><td>Waiting to perform checkpoint.</td></tr><tr><td><code class="literal">CLogControlLock</code></td><td>Waiting to read or update transaction status.</td></tr><tr><td><code class="literal">SubtransControlLock</code></td><td>Waiting to read or update sub-transaction information.</td></tr><tr><td><code class="literal">MultiXactGenLock</code></td><td>Waiting to read or update shared multixact state.</td></tr><tr><td><code class="literal">MultiXactOffsetControlLock</code></td><td>Waiting to read or update multixact offset mappings.</td></tr><tr><td><code class="literal">MultiXactMemberControlLock</code></td><td>Waiting to read or update multixact member mappings.</td></tr><tr><td><code class="literal">RelCacheInitLock</code></td><td>Waiting to read or write relation cache initialization
  326. file.</td></tr><tr><td><code class="literal">CheckpointerCommLock</code></td><td>Waiting to manage fsync requests.</td></tr><tr><td><code class="literal">TwoPhaseStateLock</code></td><td>Waiting to read or update the state of prepared transactions.</td></tr><tr><td><code class="literal">TablespaceCreateLock</code></td><td>Waiting to create or drop the tablespace.</td></tr><tr><td><code class="literal">BtreeVacuumLock</code></td><td>Waiting to read or update vacuum-related information for a
  327. B-tree index.</td></tr><tr><td><code class="literal">AddinShmemInitLock</code></td><td>Waiting to manage space allocation in shared memory.</td></tr><tr><td><code class="literal">AutovacuumLock</code></td><td>Autovacuum worker or launcher waiting to update or
  328. read the current state of autovacuum workers.</td></tr><tr><td><code class="literal">AutovacuumScheduleLock</code></td><td>Waiting to ensure that the table it has selected for a vacuum
  329. still needs vacuuming.
  330. </td></tr><tr><td><code class="literal">SyncScanLock</code></td><td>Waiting to get the start location of a scan on a table for
  331. synchronized scans.</td></tr><tr><td><code class="literal">RelationMappingLock</code></td><td>Waiting to update the relation map file used to store catalog
  332. to filenode mapping.
  333. </td></tr><tr><td><code class="literal">AsyncCtlLock</code></td><td>Waiting to read or update shared notification state.</td></tr><tr><td><code class="literal">AsyncQueueLock</code></td><td>Waiting to read or update notification messages.</td></tr><tr><td><code class="literal">SerializableXactHashLock</code></td><td>Waiting to retrieve or store information about serializable
  334. transactions.</td></tr><tr><td><code class="literal">SerializableFinishedListLock</code></td><td>Waiting to access the list of finished serializable
  335. transactions.</td></tr><tr><td><code class="literal">SerializablePredicateLockListLock</code></td><td>Waiting to perform an operation on a list of locks held by
  336. serializable transactions.</td></tr><tr><td><code class="literal">OldSerXidLock</code></td><td>Waiting to read or record conflicting serializable
  337. transactions.</td></tr><tr><td><code class="literal">SyncRepLock</code></td><td>Waiting to read or update information about synchronous
  338. replicas.</td></tr><tr><td><code class="literal">BackgroundWorkerLock</code></td><td>Waiting to read or update background worker state.</td></tr><tr><td><code class="literal">DynamicSharedMemoryControlLock</code></td><td>Waiting to read or update dynamic shared memory state.</td></tr><tr><td><code class="literal">AutoFileLock</code></td><td>Waiting to update the <code class="filename">postgresql.auto.conf</code> file.</td></tr><tr><td><code class="literal">ReplicationSlotAllocationLock</code></td><td>Waiting to allocate or free a replication slot.</td></tr><tr><td><code class="literal">ReplicationSlotControlLock</code></td><td>Waiting to read or update replication slot state.</td></tr><tr><td><code class="literal">CommitTsControlLock</code></td><td>Waiting to read or update transaction commit timestamps.</td></tr><tr><td><code class="literal">CommitTsLock</code></td><td>Waiting to read or update the last value set for the
  339. transaction timestamp.</td></tr><tr><td><code class="literal">ReplicationOriginLock</code></td><td>Waiting to setup, drop or use replication origin.</td></tr><tr><td><code class="literal">MultiXactTruncationLock</code></td><td>Waiting to read or truncate multixact information.</td></tr><tr><td><code class="literal">OldSnapshotTimeMapLock</code></td><td>Waiting to read or update old snapshot control information.</td></tr><tr><td><code class="literal">LogicalRepWorkerLock</code></td><td>Waiting for action on logical replication worker to finish.</td></tr><tr><td><code class="literal">CLogTruncationLock</code></td><td>Waiting to execute <code class="function">txid_status</code> or update
  340. the oldest transaction id available to it.</td></tr><tr><td><code class="literal">clog</code></td><td>Waiting for I/O on a clog (transaction status) buffer.</td></tr><tr><td><code class="literal">commit_timestamp</code></td><td>Waiting for I/O on commit timestamp buffer.</td></tr><tr><td><code class="literal">subtrans</code></td><td>Waiting for I/O a subtransaction buffer.</td></tr><tr><td><code class="literal">multixact_offset</code></td><td>Waiting for I/O on a multixact offset buffer.</td></tr><tr><td><code class="literal">multixact_member</code></td><td>Waiting for I/O on a multixact_member buffer.</td></tr><tr><td><code class="literal">async</code></td><td>Waiting for I/O on an async (notify) buffer.</td></tr><tr><td><code class="literal">oldserxid</code></td><td>Waiting for I/O on an oldserxid buffer.</td></tr><tr><td><code class="literal">wal_insert</code></td><td>Waiting to insert WAL into a memory buffer.</td></tr><tr><td><code class="literal">buffer_content</code></td><td>Waiting to read or write a data page in memory.</td></tr><tr><td><code class="literal">buffer_io</code></td><td>Waiting for I/O on a data page.</td></tr><tr><td><code class="literal">replication_origin</code></td><td>Waiting to read or update the replication progress.</td></tr><tr><td><code class="literal">replication_slot_io</code></td><td>Waiting for I/O on a replication slot.</td></tr><tr><td><code class="literal">proc</code></td><td>Waiting to read or update the fast-path lock information.</td></tr><tr><td><code class="literal">buffer_mapping</code></td><td>Waiting to associate a data block with a buffer in the buffer
  341. pool.</td></tr><tr><td><code class="literal">lock_manager</code></td><td>Waiting to add or examine locks for backends, or waiting to
  342. join or exit a locking group (used by parallel query).</td></tr><tr><td><code class="literal">predicate_lock_manager</code></td><td>Waiting to add or examine predicate lock information.</td></tr><tr><td><code class="literal">serializable_xact</code></td><td>Waiting to perform an operation on a serializable transaction
  343. in a parallel query.</td></tr><tr><td><code class="literal">parallel_query_dsa</code></td><td>Waiting for parallel query dynamic shared memory allocation lock.</td></tr><tr><td><code class="literal">tbm</code></td><td>Waiting for TBM shared iterator lock.</td></tr><tr><td><code class="literal">parallel_append</code></td><td>Waiting to choose the next subplan during Parallel Append plan
  344. execution.</td></tr><tr><td><code class="literal">parallel_hash_join</code></td><td>Waiting to allocate or exchange a chunk of memory or update
  345. counters during Parallel Hash plan execution.</td></tr><tr><td rowspan="10"><code class="literal">Lock</code></td><td><code class="literal">relation</code></td><td>Waiting to acquire a lock on a relation.</td></tr><tr><td><code class="literal">extend</code></td><td>Waiting to extend a relation.</td></tr><tr><td><code class="literal">page</code></td><td>Waiting to acquire a lock on page of a relation.</td></tr><tr><td><code class="literal">tuple</code></td><td>Waiting to acquire a lock on a tuple.</td></tr><tr><td><code class="literal">transactionid</code></td><td>Waiting for a transaction to finish.</td></tr><tr><td><code class="literal">virtualxid</code></td><td>Waiting to acquire a virtual xid lock.</td></tr><tr><td><code class="literal">speculative token</code></td><td>Waiting to acquire a speculative insertion lock.</td></tr><tr><td><code class="literal">object</code></td><td>Waiting to acquire a lock on a non-relation database object.</td></tr><tr><td><code class="literal">userlock</code></td><td>Waiting to acquire a user lock.</td></tr><tr><td><code class="literal">advisory</code></td><td>Waiting to acquire an advisory user lock.</td></tr><tr><td><code class="literal">BufferPin</code></td><td><code class="literal">BufferPin</code></td><td>Waiting to acquire a pin on a buffer.</td></tr><tr><td rowspan="14"><code class="literal">Activity</code></td><td><code class="literal">ArchiverMain</code></td><td>Waiting in main loop of the archiver process.</td></tr><tr><td><code class="literal">AutoVacuumMain</code></td><td>Waiting in main loop of autovacuum launcher process.</td></tr><tr><td><code class="literal">BgWriterHibernate</code></td><td>Waiting in background writer process, hibernating.</td></tr><tr><td><code class="literal">BgWriterMain</code></td><td>Waiting in main loop of background writer process background worker.</td></tr><tr><td><code class="literal">CheckpointerMain</code></td><td>Waiting in main loop of checkpointer process.</td></tr><tr><td><code class="literal">LogicalApplyMain</code></td><td>Waiting in main loop of logical apply process.</td></tr><tr><td><code class="literal">LogicalLauncherMain</code></td><td>Waiting in main loop of logical launcher process.</td></tr><tr><td><code class="literal">PgStatMain</code></td><td>Waiting in main loop of the statistics collector process.</td></tr><tr><td><code class="literal">RecoveryWalAll</code></td><td>Waiting for WAL from a stream at recovery.</td></tr><tr><td><code class="literal">RecoveryWalStream</code></td><td>
  346. Waiting when WAL data is not available from any kind of sources
  347. (local, archive or stream) before trying again to retrieve WAL data,
  348. at recovery.
  349. </td></tr><tr><td><code class="literal">SysLoggerMain</code></td><td>Waiting in main loop of syslogger process.</td></tr><tr><td><code class="literal">WalReceiverMain</code></td><td>Waiting in main loop of WAL receiver process.</td></tr><tr><td><code class="literal">WalSenderMain</code></td><td>Waiting in main loop of WAL sender process.</td></tr><tr><td><code class="literal">WalWriterMain</code></td><td>Waiting in main loop of WAL writer process.</td></tr><tr><td rowspan="9"><code class="literal">Client</code></td><td><code class="literal">ClientRead</code></td><td>Waiting to read data from the client.</td></tr><tr><td><code class="literal">ClientWrite</code></td><td>Waiting to write data to the client.</td></tr><tr><td><code class="literal">GSSOpenServer</code></td><td>Waiting to read data from the client while establishing the GSSAPI session.</td></tr><tr><td><code class="literal">LibPQWalReceiverConnect</code></td><td>Waiting in WAL receiver to establish connection to remote server.</td></tr><tr><td><code class="literal">LibPQWalReceiverReceive</code></td><td>Waiting in WAL receiver to receive data from remote server.</td></tr><tr><td><code class="literal">SSLOpenServer</code></td><td>Waiting for SSL while attempting connection.</td></tr><tr><td><code class="literal">WalReceiverWaitStart</code></td><td>Waiting for startup process to send initial data for streaming replication.</td></tr><tr><td><code class="literal">WalSenderWaitForWAL</code></td><td>Waiting for WAL to be flushed in WAL sender process.</td></tr><tr><td><code class="literal">WalSenderWriteData</code></td><td>Waiting for any activity when processing replies from WAL receiver in WAL sender process.</td></tr><tr><td><code class="literal">Extension</code></td><td><code class="literal">Extension</code></td><td>Waiting in an extension.</td></tr><tr><td rowspan="37"><code class="literal">IPC</code></td><td><code class="literal">BgWorkerShutdown</code></td><td>Waiting for background worker to shut down.</td></tr><tr><td><code class="literal">BgWorkerStartup</code></td><td>Waiting for background worker to start up.</td></tr><tr><td><code class="literal">BtreePage</code></td><td>Waiting for the page number needed to continue a parallel B-tree scan to become available.</td></tr><tr><td><code class="literal">CheckpointDone</code></td><td>Waiting for a checkpoint to complete.</td></tr><tr><td><code class="literal">CheckpointStart</code></td><td>Waiting for a checkpoint to start.</td></tr><tr><td><code class="literal">ClogGroupUpdate</code></td><td>Waiting for group leader to update transaction status at transaction end.</td></tr><tr><td><code class="literal">ExecuteGather</code></td><td>Waiting for activity from child process when executing <code class="literal">Gather</code> node.</td></tr><tr><td><code class="literal">Hash/Batch/Allocating</code></td><td>Waiting for an elected Parallel Hash participant to allocate a hash table.</td></tr><tr><td><code class="literal">Hash/Batch/Electing</code></td><td>Electing a Parallel Hash participant to allocate a hash table.</td></tr><tr><td><code class="literal">Hash/Batch/Loading</code></td><td>Waiting for other Parallel Hash participants to finish loading a hash table.</td></tr><tr><td><code class="literal">Hash/Build/Allocating</code></td><td>Waiting for an elected Parallel Hash participant to allocate the initial hash table.</td></tr><tr><td><code class="literal">Hash/Build/Electing</code></td><td>Electing a Parallel Hash participant to allocate the initial hash table.</td></tr><tr><td><code class="literal">Hash/Build/HashingInner</code></td><td>Waiting for other Parallel Hash participants to finish hashing the inner relation.</td></tr><tr><td><code class="literal">Hash/Build/HashingOuter</code></td><td>Waiting for other Parallel Hash participants to finish partitioning the outer relation.</td></tr><tr><td><code class="literal">Hash/GrowBatches/Allocating</code></td><td>Waiting for an elected Parallel Hash participant to allocate more batches.</td></tr><tr><td><code class="literal">Hash/GrowBatches/Deciding</code></td><td>Electing a Parallel Hash participant to decide on future batch growth.</td></tr><tr><td><code class="literal">Hash/GrowBatches/Electing</code></td><td>Electing a Parallel Hash participant to allocate more batches.</td></tr><tr><td><code class="literal">Hash/GrowBatches/Finishing</code></td><td>Waiting for an elected Parallel Hash participant to decide on future batch growth.</td></tr><tr><td><code class="literal">Hash/GrowBatches/Repartitioning</code></td><td>Waiting for other Parallel Hash participants to finishing repartitioning.</td></tr><tr><td><code class="literal">Hash/GrowBuckets/Allocating</code></td><td>Waiting for an elected Parallel Hash participant to finish allocating more buckets.</td></tr><tr><td><code class="literal">Hash/GrowBuckets/Electing</code></td><td>Electing a Parallel Hash participant to allocate more buckets.</td></tr><tr><td><code class="literal">Hash/GrowBuckets/Reinserting</code></td><td>Waiting for other Parallel Hash participants to finish inserting tuples into new buckets.</td></tr><tr><td><code class="literal">LogicalSyncData</code></td><td>Waiting for logical replication remote server to send data for initial table synchronization.</td></tr><tr><td><code class="literal">LogicalSyncStateChange</code></td><td>Waiting for logical replication remote server to change state.</td></tr><tr><td><code class="literal">MessageQueueInternal</code></td><td>Waiting for other process to be attached in shared message queue.</td></tr><tr><td><code class="literal">MessageQueuePutMessage</code></td><td>Waiting to write a protocol message to a shared message queue.</td></tr><tr><td><code class="literal">MessageQueueReceive</code></td><td>Waiting to receive bytes from a shared message queue.</td></tr><tr><td><code class="literal">MessageQueueSend</code></td><td>Waiting to send bytes to a shared message queue.</td></tr><tr><td><code class="literal">ParallelBitmapScan</code></td><td>Waiting for parallel bitmap scan to become initialized.</td></tr><tr><td><code class="literal">ParallelCreateIndexScan</code></td><td>Waiting for parallel <code class="command">CREATE INDEX</code> workers to finish heap scan.</td></tr><tr><td><code class="literal">ParallelFinish</code></td><td>Waiting for parallel workers to finish computing.</td></tr><tr><td><code class="literal">ProcArrayGroupUpdate</code></td><td>Waiting for group leader to clear transaction id at transaction end.</td></tr><tr><td><code class="literal">Promote</code></td><td>Waiting for standby promotion.</td></tr><tr><td><code class="literal">ReplicationOriginDrop</code></td><td>Waiting for a replication origin to become inactive to be dropped.</td></tr><tr><td><code class="literal">ReplicationSlotDrop</code></td><td>Waiting for a replication slot to become inactive to be dropped.</td></tr><tr><td><code class="literal">SafeSnapshot</code></td><td>Waiting for a snapshot for a <code class="literal">READ ONLY DEFERRABLE</code> transaction.</td></tr><tr><td><code class="literal">SyncRep</code></td><td>Waiting for confirmation from remote server during synchronous replication.</td></tr><tr><td rowspan="3"><code class="literal">Timeout</code></td><td><code class="literal">BaseBackupThrottle</code></td><td>Waiting during base backup when throttling activity.</td></tr><tr><td><code class="literal">PgSleep</code></td><td>Waiting in process that called <code class="function">pg_sleep</code>.</td></tr><tr><td><code class="literal">RecoveryApplyDelay</code></td><td>Waiting to apply WAL at recovery because it is delayed.</td></tr><tr><td rowspan="68"><code class="literal">IO</code></td><td><code class="literal">BufFileRead</code></td><td>Waiting for a read from a buffered file.</td></tr><tr><td><code class="literal">BufFileWrite</code></td><td>Waiting for a write to a buffered file.</td></tr><tr><td><code class="literal">ControlFileRead</code></td><td>Waiting for a read from the control file.</td></tr><tr><td><code class="literal">ControlFileSync</code></td><td>Waiting for the control file to reach stable storage.</td></tr><tr><td><code class="literal">ControlFileSyncUpdate</code></td><td>Waiting for an update to the control file to reach stable storage.</td></tr><tr><td><code class="literal">ControlFileWrite</code></td><td>Waiting for a write to the control file.</td></tr><tr><td><code class="literal">ControlFileWriteUpdate</code></td><td>Waiting for a write to update the control file.</td></tr><tr><td><code class="literal">CopyFileRead</code></td><td>Waiting for a read during a file copy operation.</td></tr><tr><td><code class="literal">CopyFileWrite</code></td><td>Waiting for a write during a file copy operation.</td></tr><tr><td><code class="literal">DataFileExtend</code></td><td>Waiting for a relation data file to be extended.</td></tr><tr><td><code class="literal">DataFileFlush</code></td><td>Waiting for a relation data file to reach stable storage.</td></tr><tr><td><code class="literal">DataFileImmediateSync</code></td><td>Waiting for an immediate synchronization of a relation data file to stable storage.</td></tr><tr><td><code class="literal">DataFilePrefetch</code></td><td>Waiting for an asynchronous prefetch from a relation data file.</td></tr><tr><td><code class="literal">DataFileRead</code></td><td>Waiting for a read from a relation data file.</td></tr><tr><td><code class="literal">DataFileSync</code></td><td>Waiting for changes to a relation data file to reach stable storage.</td></tr><tr><td><code class="literal">DataFileTruncate</code></td><td>Waiting for a relation data file to be truncated.</td></tr><tr><td><code class="literal">DataFileWrite</code></td><td>Waiting for a write to a relation data file.</td></tr><tr><td><code class="literal">DSMFillZeroWrite</code></td><td>Waiting to write zero bytes to a dynamic shared memory backing file.</td></tr><tr><td><code class="literal">LockFileAddToDataDirRead</code></td><td>Waiting for a read while adding a line to the data directory lock file.</td></tr><tr><td><code class="literal">LockFileAddToDataDirSync</code></td><td>Waiting for data to reach stable storage while adding a line to the data directory lock file.</td></tr><tr><td><code class="literal">LockFileAddToDataDirWrite</code></td><td>Waiting for a write while adding a line to the data directory lock file.</td></tr><tr><td><code class="literal">LockFileCreateRead</code></td><td>Waiting to read while creating the data directory lock file.</td></tr><tr><td><code class="literal">LockFileCreateSync</code></td><td>Waiting for data to reach stable storage while creating the data directory lock file.</td></tr><tr><td><code class="literal">LockFileCreateWrite</code></td><td>Waiting for a write while creating the data directory lock file.</td></tr><tr><td><code class="literal">LockFileReCheckDataDirRead</code></td><td>Waiting for a read during recheck of the data directory lock file.</td></tr><tr><td><code class="literal">LogicalRewriteCheckpointSync</code></td><td>Waiting for logical rewrite mappings to reach stable storage during a checkpoint.</td></tr><tr><td><code class="literal">LogicalRewriteMappingSync</code></td><td>Waiting for mapping data to reach stable storage during a logical rewrite.</td></tr><tr><td><code class="literal">LogicalRewriteMappingWrite</code></td><td>Waiting for a write of mapping data during a logical rewrite.</td></tr><tr><td><code class="literal">LogicalRewriteSync</code></td><td>Waiting for logical rewrite mappings to reach stable storage.</td></tr><tr><td><code class="literal">LogicalRewriteTruncate</code></td><td>Waiting for truncate of mapping data during a logical rewrite.</td></tr><tr><td><code class="literal">LogicalRewriteWrite</code></td><td>Waiting for a write of logical rewrite mappings.</td></tr><tr><td><code class="literal">RelationMapRead</code></td><td>Waiting for a read of the relation map file.</td></tr><tr><td><code class="literal">RelationMapSync</code></td><td>Waiting for the relation map file to reach stable storage.</td></tr><tr><td><code class="literal">RelationMapWrite</code></td><td>Waiting for a write to the relation map file.</td></tr><tr><td><code class="literal">ReorderBufferRead</code></td><td>Waiting for a read during reorder buffer management.</td></tr><tr><td><code class="literal">ReorderBufferWrite</code></td><td>Waiting for a write during reorder buffer management.</td></tr><tr><td><code class="literal">ReorderLogicalMappingRead</code></td><td>Waiting for a read of a logical mapping during reorder buffer management.</td></tr><tr><td><code class="literal">ReplicationSlotRead</code></td><td>Waiting for a read from a replication slot control file.</td></tr><tr><td><code class="literal">ReplicationSlotRestoreSync</code></td><td>Waiting for a replication slot control file to reach stable storage while restoring it to memory.</td></tr><tr><td><code class="literal">ReplicationSlotSync</code></td><td>Waiting for a replication slot control file to reach stable storage.</td></tr><tr><td><code class="literal">ReplicationSlotWrite</code></td><td>Waiting for a write to a replication slot control file.</td></tr><tr><td><code class="literal">SLRUFlushSync</code></td><td>Waiting for SLRU data to reach stable storage during a checkpoint or database shutdown.</td></tr><tr><td><code class="literal">SLRURead</code></td><td>Waiting for a read of an SLRU page.</td></tr><tr><td><code class="literal">SLRUSync</code></td><td>Waiting for SLRU data to reach stable storage following a page write.</td></tr><tr><td><code class="literal">SLRUWrite</code></td><td>Waiting for a write of an SLRU page.</td></tr><tr><td><code class="literal">SnapbuildRead</code></td><td>Waiting for a read of a serialized historical catalog snapshot.</td></tr><tr><td><code class="literal">SnapbuildSync</code></td><td>Waiting for a serialized historical catalog snapshot to reach stable storage.</td></tr><tr><td><code class="literal">SnapbuildWrite</code></td><td>Waiting for a write of a serialized historical catalog snapshot.</td></tr><tr><td><code class="literal">TimelineHistoryFileSync</code></td><td>Waiting for a timeline history file received via streaming replication to reach stable storage.</td></tr><tr><td><code class="literal">TimelineHistoryFileWrite</code></td><td>Waiting for a write of a timeline history file received via streaming replication.</td></tr><tr><td><code class="literal">TimelineHistoryRead</code></td><td>Waiting for a read of a timeline history file.</td></tr><tr><td><code class="literal">TimelineHistorySync</code></td><td>Waiting for a newly created timeline history file to reach stable storage.</td></tr><tr><td><code class="literal">TimelineHistoryWrite</code></td><td>Waiting for a write of a newly created timeline history file.</td></tr><tr><td><code class="literal">TwophaseFileRead</code></td><td>Waiting for a read of a two phase state file.</td></tr><tr><td><code class="literal">TwophaseFileSync</code></td><td>Waiting for a two phase state file to reach stable storage.</td></tr><tr><td><code class="literal">TwophaseFileWrite</code></td><td>Waiting for a write of a two phase state file.</td></tr><tr><td><code class="literal">WALBootstrapSync</code></td><td>Waiting for WAL to reach stable storage during bootstrapping.</td></tr><tr><td><code class="literal">WALBootstrapWrite</code></td><td>Waiting for a write of a WAL page during bootstrapping.</td></tr><tr><td><code class="literal">WALCopyRead</code></td><td>Waiting for a read when creating a new WAL segment by copying an existing one.</td></tr><tr><td><code class="literal">WALCopySync</code></td><td>Waiting a new WAL segment created by copying an existing one to reach stable storage.</td></tr><tr><td><code class="literal">WALCopyWrite</code></td><td>Waiting for a write when creating a new WAL segment by copying an existing one.</td></tr><tr><td><code class="literal">WALInitSync</code></td><td>Waiting for a newly initialized WAL file to reach stable storage.</td></tr><tr><td><code class="literal">WALInitWrite</code></td><td>Waiting for a write while initializing a new WAL file.</td></tr><tr><td><code class="literal">WALRead</code></td><td>Waiting for a read from a WAL file.</td></tr><tr><td><code class="literal">WALSenderTimelineHistoryRead</code></td><td>Waiting for a read from a timeline history file during walsender timeline command.</td></tr><tr><td><code class="literal">WALSync</code></td><td>Waiting for a WAL file to reach stable storage.</td></tr><tr><td><code class="literal">WALSyncMethodAssign</code></td><td>Waiting for data to reach stable storage while assigning WAL sync method.</td></tr><tr><td><code class="literal">WALWrite</code></td><td>Waiting for a write to a WAL file.</td></tr></tbody></table></div></div><br class="table-break" /><div class="note"><h3 class="title">Note</h3><p>
  350. For tranches registered by extensions, the name is specified by extension
  351. and this will be displayed as <code class="structfield">wait_event</code>. It is quite
  352. possible that user has registered the tranche in one of the backends (by
  353. having allocation in dynamic shared memory) in which case other backends
  354. won't have that information, so we display <code class="literal">extension</code> for such
  355. cases.
  356. </p></div><p>
  357. Here is an example of how wait events can be viewed
  358. </p><pre class="programlisting">
  359. SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
  360. pid | wait_event_type | wait_event
  361. ------+-----------------+---------------
  362. 2540 | Lock | relation
  363. 6644 | LWLock | ProcArrayLock
  364. (2 rows)
  365. </pre><p>
  366. </p><div class="table" id="PG-STAT-REPLICATION-VIEW"><p class="title"><strong>Table 27.5. <code class="structname">pg_stat_replication</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_replication View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of a WAL sender process</td></tr><tr><td><code class="structfield">usesysid</code></td><td><code class="type">oid</code></td><td>OID of the user logged into this WAL sender process</td></tr><tr><td><code class="structfield">usename</code></td><td><code class="type">name</code></td><td>Name of the user logged into this WAL sender process</td></tr><tr><td><code class="structfield">application_name</code></td><td><code class="type">text</code></td><td>Name of the application that is connected
  367. to this WAL sender</td></tr><tr><td><code class="structfield">client_addr</code></td><td><code class="type">inet</code></td><td>IP address of the client connected to this WAL sender.
  368. If this field is null, it indicates that the client is
  369. connected via a Unix socket on the server machine.
  370. </td></tr><tr><td><code class="structfield">client_hostname</code></td><td><code class="type">text</code></td><td>Host name of the connected client, as reported by a
  371. reverse DNS lookup of <code class="structfield">client_addr</code>. This field will
  372. only be non-null for IP connections, and only when <a class="xref" href="runtime-config-logging.html#GUC-LOG-HOSTNAME">log_hostname</a> is enabled.
  373. </td></tr><tr><td><code class="structfield">client_port</code></td><td><code class="type">integer</code></td><td>TCP port number that the client is using for communication
  374. with this WAL sender, or <code class="literal">-1</code> if a Unix socket is used
  375. </td></tr><tr><td><code class="structfield">backend_start</code></td><td><code class="type">timestamp with time zone</code></td><td>Time when this process was started, i.e., when the
  376. client connected to this WAL sender
  377. </td></tr><tr><td><code class="structfield">backend_xmin</code></td><td><code class="type">xid</code></td><td>This standby's <code class="literal">xmin</code> horizon reported
  378. by <a class="xref" href="runtime-config-replication.html#GUC-HOT-STANDBY-FEEDBACK">hot_standby_feedback</a>.</td></tr><tr><td><code class="structfield">state</code></td><td><code class="type">text</code></td><td>Current WAL sender state.
  379. Possible values are:
  380. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  381. <code class="literal">startup</code>: This WAL sender is starting up.
  382. </p></li><li class="listitem"><p>
  383. <code class="literal">catchup</code>: This WAL sender's connected standby is
  384. catching up with the primary.
  385. </p></li><li class="listitem"><p>
  386. <code class="literal">streaming</code>: This WAL sender is streaming changes
  387. after its connected standby server has caught up with the primary.
  388. </p></li><li class="listitem"><p>
  389. <code class="literal">backup</code>: This WAL sender is sending a backup.
  390. </p></li><li class="listitem"><p>
  391. <code class="literal">stopping</code>: This WAL sender is stopping.
  392. </p></li></ul></div>
  393. </td></tr><tr><td><code class="structfield">sent_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location sent on this connection</td></tr><tr><td><code class="structfield">write_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location written to disk by this standby
  394. server</td></tr><tr><td><code class="structfield">flush_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location flushed to disk by this standby
  395. server</td></tr><tr><td><code class="structfield">replay_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location replayed into the database on this
  396. standby server</td></tr><tr><td><code class="structfield">write_lag</code></td><td><code class="type">interval</code></td><td>Time elapsed between flushing recent WAL locally and receiving
  397. notification that this standby server has written it (but not yet
  398. flushed it or applied it). This can be used to gauge the delay that
  399. <code class="literal">synchronous_commit</code> level
  400. <code class="literal">remote_write</code> incurred while committing if this
  401. server was configured as a synchronous standby.</td></tr><tr><td><code class="structfield">flush_lag</code></td><td><code class="type">interval</code></td><td>Time elapsed between flushing recent WAL locally and receiving
  402. notification that this standby server has written and flushed it
  403. (but not yet applied it). This can be used to gauge the delay that
  404. <code class="literal">synchronous_commit</code> level
  405. <code class="literal">on</code> incurred while committing if this
  406. server was configured as a synchronous standby.</td></tr><tr><td><code class="structfield">replay_lag</code></td><td><code class="type">interval</code></td><td>Time elapsed between flushing recent WAL locally and receiving
  407. notification that this standby server has written, flushed and
  408. applied it. This can be used to gauge the delay that
  409. <code class="literal">synchronous_commit</code> level
  410. <code class="literal">remote_apply</code> incurred while committing if this
  411. server was configured as a synchronous standby.</td></tr><tr><td><code class="structfield">sync_priority</code></td><td><code class="type">integer</code></td><td>Priority of this standby server for being chosen as the
  412. synchronous standby in a priority-based synchronous replication.
  413. This has no effect in a quorum-based synchronous replication.</td></tr><tr><td><code class="structfield">sync_state</code></td><td><code class="type">text</code></td><td>Synchronous state of this standby server.
  414. Possible values are:
  415. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  416. <code class="literal">async</code>: This standby server is asynchronous.
  417. </p></li><li class="listitem"><p>
  418. <code class="literal">potential</code>: This standby server is now asynchronous,
  419. but can potentially become synchronous if one of current
  420. synchronous ones fails.
  421. </p></li><li class="listitem"><p>
  422. <code class="literal">sync</code>: This standby server is synchronous.
  423. </p></li><li class="listitem"><p>
  424. <code class="literal">quorum</code>: This standby server is considered as a candidate
  425. for quorum standbys.
  426. </p></li></ul></div>
  427. </td></tr><tr><td><code class="structfield">reply_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Send time of last reply message received from standby server</td></tr></tbody></table></div></div><br class="table-break" /><p>
  428. The <code class="structname">pg_stat_replication</code> view will contain one row
  429. per WAL sender process, showing statistics about replication to that
  430. sender's connected standby server. Only directly connected standbys are
  431. listed; no information is available about downstream standby servers.
  432. </p><p>
  433. The lag times reported in the <code class="structname">pg_stat_replication</code>
  434. view are measurements of the time taken for recent WAL to be written,
  435. flushed and replayed and for the sender to know about it. These times
  436. represent the commit delay that was (or would have been) introduced by each
  437. synchronous commit level, if the remote server was configured as a
  438. synchronous standby. For an asynchronous standby, the
  439. <code class="structfield">replay_lag</code> column approximates the delay
  440. before recent transactions became visible to queries. If the standby
  441. server has entirely caught up with the sending server and there is no more
  442. WAL activity, the most recently measured lag times will continue to be
  443. displayed for a short time and then show NULL.
  444. </p><p>
  445. Lag times work automatically for physical replication. Logical decoding
  446. plugins may optionally emit tracking messages; if they do not, the tracking
  447. mechanism will simply display NULL lag.
  448. </p><div class="note"><h3 class="title">Note</h3><p>
  449. The reported lag times are not predictions of how long it will take for
  450. the standby to catch up with the sending server assuming the current
  451. rate of replay. Such a system would show similar times while new WAL is
  452. being generated, but would differ when the sender becomes idle. In
  453. particular, when the standby has caught up completely,
  454. <code class="structname">pg_stat_replication</code> shows the time taken to
  455. write, flush and replay the most recent reported WAL location rather than
  456. zero as some users might expect. This is consistent with the goal of
  457. measuring synchronous commit and transaction visibility delays for
  458. recent write transactions.
  459. To reduce confusion for users expecting a different model of lag, the
  460. lag columns revert to NULL after a short time on a fully replayed idle
  461. system. Monitoring systems should choose whether to represent this
  462. as missing data, zero or continue to display the last known value.
  463. </p></div><div class="table" id="PG-STAT-WAL-RECEIVER-VIEW"><p class="title"><strong>Table 27.6. <code class="structname">pg_stat_wal_receiver</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_wal_receiver View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of the WAL receiver process</td></tr><tr><td><code class="structfield">status</code></td><td><code class="type">text</code></td><td>Activity status of the WAL receiver process</td></tr><tr><td><code class="structfield">receive_start_lsn</code></td><td><code class="type">pg_lsn</code></td><td>First write-ahead log location used when WAL receiver is
  464. started</td></tr><tr><td><code class="structfield">receive_start_tli</code></td><td><code class="type">integer</code></td><td>First timeline number used when WAL receiver is started</td></tr><tr><td><code class="structfield">received_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location already received and flushed to
  465. disk, the initial value of this field being the first log location used
  466. when WAL receiver is started</td></tr><tr><td><code class="structfield">received_tli</code></td><td><code class="type">integer</code></td><td>Timeline number of last write-ahead log location received and
  467. flushed to disk, the initial value of this field being the timeline
  468. number of the first log location used when WAL receiver is started
  469. </td></tr><tr><td><code class="structfield">last_msg_send_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Send time of last message received from origin WAL sender</td></tr><tr><td><code class="structfield">last_msg_receipt_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Receipt time of last message received from origin WAL sender</td></tr><tr><td><code class="structfield">latest_end_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location reported to origin WAL sender</td></tr><tr><td><code class="structfield">latest_end_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Time of last write-ahead log location reported to origin WAL sender</td></tr><tr><td><code class="structfield">slot_name</code></td><td><code class="type">text</code></td><td>Replication slot name used by this WAL receiver</td></tr><tr><td><code class="structfield">sender_host</code></td><td><code class="type">text</code></td><td>
  470. Host of the <span class="productname">PostgreSQL</span> instance
  471. this WAL receiver is connected to. This can be a host name,
  472. an IP address, or a directory path if the connection is via
  473. Unix socket. (The path case can be distinguished because it
  474. will always be an absolute path, beginning with <code class="literal">/</code>.)
  475. </td></tr><tr><td><code class="structfield">sender_port</code></td><td><code class="type">integer</code></td><td>
  476. Port number of the <span class="productname">PostgreSQL</span> instance
  477. this WAL receiver is connected to.
  478. </td></tr><tr><td><code class="structfield">conninfo</code></td><td><code class="type">text</code></td><td>
  479. Connection string used by this WAL receiver,
  480. with security-sensitive fields obfuscated.
  481. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  482. The <code class="structname">pg_stat_wal_receiver</code> view will contain only
  483. one row, showing statistics about the WAL receiver from that receiver's
  484. connected server.
  485. </p><div class="table" id="PG-STAT-SUBSCRIPTION"><p class="title"><strong>Table 27.7. <code class="structname">pg_stat_subscription</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_subscription View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">subid</code></td><td><code class="type">oid</code></td><td>OID of the subscription</td></tr><tr><td><code class="structfield">subname</code></td><td><code class="type">text</code></td><td>Name of the subscription</td></tr><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of the subscription worker process</td></tr><tr><td><code class="structfield">relid</code></td><td><code class="type">Oid</code></td><td>OID of the relation that the worker is synchronizing; null for the
  486. main apply worker</td></tr><tr><td><code class="structfield">received_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location received, the initial value of
  487. this field being 0</td></tr><tr><td><code class="structfield">last_msg_send_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Send time of last message received from origin WAL sender</td></tr><tr><td><code class="structfield">last_msg_receipt_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Receipt time of last message received from origin WAL sender
  488. </td></tr><tr><td><code class="structfield">latest_end_lsn</code></td><td><code class="type">pg_lsn</code></td><td>Last write-ahead log location reported to origin WAL sender
  489. </td></tr><tr><td><code class="structfield">latest_end_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Time of last write-ahead log location reported to origin WAL
  490. sender</td></tr></tbody></table></div></div><br class="table-break" /><p>
  491. The <code class="structname">pg_stat_subscription</code> view will contain one
  492. row per subscription for main worker (with null PID if the worker is
  493. not running), and additional rows for workers handling the initial data
  494. copy of the subscribed tables.
  495. </p><div class="table" id="PG-STAT-SSL-VIEW"><p class="title"><strong>Table 27.8. <code class="structname">pg_stat_ssl</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_ssl View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of a backend or WAL sender process</td></tr><tr><td><code class="structfield">ssl</code></td><td><code class="type">boolean</code></td><td>True if SSL is used on this connection</td></tr><tr><td><code class="structfield">version</code></td><td><code class="type">text</code></td><td>Version of SSL in use, or NULL if SSL is not in use
  496. on this connection</td></tr><tr><td><code class="structfield">cipher</code></td><td><code class="type">text</code></td><td>Name of SSL cipher in use, or NULL if SSL is not in use
  497. on this connection</td></tr><tr><td><code class="structfield">bits</code></td><td><code class="type">integer</code></td><td>Number of bits in the encryption algorithm used, or NULL
  498. if SSL is not used on this connection</td></tr><tr><td><code class="structfield">compression</code></td><td><code class="type">boolean</code></td><td>True if SSL compression is in use, false if not,
  499. or NULL if SSL is not in use on this connection</td></tr><tr><td><code class="structfield">client_dn</code></td><td><code class="type">text</code></td><td>Distinguished Name (DN) field from the client certificate
  500. used, or NULL if no client certificate was supplied or if SSL
  501. is not in use on this connection. This field is truncated if the
  502. DN field is longer than <code class="symbol">NAMEDATALEN</code> (64 characters
  503. in a standard build).
  504. </td></tr><tr><td><code class="structfield">client_serial</code></td><td><code class="type">numeric</code></td><td>Serial number of the client certificate, or NULL if no client
  505. certificate was supplied or if SSL is not in use on this connection. The
  506. combination of certificate serial number and certificate issuer uniquely
  507. identifies a certificate (unless the issuer erroneously reuses serial
  508. numbers).</td></tr><tr><td><code class="structfield">issuer_dn</code></td><td><code class="type">text</code></td><td>DN of the issuer of the client certificate, or NULL if no client
  509. certificate was supplied or if SSL is not in use on this connection.
  510. This field is truncated like <code class="structfield">client_dn</code>.</td></tr></tbody></table></div></div><br class="table-break" /><p>
  511. The <code class="structname">pg_stat_ssl</code> view will contain one row per
  512. backend or WAL sender process, showing statistics about SSL usage on
  513. this connection. It can be joined to <code class="structname">pg_stat_activity</code>
  514. or <code class="structname">pg_stat_replication</code> on the
  515. <code class="structfield">pid</code> column to get more details about the
  516. connection.
  517. </p><div class="table" id="PG-STAT-GSSAPI-VIEW"><p class="title"><strong>Table 27.9. <code class="structname">pg_stat_gssapi</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_gssapi View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">pid</code></td><td><code class="type">integer</code></td><td>Process ID of a backend</td></tr><tr><td><code class="structfield">gss_authenticated</code></td><td><code class="type">boolean</code></td><td>True if GSSAPI authentication was used for this connection</td></tr><tr><td><code class="structfield">principal</code></td><td><code class="type">text</code></td><td>Principal used to authenticate this connection, or NULL
  518. if GSSAPI was not used to authenticate this connection. This
  519. field is truncated if the principal is longer than
  520. <code class="symbol">NAMEDATALEN</code> (64 characters in a standard build).
  521. </td></tr><tr><td><code class="structfield">encrypted</code></td><td><code class="type">boolean</code></td><td>True if GSSAPI encryption is in use on this connection</td></tr></tbody></table></div></div><br class="table-break" /><p>
  522. The <code class="structname">pg_stat_gssapi</code> view will contain one row per
  523. backend, showing information about GSSAPI usage on this connection. It can
  524. be joined to <code class="structname">pg_stat_activity</code> or
  525. <code class="structname">pg_stat_replication</code> on the
  526. <code class="structfield">pid</code> column to get more details about the
  527. connection.
  528. </p><div class="table" id="PG-STAT-ARCHIVER-VIEW"><p class="title"><strong>Table 27.10. <code class="structname">pg_stat_archiver</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_archiver View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">archived_count</code></td><td><code class="type">bigint</code></td><td>Number of WAL files that have been successfully archived</td></tr><tr><td><code class="structfield">last_archived_wal</code></td><td><code class="type">text</code></td><td>Name of the last WAL file successfully archived</td></tr><tr><td><code class="structfield">last_archived_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Time of the last successful archive operation</td></tr><tr><td><code class="structfield">failed_count</code></td><td><code class="type">bigint</code></td><td>Number of failed attempts for archiving WAL files</td></tr><tr><td><code class="structfield">last_failed_wal</code></td><td><code class="type">text</code></td><td>Name of the WAL file of the last failed archival operation</td></tr><tr><td><code class="structfield">last_failed_time</code></td><td><code class="type">timestamp with time zone</code></td><td>Time of the last failed archival operation</td></tr><tr><td><code class="structfield">stats_reset</code></td><td><code class="type">timestamp with time zone</code></td><td>Time at which these statistics were last reset</td></tr></tbody></table></div></div><br class="table-break" /><p>
  529. The <code class="structname">pg_stat_archiver</code> view will always have a
  530. single row, containing data about the archiver process of the cluster.
  531. </p><div class="table" id="PG-STAT-BGWRITER-VIEW"><p class="title"><strong>Table 27.11. <code class="structname">pg_stat_bgwriter</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_bgwriter View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">checkpoints_timed</code></td><td><code class="type">bigint</code></td><td>Number of scheduled checkpoints that have been performed</td></tr><tr><td><code class="structfield">checkpoints_req</code></td><td><code class="type">bigint</code></td><td>Number of requested checkpoints that have been performed</td></tr><tr><td><code class="structfield">checkpoint_write_time</code></td><td><code class="type">double precision</code></td><td>
  532. Total amount of time that has been spent in the portion of
  533. checkpoint processing where files are written to disk, in milliseconds
  534. </td></tr><tr><td><code class="structfield">checkpoint_sync_time</code></td><td><code class="type">double precision</code></td><td>
  535. Total amount of time that has been spent in the portion of
  536. checkpoint processing where files are synchronized to disk, in
  537. milliseconds
  538. </td></tr><tr><td><code class="structfield">buffers_checkpoint</code></td><td><code class="type">bigint</code></td><td>Number of buffers written during checkpoints</td></tr><tr><td><code class="structfield">buffers_clean</code></td><td><code class="type">bigint</code></td><td>Number of buffers written by the background writer</td></tr><tr><td><code class="structfield">maxwritten_clean</code></td><td><code class="type">bigint</code></td><td>Number of times the background writer stopped a cleaning
  539. scan because it had written too many buffers</td></tr><tr><td><code class="structfield">buffers_backend</code></td><td><code class="type">bigint</code></td><td>Number of buffers written directly by a backend</td></tr><tr><td><code class="structfield">buffers_backend_fsync</code></td><td><code class="type">bigint</code></td><td>Number of times a backend had to execute its own
  540. <code class="function">fsync</code> call (normally the background writer handles those
  541. even when the backend does its own write)</td></tr><tr><td><code class="structfield">buffers_alloc</code></td><td><code class="type">bigint</code></td><td>Number of buffers allocated</td></tr><tr><td><code class="structfield">stats_reset</code></td><td><code class="type">timestamp with time zone</code></td><td>Time at which these statistics were last reset</td></tr></tbody></table></div></div><br class="table-break" /><p>
  542. The <code class="structname">pg_stat_bgwriter</code> view will always have a
  543. single row, containing global data for the cluster.
  544. </p><div class="table" id="PG-STAT-DATABASE-VIEW"><p class="title"><strong>Table 27.12. <code class="structname">pg_stat_database</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_database View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">datid</code></td><td><code class="type">oid</code></td><td>OID of this database, or 0 for objects belonging to a shared
  545. relation</td></tr><tr><td><code class="structfield">datname</code></td><td><code class="type">name</code></td><td>Name of this database, or <code class="literal">NULL</code> for the shared
  546. objects.</td></tr><tr><td><code class="structfield">numbackends</code></td><td><code class="type">integer</code></td><td>Number of backends currently connected to this database, or
  547. <code class="literal">NULL</code> for the shared objects. This is the only column
  548. in this view that returns a value reflecting current state; all other
  549. columns return the accumulated values since the last reset.</td></tr><tr><td><code class="structfield">xact_commit</code></td><td><code class="type">bigint</code></td><td>Number of transactions in this database that have been
  550. committed</td></tr><tr><td><code class="structfield">xact_rollback</code></td><td><code class="type">bigint</code></td><td>Number of transactions in this database that have been
  551. rolled back</td></tr><tr><td><code class="structfield">blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read in this database</td></tr><tr><td><code class="structfield">blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of times disk blocks were found already in the buffer
  552. cache, so that a read was not necessary (this only includes hits in the
  553. PostgreSQL buffer cache, not the operating system's file system cache)
  554. </td></tr><tr><td><code class="structfield">tup_returned</code></td><td><code class="type">bigint</code></td><td>Number of rows returned by queries in this database</td></tr><tr><td><code class="structfield">tup_fetched</code></td><td><code class="type">bigint</code></td><td>Number of rows fetched by queries in this database</td></tr><tr><td><code class="structfield">tup_inserted</code></td><td><code class="type">bigint</code></td><td>Number of rows inserted by queries in this database</td></tr><tr><td><code class="structfield">tup_updated</code></td><td><code class="type">bigint</code></td><td>Number of rows updated by queries in this database</td></tr><tr><td><code class="structfield">tup_deleted</code></td><td><code class="type">bigint</code></td><td>Number of rows deleted by queries in this database</td></tr><tr><td><code class="structfield">conflicts</code></td><td><code class="type">bigint</code></td><td>Number of queries canceled due to conflicts with recovery
  555. in this database. (Conflicts occur only on standby servers; see
  556. <a class="xref" href="monitoring-stats.html#PG-STAT-DATABASE-CONFLICTS-VIEW" title="Table 27.13. pg_stat_database_conflicts View">pg_stat_database_conflicts</a> for details.)
  557. </td></tr><tr><td><code class="structfield">temp_files</code></td><td><code class="type">bigint</code></td><td>Number of temporary files created by queries in this database.
  558. All temporary files are counted, regardless of why the temporary file
  559. was created (e.g., sorting or hashing), and regardless of the
  560. <a class="xref" href="runtime-config-logging.html#GUC-LOG-TEMP-FILES">log_temp_files</a> setting.
  561. </td></tr><tr><td><code class="structfield">temp_bytes</code></td><td><code class="type">bigint</code></td><td>Total amount of data written to temporary files by queries in
  562. this database. All temporary files are counted, regardless of why
  563. the temporary file was created, and
  564. regardless of the <a class="xref" href="runtime-config-logging.html#GUC-LOG-TEMP-FILES">log_temp_files</a> setting.
  565. </td></tr><tr><td><code class="structfield">deadlocks</code></td><td><code class="type">bigint</code></td><td>Number of deadlocks detected in this database</td></tr><tr><td><code class="structfield">checksum_failures</code></td><td><code class="type">bigint</code></td><td>Number of data page checksum failures detected in this
  566. database (or on a shared object), or NULL if data checksums are not
  567. enabled.</td></tr><tr><td><code class="structfield">checksum_last_failure</code></td><td><code class="type">timestamp with time zone</code></td><td>Time at which the last data page checksum failure was detected in
  568. this database (or on a shared object), or NULL if data checksums are not
  569. enabled.</td></tr><tr><td><code class="structfield">blk_read_time</code></td><td><code class="type">double precision</code></td><td>Time spent reading data file blocks by backends in this database,
  570. in milliseconds</td></tr><tr><td><code class="structfield">blk_write_time</code></td><td><code class="type">double precision</code></td><td>Time spent writing data file blocks by backends in this database,
  571. in milliseconds</td></tr><tr><td><code class="structfield">stats_reset</code></td><td><code class="type">timestamp with time zone</code></td><td>Time at which these statistics were last reset</td></tr></tbody></table></div></div><br class="table-break" /><p>
  572. The <code class="structname">pg_stat_database</code> view will contain one row
  573. for each database in the cluster, plus one for the shared objects, showing
  574. database-wide statistics.
  575. </p><div class="table" id="PG-STAT-DATABASE-CONFLICTS-VIEW"><p class="title"><strong>Table 27.13. <code class="structname">pg_stat_database_conflicts</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_database_conflicts View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">datid</code></td><td><code class="type">oid</code></td><td>OID of a database</td></tr><tr><td><code class="structfield">datname</code></td><td><code class="type">name</code></td><td>Name of this database</td></tr><tr><td><code class="structfield">confl_tablespace</code></td><td><code class="type">bigint</code></td><td>Number of queries in this database that have been canceled due to
  576. dropped tablespaces</td></tr><tr><td><code class="structfield">confl_lock</code></td><td><code class="type">bigint</code></td><td>Number of queries in this database that have been canceled due to
  577. lock timeouts</td></tr><tr><td><code class="structfield">confl_snapshot</code></td><td><code class="type">bigint</code></td><td>Number of queries in this database that have been canceled due to
  578. old snapshots</td></tr><tr><td><code class="structfield">confl_bufferpin</code></td><td><code class="type">bigint</code></td><td>Number of queries in this database that have been canceled due to
  579. pinned buffers</td></tr><tr><td><code class="structfield">confl_deadlock</code></td><td><code class="type">bigint</code></td><td>Number of queries in this database that have been canceled due to
  580. deadlocks</td></tr></tbody></table></div></div><br class="table-break" /><p>
  581. The <code class="structname">pg_stat_database_conflicts</code> view will contain
  582. one row per database, showing database-wide statistics about
  583. query cancels occurring due to conflicts with recovery on standby servers.
  584. This view will only contain information on standby servers, since
  585. conflicts do not occur on master servers.
  586. </p><div class="table" id="PG-STAT-ALL-TABLES-VIEW"><p class="title"><strong>Table 27.14. <code class="structname">pg_stat_all_tables</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_all_tables View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">relid</code></td><td><code class="type">oid</code></td><td>OID of a table</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema that this table is in</td></tr><tr><td><code class="structfield">relname</code></td><td><code class="type">name</code></td><td>Name of this table</td></tr><tr><td><code class="structfield">seq_scan</code></td><td><code class="type">bigint</code></td><td>Number of sequential scans initiated on this table</td></tr><tr><td><code class="structfield">seq_tup_read</code></td><td><code class="type">bigint</code></td><td>Number of live rows fetched by sequential scans</td></tr><tr><td><code class="structfield">idx_scan</code></td><td><code class="type">bigint</code></td><td>Number of index scans initiated on this table</td></tr><tr><td><code class="structfield">idx_tup_fetch</code></td><td><code class="type">bigint</code></td><td>Number of live rows fetched by index scans</td></tr><tr><td><code class="structfield">n_tup_ins</code></td><td><code class="type">bigint</code></td><td>Number of rows inserted</td></tr><tr><td><code class="structfield">n_tup_upd</code></td><td><code class="type">bigint</code></td><td>Number of rows updated (includes HOT updated rows)</td></tr><tr><td><code class="structfield">n_tup_del</code></td><td><code class="type">bigint</code></td><td>Number of rows deleted</td></tr><tr><td><code class="structfield">n_tup_hot_upd</code></td><td><code class="type">bigint</code></td><td>Number of rows HOT updated (i.e., with no separate index
  587. update required)</td></tr><tr><td><code class="structfield">n_live_tup</code></td><td><code class="type">bigint</code></td><td>Estimated number of live rows</td></tr><tr><td><code class="structfield">n_dead_tup</code></td><td><code class="type">bigint</code></td><td>Estimated number of dead rows</td></tr><tr><td><code class="structfield">n_mod_since_analyze</code></td><td><code class="type">bigint</code></td><td>Estimated number of rows modified since this table was last analyzed</td></tr><tr><td><code class="structfield">last_vacuum</code></td><td><code class="type">timestamp with time zone</code></td><td>Last time at which this table was manually vacuumed
  588. (not counting <code class="command">VACUUM FULL</code>)</td></tr><tr><td><code class="structfield">last_autovacuum</code></td><td><code class="type">timestamp with time zone</code></td><td>Last time at which this table was vacuumed by the autovacuum
  589. daemon</td></tr><tr><td><code class="structfield">last_analyze</code></td><td><code class="type">timestamp with time zone</code></td><td>Last time at which this table was manually analyzed</td></tr><tr><td><code class="structfield">last_autoanalyze</code></td><td><code class="type">timestamp with time zone</code></td><td>Last time at which this table was analyzed by the autovacuum
  590. daemon</td></tr><tr><td><code class="structfield">vacuum_count</code></td><td><code class="type">bigint</code></td><td>Number of times this table has been manually vacuumed
  591. (not counting <code class="command">VACUUM FULL</code>)</td></tr><tr><td><code class="structfield">autovacuum_count</code></td><td><code class="type">bigint</code></td><td>Number of times this table has been vacuumed by the autovacuum
  592. daemon</td></tr><tr><td><code class="structfield">analyze_count</code></td><td><code class="type">bigint</code></td><td>Number of times this table has been manually analyzed</td></tr><tr><td><code class="structfield">autoanalyze_count</code></td><td><code class="type">bigint</code></td><td>Number of times this table has been analyzed by the autovacuum
  593. daemon</td></tr></tbody></table></div></div><br class="table-break" /><p>
  594. The <code class="structname">pg_stat_all_tables</code> view will contain
  595. one row for each table in the current database (including TOAST
  596. tables), showing statistics about accesses to that specific table. The
  597. <code class="structname">pg_stat_user_tables</code> and
  598. <code class="structname">pg_stat_sys_tables</code> views
  599. contain the same information,
  600. but filtered to only show user and system tables respectively.
  601. </p><div class="table" id="PG-STAT-ALL-INDEXES-VIEW"><p class="title"><strong>Table 27.15. <code class="structname">pg_stat_all_indexes</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_all_indexes View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">relid</code></td><td><code class="type">oid</code></td><td>OID of the table for this index</td></tr><tr><td><code class="structfield">indexrelid</code></td><td><code class="type">oid</code></td><td>OID of this index</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema this index is in</td></tr><tr><td><code class="structfield">relname</code></td><td><code class="type">name</code></td><td>Name of the table for this index</td></tr><tr><td><code class="structfield">indexrelname</code></td><td><code class="type">name</code></td><td>Name of this index</td></tr><tr><td><code class="structfield">idx_scan</code></td><td><code class="type">bigint</code></td><td>Number of index scans initiated on this index</td></tr><tr><td><code class="structfield">idx_tup_read</code></td><td><code class="type">bigint</code></td><td>Number of index entries returned by scans on this index</td></tr><tr><td><code class="structfield">idx_tup_fetch</code></td><td><code class="type">bigint</code></td><td>Number of live table rows fetched by simple index scans using this
  602. index</td></tr></tbody></table></div></div><br class="table-break" /><p>
  603. The <code class="structname">pg_stat_all_indexes</code> view will contain
  604. one row for each index in the current database,
  605. showing statistics about accesses to that specific index. The
  606. <code class="structname">pg_stat_user_indexes</code> and
  607. <code class="structname">pg_stat_sys_indexes</code> views
  608. contain the same information,
  609. but filtered to only show user and system indexes respectively.
  610. </p><p>
  611. Indexes can be used by simple index scans, <span class="quote">“<span class="quote">bitmap</span>”</span> index scans,
  612. and the optimizer. In a bitmap scan
  613. the output of several indexes can be combined via AND or OR rules,
  614. so it is difficult to associate individual heap row fetches
  615. with specific indexes when a bitmap scan is used. Therefore, a bitmap
  616. scan increments the
  617. <code class="structname">pg_stat_all_indexes</code>.<code class="structfield">idx_tup_read</code>
  618. count(s) for the index(es) it uses, and it increments the
  619. <code class="structname">pg_stat_all_tables</code>.<code class="structfield">idx_tup_fetch</code>
  620. count for the table, but it does not affect
  621. <code class="structname">pg_stat_all_indexes</code>.<code class="structfield">idx_tup_fetch</code>.
  622. The optimizer also accesses indexes to check for supplied constants
  623. whose values are outside the recorded range of the optimizer statistics
  624. because the optimizer statistics might be stale.
  625. </p><div class="note"><h3 class="title">Note</h3><p>
  626. The <code class="structfield">idx_tup_read</code> and <code class="structfield">idx_tup_fetch</code> counts
  627. can be different even without any use of bitmap scans,
  628. because <code class="structfield">idx_tup_read</code> counts
  629. index entries retrieved from the index while <code class="structfield">idx_tup_fetch</code>
  630. counts live rows fetched from the table. The latter will be less if any
  631. dead or not-yet-committed rows are fetched using the index, or if any
  632. heap fetches are avoided by means of an index-only scan.
  633. </p></div><div class="table" id="PG-STATIO-ALL-TABLES-VIEW"><p class="title"><strong>Table 27.16. <code class="structname">pg_statio_all_tables</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_statio_all_tables View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">relid</code></td><td><code class="type">oid</code></td><td>OID of a table</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema that this table is in</td></tr><tr><td><code class="structfield">relname</code></td><td><code class="type">name</code></td><td>Name of this table</td></tr><tr><td><code class="structfield">heap_blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from this table</td></tr><tr><td><code class="structfield">heap_blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in this table</td></tr><tr><td><code class="structfield">idx_blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from all indexes on this table</td></tr><tr><td><code class="structfield">idx_blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in all indexes on this table</td></tr><tr><td><code class="structfield">toast_blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from this table's TOAST table (if any)</td></tr><tr><td><code class="structfield">toast_blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in this table's TOAST table (if any)</td></tr><tr><td><code class="structfield">tidx_blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from this table's TOAST table indexes (if any)</td></tr><tr><td><code class="structfield">tidx_blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in this table's TOAST table indexes (if any)</td></tr></tbody></table></div></div><br class="table-break" /><p>
  634. The <code class="structname">pg_statio_all_tables</code> view will contain
  635. one row for each table in the current database (including TOAST
  636. tables), showing statistics about I/O on that specific table. The
  637. <code class="structname">pg_statio_user_tables</code> and
  638. <code class="structname">pg_statio_sys_tables</code> views
  639. contain the same information,
  640. but filtered to only show user and system tables respectively.
  641. </p><div class="table" id="PG-STATIO-ALL-INDEXES-VIEW"><p class="title"><strong>Table 27.17. <code class="structname">pg_statio_all_indexes</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_statio_all_indexes View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">relid</code></td><td><code class="type">oid</code></td><td>OID of the table for this index</td></tr><tr><td><code class="structfield">indexrelid</code></td><td><code class="type">oid</code></td><td>OID of this index</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema this index is in</td></tr><tr><td><code class="structfield">relname</code></td><td><code class="type">name</code></td><td>Name of the table for this index</td></tr><tr><td><code class="structfield">indexrelname</code></td><td><code class="type">name</code></td><td>Name of this index</td></tr><tr><td><code class="structfield">idx_blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from this index</td></tr><tr><td><code class="structfield">idx_blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in this index</td></tr></tbody></table></div></div><br class="table-break" /><p>
  642. The <code class="structname">pg_statio_all_indexes</code> view will contain
  643. one row for each index in the current database,
  644. showing statistics about I/O on that specific index. The
  645. <code class="structname">pg_statio_user_indexes</code> and
  646. <code class="structname">pg_statio_sys_indexes</code> views
  647. contain the same information,
  648. but filtered to only show user and system indexes respectively.
  649. </p><div class="table" id="PG-STATIO-ALL-SEQUENCES-VIEW"><p class="title"><strong>Table 27.18. <code class="structname">pg_statio_all_sequences</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_statio_all_sequences View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">relid</code></td><td><code class="type">oid</code></td><td>OID of a sequence</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema this sequence is in</td></tr><tr><td><code class="structfield">relname</code></td><td><code class="type">name</code></td><td>Name of this sequence</td></tr><tr><td><code class="structfield">blks_read</code></td><td><code class="type">bigint</code></td><td>Number of disk blocks read from this sequence</td></tr><tr><td><code class="structfield">blks_hit</code></td><td><code class="type">bigint</code></td><td>Number of buffer hits in this sequence</td></tr></tbody></table></div></div><br class="table-break" /><p>
  650. The <code class="structname">pg_statio_all_sequences</code> view will contain
  651. one row for each sequence in the current database,
  652. showing statistics about I/O on that specific sequence.
  653. </p><div class="table" id="PG-STAT-USER-FUNCTIONS-VIEW"><p class="title"><strong>Table 27.19. <code class="structname">pg_stat_user_functions</code> View</strong></p><div class="table-contents"><table class="table" summary="pg_stat_user_functions View" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">funcid</code></td><td><code class="type">oid</code></td><td>OID of a function</td></tr><tr><td><code class="structfield">schemaname</code></td><td><code class="type">name</code></td><td>Name of the schema this function is in</td></tr><tr><td><code class="structfield">funcname</code></td><td><code class="type">name</code></td><td>Name of this function</td></tr><tr><td><code class="structfield">calls</code></td><td><code class="type">bigint</code></td><td>Number of times this function has been called</td></tr><tr><td><code class="structfield">total_time</code></td><td><code class="type">double precision</code></td><td>Total time spent in this function and all other functions
  654. called by it, in milliseconds</td></tr><tr><td><code class="structfield">self_time</code></td><td><code class="type">double precision</code></td><td>Total time spent in this function itself, not including
  655. other functions called by it, in milliseconds</td></tr></tbody></table></div></div><br class="table-break" /><p>
  656. The <code class="structname">pg_stat_user_functions</code> view will contain
  657. one row for each tracked function, showing statistics about executions of
  658. that function. The <a class="xref" href="runtime-config-statistics.html#GUC-TRACK-FUNCTIONS">track_functions</a> parameter
  659. controls exactly which functions are tracked.
  660. </p></div><div class="sect2" id="MONITORING-STATS-FUNCTIONS"><div class="titlepage"><div><div><h3 class="title">27.2.3. Statistics Functions</h3></div></div></div><p>
  661. Other ways of looking at the statistics can be set up by writing
  662. queries that use the same underlying statistics access functions used by
  663. the standard views shown above. For details such as the functions' names,
  664. consult the definitions of the standard views. (For example, in
  665. <span class="application">psql</span> you could issue <code class="literal">\d+ pg_stat_activity</code>.)
  666. The access functions for per-database statistics take a database OID as an
  667. argument to identify which database to report on.
  668. The per-table and per-index functions take a table or index OID.
  669. The functions for per-function statistics take a function OID.
  670. Note that only tables, indexes, and functions in the current database
  671. can be seen with these functions.
  672. </p><p>
  673. Additional functions related to statistics collection are listed in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-FUNCS-TABLE" title="Table 27.20. Additional Statistics Functions">Table 27.20</a>.
  674. </p><div class="table" id="MONITORING-STATS-FUNCS-TABLE"><p class="title"><strong>Table 27.20. Additional Statistics Functions</strong></p><div class="table-contents"><table class="table" summary="Additional Statistics Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Function</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal"><code class="function">pg_backend_pid()</code></code></td><td><code class="type">integer</code></td><td>
  675. Process ID of the server process handling the current session
  676. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_activity</code>(<code class="type">integer</code>)</code><a id="id-1.6.14.7.7.4.2.2.2.1.2" class="indexterm"></a></td><td><code class="type">setof record</code></td><td>
  677. Returns a record of information about the backend with the specified PID, or
  678. one record for each active backend in the system if <code class="symbol">NULL</code> is
  679. specified. The fields returned are a subset of those in the
  680. <code class="structname">pg_stat_activity</code> view.
  681. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_snapshot_timestamp()</code></code><a id="id-1.6.14.7.7.4.2.2.3.1.2" class="indexterm"></a></td><td><code class="type">timestamp with time zone</code></td><td>
  682. Returns the timestamp of the current statistics snapshot
  683. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_clear_snapshot()</code></code><a id="id-1.6.14.7.7.4.2.2.4.1.2" class="indexterm"></a></td><td><code class="type">void</code></td><td>
  684. Discard the current statistics snapshot
  685. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_reset()</code></code><a id="id-1.6.14.7.7.4.2.2.5.1.2" class="indexterm"></a></td><td><code class="type">void</code></td><td>
  686. Reset all statistics counters for the current database to zero
  687. (requires superuser privileges by default, but EXECUTE for this
  688. function can be granted to others.)
  689. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_reset_shared</code>(text)</code><a id="id-1.6.14.7.7.4.2.2.6.1.2" class="indexterm"></a></td><td><code class="type">void</code></td><td>
  690. Reset some cluster-wide statistics counters to zero, depending on the
  691. argument (requires superuser privileges by default, but EXECUTE for
  692. this function can be granted to others).
  693. Calling <code class="literal">pg_stat_reset_shared('bgwriter')</code> will zero all the
  694. counters shown in the <code class="structname">pg_stat_bgwriter</code> view.
  695. Calling <code class="literal">pg_stat_reset_shared('archiver')</code> will zero all the
  696. counters shown in the <code class="structname">pg_stat_archiver</code> view.
  697. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_reset_single_table_counters</code>(oid)</code><a id="id-1.6.14.7.7.4.2.2.7.1.2" class="indexterm"></a></td><td><code class="type">void</code></td><td>
  698. Reset statistics for a single table or index in the current database to
  699. zero (requires superuser privileges by default, but EXECUTE for this
  700. function can be granted to others)
  701. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_reset_single_function_counters</code>(oid)</code><a id="id-1.6.14.7.7.4.2.2.8.1.2" class="indexterm"></a></td><td><code class="type">void</code></td><td>
  702. Reset statistics for a single function in the current database to
  703. zero (requires superuser privileges by default, but EXECUTE for this
  704. function can be granted to others)
  705. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  706. <code class="function">pg_stat_get_activity</code>, the underlying function of
  707. the <code class="structname">pg_stat_activity</code> view, returns a set of records
  708. containing all the available information about each backend process.
  709. Sometimes it may be more convenient to obtain just a subset of this
  710. information. In such cases, an older set of per-backend statistics
  711. access functions can be used; these are shown in <a class="xref" href="monitoring-stats.html#MONITORING-STATS-BACKEND-FUNCS-TABLE" title="Table 27.21. Per-Backend Statistics Functions">Table 27.21</a>.
  712. These access functions use a backend ID number, which ranges from one
  713. to the number of currently active backends.
  714. The function <code class="function">pg_stat_get_backend_idset</code> provides a
  715. convenient way to generate one row for each active backend for
  716. invoking these functions. For example, to show the <acronym class="acronym">PID</acronym>s and
  717. current queries of all backends:
  718. </p><pre class="programlisting">
  719. SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
  720. pg_stat_get_backend_activity(s.backendid) AS query
  721. FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
  722. </pre><p>
  723. </p><div class="table" id="MONITORING-STATS-BACKEND-FUNCS-TABLE"><p class="title"><strong>Table 27.21. Per-Backend Statistics Functions</strong></p><div class="table-contents"><table class="table" summary="Per-Backend Statistics Functions" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Function</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal"><code class="function">pg_stat_get_backend_idset()</code></code></td><td><code class="type">setof integer</code></td><td>Set of currently active backend ID numbers (from 1 to the
  724. number of active backends)</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_activity(integer)</code></code></td><td><code class="type">text</code></td><td>Text of this backend's most recent query</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_activity_start(integer)</code></code></td><td><code class="type">timestamp with time zone</code></td><td>Time when the most recent query was started</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_client_addr(integer)</code></code></td><td><code class="type">inet</code></td><td>IP address of the client connected to this backend</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_client_port(integer)</code></code></td><td><code class="type">integer</code></td><td>TCP port number that the client is using for communication</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_dbid(integer)</code></code></td><td><code class="type">oid</code></td><td>OID of the database this backend is connected to</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_pid(integer)</code></code></td><td><code class="type">integer</code></td><td>Process ID of this backend</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_start(integer)</code></code></td><td><code class="type">timestamp with time zone</code></td><td>Time when this process was started</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_userid(integer)</code></code></td><td><code class="type">oid</code></td><td>OID of the user logged into this backend</td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_wait_event_type(integer)</code></code></td><td><code class="type">text</code></td><td>Wait event type name if backend is currently waiting, otherwise NULL.
  725. See <a class="xref" href="monitoring-stats.html#WAIT-EVENT-TABLE" title="Table 27.4. wait_event Description">Table 27.4</a> for details.
  726. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_wait_event(integer)</code></code></td><td><code class="type">text</code></td><td>Wait event name if backend is currently waiting, otherwise NULL.
  727. See <a class="xref" href="monitoring-stats.html#WAIT-EVENT-TABLE" title="Table 27.4. wait_event Description">Table 27.4</a> for details.
  728. </td></tr><tr><td><code class="literal"><code class="function">pg_stat_get_backend_xact_start(integer)</code></code></td><td><code class="type">timestamp with time zone</code></td><td>Time when the current transaction was started</td></tr></tbody></table></div></div><br class="table-break" /></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="monitoring-ps.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="monitoring.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="monitoring-locks.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">27.1. Standard Unix Tools </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 27.3. Viewing Locks</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1