1 <!-- doc/src/sgml/monitoring.sgml -->
3 <chapter id=
"monitoring">
4 <title>Monitoring Database Activity
</title>
6 <indexterm zone=
"monitoring">
7 <primary>monitoring
</primary>
8 <secondary>database activity
</secondary>
11 <indexterm zone=
"monitoring">
12 <primary>database activity
</primary>
13 <secondary>monitoring
</secondary>
17 A database administrator frequently wonders,
<quote>What is the system
18 doing right now?
</quote>
19 This chapter discusses how to find that out.
23 Several tools are available for monitoring database activity and
24 analyzing performance. Most of this chapter is devoted to describing
25 <productname>PostgreSQL
</productname>'s cumulative statistics system,
26 but one should not neglect regular Unix monitoring programs such as
27 <command>ps
</command>,
<command>top
</command>,
<command>iostat
</command>, and
<command>vmstat
</command>.
28 Also, once one has identified a
29 poorly-performing query, further investigation might be needed using
30 <productname>PostgreSQL
</productname>'s
<link linkend=
"sql-explain"><command>EXPLAIN
</command></link> command.
31 <xref linkend=
"using-explain"/> discusses
<command>EXPLAIN
</command>
32 and other methods for understanding the behavior of an individual
36 <sect1 id=
"monitoring-ps">
37 <title>Standard Unix Tools
</title>
39 <indexterm zone=
"monitoring-ps">
41 <secondary>to monitor activity
</secondary>
45 On most Unix platforms,
<productname>PostgreSQL
</productname> modifies its
46 command title as reported by
<command>ps
</command>, so that individual server
47 processes can readily be identified. A sample display is
50 $ ps auxww | grep ^postgres
51 postgres
15551 0.0 0.1 57536 7132 pts/
0 S
18:
02 0:
00 postgres -i
52 postgres
15554 0.0 0.0 57536 1184 ? Ss
18:
02 0:
00 postgres: background writer
53 postgres
15555 0.0 0.0 57536 916 ? Ss
18:
02 0:
00 postgres: checkpointer
54 postgres
15556 0.0 0.0 57536 916 ? Ss
18:
02 0:
00 postgres: walwriter
55 postgres
15557 0.0 0.0 58504 2244 ? Ss
18:
02 0:
00 postgres: autovacuum launcher
56 postgres
15582 0.0 0.0 58772 3080 ? Ss
18:
04 0:
00 postgres: joe runbug
127.0.0.1 idle
57 postgres
15606 0.0 0.0 58772 3052 ? Ss
18:
07 0:
00 postgres: tgl regression [local] SELECT waiting
58 postgres
15610 0.0 0.0 58772 3056 ? Ss
18:
07 0:
00 postgres: tgl regression [local] idle in transaction
61 (The appropriate invocation of
<command>ps
</command> varies across different
62 platforms, as do the details of what is shown. This example is from a
63 recent Linux system.) The first process listed here is the
64 primary server process. The command arguments
65 shown for it are the same ones used when it was launched. The next four
66 processes are background worker processes automatically launched by the
67 primary process. (The
<quote>autovacuum launcher
</quote> process will not
68 be present if you have set the system not to run autovacuum.)
70 processes is a server process handling one client connection. Each such
71 process sets its command line display in the form
74 postgres:
<replaceable>user
</replaceable> <replaceable>database
</replaceable> <replaceable>host
</replaceable> <replaceable>activity
</replaceable>
77 The user, database, and (client) host items remain the same for
78 the life of the client connection, but the activity indicator changes.
79 The activity can be
<literal>idle
</literal> (i.e., waiting for a client command),
80 <literal>idle in transaction
</literal> (waiting for client inside a
<command>BEGIN
</command> block),
81 or a command type name such as
<literal>SELECT
</literal>. Also,
82 <literal>waiting
</literal> is appended if the server process is presently waiting
83 on a lock held by another session. In the above example we can infer
84 that process
15606 is waiting for process
15610 to complete its transaction
85 and thereby release some lock. (Process
15610 must be the blocker, because
86 there is no other active session. In more complicated cases it would be
87 necessary to look into the
88 <link linkend=
"view-pg-locks"><structname>pg_locks
</structname></link>
89 system view to determine who is blocking whom.)
93 If
<xref linkend=
"guc-cluster-name"/> has been configured the
94 cluster name will also be shown in
<command>ps
</command> output:
96 $ psql -c 'SHOW cluster_name'
102 $ ps aux|grep server1
103 postgres
27093 0.0 0.0 30096 2752 ? Ss
11:
34 0:
00 postgres: server1: background writer
109 If you have turned off
<xref linkend=
"guc-update-process-title"/> then the
110 activity indicator is not updated; the process title is set only once
111 when a new process is launched. On some platforms this saves a measurable
112 amount of per-command overhead; on others it's insignificant.
117 <productname>Solaris
</productname> requires special handling. You must
118 use
<command>/usr/ucb/ps
</command>, rather than
119 <command>/bin/ps
</command>. You also must use two
<option>w
</option>
120 flags, not just one. In addition, your original invocation of the
121 <command>postgres
</command> command must have a shorter
122 <command>ps
</command> status display than that provided by each
123 server process. If you fail to do all three things, the
<command>ps
</command>
124 output for each server process will be the original
<command>postgres
</command>
130 <sect1 id=
"monitoring-stats">
131 <title>The Cumulative Statistics System
</title>
133 <indexterm zone=
"monitoring-stats">
134 <primary>statistics
</primary>
138 <productname>PostgreSQL
</productname>'s
<firstterm>cumulative statistics
139 system
</firstterm> supports collection and reporting of information about
140 server activity. Presently, accesses to tables and indexes in both
141 disk-block and individual-row terms are counted. The total number of rows
142 in each table, and information about vacuum and analyze actions for each
143 table are also counted. If enabled, calls to user-defined functions and
144 the total time spent in each one are counted as well.
148 <productname>PostgreSQL
</productname> also supports reporting dynamic
149 information about exactly what is going on in the system right now, such as
150 the exact command currently being executed by other server processes, and
151 which other connections exist in the system. This facility is independent
152 of the cumulative statistics system.
155 <sect2 id=
"monitoring-stats-setup">
156 <title>Statistics Collection Configuration
</title>
159 Since collection of statistics adds some overhead to query execution,
160 the system can be configured to collect or not collect information.
161 This is controlled by configuration parameters that are normally set in
162 <filename>postgresql.conf
</filename>. (See
<xref linkend=
"runtime-config"/> for
163 details about setting configuration parameters.)
167 The parameter
<xref linkend=
"guc-track-activities"/> enables monitoring
168 of the current command being executed by any server process.
172 The parameter
<xref linkend=
"guc-track-counts"/> controls whether
173 cumulative statistics are collected about table and index accesses.
177 The parameter
<xref linkend=
"guc-track-functions"/> enables tracking of
178 usage of user-defined functions.
182 The parameter
<xref linkend=
"guc-track-io-timing"/> enables monitoring
183 of block read, write, extend, and fsync times.
187 The parameter
<xref linkend=
"guc-track-wal-io-timing"/> enables monitoring
188 of WAL write and fsync times.
192 Normally these parameters are set in
<filename>postgresql.conf
</filename> so
193 that they apply to all server processes, but it is possible to turn
194 them on or off in individual sessions using the
<xref
195 linkend=
"sql-set"/> command. (To prevent
196 ordinary users from hiding their activity from the administrator,
197 only superusers are allowed to change these parameters with
198 <command>SET
</command>.)
202 Cumulative statistics are collected in shared memory. Every
203 <productname>PostgreSQL
</productname> process collects statistics locally,
204 then updates the shared data at appropriate intervals. When a server,
205 including a physical replica, shuts down cleanly, a permanent copy of the
206 statistics data is stored in the
<filename>pg_stat
</filename> subdirectory,
207 so that statistics can be retained across server restarts. In contrast,
208 when starting from an unclean shutdown (e.g., after an immediate shutdown,
209 a server crash, starting from a base backup, and point-in-time recovery),
210 all statistics counters are reset.
215 <sect2 id=
"monitoring-stats-views">
216 <title>Viewing Statistics
</title>
219 Several predefined views, listed in
<xref
220 linkend=
"monitoring-stats-dynamic-views-table"/>, are available to show
221 the current state of the system. There are also several other
222 views, listed in
<xref
223 linkend=
"monitoring-stats-views-table"/>, available to show the accumulated
224 statistics. Alternatively, one can
225 build custom views using the underlying cumulative statistics functions, as
226 discussed in
<xref linkend=
"monitoring-stats-functions"/>.
230 When using the cumulative statistics views and functions to monitor
231 collected data, it is important to realize that the information does not
232 update instantaneously. Each individual server process flushes out
233 accumulated statistics to shared memory just before going idle, but not
234 more frequently than once per
<varname>PGSTAT_MIN_INTERVAL
</varname>
235 milliseconds (
1 second unless altered while building the server); so a
236 query or transaction still in progress does not affect the displayed totals
237 and the displayed information lags behind actual activity. However,
238 current-query information collected by
<varname>track_activities
</varname>
239 is always up-to-date.
243 Another important point is that when a server process is asked to display
244 any of the accumulated statistics, accessed values are cached until the end
245 of its current transaction in the default configuration. So the statistics
246 will show static information as long as you continue the current
247 transaction. Similarly, information about the current queries of all
248 sessions is collected when any such information is first requested within a
249 transaction, and the same information will be displayed throughout the
250 transaction. This is a feature, not a bug, because it allows you to perform
251 several queries on the statistics and correlate the results without
252 worrying that the numbers are changing underneath you.
254 When analyzing statistics interactively, or with expensive queries, the
255 time delta between accesses to individual statistics can lead to
256 significant skew in the cached statistics. To minimize skew,
257 <varname>stats_fetch_consistency
</varname> can be set to
258 <literal>snapshot
</literal>, at the price of increased memory usage for
259 caching not-needed statistics data. Conversely, if it's known that
260 statistics are only accessed once, caching accessed statistics is
261 unnecessary and can be avoided by setting
262 <varname>stats_fetch_consistency
</varname> to
<literal>none
</literal>.
264 You can invoke
<function>pg_stat_clear_snapshot()
</function> to discard the
265 current transaction's statistics snapshot or cached values (if any). The
266 next use of statistical information will (when in snapshot mode) cause a
267 new snapshot to be built or (when in cache mode) accessed statistics to be
272 A transaction can also see its own statistics (not yet flushed out to the
273 shared memory statistics) in the views
274 <structname>pg_stat_xact_all_tables
</structname>,
275 <structname>pg_stat_xact_sys_tables
</structname>,
276 <structname>pg_stat_xact_user_tables
</structname>, and
277 <structname>pg_stat_xact_user_functions
</structname>. These numbers do not act as
278 stated above; instead they update continuously throughout the transaction.
282 Some of the information in the dynamic statistics views shown in
<xref
283 linkend=
"monitoring-stats-dynamic-views-table"/> is security restricted.
284 Ordinary users can only see all the information about their own sessions
285 (sessions belonging to a role that they are a member of). In rows about
286 other sessions, many columns will be null. Note, however, that the
287 existence of a session and its general properties such as its sessions user
288 and database are visible to all users. Superusers and roles with privileges of
289 built-in role
<link linkend=
"predefined-role-pg-monitor"><literal>pg_read_all_stats
</literal></link>
290 can see all the information about all sessions.
293 <table id=
"monitoring-stats-dynamic-views-table">
294 <title>Dynamic Statistics Views
</title>
299 <entry>View Name
</entry>
300 <entry>Description
</entry>
307 <structname>pg_stat_activity
</structname>
308 <indexterm><primary>pg_stat_activity
</primary></indexterm>
311 One row per server process, showing information related to
312 the current activity of that process, such as state and current query.
313 See
<link linkend=
"monitoring-pg-stat-activity-view">
314 <structname>pg_stat_activity
</structname></link> for details.
319 <entry><structname>pg_stat_replication
</structname><indexterm><primary>pg_stat_replication
</primary></indexterm></entry>
320 <entry>One row per WAL sender process, showing statistics about
321 replication to that sender's connected standby server.
322 See
<link linkend=
"monitoring-pg-stat-replication-view">
323 <structname>pg_stat_replication
</structname></link> for details.
328 <entry><structname>pg_stat_wal_receiver
</structname><indexterm><primary>pg_stat_wal_receiver
</primary></indexterm></entry>
329 <entry>Only one row, showing statistics about the WAL receiver from
330 that receiver's connected server.
331 See
<link linkend=
"monitoring-pg-stat-wal-receiver-view">
332 <structname>pg_stat_wal_receiver
</structname></link> for details.
337 <entry><structname>pg_stat_recovery_prefetch
</structname><indexterm><primary>pg_stat_recovery_prefetch
</primary></indexterm></entry>
338 <entry>Only one row, showing statistics about blocks prefetched during recovery.
339 See
<link linkend=
"monitoring-pg-stat-recovery-prefetch">
340 <structname>pg_stat_recovery_prefetch
</structname></link> for details.
345 <entry><structname>pg_stat_subscription
</structname><indexterm><primary>pg_stat_subscription
</primary></indexterm></entry>
346 <entry>At least one row per subscription, showing information about
347 the subscription workers.
348 See
<link linkend=
"monitoring-pg-stat-subscription">
349 <structname>pg_stat_subscription
</structname></link> for details.
354 <entry><structname>pg_stat_ssl
</structname><indexterm><primary>pg_stat_ssl
</primary></indexterm></entry>
355 <entry>One row per connection (regular and replication), showing information about
356 SSL used on this connection.
357 See
<link linkend=
"monitoring-pg-stat-ssl-view">
358 <structname>pg_stat_ssl
</structname></link> for details.
363 <entry><structname>pg_stat_gssapi
</structname><indexterm><primary>pg_stat_gssapi
</primary></indexterm></entry>
364 <entry>One row per connection (regular and replication), showing information about
365 GSSAPI authentication and encryption used on this connection.
366 See
<link linkend=
"monitoring-pg-stat-gssapi-view">
367 <structname>pg_stat_gssapi
</structname></link> for details.
372 <entry><structname>pg_stat_progress_analyze
</structname><indexterm><primary>pg_stat_progress_analyze
</primary></indexterm></entry>
373 <entry>One row for each backend (including autovacuum worker processes) running
374 <command>ANALYZE
</command>, showing current progress.
375 See
<xref linkend=
"analyze-progress-reporting"/>.
380 <entry><structname>pg_stat_progress_create_index
</structname><indexterm><primary>pg_stat_progress_create_index
</primary></indexterm></entry>
381 <entry>One row for each backend running
<command>CREATE INDEX
</command> or
<command>REINDEX
</command>, showing
383 See
<xref linkend=
"create-index-progress-reporting"/>.
388 <entry><structname>pg_stat_progress_vacuum
</structname><indexterm><primary>pg_stat_progress_vacuum
</primary></indexterm></entry>
389 <entry>One row for each backend (including autovacuum worker processes) running
390 <command>VACUUM
</command>, showing current progress.
391 See
<xref linkend=
"vacuum-progress-reporting"/>.
396 <entry><structname>pg_stat_progress_cluster
</structname><indexterm><primary>pg_stat_progress_cluster
</primary></indexterm></entry>
397 <entry>One row for each backend running
398 <command>CLUSTER
</command> or
<command>VACUUM FULL
</command>, showing current progress.
399 See
<xref linkend=
"cluster-progress-reporting"/>.
404 <entry><structname>pg_stat_progress_basebackup
</structname><indexterm><primary>pg_stat_progress_basebackup
</primary></indexterm></entry>
405 <entry>One row for each WAL sender process streaming a base backup,
406 showing current progress.
407 See
<xref linkend=
"basebackup-progress-reporting"/>.
412 <entry><structname>pg_stat_progress_copy
</structname><indexterm><primary>pg_stat_progress_copy
</primary></indexterm></entry>
413 <entry>One row for each backend running
<command>COPY
</command>, showing current progress.
414 See
<xref linkend=
"copy-progress-reporting"/>.
421 <table id=
"monitoring-stats-views-table">
422 <title>Collected Statistics Views
</title>
427 <entry>View Name
</entry>
428 <entry>Description
</entry>
434 <!-- everything related to global objects, alphabetically -->
437 <entry><structname>pg_stat_archiver
</structname><indexterm><primary>pg_stat_archiver
</primary></indexterm></entry>
438 <entry>One row only, showing statistics about the
439 WAL archiver process's activity. See
440 <link linkend=
"monitoring-pg-stat-archiver-view">
441 <structname>pg_stat_archiver
</structname></link> for details.
446 <entry><structname>pg_stat_bgwriter
</structname><indexterm><primary>pg_stat_bgwriter
</primary></indexterm></entry>
447 <entry>One row only, showing statistics about the
448 background writer process's activity. See
449 <link linkend=
"monitoring-pg-stat-bgwriter-view">
450 <structname>pg_stat_bgwriter
</structname></link> for details.
455 <entry><structname>pg_stat_checkpointer
</structname><indexterm><primary>pg_stat_checkpointer
</primary></indexterm></entry>
456 <entry>One row only, showing statistics about the
457 checkpointer process's activity. See
458 <link linkend=
"monitoring-pg-stat-checkpointer-view">
459 <structname>pg_stat_checkpointer
</structname></link> for details.
464 <entry><structname>pg_stat_database
</structname><indexterm><primary>pg_stat_database
</primary></indexterm></entry>
465 <entry>One row per database, showing database-wide statistics. See
466 <link linkend=
"monitoring-pg-stat-database-view">
467 <structname>pg_stat_database
</structname></link> for details.
472 <entry><structname>pg_stat_database_conflicts
</structname><indexterm><primary>pg_stat_database_conflicts
</primary></indexterm></entry>
474 One row per database, showing database-wide statistics about
475 query cancels due to conflict with recovery on standby servers.
476 See
<link linkend=
"monitoring-pg-stat-database-conflicts-view">
477 <structname>pg_stat_database_conflicts
</structname></link> for details.
482 <entry><structname>pg_stat_io
</structname><indexterm><primary>pg_stat_io
</primary></indexterm></entry>
484 One row for each combination of backend type, context, and target object
485 containing cluster-wide I/O statistics.
486 See
<link linkend=
"monitoring-pg-stat-io-view">
487 <structname>pg_stat_io
</structname></link> for details.
492 <entry><structname>pg_stat_replication_slots
</structname><indexterm><primary>pg_stat_replication_slots
</primary></indexterm></entry>
493 <entry>One row per replication slot, showing statistics about the
494 replication slot's usage. See
495 <link linkend=
"monitoring-pg-stat-replication-slots-view">
496 <structname>pg_stat_replication_slots
</structname></link> for details.
501 <entry><structname>pg_stat_slru
</structname><indexterm><primary>pg_stat_slru
</primary></indexterm></entry>
502 <entry>One row per SLRU, showing statistics of operations. See
503 <link linkend=
"monitoring-pg-stat-slru-view">
504 <structname>pg_stat_slru
</structname></link> for details.
509 <entry><structname>pg_stat_subscription_stats
</structname><indexterm><primary>pg_stat_subscription_stats
</primary></indexterm></entry>
510 <entry>One row per subscription, showing statistics about errors and conflicts.
511 See
<link linkend=
"monitoring-pg-stat-subscription-stats">
512 <structname>pg_stat_subscription_stats
</structname></link> for details.
517 <entry><structname>pg_stat_wal
</structname><indexterm><primary>pg_stat_wal
</primary></indexterm></entry>
518 <entry>One row only, showing statistics about WAL activity. See
519 <link linkend=
"monitoring-pg-stat-wal-view">
520 <structname>pg_stat_wal
</structname></link> for details.
524 <!-- all "stat" for schema objects, by "importance" -->
527 <entry><structname>pg_stat_all_tables
</structname><indexterm><primary>pg_stat_all_tables
</primary></indexterm></entry>
529 One row for each table in the current database, showing statistics
530 about accesses to that specific table.
531 See
<link linkend=
"monitoring-pg-stat-all-tables-view">
532 <structname>pg_stat_all_tables
</structname></link> for details.
537 <entry><structname>pg_stat_sys_tables
</structname><indexterm><primary>pg_stat_sys_tables
</primary></indexterm></entry>
538 <entry>Same as
<structname>pg_stat_all_tables
</structname>, except that only
539 system tables are shown.
</entry>
543 <entry><structname>pg_stat_user_tables
</structname><indexterm><primary>pg_stat_user_tables
</primary></indexterm></entry>
544 <entry>Same as
<structname>pg_stat_all_tables
</structname>, except that only user
545 tables are shown.
</entry>
549 <entry><structname>pg_stat_xact_all_tables
</structname><indexterm><primary>pg_stat_xact_all_tables
</primary></indexterm></entry>
550 <entry>Similar to
<structname>pg_stat_all_tables
</structname>, but counts actions
551 taken so far within the current transaction (which are
<emphasis>not
</emphasis>
552 yet included in
<structname>pg_stat_all_tables
</structname> and related views).
553 The columns for numbers of live and dead rows and vacuum and
554 analyze actions are not present in this view.
</entry>
558 <entry><structname>pg_stat_xact_sys_tables
</structname><indexterm><primary>pg_stat_xact_sys_tables
</primary></indexterm></entry>
559 <entry>Same as
<structname>pg_stat_xact_all_tables
</structname>, except that only
560 system tables are shown.
</entry>
564 <entry><structname>pg_stat_xact_user_tables
</structname><indexterm><primary>pg_stat_xact_user_tables
</primary></indexterm></entry>
565 <entry>Same as
<structname>pg_stat_xact_all_tables
</structname>, except that only
566 user tables are shown.
</entry>
570 <entry><structname>pg_stat_all_indexes
</structname><indexterm><primary>pg_stat_all_indexes
</primary></indexterm></entry>
572 One row for each index in the current database, showing statistics
573 about accesses to that specific index.
574 See
<link linkend=
"monitoring-pg-stat-all-indexes-view">
575 <structname>pg_stat_all_indexes
</structname></link> for details.
580 <entry><structname>pg_stat_sys_indexes
</structname><indexterm><primary>pg_stat_sys_indexes
</primary></indexterm></entry>
581 <entry>Same as
<structname>pg_stat_all_indexes
</structname>, except that only
582 indexes on system tables are shown.
</entry>
586 <entry><structname>pg_stat_user_indexes
</structname><indexterm><primary>pg_stat_user_indexes
</primary></indexterm></entry>
587 <entry>Same as
<structname>pg_stat_all_indexes
</structname>, except that only
588 indexes on user tables are shown.
</entry>
592 <entry><structname>pg_stat_user_functions
</structname><indexterm><primary>pg_stat_user_functions
</primary></indexterm></entry>
594 One row for each tracked function, showing statistics
595 about executions of that function. See
596 <link linkend=
"monitoring-pg-stat-user-functions-view">
597 <structname>pg_stat_user_functions
</structname></link> for details.
602 <entry><structname>pg_stat_xact_user_functions
</structname><indexterm><primary>pg_stat_xact_user_functions
</primary></indexterm></entry>
603 <entry>Similar to
<structname>pg_stat_user_functions
</structname>, but counts only
604 calls during the current transaction (which are
<emphasis>not
</emphasis>
605 yet included in
<structname>pg_stat_user_functions
</structname>).
</entry>
608 <!-- all "statio" for schema objects, by "importance" -->
611 <entry><structname>pg_statio_all_tables
</structname><indexterm><primary>pg_statio_all_tables
</primary></indexterm></entry>
613 One row for each table in the current database, showing statistics
614 about I/O on that specific table.
615 See
<link linkend=
"monitoring-pg-statio-all-tables-view">
616 <structname>pg_statio_all_tables
</structname></link> for details.
621 <entry><structname>pg_statio_sys_tables
</structname><indexterm><primary>pg_statio_sys_tables
</primary></indexterm></entry>
622 <entry>Same as
<structname>pg_statio_all_tables
</structname>, except that only
623 system tables are shown.
</entry>
627 <entry><structname>pg_statio_user_tables
</structname><indexterm><primary>pg_statio_user_tables
</primary></indexterm></entry>
628 <entry>Same as
<structname>pg_statio_all_tables
</structname>, except that only
629 user tables are shown.
</entry>
633 <entry><structname>pg_statio_all_indexes
</structname><indexterm><primary>pg_statio_all_indexes
</primary></indexterm></entry>
635 One row for each index in the current database,
636 showing statistics about I/O on that specific index.
637 See
<link linkend=
"monitoring-pg-statio-all-indexes-view">
638 <structname>pg_statio_all_indexes
</structname></link> for details.
643 <entry><structname>pg_statio_sys_indexes
</structname><indexterm><primary>pg_statio_sys_indexes
</primary></indexterm></entry>
644 <entry>Same as
<structname>pg_statio_all_indexes
</structname>, except that only
645 indexes on system tables are shown.
</entry>
649 <entry><structname>pg_statio_user_indexes
</structname><indexterm><primary>pg_statio_user_indexes
</primary></indexterm></entry>
650 <entry>Same as
<structname>pg_statio_all_indexes
</structname>, except that only
651 indexes on user tables are shown.
</entry>
655 <entry><structname>pg_statio_all_sequences
</structname><indexterm><primary>pg_statio_all_sequences
</primary></indexterm></entry>
657 One row for each sequence in the current database,
658 showing statistics about I/O on that specific sequence.
659 See
<link linkend=
"monitoring-pg-statio-all-sequences-view">
660 <structname>pg_statio_all_sequences
</structname></link> for details.
665 <entry><structname>pg_statio_sys_sequences
</structname><indexterm><primary>pg_statio_sys_sequences
</primary></indexterm></entry>
666 <entry>Same as
<structname>pg_statio_all_sequences
</structname>, except that only
667 system sequences are shown. (Presently, no system sequences are defined,
668 so this view is always empty.)
</entry>
672 <entry><structname>pg_statio_user_sequences
</structname><indexterm><primary>pg_statio_user_sequences
</primary></indexterm></entry>
673 <entry>Same as
<structname>pg_statio_all_sequences
</structname>, except that only
674 user sequences are shown.
</entry>
682 The per-index statistics are particularly useful to determine which
683 indexes are being used and how effective they are.
687 The
<structname>pg_stat_io
</structname> and
688 <structname>pg_statio_
</structname> set of views are useful for determining
689 the effectiveness of the buffer cache. They can be used to calculate a cache
690 hit ratio. Note that while
<productname>PostgreSQL
</productname>'s I/O
691 statistics capture most instances in which the kernel was invoked in order
692 to perform I/O, they do not differentiate between data which had to be
693 fetched from disk and that which already resided in the kernel page cache.
694 Users are advised to use the
<productname>PostgreSQL
</productname>
695 statistics views in combination with operating system utilities for a more
696 complete picture of their database's I/O performance.
701 <sect2 id=
"monitoring-pg-stat-activity-view">
702 <title><structname>pg_stat_activity
</structname></title>
705 <primary>pg_stat_activity
</primary>
709 The
<structname>pg_stat_activity
</structname> view will have one row
710 per server process, showing information related to
711 the current activity of that process.
714 <table id=
"pg-stat-activity-view" xreflabel=
"pg_stat_activity">
715 <title><structname>pg_stat_activity
</structname> View
</title>
719 <entry role=
"catalog_table_entry"><para role=
"column_definition">
730 <entry role=
"catalog_table_entry"><para role=
"column_definition">
731 <structfield>datid
</structfield> <type>oid
</type>
734 OID of the database this backend is connected to
739 <entry role=
"catalog_table_entry"><para role=
"column_definition">
740 <structfield>datname
</structfield> <type>name
</type>
743 Name of the database this backend is connected to
748 <entry role=
"catalog_table_entry"><para role=
"column_definition">
749 <structfield>pid
</structfield> <type>integer
</type>
752 Process ID of this backend
757 <entry role=
"catalog_table_entry"><para role=
"column_definition">
758 <structfield>leader_pid
</structfield> <type>integer
</type>
761 Process ID of the parallel group leader if this process is a parallel
762 query worker, or process ID of the leader apply worker if this process
763 is a parallel apply worker.
<literal>NULL
</literal> indicates that this
764 process is a parallel group leader or leader apply worker, or does not
765 participate in any parallel operation.
770 <entry role=
"catalog_table_entry"><para role=
"column_definition">
771 <structfield>usesysid
</structfield> <type>oid
</type>
774 OID of the user logged into this backend
779 <entry role=
"catalog_table_entry"><para role=
"column_definition">
780 <structfield>usename
</structfield> <type>name
</type>
783 Name of the user logged into this backend
788 <entry role=
"catalog_table_entry"><para role=
"column_definition">
789 <structfield>application_name
</structfield> <type>text
</type>
792 Name of the application that is connected
798 <entry role=
"catalog_table_entry"><para role=
"column_definition">
799 <structfield>client_addr
</structfield> <type>inet
</type>
802 IP address of the client connected to this backend.
803 If this field is null, it indicates either that the client is
804 connected via a Unix socket on the server machine or that this is an
805 internal process such as autovacuum.
810 <entry role=
"catalog_table_entry"><para role=
"column_definition">
811 <structfield>client_hostname
</structfield> <type>text
</type>
814 Host name of the connected client, as reported by a
815 reverse DNS lookup of
<structfield>client_addr
</structfield>. This field will
816 only be non-null for IP connections, and only when
<xref linkend=
"guc-log-hostname"/> is enabled.
821 <entry role=
"catalog_table_entry"><para role=
"column_definition">
822 <structfield>client_port
</structfield> <type>integer
</type>
825 TCP port number that the client is using for communication
826 with this backend, or
<literal>-
1</literal> if a Unix socket is used.
827 If this field is null, it indicates that this is an internal server process.
832 <entry role=
"catalog_table_entry"><para role=
"column_definition">
833 <structfield>backend_start
</structfield> <type>timestamp with time zone
</type>
836 Time when this process was started. For client backends,
837 this is the time the client connected to the server.
842 <entry role=
"catalog_table_entry"><para role=
"column_definition">
843 <structfield>xact_start
</structfield> <type>timestamp with time zone
</type>
846 Time when this process' current transaction was started, or null
847 if no transaction is active. If the current
848 query is the first of its transaction, this column is equal to the
849 <structfield>query_start
</structfield> column.
854 <entry role=
"catalog_table_entry"><para role=
"column_definition">
855 <structfield>query_start
</structfield> <type>timestamp with time zone
</type>
858 Time when the currently active query was started, or if
859 <structfield>state
</structfield> is not
<literal>active
</literal>, when the last query
865 <entry role=
"catalog_table_entry"><para role=
"column_definition">
866 <structfield>state_change
</structfield> <type>timestamp with time zone
</type>
869 Time when the
<structfield>state
</structfield> was last changed
874 <entry role=
"catalog_table_entry"><para role=
"column_definition">
875 <structfield>wait_event_type
</structfield> <type>text
</type>
878 The type of event for which the backend is waiting, if any;
879 otherwise NULL. See
<xref linkend=
"wait-event-table"/>.
884 <entry role=
"catalog_table_entry"><para role=
"column_definition">
885 <structfield>wait_event
</structfield> <type>text
</type>
888 Wait event name if backend is currently waiting, otherwise NULL.
889 See
<xref linkend=
"wait-event-activity-table"/> through
890 <xref linkend=
"wait-event-timeout-table"/>.
895 <entry role=
"catalog_table_entry"><para role=
"column_definition">
896 <structfield>state
</structfield> <type>text
</type>
899 Current overall state of this backend.
904 <literal>active
</literal>: The backend is executing a query.
909 <literal>idle
</literal>: The backend is waiting for a new client command.
914 <literal>idle in transaction
</literal>: The backend is in a transaction,
915 but is not currently executing a query.
920 <literal>idle in transaction (aborted)
</literal>: This state is similar to
921 <literal>idle in transaction
</literal>, except one of the statements in
922 the transaction caused an error.
927 <literal>fastpath function call
</literal>: The backend is executing a
933 <literal>disabled
</literal>: This state is reported if
<xref linkend=
"guc-track-activities"/> is disabled in this backend.
941 <entry role=
"catalog_table_entry"><para role=
"column_definition">
942 <structfield>backend_xid
</structfield> <type>xid
</type>
945 Top-level transaction identifier of this backend, if any; see
946 <xref linkend=
"transaction-id"/>.
951 <entry role=
"catalog_table_entry"><para role=
"column_definition">
952 <structfield>backend_xmin
</structfield> <type>xid
</type>
955 The current backend's
<literal>xmin
</literal> horizon.
960 <entry role=
"catalog_table_entry"><para role=
"column_definition">
961 <structfield>query_id
</structfield> <type>bigint
</type>
964 Identifier of this backend's most recent query. If
965 <structfield>state
</structfield> is
<literal>active
</literal> this
966 field shows the identifier of the currently executing query. In
967 all other states, it shows the identifier of last query that was
968 executed. Query identifiers are not computed by default so this
969 field will be null unless
<xref linkend=
"guc-compute-query-id"/>
970 parameter is enabled or a third-party module that computes query
971 identifiers is configured.
976 <entry role=
"catalog_table_entry"><para role=
"column_definition">
977 <structfield>query
</structfield> <type>text
</type>
980 Text of this backend's most recent query. If
981 <structfield>state
</structfield> is
<literal>active
</literal> this field shows the
982 currently executing query. In all other states, it shows the last query
983 that was executed. By default the query text is truncated at
1024
984 bytes; this value can be changed via the parameter
985 <xref linkend=
"guc-track-activity-query-size"/>.
990 <entry role=
"catalog_table_entry"><para role=
"column_definition">
991 <structfield>backend_type
</structfield> <type>text
</type>
994 Type of current backend. Possible types are
995 <literal>autovacuum launcher
</literal>,
<literal>autovacuum worker
</literal>,
996 <literal>logical replication launcher
</literal>,
997 <literal>logical replication worker
</literal>,
998 <literal>parallel worker
</literal>,
<literal>background writer
</literal>,
999 <literal>client backend
</literal>,
<literal>checkpointer
</literal>,
1000 <literal>archiver
</literal>,
<literal>standalone backend
</literal>,
1001 <literal>startup
</literal>,
<literal>walreceiver
</literal>,
1002 <literal>walsender
</literal>,
<literal>walwriter
</literal> and
1003 <literal>walsummarizer
</literal>.
1004 In addition, background workers registered by extensions may have
1014 The
<structfield>wait_event
</structfield> and
<structfield>state
</structfield> columns are
1015 independent. If a backend is in the
<literal>active
</literal> state,
1016 it may or may not be
<literal>waiting
</literal> on some event. If the state
1017 is
<literal>active
</literal> and
<structfield>wait_event
</structfield> is non-null, it
1018 means that a query is being executed, but is being blocked somewhere
1023 <table id=
"wait-event-table">
1024 <title>Wait Event Types
</title>
1028 <entry>Wait Event Type
</entry>
1029 <entry>Description
</entry>
1035 <entry><literal>Activity
</literal></entry>
1036 <entry>The server process is idle. This event type indicates a process
1037 waiting for activity in its main processing loop.
1038 <literal>wait_event
</literal> will identify the specific wait point;
1039 see
<xref linkend=
"wait-event-activity-table"/>.
1043 <entry><literal>BufferPin
</literal></entry>
1044 <entry>The server process is waiting for exclusive access to
1045 a data buffer. Buffer pin waits can be protracted if
1046 another process holds an open cursor that last read data from the
1047 buffer in question. See
<xref linkend=
"wait-event-bufferpin-table"/>.
1051 <entry><literal>Client
</literal></entry>
1052 <entry>The server process is waiting for activity on a socket
1053 connected to a user application. Thus, the server expects something
1054 to happen that is independent of its internal processes.
1055 <literal>wait_event
</literal> will identify the specific wait point;
1056 see
<xref linkend=
"wait-event-client-table"/>.
1060 <entry><literal>Extension
</literal></entry>
1061 <entry>The server process is waiting for some condition defined by an
1063 See
<xref linkend=
"wait-event-extension-table"/>.
1067 <entry><literal>InjectionPoint
</literal></entry>
1068 <entry>The server process is waiting for an injection point to reach an
1069 outcome defined in a test. See
1070 <xref linkend=
"xfunc-addin-injection-points"/> for more details. This
1071 type has no predefined wait points.
1075 <entry><literal>IO
</literal></entry>
1076 <entry>The server process is waiting for an I/O operation to complete.
1077 <literal>wait_event
</literal> will identify the specific wait point;
1078 see
<xref linkend=
"wait-event-io-table"/>.
1082 <entry><literal>IPC
</literal></entry>
1083 <entry>The server process is waiting for some interaction with
1084 another server process.
<literal>wait_event
</literal> will
1085 identify the specific wait point;
1086 see
<xref linkend=
"wait-event-ipc-table"/>.
1090 <entry><literal>Lock
</literal></entry>
1091 <entry>The server process is waiting for a heavyweight lock.
1092 Heavyweight locks, also known as lock manager locks or simply locks,
1093 primarily protect SQL-visible objects such as tables. However,
1094 they are also used to ensure mutual exclusion for certain internal
1095 operations such as relation extension.
<literal>wait_event
</literal>
1096 will identify the type of lock awaited;
1097 see
<xref linkend=
"wait-event-lock-table"/>.
1101 <entry><literal>LWLock
</literal></entry>
1102 <entry> The server process is waiting for a lightweight lock.
1103 Most such locks protect a particular data structure in shared memory.
1104 <literal>wait_event
</literal> will contain a name identifying the purpose
1105 of the lightweight lock. (Some locks have specific names; others
1106 are part of a group of locks each with a similar purpose.)
1107 See
<xref linkend=
"wait-event-lwlock-table"/>.
1111 <entry><literal>Timeout
</literal></entry>
1112 <entry>The server process is waiting for a timeout
1113 to expire.
<literal>wait_event
</literal> will identify the specific wait
1114 point; see
<xref linkend=
"wait-event-timeout-table"/>.
1124 Here are examples of how wait events can be viewed:
1127 SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
1128 pid | wait_event_type | wait_event
1129 ------+-----------------+------------
1130 2540 | Lock | relation
1131 6644 | LWLock | ProcArray
1136 SELECT a.pid, a.wait_event, w.description
1137 FROM pg_stat_activity a JOIN
1138 pg_wait_events w ON (a.wait_event_type = w.type AND
1139 a.wait_event = w.name)
1140 WHERE a.wait_event is NOT NULL and a.state = 'active';
1141 -[ RECORD
1 ]------------------------------------------------------
&zwsp;------------
1143 wait_event | WALInitSync
1144 description | Waiting for a newly initialized WAL file to reach durable storage
1150 Extensions can add
<literal>Extension
</literal>,
1151 <literal>InjectionPoint
</literal>. and
<literal>LWLock
</literal> events
1152 to the lists shown in
<xref linkend=
"wait-event-extension-table"/> and
1153 <xref linkend=
"wait-event-lwlock-table"/>. In some cases, the name
1154 of an
<literal>LWLock
</literal> assigned by an extension will not be
1155 available in all server processes. It might be reported as just
1156 <quote><literal>extension
</literal></quote> rather than the
1157 extension-assigned name.
1162 <sect2 id=
"monitoring-pg-stat-replication-view">
1163 <title><structname>pg_stat_replication
</structname></title>
1166 <primary>pg_stat_replication
</primary>
1170 The
<structname>pg_stat_replication
</structname> view will contain one row
1171 per WAL sender process, showing statistics about replication to that
1172 sender's connected standby server. Only directly connected standbys are
1173 listed; no information is available about downstream standby servers.
1176 <table id=
"pg-stat-replication-view" xreflabel=
"pg_stat_replication">
1177 <title><structname>pg_stat_replication
</structname> View
</title>
1181 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1192 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1193 <structfield>pid
</structfield> <type>integer
</type>
1196 Process ID of a WAL sender process
1201 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1202 <structfield>usesysid
</structfield> <type>oid
</type>
1205 OID of the user logged into this WAL sender process
1210 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1211 <structfield>usename
</structfield> <type>name
</type>
1214 Name of the user logged into this WAL sender process
1219 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1220 <structfield>application_name
</structfield> <type>text
</type>
1223 Name of the application that is connected
1229 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1230 <structfield>client_addr
</structfield> <type>inet
</type>
1233 IP address of the client connected to this WAL sender.
1234 If this field is null, it indicates that the client is
1235 connected via a Unix socket on the server machine.
1240 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1241 <structfield>client_hostname
</structfield> <type>text
</type>
1244 Host name of the connected client, as reported by a
1245 reverse DNS lookup of
<structfield>client_addr
</structfield>. This field will
1246 only be non-null for IP connections, and only when
<xref linkend=
"guc-log-hostname"/> is enabled.
1251 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1252 <structfield>client_port
</structfield> <type>integer
</type>
1255 TCP port number that the client is using for communication
1256 with this WAL sender, or
<literal>-
1</literal> if a Unix socket is used
1261 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1262 <structfield>backend_start
</structfield> <type>timestamp with time zone
</type>
1265 Time when this process was started, i.e., when the
1266 client connected to this WAL sender
1271 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1272 <structfield>backend_xmin
</structfield> <type>xid
</type>
1275 This standby's
<literal>xmin
</literal> horizon reported
1276 by
<xref linkend=
"guc-hot-standby-feedback"/>.
1281 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1282 <structfield>state
</structfield> <type>text
</type>
1285 Current WAL sender state.
1286 Possible values are:
1290 <literal>startup
</literal>: This WAL sender is starting up.
1295 <literal>catchup
</literal>: This WAL sender's connected standby is
1296 catching up with the primary.
1301 <literal>streaming
</literal>: This WAL sender is streaming changes
1302 after its connected standby server has caught up with the primary.
1307 <literal>backup
</literal>: This WAL sender is sending a backup.
1312 <literal>stopping
</literal>: This WAL sender is stopping.
1320 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1321 <structfield>sent_lsn
</structfield> <type>pg_lsn
</type>
1324 Last write-ahead log location sent on this connection
1329 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1330 <structfield>write_lsn
</structfield> <type>pg_lsn
</type>
1333 Last write-ahead log location written to disk by this standby
1339 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1340 <structfield>flush_lsn
</structfield> <type>pg_lsn
</type>
1343 Last write-ahead log location flushed to disk by this standby
1349 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1350 <structfield>replay_lsn
</structfield> <type>pg_lsn
</type>
1353 Last write-ahead log location replayed into the database on this
1359 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1360 <structfield>write_lag
</structfield> <type>interval
</type>
1363 Time elapsed between flushing recent WAL locally and receiving
1364 notification that this standby server has written it (but not yet
1365 flushed it or applied it). This can be used to gauge the delay that
1366 <literal>synchronous_commit
</literal> level
1367 <literal>remote_write
</literal> incurred while committing if this
1368 server was configured as a synchronous standby.
1373 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1374 <structfield>flush_lag
</structfield> <type>interval
</type>
1377 Time elapsed between flushing recent WAL locally and receiving
1378 notification that this standby server has written and flushed it
1379 (but not yet applied it). This can be used to gauge the delay that
1380 <literal>synchronous_commit
</literal> level
1381 <literal>on
</literal> incurred while committing if this
1382 server was configured as a synchronous standby.
1387 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1388 <structfield>replay_lag
</structfield> <type>interval
</type>
1391 Time elapsed between flushing recent WAL locally and receiving
1392 notification that this standby server has written, flushed and
1393 applied it. This can be used to gauge the delay that
1394 <literal>synchronous_commit
</literal> level
1395 <literal>remote_apply
</literal> incurred while committing if this
1396 server was configured as a synchronous standby.
1401 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1402 <structfield>sync_priority
</structfield> <type>integer
</type>
1405 Priority of this standby server for being chosen as the
1406 synchronous standby in a priority-based synchronous replication.
1407 This has no effect in a quorum-based synchronous replication.
1412 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1413 <structfield>sync_state
</structfield> <type>text
</type>
1416 Synchronous state of this standby server.
1417 Possible values are:
1421 <literal>async
</literal>: This standby server is asynchronous.
1426 <literal>potential
</literal>: This standby server is now asynchronous,
1427 but can potentially become synchronous if one of current
1428 synchronous ones fails.
1433 <literal>sync
</literal>: This standby server is synchronous.
1438 <literal>quorum
</literal>: This standby server is considered as a candidate
1439 for quorum standbys.
1447 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1448 <structfield>reply_time
</structfield> <type>timestamp with time zone
</type>
1451 Send time of last reply message received from standby server
1459 The lag times reported in the
<structname>pg_stat_replication
</structname>
1460 view are measurements of the time taken for recent WAL to be written,
1461 flushed and replayed and for the sender to know about it. These times
1462 represent the commit delay that was (or would have been) introduced by each
1463 synchronous commit level, if the remote server was configured as a
1464 synchronous standby. For an asynchronous standby, the
1465 <structfield>replay_lag
</structfield> column approximates the delay
1466 before recent transactions became visible to queries. If the standby
1467 server has entirely caught up with the sending server and there is no more
1468 WAL activity, the most recently measured lag times will continue to be
1469 displayed for a short time and then show NULL.
1473 Lag times work automatically for physical replication. Logical decoding
1474 plugins may optionally emit tracking messages; if they do not, the tracking
1475 mechanism will simply display NULL lag.
1480 The reported lag times are not predictions of how long it will take for
1481 the standby to catch up with the sending server assuming the current
1482 rate of replay. Such a system would show similar times while new WAL is
1483 being generated, but would differ when the sender becomes idle. In
1484 particular, when the standby has caught up completely,
1485 <structname>pg_stat_replication
</structname> shows the time taken to
1486 write, flush and replay the most recent reported WAL location rather than
1487 zero as some users might expect. This is consistent with the goal of
1488 measuring synchronous commit and transaction visibility delays for
1489 recent write transactions.
1490 To reduce confusion for users expecting a different model of lag, the
1491 lag columns revert to NULL after a short time on a fully replayed idle
1492 system. Monitoring systems should choose whether to represent this
1493 as missing data, zero or continue to display the last known value.
1499 <sect2 id=
"monitoring-pg-stat-replication-slots-view">
1500 <title><structname>pg_stat_replication_slots
</structname></title>
1503 <primary>pg_stat_replication_slots
</primary>
1507 The
<structname>pg_stat_replication_slots
</structname> view will contain
1508 one row per logical replication slot, showing statistics about its usage.
1511 <table id=
"pg-stat-replication-slots-view" xreflabel=
"pg_stat_replication_slots">
1512 <title><structname>pg_stat_replication_slots
</structname> View
</title>
1516 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1527 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1528 <structfield>slot_name
</structfield> <type>text
</type>
1531 A unique, cluster-wide identifier for the replication slot
1536 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1537 <structfield>spill_txns
</structfield> <type>bigint
</type>
1540 Number of transactions spilled to disk once the memory used by
1541 logical decoding to decode changes from WAL has exceeded
1542 <literal>logical_decoding_work_mem
</literal>. The counter gets
1543 incremented for both top-level transactions and subtransactions.
1548 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1549 <structfield>spill_count
</structfield> <type>bigint
</type>
1552 Number of times transactions were spilled to disk while decoding
1553 changes from WAL for this slot. This counter is incremented each time
1554 a transaction is spilled, and the same transaction may be spilled
1560 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1561 <structfield>spill_bytes
</structfield> <type>bigint
</type>
1564 Amount of decoded transaction data spilled to disk while performing
1565 decoding of changes from WAL for this slot. This and other spill
1566 counters can be used to gauge the I/O which occurred during logical
1567 decoding and allow tuning
<literal>logical_decoding_work_mem
</literal>.
1572 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1573 <structfield>stream_txns
</structfield> <type>bigint
</type>
1576 Number of in-progress transactions streamed to the decoding output
1577 plugin after the memory used by logical decoding to decode changes
1578 from WAL for this slot has exceeded
1579 <literal>logical_decoding_work_mem
</literal>. Streaming only
1580 works with top-level transactions (subtransactions can't be streamed
1581 independently), so the counter is not incremented for subtransactions.
1586 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1587 <structfield>stream_count
</structfield><type>bigint
</type>
1590 Number of times in-progress transactions were streamed to the decoding
1591 output plugin while decoding changes from WAL for this slot. This
1592 counter is incremented each time a transaction is streamed, and the
1593 same transaction may be streamed multiple times.
1598 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1599 <structfield>stream_bytes
</structfield><type>bigint
</type>
1602 Amount of transaction data decoded for streaming in-progress
1603 transactions to the decoding output plugin while decoding changes from
1604 WAL for this slot. This and other streaming counters for this slot can
1605 be used to tune
<literal>logical_decoding_work_mem
</literal>.
1611 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1612 <structfield>total_txns
</structfield> <type>bigint
</type>
1615 Number of decoded transactions sent to the decoding output plugin for
1616 this slot. This counts top-level transactions only, and is not incremented
1617 for subtransactions. Note that this includes the transactions that are
1618 streamed and/or spilled.
1623 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1624 <structfield>total_bytes
</structfield><type>bigint
</type>
1627 Amount of transaction data decoded for sending transactions to the
1628 decoding output plugin while decoding changes from WAL for this slot.
1629 Note that this includes data that is streamed and/or spilled.
1635 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1636 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
1639 Time at which these statistics were last reset
1648 <sect2 id=
"monitoring-pg-stat-wal-receiver-view">
1649 <title><structname>pg_stat_wal_receiver
</structname></title>
1652 <primary>pg_stat_wal_receiver
</primary>
1656 The
<structname>pg_stat_wal_receiver
</structname> view will contain only
1657 one row, showing statistics about the WAL receiver from that receiver's
1661 <table id=
"pg-stat-wal-receiver-view" xreflabel=
"pg_stat_wal_receiver">
1662 <title><structname>pg_stat_wal_receiver
</structname> View
</title>
1666 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1677 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1678 <structfield>pid
</structfield> <type>integer
</type>
1681 Process ID of the WAL receiver process
1686 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1687 <structfield>status
</structfield> <type>text
</type>
1690 Activity status of the WAL receiver process
1695 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1696 <structfield>receive_start_lsn
</structfield> <type>pg_lsn
</type>
1699 First write-ahead log location used when WAL receiver is
1705 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1706 <structfield>receive_start_tli
</structfield> <type>integer
</type>
1709 First timeline number used when WAL receiver is started
1714 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1715 <structfield>written_lsn
</structfield> <type>pg_lsn
</type>
1718 Last write-ahead log location already received and written to disk,
1719 but not flushed. This should not be used for data integrity checks.
1724 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1725 <structfield>flushed_lsn
</structfield> <type>pg_lsn
</type>
1728 Last write-ahead log location already received and flushed to
1729 disk, the initial value of this field being the first log location used
1730 when WAL receiver is started
1735 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1736 <structfield>received_tli
</structfield> <type>integer
</type>
1739 Timeline number of last write-ahead log location received and
1740 flushed to disk, the initial value of this field being the timeline
1741 number of the first log location used when WAL receiver is started
1746 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1747 <structfield>last_msg_send_time
</structfield> <type>timestamp with time zone
</type>
1750 Send time of last message received from origin WAL sender
1755 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1756 <structfield>last_msg_receipt_time
</structfield> <type>timestamp with time zone
</type>
1759 Receipt time of last message received from origin WAL sender
1764 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1765 <structfield>latest_end_lsn
</structfield> <type>pg_lsn
</type>
1768 Last write-ahead log location reported to origin WAL sender
1773 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1774 <structfield>latest_end_time
</structfield> <type>timestamp with time zone
</type>
1777 Time of last write-ahead log location reported to origin WAL sender
1782 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1783 <structfield>slot_name
</structfield> <type>text
</type>
1786 Replication slot name used by this WAL receiver
1791 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1792 <structfield>sender_host
</structfield> <type>text
</type>
1795 Host of the
<productname>PostgreSQL
</productname> instance
1796 this WAL receiver is connected to. This can be a host name,
1797 an IP address, or a directory path if the connection is via
1798 Unix socket. (The path case can be distinguished because it
1799 will always be an absolute path, beginning with
<literal>/
</literal>.)
1804 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1805 <structfield>sender_port
</structfield> <type>integer
</type>
1808 Port number of the
<productname>PostgreSQL
</productname> instance
1809 this WAL receiver is connected to.
1814 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1815 <structfield>conninfo
</structfield> <type>text
</type>
1818 Connection string used by this WAL receiver,
1819 with security-sensitive fields obfuscated.
1828 <sect2 id=
"monitoring-pg-stat-recovery-prefetch">
1829 <title><structname>pg_stat_recovery_prefetch
</structname></title>
1832 <primary>pg_stat_recovery_prefetch
</primary>
1836 The
<structname>pg_stat_recovery_prefetch
</structname> view will contain
1837 only one row. The columns
<structfield>wal_distance
</structfield>,
1838 <structfield>block_distance
</structfield> and
1839 <structfield>io_depth
</structfield> show current values, and the
1840 other columns show cumulative counters that can be reset
1841 with the
<function>pg_stat_reset_shared
</function> function.
1844 <table id=
"pg-stat-recovery-prefetch-view" xreflabel=
"pg_stat_recovery_prefetch">
1845 <title><structname>pg_stat_recovery_prefetch
</structname> View
</title>
1849 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1860 <entry role=
"catalog_table_entry">
1861 <para role=
"column_definition">
1862 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
1865 Time at which these statistics were last reset
1871 <entry role=
"catalog_table_entry">
1872 <para role=
"column_definition">
1873 <structfield>prefetch
</structfield> <type>bigint
</type>
1876 Number of blocks prefetched because they were not in the buffer pool
1882 <entry role=
"catalog_table_entry">
1883 <para role=
"column_definition">
1884 <structfield>hit
</structfield> <type>bigint
</type>
1887 Number of blocks not prefetched because they were already in the buffer pool
1893 <entry role=
"catalog_table_entry">
1894 <para role=
"column_definition">
1895 <structfield>skip_init
</structfield> <type>bigint
</type>
1898 Number of blocks not prefetched because they would be zero-initialized
1904 <entry role=
"catalog_table_entry">
1905 <para role=
"column_definition">
1906 <structfield>skip_new
</structfield> <type>bigint
</type>
1909 Number of blocks not prefetched because they didn't exist yet
1915 <entry role=
"catalog_table_entry">
1916 <para role=
"column_definition">
1917 <structfield>skip_fpw
</structfield> <type>bigint
</type>
1920 Number of blocks not prefetched because a full page image was included in the WAL
1926 <entry role=
"catalog_table_entry">
1927 <para role=
"column_definition">
1928 <structfield>skip_rep
</structfield> <type>bigint
</type>
1931 Number of blocks not prefetched because they were already recently prefetched
1937 <entry role=
"catalog_table_entry">
1938 <para role=
"column_definition">
1939 <structfield>wal_distance
</structfield> <type>int
</type>
1942 How many bytes ahead the prefetcher is looking
1948 <entry role=
"catalog_table_entry">
1949 <para role=
"column_definition">
1950 <structfield>block_distance
</structfield> <type>int
</type>
1953 How many blocks ahead the prefetcher is looking
1959 <entry role=
"catalog_table_entry">
1960 <para role=
"column_definition">
1961 <structfield>io_depth
</structfield> <type>int
</type>
1964 How many prefetches have been initiated but are not yet known to have completed
1974 <sect2 id=
"monitoring-pg-stat-subscription">
1975 <title><structname>pg_stat_subscription
</structname></title>
1978 <primary>pg_stat_subscription
</primary>
1981 <table id=
"pg-stat-subscription" xreflabel=
"pg_stat_subscription">
1982 <title><structname>pg_stat_subscription
</structname> View
</title>
1986 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1997 <entry role=
"catalog_table_entry"><para role=
"column_definition">
1998 <structfield>subid
</structfield> <type>oid
</type>
2001 OID of the subscription
2006 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2007 <structfield>subname
</structfield> <type>name
</type>
2010 Name of the subscription
2015 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2016 <structfield>worker_type
</structfield> <type>text
</type>
2019 Type of the subscription worker process. Possible types are
2020 <literal>apply
</literal>,
<literal>parallel apply
</literal>, and
2021 <literal>table synchronization
</literal>.
2026 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2027 <structfield>pid
</structfield> <type>integer
</type>
2030 Process ID of the subscription worker process
2035 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2036 <structfield>leader_pid
</structfield> <type>integer
</type>
2039 Process ID of the leader apply worker if this process is a parallel
2040 apply worker; NULL if this process is a leader apply worker or a table
2041 synchronization worker
2046 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2047 <structfield>relid
</structfield> <type>oid
</type>
2050 OID of the relation that the worker is synchronizing; NULL for the
2051 leader apply worker and parallel apply workers
2056 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2057 <structfield>received_lsn
</structfield> <type>pg_lsn
</type>
2060 Last write-ahead log location received, the initial value of
2061 this field being
0; NULL for parallel apply workers
2066 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2067 <structfield>last_msg_send_time
</structfield> <type>timestamp with time zone
</type>
2070 Send time of last message received from origin WAL sender; NULL for
2071 parallel apply workers
2076 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2077 <structfield>last_msg_receipt_time
</structfield> <type>timestamp with time zone
</type>
2080 Receipt time of last message received from origin WAL sender; NULL for
2081 parallel apply workers
2086 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2087 <structfield>latest_end_lsn
</structfield> <type>pg_lsn
</type>
2090 Last write-ahead log location reported to origin WAL sender; NULL for
2091 parallel apply workers
2096 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2097 <structfield>latest_end_time
</structfield> <type>timestamp with time zone
</type>
2100 Time of last write-ahead log location reported to origin WAL
2101 sender; NULL for parallel apply workers
2110 <sect2 id=
"monitoring-pg-stat-subscription-stats">
2111 <title><structname>pg_stat_subscription_stats
</structname></title>
2114 <primary>pg_stat_subscription_stats
</primary>
2118 The
<structname>pg_stat_subscription_stats
</structname> view will contain
2119 one row per subscription.
2122 <table id=
"pg-stat-subscription-stats" xreflabel=
"pg_stat_subscription_stats">
2123 <title><structname>pg_stat_subscription_stats
</structname> View
</title>
2127 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2138 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2139 <structfield>subid
</structfield> <type>oid
</type>
2142 OID of the subscription
2147 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2148 <structfield>subname
</structfield> <type>name
</type>
2151 Name of the subscription
2156 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2157 <structfield>apply_error_count
</structfield> <type>bigint
</type>
2160 Number of times an error occurred while applying changes. Note that any
2161 conflict resulting in an apply error will be counted in both
2162 <literal>apply_error_count
</literal> and the corresponding conflict
2163 count (e.g.,
<literal>confl_*
</literal>).
2168 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2169 <structfield>sync_error_count
</structfield> <type>bigint
</type>
2172 Number of times an error occurred during the initial table
2178 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2179 <structfield>confl_insert_exists
</structfield> <type>bigint
</type>
2182 Number of times a row insertion violated a
2183 <literal>NOT DEFERRABLE
</literal> unique constraint during the
2184 application of changes. See
<xref linkend=
"conflict-insert-exists"/>
2185 for details about this conflict.
2190 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2191 <structfield>confl_update_origin_differs
</structfield> <type>bigint
</type>
2194 Number of times an update was applied to a row that had been previously
2195 modified by another source during the application of changes. See
2196 <xref linkend=
"conflict-update-origin-differs"/> for details about this
2202 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2203 <structfield>confl_update_exists
</structfield> <type>bigint
</type>
2206 Number of times that an updated row value violated a
2207 <literal>NOT DEFERRABLE
</literal> unique constraint during the
2208 application of changes. See
<xref linkend=
"conflict-update-exists"/>
2209 for details about this conflict.
2214 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2215 <structfield>confl_update_missing
</structfield> <type>bigint
</type>
2218 Number of times the tuple to be updated was not found during the
2219 application of changes. See
<xref linkend=
"conflict-update-missing"/>
2220 for details about this conflict.
2225 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2226 <structfield>confl_delete_origin_differs
</structfield> <type>bigint
</type>
2229 Number of times a delete operation was applied to row that had been
2230 previously modified by another source during the application of changes.
2231 See
<xref linkend=
"conflict-delete-origin-differs"/> for details about
2237 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2238 <structfield>confl_delete_missing
</structfield> <type>bigint
</type>
2241 Number of times the tuple to be deleted was not found during the application
2242 of changes. See
<xref linkend=
"conflict-delete-missing"/> for details
2243 about this conflict.
2248 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2249 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
2252 Time at which these statistics were last reset
2261 <sect2 id=
"monitoring-pg-stat-ssl-view">
2262 <title><structname>pg_stat_ssl
</structname></title>
2265 <primary>pg_stat_ssl
</primary>
2269 The
<structname>pg_stat_ssl
</structname> view will contain one row per
2270 backend or WAL sender process, showing statistics about SSL usage on
2271 this connection. It can be joined to
<structname>pg_stat_activity
</structname>
2272 or
<structname>pg_stat_replication
</structname> on the
2273 <structfield>pid
</structfield> column to get more details about the
2277 <table id=
"pg-stat-ssl-view" xreflabel=
"pg_stat_ssl">
2278 <title><structname>pg_stat_ssl
</structname> View
</title>
2282 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2293 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2294 <structfield>pid
</structfield> <type>integer
</type>
2297 Process ID of a backend or WAL sender process
2302 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2303 <structfield>ssl
</structfield> <type>boolean
</type>
2306 True if SSL is used on this connection
2311 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2312 <structfield>version
</structfield> <type>text
</type>
2315 Version of SSL in use, or NULL if SSL is not in use
2321 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2322 <structfield>cipher
</structfield> <type>text
</type>
2325 Name of SSL cipher in use, or NULL if SSL is not in use
2331 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2332 <structfield>bits
</structfield> <type>integer
</type>
2335 Number of bits in the encryption algorithm used, or NULL
2336 if SSL is not used on this connection
2341 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2342 <structfield>client_dn
</structfield> <type>text
</type>
2345 Distinguished Name (DN) field from the client certificate
2346 used, or NULL if no client certificate was supplied or if SSL
2347 is not in use on this connection. This field is truncated if the
2348 DN field is longer than
<symbol>NAMEDATALEN
</symbol> (
64 characters
2349 in a standard build).
2354 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2355 <structfield>client_serial
</structfield> <type>numeric
</type>
2358 Serial number of the client certificate, or NULL if no client
2359 certificate was supplied or if SSL is not in use on this connection. The
2360 combination of certificate serial number and certificate issuer uniquely
2361 identifies a certificate (unless the issuer erroneously reuses serial
2367 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2368 <structfield>issuer_dn
</structfield> <type>text
</type>
2371 DN of the issuer of the client certificate, or NULL if no client
2372 certificate was supplied or if SSL is not in use on this connection.
2373 This field is truncated like
<structfield>client_dn
</structfield>.
2382 <sect2 id=
"monitoring-pg-stat-gssapi-view">
2383 <title><structname>pg_stat_gssapi
</structname></title>
2386 <primary>pg_stat_gssapi
</primary>
2390 The
<structname>pg_stat_gssapi
</structname> view will contain one row per
2391 backend, showing information about GSSAPI usage on this connection. It can
2392 be joined to
<structname>pg_stat_activity
</structname> or
2393 <structname>pg_stat_replication
</structname> on the
2394 <structfield>pid
</structfield> column to get more details about the
2398 <table id=
"pg-stat-gssapi-view" xreflabel=
"pg_stat_gssapi">
2399 <title><structname>pg_stat_gssapi
</structname> View
</title>
2403 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2414 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2415 <structfield>pid
</structfield> <type>integer
</type>
2418 Process ID of a backend
2423 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2424 <structfield>gss_authenticated
</structfield> <type>boolean
</type>
2427 True if GSSAPI authentication was used for this connection
2432 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2433 <structfield>principal
</structfield> <type>text
</type>
2436 Principal used to authenticate this connection, or NULL
2437 if GSSAPI was not used to authenticate this connection. This
2438 field is truncated if the principal is longer than
2439 <symbol>NAMEDATALEN
</symbol> (
64 characters in a standard build).
2444 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2445 <structfield>encrypted
</structfield> <type>boolean
</type>
2448 True if GSSAPI encryption is in use on this connection
2453 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2454 <structfield>credentials_delegated
</structfield> <type>boolean
</type>
2457 True if GSSAPI credentials were delegated on this connection.
2466 <sect2 id=
"monitoring-pg-stat-archiver-view">
2467 <title><structname>pg_stat_archiver
</structname></title>
2470 <primary>pg_stat_archiver
</primary>
2474 The
<structname>pg_stat_archiver
</structname> view will always have a
2475 single row, containing data about the archiver process of the cluster.
2478 <table id=
"pg-stat-archiver-view" xreflabel=
"pg_stat_archiver">
2479 <title><structname>pg_stat_archiver
</structname> View
</title>
2483 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2494 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2495 <structfield>archived_count
</structfield> <type>bigint
</type>
2498 Number of WAL files that have been successfully archived
2503 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2504 <structfield>last_archived_wal
</structfield> <type>text
</type>
2507 Name of the WAL file most recently successfully archived
2512 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2513 <structfield>last_archived_time
</structfield> <type>timestamp with time zone
</type>
2516 Time of the most recent successful archive operation
2521 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2522 <structfield>failed_count
</structfield> <type>bigint
</type>
2525 Number of failed attempts for archiving WAL files
2530 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2531 <structfield>last_failed_wal
</structfield> <type>text
</type>
2534 Name of the WAL file of the most recent failed archival operation
2539 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2540 <structfield>last_failed_time
</structfield> <type>timestamp with time zone
</type>
2543 Time of the most recent failed archival operation
2548 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2549 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
2552 Time at which these statistics were last reset
2560 Normally, WAL files are archived in order, oldest to newest, but that is
2561 not guaranteed, and does not hold under special circumstances like when
2562 promoting a standby or after crash recovery. Therefore it is not safe to
2563 assume that all files older than
2564 <structfield>last_archived_wal
</structfield> have also been successfully
2569 <sect2 id=
"monitoring-pg-stat-io-view">
2570 <title><structname>pg_stat_io
</structname></title>
2573 <primary>pg_stat_io
</primary>
2577 The
<structname>pg_stat_io
</structname> view will contain one row for each
2578 combination of backend type, target I/O object, and I/O context, showing
2579 cluster-wide I/O statistics. Combinations which do not make sense are
2584 Currently, I/O on relations (e.g. tables, indexes) is tracked. However,
2585 relation I/O which bypasses shared buffers (e.g. when moving a table from one
2586 tablespace to another) is currently not tracked.
2589 <table id=
"pg-stat-io-view" xreflabel=
"pg_stat_io">
2590 <title><structname>pg_stat_io
</structname> View
</title>
2594 <entry role=
"catalog_table_entry">
2595 <para role=
"column_definition">
2606 <entry role=
"catalog_table_entry">
2607 <para role=
"column_definition">
2608 <structfield>backend_type
</structfield> <type>text
</type>
2611 Type of backend (e.g. background worker, autovacuum worker). See
<link
2612 linkend=
"monitoring-pg-stat-activity-view">
2613 <structname>pg_stat_activity
</structname></link> for more information
2614 on
<varname>backend_type
</varname>s. Some
2615 <varname>backend_type
</varname>s do not accumulate I/O operation
2616 statistics and will not be included in the view.
2622 <entry role=
"catalog_table_entry">
2623 <para role=
"column_definition">
2624 <structfield>object
</structfield> <type>text
</type>
2627 Target object of an I/O operation. Possible values are:
2631 <literal>relation
</literal>: Permanent relations.
2636 <literal>temp relation
</literal>: Temporary relations.
2645 <entry role=
"catalog_table_entry">
2646 <para role=
"column_definition">
2647 <structfield>context
</structfield> <type>text
</type>
2650 The context of an I/O operation. Possible values are:
2655 <literal>normal
</literal>: The default or standard
2656 <varname>context
</varname> for a type of I/O operation. For
2657 example, by default, relation data is read into and written out from
2658 shared buffers. Thus, reads and writes of relation data to and from
2659 shared buffers are tracked in
<varname>context
</varname>
2660 <literal>normal
</literal>.
2665 <literal>vacuum
</literal>: I/O operations performed outside of shared
2666 buffers while vacuuming and analyzing permanent relations. Temporary
2667 table vacuums use the same local buffer pool as other temporary table
2668 I/O operations and are tracked in
<varname>context
</varname>
2669 <literal>normal
</literal>.
2674 <literal>bulkread
</literal>: Certain large read I/O operations
2675 done outside of shared buffers, for example, a sequential scan of a
2681 <literal>bulkwrite
</literal>: Certain large write I/O operations
2682 done outside of shared buffers, such as
<command>COPY
</command>.
2690 <entry role=
"catalog_table_entry">
2691 <para role=
"column_definition">
2692 <structfield>reads
</structfield> <type>bigint
</type>
2695 Number of read operations.
2701 <entry role=
"catalog_table_entry">
2702 <para role=
"column_definition">
2703 <structfield>read_bytes
</structfield> <type>numeric
</type>
2706 The total size of read operations in bytes.
2712 <entry role=
"catalog_table_entry">
2713 <para role=
"column_definition">
2714 <structfield>read_time
</structfield> <type>double precision
</type>
2717 Time spent in read operations in milliseconds (if
2718 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2724 <entry role=
"catalog_table_entry">
2725 <para role=
"column_definition">
2726 <structfield>writes
</structfield> <type>bigint
</type>
2729 Number of write operations.
2735 <entry role=
"catalog_table_entry">
2736 <para role=
"column_definition">
2737 <structfield>write_bytes
</structfield> <type>numeric
</type>
2740 The total size of write operations in bytes.
2746 <entry role=
"catalog_table_entry">
2747 <para role=
"column_definition">
2748 <structfield>write_time
</structfield> <type>double precision
</type>
2751 Time spent in write operations in milliseconds (if
2752 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2758 <entry role=
"catalog_table_entry">
2759 <para role=
"column_definition">
2760 <structfield>writebacks
</structfield> <type>bigint
</type>
2763 Number of units of size
<symbol>BLCKSZ
</symbol> (typically
8kB) which
2764 the process requested the kernel write out to permanent storage.
2770 <entry role=
"catalog_table_entry">
2771 <para role=
"column_definition">
2772 <structfield>writeback_time
</structfield> <type>double precision
</type>
2775 Time spent in writeback operations in milliseconds (if
2776 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero). This
2777 includes the time spent queueing write-out requests and, potentially,
2778 the time spent to write out the dirty data.
2784 <entry role=
"catalog_table_entry">
2785 <para role=
"column_definition">
2786 <structfield>extends
</structfield> <type>bigint
</type>
2789 Number of relation extend operations.
2795 <entry role=
"catalog_table_entry">
2796 <para role=
"column_definition">
2797 <structfield>extend_bytes
</structfield> <type>numeric
</type>
2800 The total size of relation extend operations in bytes.
2806 <entry role=
"catalog_table_entry">
2807 <para role=
"column_definition">
2808 <structfield>extend_time
</structfield> <type>double precision
</type>
2811 Time spent in extend operations in milliseconds (if
2812 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2818 <entry role=
"catalog_table_entry">
2819 <para role=
"column_definition">
2820 <structfield>hits
</structfield> <type>bigint
</type>
2823 The number of times a desired block was found in a shared buffer.
2829 <entry role=
"catalog_table_entry">
2830 <para role=
"column_definition">
2831 <structfield>evictions
</structfield> <type>bigint
</type>
2834 Number of times a block has been written out from a shared or local
2835 buffer in order to make it available for another use.
2838 In
<varname>context
</varname> <literal>normal
</literal>, this counts
2839 the number of times a block was evicted from a buffer and replaced with
2840 another block. In
<varname>context
</varname>s
2841 <literal>bulkwrite
</literal>,
<literal>bulkread
</literal>, and
2842 <literal>vacuum
</literal>, this counts the number of times a block was
2843 evicted from shared buffers in order to add the shared buffer to a
2844 separate, size-limited ring buffer for use in a bulk I/O operation.
2850 <entry role=
"catalog_table_entry">
2851 <para role=
"column_definition">
2852 <structfield>reuses
</structfield> <type>bigint
</type>
2855 The number of times an existing buffer in a size-limited ring buffer
2856 outside of shared buffers was reused as part of an I/O operation in the
2857 <literal>bulkread
</literal>,
<literal>bulkwrite
</literal>, or
2858 <literal>vacuum
</literal> <varname>context
</varname>s.
2864 <entry role=
"catalog_table_entry">
2865 <para role=
"column_definition">
2866 <structfield>fsyncs
</structfield> <type>bigint
</type>
2869 Number of
<literal>fsync
</literal> calls. These are only tracked in
2870 <varname>context
</varname> <literal>normal
</literal>.
2876 <entry role=
"catalog_table_entry">
2877 <para role=
"column_definition">
2878 <structfield>fsync_time
</structfield> <type>double precision
</type>
2881 Time spent in fsync operations in milliseconds (if
2882 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2888 <entry role=
"catalog_table_entry">
2889 <para role=
"column_definition">
2890 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
2893 Time at which these statistics were last reset.
2902 Some backend types never perform I/O operations on some I/O objects and/or
2903 in some I/O contexts. These rows are omitted from the view. For example, the
2904 checkpointer does not checkpoint temporary tables, so there will be no rows
2905 for
<varname>backend_type
</varname> <literal>checkpointer
</literal> and
2906 <varname>object
</varname> <literal>temp relation
</literal>.
2910 In addition, some I/O operations will never be performed either by certain
2911 backend types or on certain I/O objects and/or in certain I/O contexts.
2912 These cells will be NULL. For example, temporary tables are not
2913 <literal>fsync
</literal>ed, so
<varname>fsyncs
</varname> will be NULL for
2914 <varname>object
</varname> <literal>temp relation
</literal>. Also, the
2915 background writer does not perform reads, so
<varname>reads
</varname> will
2916 be NULL in rows for
<varname>backend_type
</varname> <literal>background
2921 <structname>pg_stat_io
</structname> can be used to inform database tuning.
2926 A high
<varname>evictions
</varname> count can indicate that shared
2927 buffers should be increased.
2932 Client backends rely on the checkpointer to ensure data is persisted to
2933 permanent storage. Large numbers of
<varname>fsyncs
</varname> by
2934 <literal>client backend
</literal>s could indicate a misconfiguration of
2935 shared buffers or of the checkpointer. More information on configuring
2936 the checkpointer can be found in
<xref linkend=
"wal-configuration"/>.
2941 Normally, client backends should be able to rely on auxiliary processes
2942 like the checkpointer and the background writer to write out dirty data
2943 as much as possible. Large numbers of writes by client backends could
2944 indicate a misconfiguration of shared buffers or of the checkpointer.
2945 More information on configuring the checkpointer can be found in
<xref
2946 linkend=
"wal-configuration"/>.
2954 Columns tracking I/O time will only be non-zero when
2955 <xref linkend=
"guc-track-io-timing"/> is enabled. The user should be
2956 careful when referencing these columns in combination with their
2957 corresponding I/O operations in case
<varname>track_io_timing
</varname>
2958 was not enabled for the entire time since the last stats reset.
2966 <sect2 id=
"monitoring-pg-stat-bgwriter-view">
2967 <title><structname>pg_stat_bgwriter
</structname></title>
2970 <primary>pg_stat_bgwriter
</primary>
2974 The
<structname>pg_stat_bgwriter
</structname> view will always have a
2975 single row, containing data about the background writer of the cluster.
2978 <table id=
"pg-stat-bgwriter-view" xreflabel=
"pg_stat_bgwriter">
2979 <title><structname>pg_stat_bgwriter
</structname> View
</title>
2983 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2994 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2995 <structfield>buffers_clean
</structfield> <type>bigint
</type>
2998 Number of buffers written by the background writer
3003 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3004 <structfield>maxwritten_clean
</structfield> <type>bigint
</type>
3007 Number of times the background writer stopped a cleaning
3008 scan because it had written too many buffers
3013 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3014 <structfield>buffers_alloc
</structfield> <type>bigint
</type>
3017 Number of buffers allocated
3022 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3023 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3026 Time at which these statistics were last reset
3035 <sect2 id=
"monitoring-pg-stat-checkpointer-view">
3036 <title><structname>pg_stat_checkpointer
</structname></title>
3039 <primary>pg_stat_checkpointer
</primary>
3043 The
<structname>pg_stat_checkpointer
</structname> view will always have a
3044 single row, containing data about the checkpointer process of the cluster.
3047 <table id=
"pg-stat-checkpointer-view" xreflabel=
"pg_stat_checkpointer">
3048 <title><structname>pg_stat_checkpointer
</structname> View
</title>
3052 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3063 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3064 <structfield>num_timed
</structfield> <type>bigint
</type>
3067 Number of scheduled checkpoints due to timeout
3072 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3073 <structfield>num_requested
</structfield> <type>bigint
</type>
3076 Number of requested checkpoints
3081 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3082 <structfield>num_done
</structfield> <type>bigint
</type>
3085 Number of checkpoints that have been performed
3090 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3091 <structfield>restartpoints_timed
</structfield> <type>bigint
</type>
3094 Number of scheduled restartpoints due to timeout or after a failed attempt to perform it
3099 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3100 <structfield>restartpoints_req
</structfield> <type>bigint
</type>
3103 Number of requested restartpoints
3108 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3109 <structfield>restartpoints_done
</structfield> <type>bigint
</type>
3112 Number of restartpoints that have been performed
3117 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3118 <structfield>write_time
</structfield> <type>double precision
</type>
3121 Total amount of time that has been spent in the portion of
3122 processing checkpoints and restartpoints where files are written to disk,
3128 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3129 <structfield>sync_time
</structfield> <type>double precision
</type>
3132 Total amount of time that has been spent in the portion of
3133 processing checkpoints and restartpoints where files are synchronized to
3134 disk, in milliseconds
3139 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3140 <structfield>buffers_written
</structfield> <type>bigint
</type>
3143 Number of shared buffers written during checkpoints and restartpoints
3148 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3149 <structfield>slru_written
</structfield> <type>bigint
</type>
3152 Number of SLRU buffers written during checkpoints and restartpoints
3157 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3158 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3161 Time at which these statistics were last reset
3169 Checkpoints may be skipped if the server has been idle since the last one.
3170 <structfield>num_timed
</structfield> and
3171 <structfield>num_requested
</structfield> count both completed and skipped
3172 checkpoints, while
<structfield>num_done
</structfield> tracks only
3173 the completed ones. Similarly, restartpoints may be skipped
3174 if the last replayed checkpoint record is already the last restartpoint.
3175 <structfield>restartpoints_timed
</structfield> and
3176 <structfield>restartpoints_req
</structfield> count both completed and
3177 skipped restartpoints, while
<structfield>restartpoints_done
</structfield>
3178 tracks only the completed ones.
3182 <sect2 id=
"monitoring-pg-stat-wal-view">
3183 <title><structname>pg_stat_wal
</structname></title>
3186 <primary>pg_stat_wal
</primary>
3190 The
<structname>pg_stat_wal
</structname> view will always have a
3191 single row, containing data about WAL activity of the cluster.
3194 <table id=
"pg-stat-wal-view" xreflabel=
"pg_stat_wal">
3195 <title><structname>pg_stat_wal
</structname> View
</title>
3199 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3210 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3211 <structfield>wal_records
</structfield> <type>bigint
</type>
3214 Total number of WAL records generated
3219 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3220 <structfield>wal_fpi
</structfield> <type>bigint
</type>
3223 Total number of WAL full page images generated
3228 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3229 <structfield>wal_bytes
</structfield> <type>numeric
</type>
3232 Total amount of WAL generated in bytes
3237 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3238 <structfield>wal_buffers_full
</structfield> <type>bigint
</type>
3241 Number of times WAL data was written to disk because WAL buffers became full
3246 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3247 <structfield>wal_write
</structfield> <type>bigint
</type>
3250 Number of times WAL buffers were written out to disk via
3251 <function>XLogWrite
</function> request.
3252 See
<xref linkend=
"wal-configuration"/> for more information about
3253 the internal WAL function
<function>XLogWrite
</function>.
3258 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3259 <structfield>wal_sync
</structfield> <type>bigint
</type>
3262 Number of times WAL files were synced to disk via
3263 <function>issue_xlog_fsync
</function> request
3264 (if
<xref linkend=
"guc-fsync"/> is
<literal>on
</literal> and
3265 <xref linkend=
"guc-wal-sync-method"/> is either
3266 <literal>fdatasync
</literal>,
<literal>fsync
</literal> or
3267 <literal>fsync_writethrough
</literal>, otherwise zero).
3268 See
<xref linkend=
"wal-configuration"/> for more information about
3269 the internal WAL function
<function>issue_xlog_fsync
</function>.
3274 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3275 <structfield>wal_write_time
</structfield> <type>double precision
</type>
3278 Total amount of time spent writing WAL buffers to disk via
3279 <function>XLogWrite
</function> request, in milliseconds
3280 (if
<xref linkend=
"guc-track-wal-io-timing"/> is enabled,
3281 otherwise zero). This includes the sync time when
3282 <varname>wal_sync_method
</varname> is either
3283 <literal>open_datasync
</literal> or
<literal>open_sync
</literal>.
3288 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3289 <structfield>wal_sync_time
</structfield> <type>double precision
</type>
3292 Total amount of time spent syncing WAL files to disk via
3293 <function>issue_xlog_fsync
</function> request, in milliseconds
3294 (if
<varname>track_wal_io_timing
</varname> is enabled,
3295 <varname>fsync
</varname> is
<literal>on
</literal>, and
3296 <varname>wal_sync_method
</varname> is either
3297 <literal>fdatasync
</literal>,
<literal>fsync
</literal> or
3298 <literal>fsync_writethrough
</literal>, otherwise zero).
3303 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3304 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3307 Time at which these statistics were last reset
3316 <sect2 id=
"monitoring-pg-stat-database-view">
3317 <title><structname>pg_stat_database
</structname></title>
3320 <primary>pg_stat_database
</primary>
3324 The
<structname>pg_stat_database
</structname> view will contain one row
3325 for each database in the cluster, plus one for shared objects, showing
3326 database-wide statistics.
3329 <table id=
"pg-stat-database-view" xreflabel=
"pg_stat_database">
3330 <title><structname>pg_stat_database
</structname> View
</title>
3334 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3345 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3346 <structfield>datid
</structfield> <type>oid
</type>
3349 OID of this database, or
0 for objects belonging to a shared
3355 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3356 <structfield>datname
</structfield> <type>name
</type>
3359 Name of this database, or
<literal>NULL
</literal> for shared
3365 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3366 <structfield>numbackends
</structfield> <type>integer
</type>
3369 Number of backends currently connected to this database, or
3370 <literal>NULL
</literal> for shared objects. This is the only column
3371 in this view that returns a value reflecting current state; all other
3372 columns return the accumulated values since the last reset.
3377 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3378 <structfield>xact_commit
</structfield> <type>bigint
</type>
3381 Number of transactions in this database that have been
3387 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3388 <structfield>xact_rollback
</structfield> <type>bigint
</type>
3391 Number of transactions in this database that have been
3397 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3398 <structfield>blks_read
</structfield> <type>bigint
</type>
3401 Number of disk blocks read in this database
3406 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3407 <structfield>blks_hit
</structfield> <type>bigint
</type>
3410 Number of times disk blocks were found already in the buffer
3411 cache, so that a read was not necessary (this only includes hits in the
3412 PostgreSQL buffer cache, not the operating system's file system cache)
3417 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3418 <structfield>tup_returned
</structfield> <type>bigint
</type>
3421 Number of live rows fetched by sequential scans and index entries returned by index scans in this database
3426 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3427 <structfield>tup_fetched
</structfield> <type>bigint
</type>
3430 Number of live rows fetched by index scans in this database
3435 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3436 <structfield>tup_inserted
</structfield> <type>bigint
</type>
3439 Number of rows inserted by queries in this database
3444 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3445 <structfield>tup_updated
</structfield> <type>bigint
</type>
3448 Number of rows updated by queries in this database
3453 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3454 <structfield>tup_deleted
</structfield> <type>bigint
</type>
3457 Number of rows deleted by queries in this database
3462 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3463 <structfield>conflicts
</structfield> <type>bigint
</type>
3466 Number of queries canceled due to conflicts with recovery
3467 in this database. (Conflicts occur only on standby servers; see
3468 <link linkend=
"monitoring-pg-stat-database-conflicts-view">
3469 <structname>pg_stat_database_conflicts
</structname></link> for details.)
3474 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3475 <structfield>temp_files
</structfield> <type>bigint
</type>
3478 Number of temporary files created by queries in this database.
3479 All temporary files are counted, regardless of why the temporary file
3480 was created (e.g., sorting or hashing), and regardless of the
3481 <xref linkend=
"guc-log-temp-files"/> setting.
3486 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3487 <structfield>temp_bytes
</structfield> <type>bigint
</type>
3490 Total amount of data written to temporary files by queries in
3491 this database. All temporary files are counted, regardless of why
3492 the temporary file was created, and
3493 regardless of the
<xref linkend=
"guc-log-temp-files"/> setting.
3498 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3499 <structfield>deadlocks
</structfield> <type>bigint
</type>
3502 Number of deadlocks detected in this database
3507 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3508 <structfield>checksum_failures
</structfield> <type>bigint
</type>
3511 Number of data page checksum failures detected in this
3512 database (or on a shared object), or NULL if data checksums are not
3518 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3519 <structfield>checksum_last_failure
</structfield> <type>timestamp with time zone
</type>
3522 Time at which the last data page checksum failure was detected in
3523 this database (or on a shared object), or NULL if data checksums are not
3529 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3530 <structfield>blk_read_time
</structfield> <type>double precision
</type>
3533 Time spent reading data file blocks by backends in this database,
3534 in milliseconds (if
<xref linkend=
"guc-track-io-timing"/> is enabled,
3540 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3541 <structfield>blk_write_time
</structfield> <type>double precision
</type>
3544 Time spent writing data file blocks by backends in this database,
3545 in milliseconds (if
<xref linkend=
"guc-track-io-timing"/> is enabled,
3551 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3552 <structfield>session_time
</structfield> <type>double precision
</type>
3555 Time spent by database sessions in this database, in milliseconds
3556 (note that statistics are only updated when the state of a session
3557 changes, so if sessions have been idle for a long time, this idle time
3563 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3564 <structfield>active_time
</structfield> <type>double precision
</type>
3567 Time spent executing SQL statements in this database, in milliseconds
3568 (this corresponds to the states
<literal>active
</literal> and
3569 <literal>fastpath function call
</literal> in
3570 <link linkend=
"monitoring-pg-stat-activity-view">
3571 <structname>pg_stat_activity
</structname></link>)
3576 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3577 <structfield>idle_in_transaction_time
</structfield> <type>double precision
</type>
3580 Time spent idling while in a transaction in this database, in milliseconds
3581 (this corresponds to the states
<literal>idle in transaction
</literal> and
3582 <literal>idle in transaction (aborted)
</literal> in
3583 <link linkend=
"monitoring-pg-stat-activity-view">
3584 <structname>pg_stat_activity
</structname></link>)
3589 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3590 <structfield>sessions
</structfield> <type>bigint
</type>
3593 Total number of sessions established to this database
3598 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3599 <structfield>sessions_abandoned
</structfield> <type>bigint
</type>
3602 Number of database sessions to this database that were terminated
3603 because connection to the client was lost
3608 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3609 <structfield>sessions_fatal
</structfield> <type>bigint
</type>
3612 Number of database sessions to this database that were terminated
3618 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3619 <structfield>sessions_killed
</structfield> <type>bigint
</type>
3622 Number of database sessions to this database that were terminated
3623 by operator intervention
3628 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3629 <structfield>parallel_workers_to_launch
</structfield> <type>bigint
</type>
3632 Number of parallel workers planned to be launched by queries on this database
3637 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3638 <structfield>parallel_workers_launched
</structfield> <type>bigint
</type>
3641 Number of parallel workers launched by queries on this database
3646 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3647 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3650 Time at which these statistics were last reset
3659 <sect2 id=
"monitoring-pg-stat-database-conflicts-view">
3660 <title><structname>pg_stat_database_conflicts
</structname></title>
3663 <primary>pg_stat_database_conflicts
</primary>
3667 The
<structname>pg_stat_database_conflicts
</structname> view will contain
3668 one row per database, showing database-wide statistics about
3669 query cancels occurring due to conflicts with recovery on standby servers.
3670 This view will only contain information on standby servers, since
3671 conflicts do not occur on primary servers.
3674 <table id=
"pg-stat-database-conflicts-view" xreflabel=
"pg_stat_database_conflicts">
3675 <title><structname>pg_stat_database_conflicts
</structname> View
</title>
3679 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3690 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3691 <structfield>datid
</structfield> <type>oid
</type>
3699 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3700 <structfield>datname
</structfield> <type>name
</type>
3703 Name of this database
3708 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3709 <structfield>confl_tablespace
</structfield> <type>bigint
</type>
3712 Number of queries in this database that have been canceled due to
3718 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3719 <structfield>confl_lock
</structfield> <type>bigint
</type>
3722 Number of queries in this database that have been canceled due to
3728 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3729 <structfield>confl_snapshot
</structfield> <type>bigint
</type>
3732 Number of queries in this database that have been canceled due to
3738 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3739 <structfield>confl_bufferpin
</structfield> <type>bigint
</type>
3742 Number of queries in this database that have been canceled due to
3748 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3749 <structfield>confl_deadlock
</structfield> <type>bigint
</type>
3752 Number of queries in this database that have been canceled due to
3758 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3759 <structfield>confl_active_logicalslot
</structfield> <type>bigint
</type>
3762 Number of uses of logical slots in this database that have been
3763 canceled due to old snapshots or too low a
<xref linkend=
"guc-wal-level"/>
3773 <sect2 id=
"monitoring-pg-stat-all-tables-view">
3774 <title><structname>pg_stat_all_tables
</structname></title>
3777 <primary>pg_stat_all_tables
</primary>
3781 The
<structname>pg_stat_all_tables
</structname> view will contain
3782 one row for each table in the current database (including TOAST
3783 tables), showing statistics about accesses to that specific table. The
3784 <structname>pg_stat_user_tables
</structname> and
3785 <structname>pg_stat_sys_tables
</structname> views
3786 contain the same information,
3787 but filtered to only show user and system tables respectively.
3790 <table id=
"pg-stat-all-tables-view" xreflabel=
"pg_stat_all_tables">
3791 <title><structname>pg_stat_all_tables
</structname> View
</title>
3795 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3806 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3807 <structfield>relid
</structfield> <type>oid
</type>
3815 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3816 <structfield>schemaname
</structfield> <type>name
</type>
3819 Name of the schema that this table is in
3824 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3825 <structfield>relname
</structfield> <type>name
</type>
3833 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3834 <structfield>seq_scan
</structfield> <type>bigint
</type>
3837 Number of sequential scans initiated on this table
3842 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3843 <structfield>last_seq_scan
</structfield> <type>timestamp with time zone
</type>
3846 The time of the last sequential scan on this table, based on the
3847 most recent transaction stop time
3852 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3853 <structfield>seq_tup_read
</structfield> <type>bigint
</type>
3856 Number of live rows fetched by sequential scans
3861 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3862 <structfield>idx_scan
</structfield> <type>bigint
</type>
3865 Number of index scans initiated on this table
3870 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3871 <structfield>last_idx_scan
</structfield> <type>timestamp with time zone
</type>
3874 The time of the last index scan on this table, based on the
3875 most recent transaction stop time
3880 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3881 <structfield>idx_tup_fetch
</structfield> <type>bigint
</type>
3884 Number of live rows fetched by index scans
3889 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3890 <structfield>n_tup_ins
</structfield> <type>bigint
</type>
3893 Total number of rows inserted
3898 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3899 <structfield>n_tup_upd
</structfield> <type>bigint
</type>
3902 Total number of rows updated. (This includes row updates
3903 counted in
<structfield>n_tup_hot_upd
</structfield> and
3904 <structfield>n_tup_newpage_upd
</structfield>, and remaining
3905 non-
<acronym>HOT
</acronym> updates.)
3910 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3911 <structfield>n_tup_del
</structfield> <type>bigint
</type>
3914 Total number of rows deleted
3919 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3920 <structfield>n_tup_hot_upd
</structfield> <type>bigint
</type>
3923 Number of rows
<link linkend=
"storage-hot">HOT updated
</link>.
3924 These are updates where no successor versions are required in
3930 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3931 <structfield>n_tup_newpage_upd
</structfield> <type>bigint
</type>
3934 Number of rows updated where the successor version goes onto a
3935 <emphasis>new
</emphasis> heap page, leaving behind an original
3937 <link linkend=
"storage-tuple-layout"><structfield>t_ctid
</structfield>
3938 field
</link> that points to a different heap page. These are
3939 always non-
<acronym>HOT
</acronym> updates.
3944 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3945 <structfield>n_live_tup
</structfield> <type>bigint
</type>
3948 Estimated number of live rows
3953 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3954 <structfield>n_dead_tup
</structfield> <type>bigint
</type>
3957 Estimated number of dead rows
3962 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3963 <structfield>n_mod_since_analyze
</structfield> <type>bigint
</type>
3966 Estimated number of rows modified since this table was last analyzed
3971 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3972 <structfield>n_ins_since_vacuum
</structfield> <type>bigint
</type>
3975 Estimated number of rows inserted since this table was last vacuumed
3980 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3981 <structfield>last_vacuum
</structfield> <type>timestamp with time zone
</type>
3984 Last time at which this table was manually vacuumed
3985 (not counting
<command>VACUUM FULL
</command>)
3990 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3991 <structfield>last_autovacuum
</structfield> <type>timestamp with time zone
</type>
3994 Last time at which this table was vacuumed by the autovacuum
4000 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4001 <structfield>last_analyze
</structfield> <type>timestamp with time zone
</type>
4004 Last time at which this table was manually analyzed
4009 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4010 <structfield>last_autoanalyze
</structfield> <type>timestamp with time zone
</type>
4013 Last time at which this table was analyzed by the autovacuum
4019 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4020 <structfield>vacuum_count
</structfield> <type>bigint
</type>
4023 Number of times this table has been manually vacuumed
4024 (not counting
<command>VACUUM FULL
</command>)
4029 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4030 <structfield>autovacuum_count
</structfield> <type>bigint
</type>
4033 Number of times this table has been vacuumed by the autovacuum
4039 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4040 <structfield>analyze_count
</structfield> <type>bigint
</type>
4043 Number of times this table has been manually analyzed
4048 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4049 <structfield>autoanalyze_count
</structfield> <type>bigint
</type>
4052 Number of times this table has been analyzed by the autovacuum
4062 <sect2 id=
"monitoring-pg-stat-all-indexes-view">
4063 <title><structname>pg_stat_all_indexes
</structname></title>
4066 <primary>pg_stat_all_indexes
</primary>
4070 The
<structname>pg_stat_all_indexes
</structname> view will contain
4071 one row for each index in the current database,
4072 showing statistics about accesses to that specific index. The
4073 <structname>pg_stat_user_indexes
</structname> and
4074 <structname>pg_stat_sys_indexes
</structname> views
4075 contain the same information,
4076 but filtered to only show user and system indexes respectively.
4079 <table id=
"pg-stat-all-indexes-view" xreflabel=
"pg_stat_all_indexes">
4080 <title><structname>pg_stat_all_indexes
</structname> View
</title>
4084 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4095 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4096 <structfield>relid
</structfield> <type>oid
</type>
4099 OID of the table for this index
4104 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4105 <structfield>indexrelid
</structfield> <type>oid
</type>
4113 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4114 <structfield>schemaname
</structfield> <type>name
</type>
4117 Name of the schema this index is in
4122 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4123 <structfield>relname
</structfield> <type>name
</type>
4126 Name of the table for this index
4131 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4132 <structfield>indexrelname
</structfield> <type>name
</type>
4140 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4141 <structfield>idx_scan
</structfield> <type>bigint
</type>
4144 Number of index scans initiated on this index
4149 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4150 <structfield>last_idx_scan
</structfield> <type>timestamp with time zone
</type>
4153 The time of the last scan on this index, based on the
4154 most recent transaction stop time
4159 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4160 <structfield>idx_tup_read
</structfield> <type>bigint
</type>
4163 Number of index entries returned by scans on this index
4168 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4169 <structfield>idx_tup_fetch
</structfield> <type>bigint
</type>
4172 Number of live table rows fetched by simple index scans using this
4181 Indexes can be used by simple index scans,
<quote>bitmap
</quote> index scans,
4182 and the optimizer. In a bitmap scan
4183 the output of several indexes can be combined via AND or OR rules,
4184 so it is difficult to associate individual heap row fetches
4185 with specific indexes when a bitmap scan is used. Therefore, a bitmap
4187 <structname>pg_stat_all_indexes
</structname>.
<structfield>idx_tup_read
</structfield>
4188 count(s) for the index(es) it uses, and it increments the
4189 <structname>pg_stat_all_tables
</structname>.
<structfield>idx_tup_fetch
</structfield>
4190 count for the table, but it does not affect
4191 <structname>pg_stat_all_indexes
</structname>.
<structfield>idx_tup_fetch
</structfield>.
4192 The optimizer also accesses indexes to check for supplied constants
4193 whose values are outside the recorded range of the optimizer statistics
4194 because the optimizer statistics might be stale.
4199 The
<structfield>idx_tup_read
</structfield> and
<structfield>idx_tup_fetch
</structfield> counts
4200 can be different even without any use of bitmap scans,
4201 because
<structfield>idx_tup_read
</structfield> counts
4202 index entries retrieved from the index while
<structfield>idx_tup_fetch
</structfield>
4203 counts live rows fetched from the table. The latter will be less if any
4204 dead or not-yet-committed rows are fetched using the index, or if any
4205 heap fetches are avoided by means of an index-only scan.
4211 Queries that use certain
<acronym>SQL
</acronym> constructs to search for
4212 rows matching any value out of a list or array of multiple scalar values
4213 (see
<xref linkend=
"functions-comparisons"/>) perform multiple
4214 <quote>primitive
</quote> index scans (up to one primitive scan per scalar
4215 value) during query execution. Each internal primitive index scan
4216 increments
<structname>pg_stat_all_indexes
</structname>.
<structfield>idx_scan
</structfield>,
4217 so it's possible for the count of index scans to significantly exceed the
4218 total number of index scan executor node executions.
4224 <sect2 id=
"monitoring-pg-statio-all-tables-view">
4225 <title><structname>pg_statio_all_tables
</structname></title>
4228 <primary>pg_statio_all_tables
</primary>
4232 The
<structname>pg_statio_all_tables
</structname> view will contain
4233 one row for each table in the current database (including TOAST
4234 tables), showing statistics about I/O on that specific table. The
4235 <structname>pg_statio_user_tables
</structname> and
4236 <structname>pg_statio_sys_tables
</structname> views
4237 contain the same information,
4238 but filtered to only show user and system tables respectively.
4241 <table id=
"pg-statio-all-tables-view" xreflabel=
"pg_statio_all_tables">
4242 <title><structname>pg_statio_all_tables
</structname> View
</title>
4246 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4257 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4258 <structfield>relid
</structfield> <type>oid
</type>
4266 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4267 <structfield>schemaname
</structfield> <type>name
</type>
4270 Name of the schema that this table is in
4275 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4276 <structfield>relname
</structfield> <type>name
</type>
4284 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4285 <structfield>heap_blks_read
</structfield> <type>bigint
</type>
4288 Number of disk blocks read from this table
4293 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4294 <structfield>heap_blks_hit
</structfield> <type>bigint
</type>
4297 Number of buffer hits in this table
4302 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4303 <structfield>idx_blks_read
</structfield> <type>bigint
</type>
4306 Number of disk blocks read from all indexes on this table
4311 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4312 <structfield>idx_blks_hit
</structfield> <type>bigint
</type>
4315 Number of buffer hits in all indexes on this table
4320 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4321 <structfield>toast_blks_read
</structfield> <type>bigint
</type>
4324 Number of disk blocks read from this table's TOAST table (if any)
4329 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4330 <structfield>toast_blks_hit
</structfield> <type>bigint
</type>
4333 Number of buffer hits in this table's TOAST table (if any)
4338 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4339 <structfield>tidx_blks_read
</structfield> <type>bigint
</type>
4342 Number of disk blocks read from this table's TOAST table indexes (if any)
4347 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4348 <structfield>tidx_blks_hit
</structfield> <type>bigint
</type>
4351 Number of buffer hits in this table's TOAST table indexes (if any)
4360 <sect2 id=
"monitoring-pg-statio-all-indexes-view">
4361 <title><structname>pg_statio_all_indexes
</structname></title>
4364 <primary>pg_statio_all_indexes
</primary>
4368 The
<structname>pg_statio_all_indexes
</structname> view will contain
4369 one row for each index in the current database,
4370 showing statistics about I/O on that specific index. The
4371 <structname>pg_statio_user_indexes
</structname> and
4372 <structname>pg_statio_sys_indexes
</structname> views
4373 contain the same information,
4374 but filtered to only show user and system indexes respectively.
4377 <table id=
"pg-statio-all-indexes-view" xreflabel=
"pg_statio_all_indexes">
4378 <title><structname>pg_statio_all_indexes
</structname> View
</title>
4382 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4393 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4394 <structfield>relid
</structfield> <type>oid
</type>
4397 OID of the table for this index
4402 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4403 <structfield>indexrelid
</structfield> <type>oid
</type>
4411 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4412 <structfield>schemaname
</structfield> <type>name
</type>
4415 Name of the schema this index is in
4420 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4421 <structfield>relname
</structfield> <type>name
</type>
4424 Name of the table for this index
4429 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4430 <structfield>indexrelname
</structfield> <type>name
</type>
4438 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4439 <structfield>idx_blks_read
</structfield> <type>bigint
</type>
4442 Number of disk blocks read from this index
4447 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4448 <structfield>idx_blks_hit
</structfield> <type>bigint
</type>
4451 Number of buffer hits in this index
4460 <sect2 id=
"monitoring-pg-statio-all-sequences-view">
4461 <title><structname>pg_statio_all_sequences
</structname></title>
4464 <primary>pg_statio_all_sequences
</primary>
4468 The
<structname>pg_statio_all_sequences
</structname> view will contain
4469 one row for each sequence in the current database,
4470 showing statistics about I/O on that specific sequence.
4473 <table id=
"pg-statio-all-sequences-view" xreflabel=
"pg_statio_all_sequences">
4474 <title><structname>pg_statio_all_sequences
</structname> View
</title>
4478 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4489 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4490 <structfield>relid
</structfield> <type>oid
</type>
4498 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4499 <structfield>schemaname
</structfield> <type>name
</type>
4502 Name of the schema this sequence is in
4507 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4508 <structfield>relname
</structfield> <type>name
</type>
4511 Name of this sequence
4516 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4517 <structfield>blks_read
</structfield> <type>bigint
</type>
4520 Number of disk blocks read from this sequence
4525 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4526 <structfield>blks_hit
</structfield> <type>bigint
</type>
4529 Number of buffer hits in this sequence
4538 <sect2 id=
"monitoring-pg-stat-user-functions-view">
4539 <title><structname>pg_stat_user_functions
</structname></title>
4542 <primary>pg_stat_user_functions
</primary>
4546 The
<structname>pg_stat_user_functions
</structname> view will contain
4547 one row for each tracked function, showing statistics about executions of
4548 that function. The
<xref linkend=
"guc-track-functions"/> parameter
4549 controls exactly which functions are tracked.
4552 <table id=
"pg-stat-user-functions-view" xreflabel=
"pg_stat_user_functions">
4553 <title><structname>pg_stat_user_functions
</structname> View
</title>
4557 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4568 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4569 <structfield>funcid
</structfield> <type>oid
</type>
4577 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4578 <structfield>schemaname
</structfield> <type>name
</type>
4581 Name of the schema this function is in
4586 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4587 <structfield>funcname
</structfield> <type>name
</type>
4590 Name of this function
4595 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4596 <structfield>calls
</structfield> <type>bigint
</type>
4599 Number of times this function has been called
4604 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4605 <structfield>total_time
</structfield> <type>double precision
</type>
4608 Total time spent in this function and all other functions
4609 called by it, in milliseconds
4614 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4615 <structfield>self_time
</structfield> <type>double precision
</type>
4618 Total time spent in this function itself, not including
4619 other functions called by it, in milliseconds
4628 <sect2 id=
"monitoring-pg-stat-slru-view">
4629 <title><structname>pg_stat_slru
</structname></title>
4632 <primary>SLRU
</primary>
4636 <primary>pg_stat_slru
</primary>
4640 <productname>PostgreSQL
</productname> accesses certain on-disk information
4641 via
<literal>SLRU
</literal> (
<firstterm>simple least-recently-used
</firstterm>)
4643 The
<structname>pg_stat_slru
</structname> view will contain
4644 one row for each tracked SLRU cache, showing statistics about access
4649 For each
<literal>SLRU
</literal> cache that's part of the core server,
4650 there is a configuration parameter that controls its size, with the suffix
4651 <literal>_buffers
</literal> appended.
4654 <table id=
"pg-stat-slru-view" xreflabel=
"pg_stat_slru">
4655 <title><structname>pg_stat_slru
</structname> View
</title>
4659 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4670 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4671 <structfield>name
</structfield> <type>text
</type>
4679 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4680 <structfield>blks_zeroed
</structfield> <type>bigint
</type>
4683 Number of blocks zeroed during initializations
4688 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4689 <structfield>blks_hit
</structfield> <type>bigint
</type>
4692 Number of times disk blocks were found already in the SLRU,
4693 so that a read was not necessary (this only includes hits in the
4694 SLRU, not the operating system's file system cache)
4699 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4700 <structfield>blks_read
</structfield> <type>bigint
</type>
4703 Number of disk blocks read for this SLRU
4708 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4709 <structfield>blks_written
</structfield> <type>bigint
</type>
4712 Number of disk blocks written for this SLRU
4717 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4718 <structfield>blks_exists
</structfield> <type>bigint
</type>
4721 Number of blocks checked for existence for this SLRU
4726 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4727 <structfield>flushes
</structfield> <type>bigint
</type>
4730 Number of flushes of dirty data for this SLRU
4735 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4736 <structfield>truncates
</structfield> <type>bigint
</type>
4739 Number of truncates for this SLRU
4744 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4745 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
4748 Time at which these statistics were last reset
4757 <sect2 id=
"monitoring-stats-functions">
4758 <title>Statistics Functions
</title>
4761 Other ways of looking at the statistics can be set up by writing
4762 queries that use the same underlying statistics access functions used by
4763 the standard views shown above. For details such as the functions' names,
4764 consult the definitions of the standard views. (For example, in
4765 <application>psql
</application> you could issue
<literal>\d+ pg_stat_activity
</literal>.)
4766 The access functions for per-database statistics take a database OID as an
4767 argument to identify which database to report on.
4768 The per-table and per-index functions take a table or index OID.
4769 The functions for per-function statistics take a function OID.
4770 Note that only tables, indexes, and functions in the current database
4771 can be seen with these functions.
4775 Additional functions related to the cumulative statistics system are listed
4776 in
<xref linkend=
"monitoring-stats-funcs-table"/>.
4779 <table id=
"monitoring-stats-funcs-table">
4780 <title>Additional Statistics Functions
</title>
4784 <entry role=
"func_table_entry"><para role=
"func_signature">
4795 <!-- See also the entry for this in func.sgml -->
4796 <entry role=
"func_table_entry"><para role=
"func_signature">
4797 <function>pg_backend_pid
</function> ()
4798 <returnvalue>integer
</returnvalue>
4801 Returns the process ID of the server process attached to the current
4807 <entry id=
"pg-stat-get-backend-io" role=
"func_table_entry"><para role=
"func_signature">
4809 <primary>pg_stat_get_backend_io
</primary>
4811 <function>pg_stat_get_backend_io
</function> (
<type>integer
</type> )
4812 <returnvalue>setof record
</returnvalue>
4815 Returns I/O statistics about the backend with the specified
4816 process ID. The output fields are exactly the same as the ones in the
4817 <structname>pg_stat_io
</structname> view.
4820 The function does not return I/O statistics for the checkpointer,
4821 the background writer, the startup process and the autovacuum launcher
4822 as they are already visible in the
<structname>pg_stat_io
</structname>
4823 view and there is only one of each.
4828 <entry role=
"func_table_entry"><para role=
"func_signature">
4830 <primary>pg_stat_get_activity
</primary>
4832 <function>pg_stat_get_activity
</function> (
<type>integer
</type> )
4833 <returnvalue>setof record
</returnvalue>
4836 Returns a record of information about the backend with the specified
4837 process ID, or one record for each active backend in the system
4838 if
<literal>NULL
</literal> is specified. The fields returned are a
4839 subset of those in the
<structname>pg_stat_activity
</structname> view.
4844 <entry role=
"func_table_entry"><para role=
"func_signature">
4846 <primary>pg_stat_get_snapshot_timestamp
</primary>
4848 <function>pg_stat_get_snapshot_timestamp
</function> ()
4849 <returnvalue>timestamp with time zone
</returnvalue>
4852 Returns the timestamp of the current statistics snapshot, or NULL if
4853 no statistics snapshot has been taken. A snapshot is taken the first
4854 time cumulative statistics are accessed in a transaction if
4855 <varname>stats_fetch_consistency
</varname> is set to
4856 <literal>snapshot
</literal>
4861 <entry role=
"func_table_entry"><para role=
"func_signature">
4863 <primary>pg_stat_get_xact_blocks_fetched
</primary>
4865 <function>pg_stat_get_xact_blocks_fetched
</function> (
<type>oid
</type> )
4866 <returnvalue>bigint
</returnvalue>
4869 Returns the number of block read requests for table or index, in the
4870 current transaction. This number minus
4871 <function>pg_stat_get_xact_blocks_hit
</function> gives the number of
4872 kernel
<function>read()
</function> calls; the number of actual
4873 physical reads is usually lower due to kernel-level buffering.
4878 <entry role=
"func_table_entry"><para role=
"func_signature">
4880 <primary>pg_stat_get_xact_blocks_hit
</primary>
4882 <function>pg_stat_get_xact_blocks_hit
</function> (
<type>oid
</type> )
4883 <returnvalue>bigint
</returnvalue>
4886 Returns the number of block read requests for table or index, in the
4887 current transaction, found in cache (not triggering kernel
4888 <function>read()
</function> calls).
4893 <entry role=
"func_table_entry"><para role=
"func_signature">
4895 <primary>pg_stat_clear_snapshot
</primary>
4897 <function>pg_stat_clear_snapshot
</function> ()
4898 <returnvalue>void
</returnvalue>
4901 Discards the current statistics snapshot or cached information.
4906 <entry role=
"func_table_entry"><para role=
"func_signature">
4908 <primary>pg_stat_reset
</primary>
4910 <function>pg_stat_reset
</function> ()
4911 <returnvalue>void
</returnvalue>
4914 Resets all statistics counters for the current database to zero.
4917 This function is restricted to superusers by default, but other users
4918 can be granted EXECUTE to run the function.
4923 <entry role=
"func_table_entry"><para role=
"func_signature">
4925 <primary>pg_stat_reset_shared
</primary>
4927 <function>pg_stat_reset_shared
</function> ( [
<parameter>target
</parameter> <type>text
</type> <literal>DEFAULT
</literal> <literal>NULL
</literal> ] )
4928 <returnvalue>void
</returnvalue>
4931 Resets some cluster-wide statistics counters to zero, depending on the
4932 argument.
<parameter>target
</parameter> can be:
4936 <literal>archiver
</literal>: Reset all the counters shown in the
4937 <structname>pg_stat_archiver
</structname> view.
4942 <literal>bgwriter
</literal>: Reset all the counters shown in the
4943 <structname>pg_stat_bgwriter
</structname> view.
4948 <literal>checkpointer
</literal>: Reset all the counters shown in the
4949 <structname>pg_stat_checkpointer
</structname> view.
4954 <literal>io
</literal>: Reset all the counters shown in the
4955 <structname>pg_stat_io
</structname> view.
4960 <literal>recovery_prefetch
</literal>: Reset all the counters shown in
4961 the
<structname>pg_stat_recovery_prefetch
</structname> view.
4966 <literal>slru
</literal>: Reset all the counters shown in the
4967 <structname>pg_stat_slru
</structname> view.
4972 <literal>wal
</literal>: Reset all the counters shown in the
4973 <structname>pg_stat_wal
</structname> view.
4978 <literal>NULL
</literal> or not specified: All the counters from the
4979 views listed above are reset.
4985 This function is restricted to superusers by default, but other users
4986 can be granted EXECUTE to run the function.
4991 <entry role=
"func_table_entry"><para role=
"func_signature">
4993 <primary>pg_stat_reset_single_table_counters
</primary>
4995 <function>pg_stat_reset_single_table_counters
</function> (
<type>oid
</type> )
4996 <returnvalue>void
</returnvalue>
4999 Resets statistics for a single table or index in the current database
5000 or shared across all databases in the cluster to zero.
5003 This function is restricted to superusers by default, but other users
5004 can be granted EXECUTE to run the function.
5009 <entry role=
"func_table_entry"><para role=
"func_signature">
5011 <primary>pg_stat_reset_backend_stats
</primary>
5013 <function>pg_stat_reset_backend_stats
</function> (
<type>integer
</type> )
5014 <returnvalue>void
</returnvalue>
5017 Resets statistics for a single backend with the specified process ID
5021 This function is restricted to superusers by default, but other users
5022 can be granted EXECUTE to run the function.
5027 <entry role=
"func_table_entry"><para role=
"func_signature">
5029 <primary>pg_stat_reset_single_function_counters
</primary>
5031 <function>pg_stat_reset_single_function_counters
</function> (
<type>oid
</type> )
5032 <returnvalue>void
</returnvalue>
5035 Resets statistics for a single function in the current database to
5039 This function is restricted to superusers by default, but other users
5040 can be granted EXECUTE to run the function.
5045 <entry role=
"func_table_entry"><para role=
"func_signature">
5047 <primary>pg_stat_reset_slru
</primary>
5049 <function>pg_stat_reset_slru
</function> ( [
<parameter>target
</parameter> <type>text
</type> <literal>DEFAULT
</literal> <literal>NULL
</literal> ] )
5050 <returnvalue>void
</returnvalue>
5053 Resets statistics to zero for a single SLRU cache, or for all SLRUs in
5054 the cluster. If
<parameter>target
</parameter> is
5055 <literal>NULL
</literal> or is not specified, all the counters shown in
5056 the
<structname>pg_stat_slru
</structname> view for all SLRU caches are
5057 reset. The argument can be one of
5058 <literal>commit_timestamp
</literal>,
5059 <literal>multixact_member
</literal>,
5060 <literal>multixact_offset
</literal>,
5061 <literal>notify
</literal>,
5062 <literal>serializable
</literal>,
5063 <literal>subtransaction
</literal>, or
5064 <literal>transaction
</literal>
5065 to reset the counters for only that entry.
5066 If the argument is
<literal>other
</literal> (or indeed, any
5067 unrecognized name), then the counters for all other SLRU caches, such
5068 as extension-defined caches, are reset.
5071 This function is restricted to superusers by default, but other users
5072 can be granted EXECUTE to run the function.
5077 <entry role=
"func_table_entry"><para role=
"func_signature">
5079 <primary>pg_stat_reset_replication_slot
</primary>
5081 <function>pg_stat_reset_replication_slot
</function> (
<type>text
</type> )
5082 <returnvalue>void
</returnvalue>
5085 Resets statistics of the replication slot defined by the argument. If
5086 the argument is
<literal>NULL
</literal>, resets statistics for all
5087 the replication slots.
5090 This function is restricted to superusers by default, but other users
5091 can be granted EXECUTE to run the function.
5096 <entry role=
"func_table_entry"><para role=
"func_signature">
5098 <primary>pg_stat_reset_subscription_stats
</primary>
5100 <function>pg_stat_reset_subscription_stats
</function> (
<type>oid
</type> )
5101 <returnvalue>void
</returnvalue>
5104 Resets statistics for a single subscription shown in the
5105 <structname>pg_stat_subscription_stats
</structname> view to zero. If
5106 the argument is
<literal>NULL
</literal>, reset statistics for all
5110 This function is restricted to superusers by default, but other users
5111 can be granted EXECUTE to run the function.
5120 Using
<function>pg_stat_reset()
</function> also resets counters that
5121 autovacuum uses to determine when to trigger a vacuum or an analyze.
5122 Resetting these counters can cause autovacuum to not perform necessary
5123 work, which can cause problems such as table bloat or out-dated
5124 table statistics. A database-wide
<command>ANALYZE
</command> is
5125 recommended after the statistics have been reset.
5130 <function>pg_stat_get_activity
</function>, the underlying function of
5131 the
<structname>pg_stat_activity
</structname> view, returns a set of records
5132 containing all the available information about each backend process.
5133 Sometimes it may be more convenient to obtain just a subset of this
5134 information. In such cases, another set of per-backend statistics
5135 access functions can be used; these are shown in
<xref
5136 linkend=
"monitoring-stats-backend-funcs-table"/>.
5137 These access functions use the session's backend ID number, which is a
5138 small integer (
>=
0) that is distinct from the backend ID of any
5139 concurrent session, although a session's ID can be recycled as soon as
5140 it exits. The backend ID is used, among other things, to identify the
5141 session's temporary schema if it has one.
5142 The function
<function>pg_stat_get_backend_idset
</function> provides a
5143 convenient way to list all the active backends' ID numbers for
5144 invoking these functions. For example, to show the
<acronym>PID
</acronym>s and
5145 current queries of all backends:
5148 SELECT pg_stat_get_backend_pid(backendid) AS pid,
5149 pg_stat_get_backend_activity(backendid) AS query
5150 FROM pg_stat_get_backend_idset() AS backendid;
5154 <table id=
"monitoring-stats-backend-funcs-table">
5155 <title>Per-Backend Statistics Functions
</title>
5159 <entry role=
"func_table_entry"><para role=
"func_signature">
5170 <entry role=
"func_table_entry"><para role=
"func_signature">
5172 <primary>pg_stat_get_backend_activity
</primary>
5174 <function>pg_stat_get_backend_activity
</function> (
<type>integer
</type> )
5175 <returnvalue>text
</returnvalue>
5178 Returns the text of this backend's most recent query.
5183 <entry role=
"func_table_entry"><para role=
"func_signature">
5185 <primary>pg_stat_get_backend_activity_start
</primary>
5187 <function>pg_stat_get_backend_activity_start
</function> (
<type>integer
</type> )
5188 <returnvalue>timestamp with time zone
</returnvalue>
5191 Returns the time when the backend's most recent query was started.
5196 <entry role=
"func_table_entry"><para role=
"func_signature">
5198 <primary>pg_stat_get_backend_client_addr
</primary>
5200 <function>pg_stat_get_backend_client_addr
</function> (
<type>integer
</type> )
5201 <returnvalue>inet
</returnvalue>
5204 Returns the IP address of the client connected to this backend.
5209 <entry role=
"func_table_entry"><para role=
"func_signature">
5211 <primary>pg_stat_get_backend_client_port
</primary>
5213 <function>pg_stat_get_backend_client_port
</function> (
<type>integer
</type> )
5214 <returnvalue>integer
</returnvalue>
5217 Returns the TCP port number that the client is using for communication.
5222 <entry role=
"func_table_entry"><para role=
"func_signature">
5224 <primary>pg_stat_get_backend_dbid
</primary>
5226 <function>pg_stat_get_backend_dbid
</function> (
<type>integer
</type> )
5227 <returnvalue>oid
</returnvalue>
5230 Returns the OID of the database this backend is connected to.
5235 <entry role=
"func_table_entry"><para role=
"func_signature">
5237 <primary>pg_stat_get_backend_idset
</primary>
5239 <function>pg_stat_get_backend_idset
</function> ()
5240 <returnvalue>setof integer
</returnvalue>
5243 Returns the set of currently active backend ID numbers.
5248 <entry role=
"func_table_entry"><para role=
"func_signature">
5250 <primary>pg_stat_get_backend_pid
</primary>
5252 <function>pg_stat_get_backend_pid
</function> (
<type>integer
</type> )
5253 <returnvalue>integer
</returnvalue>
5256 Returns the process ID of this backend.
5261 <entry role=
"func_table_entry"><para role=
"func_signature">
5263 <primary>pg_stat_get_backend_start
</primary>
5265 <function>pg_stat_get_backend_start
</function> (
<type>integer
</type> )
5266 <returnvalue>timestamp with time zone
</returnvalue>
5269 Returns the time when this process was started.
5274 <entry role=
"func_table_entry"><para role=
"func_signature">
5276 <primary>pg_stat_get_backend_subxact
</primary>
5278 <function>pg_stat_get_backend_subxact
</function> (
<type>integer
</type> )
5279 <returnvalue>record
</returnvalue>
5282 Returns a record of information about the subtransactions of the
5283 backend with the specified ID.
5284 The fields returned are
<parameter>subxact_count
</parameter>, which
5285 is the number of subtransactions in the backend's subtransaction cache,
5286 and
<parameter>subxact_overflow
</parameter>, which indicates whether
5287 the backend's subtransaction cache is overflowed or not.
5292 <entry role=
"func_table_entry"><para role=
"func_signature">
5294 <primary>pg_stat_get_backend_userid
</primary>
5296 <function>pg_stat_get_backend_userid
</function> (
<type>integer
</type> )
5297 <returnvalue>oid
</returnvalue>
5300 Returns the OID of the user logged into this backend.
5305 <entry role=
"func_table_entry"><para role=
"func_signature">
5307 <primary>pg_stat_get_backend_wait_event
</primary>
5309 <function>pg_stat_get_backend_wait_event
</function> (
<type>integer
</type> )
5310 <returnvalue>text
</returnvalue>
5313 Returns the wait event name if this backend is currently waiting,
5314 otherwise NULL. See
<xref linkend=
"wait-event-activity-table"/> through
5315 <xref linkend=
"wait-event-timeout-table"/>.
5320 <entry role=
"func_table_entry"><para role=
"func_signature">
5322 <primary>pg_stat_get_backend_wait_event_type
</primary>
5324 <function>pg_stat_get_backend_wait_event_type
</function> (
<type>integer
</type> )
5325 <returnvalue>text
</returnvalue>
5328 Returns the wait event type name if this backend is currently waiting,
5329 otherwise NULL. See
<xref linkend=
"wait-event-table"/> for details.
5334 <entry role=
"func_table_entry"><para role=
"func_signature">
5336 <primary>pg_stat_get_backend_xact_start
</primary>
5338 <function>pg_stat_get_backend_xact_start
</function> (
<type>integer
</type> )
5339 <returnvalue>timestamp with time zone
</returnvalue>
5342 Returns the time when the backend's current transaction was started.
5352 <sect1 id=
"monitoring-locks">
5353 <title>Viewing Locks
</title>
5355 <indexterm zone=
"monitoring-locks">
5356 <primary>lock
</primary>
5357 <secondary>monitoring
</secondary>
5361 Another useful tool for monitoring database activity is the
5362 <structname>pg_locks
</structname> system table. It allows the
5363 database administrator to view information about the outstanding
5364 locks in the lock manager. For example, this capability can be used
5370 View all the locks currently outstanding, all the locks on
5371 relations in a particular database, all the locks on a
5372 particular relation, or all the locks held by a particular
5373 <productname>PostgreSQL
</productname> session.
5379 Determine the relation in the current database with the most
5380 ungranted locks (which might be a source of contention among
5387 Determine the effect of lock contention on overall database
5388 performance, as well as the extent to which contention varies
5389 with overall database traffic.
5394 Details of the
<structname>pg_locks
</structname> view appear in
5395 <xref linkend=
"view-pg-locks"/>.
5396 For more information on locking and managing concurrency with
5397 <productname>PostgreSQL
</productname>, refer to
<xref linkend=
"mvcc"/>.
5401 <sect1 id=
"progress-reporting">
5402 <title>Progress Reporting
</title>
5405 <productname>PostgreSQL
</productname> has the ability to report the progress of
5406 certain commands during command execution. Currently, the only commands
5407 which support progress reporting are
<command>ANALYZE
</command>,
5408 <command>CLUSTER
</command>,
5409 <command>CREATE INDEX
</command>,
<command>VACUUM
</command>,
5410 <command>COPY
</command>,
5411 and
<xref linkend=
"protocol-replication-base-backup"/> (i.e., replication
5412 command that
<xref linkend=
"app-pgbasebackup"/> issues to take
5414 This may be expanded in the future.
5417 <sect2 id=
"analyze-progress-reporting">
5418 <title>ANALYZE Progress Reporting
</title>
5421 <primary>pg_stat_progress_analyze
</primary>
5425 Whenever
<command>ANALYZE
</command> is running, the
5426 <structname>pg_stat_progress_analyze
</structname> view will contain a
5427 row for each backend that is currently running that command. The tables
5428 below describe the information that will be reported and provide
5429 information about how to interpret it.
5432 <table id=
"pg-stat-progress-analyze-view" xreflabel=
"pg_stat_progress_analyze">
5433 <title><structname>pg_stat_progress_analyze
</structname> View
</title>
5437 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5448 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5449 <structfield>pid
</structfield> <type>integer
</type>
5452 Process ID of backend.
5457 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5458 <structfield>datid
</structfield> <type>oid
</type>
5461 OID of the database to which this backend is connected.
5466 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5467 <structfield>datname
</structfield> <type>name
</type>
5470 Name of the database to which this backend is connected.
5475 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5476 <structfield>relid
</structfield> <type>oid
</type>
5479 OID of the table being analyzed.
5484 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5485 <structfield>phase
</structfield> <type>text
</type>
5488 Current processing phase. See
<xref linkend=
"analyze-phases"/>.
5493 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5494 <structfield>sample_blks_total
</structfield> <type>bigint
</type>
5497 Total number of heap blocks that will be sampled.
5502 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5503 <structfield>sample_blks_scanned
</structfield> <type>bigint
</type>
5506 Number of heap blocks scanned.
5511 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5512 <structfield>ext_stats_total
</structfield> <type>bigint
</type>
5515 Number of extended statistics.
5520 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5521 <structfield>ext_stats_computed
</structfield> <type>bigint
</type>
5524 Number of extended statistics computed. This counter only advances
5525 when the phase is
<literal>computing extended statistics
</literal>.
5530 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5531 <structfield>child_tables_total
</structfield> <type>bigint
</type>
5534 Number of child tables.
5539 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5540 <structfield>child_tables_done
</structfield> <type>bigint
</type>
5543 Number of child tables scanned. This counter only advances when the
5544 phase is
<literal>acquiring inherited sample rows
</literal>.
5549 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5550 <structfield>current_child_table_relid
</structfield> <type>oid
</type>
5553 OID of the child table currently being scanned. This field is
5554 only valid when the phase is
5555 <literal>acquiring inherited sample rows
</literal>.
5562 <table id=
"analyze-phases">
5563 <title>ANALYZE Phases
</title>
5565 <colspec colname=
"col1" colwidth=
"1*"/>
5566 <colspec colname=
"col2" colwidth=
"2*"/>
5569 <entry>Phase
</entry>
5570 <entry>Description
</entry>
5575 <entry><literal>initializing
</literal></entry>
5577 The command is preparing to begin scanning the heap. This phase is
5578 expected to be very brief.
5582 <entry><literal>acquiring sample rows
</literal></entry>
5584 The command is currently scanning the table given by
5585 <structfield>relid
</structfield> to obtain sample rows.
5589 <entry><literal>acquiring inherited sample rows
</literal></entry>
5591 The command is currently scanning child tables to obtain sample rows.
5592 Columns
<structfield>child_tables_total
</structfield>,
5593 <structfield>child_tables_done
</structfield>, and
5594 <structfield>current_child_table_relid
</structfield> contain the
5595 progress information for this phase.
5599 <entry><literal>computing statistics
</literal></entry>
5601 The command is computing statistics from the sample rows obtained
5602 during the table scan.
5606 <entry><literal>computing extended statistics
</literal></entry>
5608 The command is computing extended statistics from the sample rows
5609 obtained during the table scan.
5613 <entry><literal>finalizing analyze
</literal></entry>
5615 The command is updating
<structname>pg_class
</structname>. When this
5616 phase is completed,
<command>ANALYZE
</command> will end.
5625 Note that when
<command>ANALYZE
</command> is run on a partitioned table
5626 without the
<literal>ONLY
</literal> keyword, all of its partitions are
5627 also recursively analyzed. In that case,
<command>ANALYZE
</command>
5628 progress is reported first for the parent table, whereby its inheritance
5629 statistics are collected, followed by that for each partition.
5634 <sect2 id=
"cluster-progress-reporting">
5635 <title>CLUSTER Progress Reporting
</title>
5638 <primary>pg_stat_progress_cluster
</primary>
5642 Whenever
<command>CLUSTER
</command> or
<command>VACUUM FULL
</command> is
5643 running, the
<structname>pg_stat_progress_cluster
</structname> view will
5644 contain a row for each backend that is currently running either command.
5645 The tables below describe the information that will be reported and
5646 provide information about how to interpret it.
5649 <table id=
"pg-stat-progress-cluster-view" xreflabel=
"pg_stat_progress_cluster">
5650 <title><structname>pg_stat_progress_cluster
</structname> View
</title>
5654 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5665 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5666 <structfield>pid
</structfield> <type>integer
</type>
5669 Process ID of backend.
5674 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5675 <structfield>datid
</structfield> <type>oid
</type>
5678 OID of the database to which this backend is connected.
5683 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5684 <structfield>datname
</structfield> <type>name
</type>
5687 Name of the database to which this backend is connected.
5692 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5693 <structfield>relid
</structfield> <type>oid
</type>
5696 OID of the table being clustered.
5701 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5702 <structfield>command
</structfield> <type>text
</type>
5705 The command that is running. Either
<literal>CLUSTER
</literal> or
<literal>VACUUM FULL
</literal>.
5710 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5711 <structfield>phase
</structfield> <type>text
</type>
5714 Current processing phase. See
<xref linkend=
"cluster-phases"/>.
5719 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5720 <structfield>cluster_index_relid
</structfield> <type>oid
</type>
5723 If the table is being scanned using an index, this is the OID of the
5724 index being used; otherwise, it is zero.
5729 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5730 <structfield>heap_tuples_scanned
</structfield> <type>bigint
</type>
5733 Number of heap tuples scanned.
5734 This counter only advances when the phase is
5735 <literal>seq scanning heap
</literal>,
5736 <literal>index scanning heap
</literal>
5737 or
<literal>writing new heap
</literal>.
5742 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5743 <structfield>heap_tuples_written
</structfield> <type>bigint
</type>
5746 Number of heap tuples written.
5747 This counter only advances when the phase is
5748 <literal>seq scanning heap
</literal>,
5749 <literal>index scanning heap
</literal>
5750 or
<literal>writing new heap
</literal>.
5755 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5756 <structfield>heap_blks_total
</structfield> <type>bigint
</type>
5759 Total number of heap blocks in the table. This number is reported
5760 as of the beginning of
<literal>seq scanning heap
</literal>.
5765 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5766 <structfield>heap_blks_scanned
</structfield> <type>bigint
</type>
5769 Number of heap blocks scanned. This counter only advances when the
5770 phase is
<literal>seq scanning heap
</literal>.
5775 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5776 <structfield>index_rebuild_count
</structfield> <type>bigint
</type>
5779 Number of indexes rebuilt. This counter only advances when the phase
5780 is
<literal>rebuilding index
</literal>.
5787 <table id=
"cluster-phases">
5788 <title>CLUSTER and VACUUM FULL Phases
</title>
5790 <colspec colname=
"col1" colwidth=
"1*"/>
5791 <colspec colname=
"col2" colwidth=
"2*"/>
5794 <entry>Phase
</entry>
5795 <entry>Description
</entry>
5801 <entry><literal>initializing
</literal></entry>
5803 The command is preparing to begin scanning the heap. This phase is
5804 expected to be very brief.
5808 <entry><literal>seq scanning heap
</literal></entry>
5810 The command is currently scanning the table using a sequential scan.
5814 <entry><literal>index scanning heap
</literal></entry>
5816 <command>CLUSTER
</command> is currently scanning the table using an index scan.
5820 <entry><literal>sorting tuples
</literal></entry>
5822 <command>CLUSTER
</command> is currently sorting tuples.
5826 <entry><literal>writing new heap
</literal></entry>
5828 <command>CLUSTER
</command> is currently writing the new heap.
5832 <entry><literal>swapping relation files
</literal></entry>
5834 The command is currently swapping newly-built files into place.
5838 <entry><literal>rebuilding index
</literal></entry>
5840 The command is currently rebuilding an index.
5844 <entry><literal>performing final cleanup
</literal></entry>
5846 The command is performing final cleanup. When this phase is
5847 completed,
<command>CLUSTER
</command>
5848 or
<command>VACUUM FULL
</command> will end.
5856 <sect2 id=
"copy-progress-reporting">
5857 <title>COPY Progress Reporting
</title>
5860 <primary>pg_stat_progress_copy
</primary>
5864 Whenever
<command>COPY
</command> is running, the
5865 <structname>pg_stat_progress_copy
</structname> view will contain one row
5866 for each backend that is currently running a
<command>COPY
</command> command.
5867 The table below describes the information that will be reported and provides
5868 information about how to interpret it.
5871 <table id=
"pg-stat-progress-copy-view" xreflabel=
"pg_stat_progress_copy">
5872 <title><structname>pg_stat_progress_copy
</structname> View
</title>
5876 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5887 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5888 <structfield>pid
</structfield> <type>integer
</type>
5891 Process ID of backend.
5896 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5897 <structfield>datid
</structfield> <type>oid
</type>
5900 OID of the database to which this backend is connected.
5905 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5906 <structfield>datname
</structfield> <type>name
</type>
5909 Name of the database to which this backend is connected.
5914 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5915 <structfield>relid
</structfield> <type>oid
</type>
5918 OID of the table on which the
<command>COPY
</command> command is
5919 executed. It is set to
<literal>0</literal> if copying from a
5920 <command>SELECT
</command> query.
5925 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5926 <structfield>command
</structfield> <type>text
</type>
5929 The command that is running:
<literal>COPY FROM
</literal>, or
5930 <literal>COPY TO
</literal>.
5935 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5936 <structfield>type
</structfield> <type>text
</type>
5939 The I/O type that the data is read from or written to:
5940 <literal>FILE
</literal>,
<literal>PROGRAM
</literal>,
5941 <literal>PIPE
</literal> (for
<command>COPY FROM STDIN
</command> and
5942 <command>COPY TO STDOUT
</command>), or
<literal>CALLBACK
</literal>
5943 (used for example during the initial table synchronization in
5944 logical replication).
5949 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5950 <structfield>bytes_processed
</structfield> <type>bigint
</type>
5953 Number of bytes already processed by
<command>COPY
</command> command.
5958 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5959 <structfield>bytes_total
</structfield> <type>bigint
</type>
5962 Size of source file for
<command>COPY FROM
</command> command in bytes.
5963 It is set to
<literal>0</literal> if not available.
5968 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5969 <structfield>tuples_processed
</structfield> <type>bigint
</type>
5972 Number of tuples already processed by
<command>COPY
</command> command.
5977 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5978 <structfield>tuples_excluded
</structfield> <type>bigint
</type>
5981 Number of tuples not processed because they were excluded by the
5982 <command>WHERE
</command> clause of the
<command>COPY
</command> command.
5987 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5988 <structfield>tuples_skipped
</structfield> <type>bigint
</type>
5991 Number of tuples skipped because they contain malformed data.
5992 This counter only advances when a value other than
5993 <literal>stop
</literal> is specified to the
<literal>ON_ERROR
</literal>
6002 <sect2 id=
"create-index-progress-reporting">
6003 <title>CREATE INDEX Progress Reporting
</title>
6006 <primary>pg_stat_progress_create_index
</primary>
6010 Whenever
<command>CREATE INDEX
</command> or
<command>REINDEX
</command> is running, the
6011 <structname>pg_stat_progress_create_index
</structname> view will contain
6012 one row for each backend that is currently creating indexes. The tables
6013 below describe the information that will be reported and provide information
6014 about how to interpret it.
6017 <table id=
"pg-stat-progress-create-index-view" xreflabel=
"pg_stat_progress_create_index">
6018 <title><structname>pg_stat_progress_create_index
</structname> View
</title>
6022 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6033 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6034 <structfield>pid
</structfield> <type>integer
</type>
6037 Process ID of the backend creating indexes.
6042 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6043 <structfield>datid
</structfield> <type>oid
</type>
6046 OID of the database to which this backend is connected.
6051 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6052 <structfield>datname
</structfield> <type>name
</type>
6055 Name of the database to which this backend is connected.
6060 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6061 <structfield>relid
</structfield> <type>oid
</type>
6064 OID of the table on which the index is being created.
6069 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6070 <structfield>index_relid
</structfield> <type>oid
</type>
6073 OID of the index being created or reindexed. During a
6074 non-concurrent
<command>CREATE INDEX
</command>, this is
0.
6079 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6080 <structfield>command
</structfield> <type>text
</type>
6083 Specific command type:
<literal>CREATE INDEX
</literal>,
6084 <literal>CREATE INDEX CONCURRENTLY
</literal>,
6085 <literal>REINDEX
</literal>, or
<literal>REINDEX CONCURRENTLY
</literal>.
6090 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6091 <structfield>phase
</structfield> <type>text
</type>
6094 Current processing phase of index creation. See
<xref linkend=
"create-index-phases"/>.
6099 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6100 <structfield>lockers_total
</structfield> <type>bigint
</type>
6103 Total number of lockers to wait for, when applicable.
6108 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6109 <structfield>lockers_done
</structfield> <type>bigint
</type>
6112 Number of lockers already waited for.
6117 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6118 <structfield>current_locker_pid
</structfield> <type>bigint
</type>
6121 Process ID of the locker currently being waited for.
6126 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6127 <structfield>blocks_total
</structfield> <type>bigint
</type>
6130 Total number of blocks to be processed in the current phase.
6135 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6136 <structfield>blocks_done
</structfield> <type>bigint
</type>
6139 Number of blocks already processed in the current phase.
6144 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6145 <structfield>tuples_total
</structfield> <type>bigint
</type>
6148 Total number of tuples to be processed in the current phase.
6153 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6154 <structfield>tuples_done
</structfield> <type>bigint
</type>
6157 Number of tuples already processed in the current phase.
6162 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6163 <structfield>partitions_total
</structfield> <type>bigint
</type>
6166 Total number of partitions on which the index is to be created
6167 or attached, including both direct and indirect partitions.
6168 <literal>0</literal> during a
<literal>REINDEX
</literal>, or when
6169 the index is not partitioned.
6174 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6175 <structfield>partitions_done
</structfield> <type>bigint
</type>
6178 Number of partitions on which the index has already been created
6179 or attached, including both direct and indirect partitions.
6180 <literal>0</literal> during a
<literal>REINDEX
</literal>, or when
6181 the index is not partitioned.
6188 <table id=
"create-index-phases">
6189 <title>CREATE INDEX Phases
</title>
6191 <colspec colname=
"col1" colwidth=
"1*"/>
6192 <colspec colname=
"col2" colwidth=
"2*"/>
6195 <entry>Phase
</entry>
6196 <entry>Description
</entry>
6201 <entry><literal>initializing
</literal></entry>
6203 <command>CREATE INDEX
</command> or
<command>REINDEX
</command> is preparing to create the index. This
6204 phase is expected to be very brief.
6208 <entry><literal>waiting for writers before build
</literal></entry>
6210 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6211 with write locks that can potentially see the table to finish.
6212 This phase is skipped when not in concurrent mode.
6213 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6214 and
<structname>current_locker_pid
</structname> contain the progress
6215 information for this phase.
6219 <entry><literal>building index
</literal></entry>
6221 The index is being built by the access method-specific code. In this phase,
6222 access methods that support progress reporting fill in their own progress data,
6223 and the subphase is indicated in this column. Typically,
6224 <structname>blocks_total
</structname> and
<structname>blocks_done
</structname>
6225 will contain progress data, as well as potentially
6226 <structname>tuples_total
</structname> and
<structname>tuples_done
</structname>.
6230 <entry><literal>waiting for writers before validation
</literal></entry>
6232 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6233 with write locks that can potentially write into the table to finish.
6234 This phase is skipped when not in concurrent mode.
6235 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6236 and
<structname>current_locker_pid
</structname> contain the progress
6237 information for this phase.
6241 <entry><literal>index validation: scanning index
</literal></entry>
6243 <command>CREATE INDEX CONCURRENTLY
</command> is scanning the index searching
6244 for tuples that need to be validated.
6245 This phase is skipped when not in concurrent mode.
6246 Columns
<structname>blocks_total
</structname> (set to the total size of the index)
6247 and
<structname>blocks_done
</structname> contain the progress information for this phase.
6251 <entry><literal>index validation: sorting tuples
</literal></entry>
6253 <command>CREATE INDEX CONCURRENTLY
</command> is sorting the output of the
6254 index scanning phase.
6258 <entry><literal>index validation: scanning table
</literal></entry>
6260 <command>CREATE INDEX CONCURRENTLY
</command> is scanning the table
6261 to validate the index tuples collected in the previous two phases.
6262 This phase is skipped when not in concurrent mode.
6263 Columns
<structname>blocks_total
</structname> (set to the total size of the table)
6264 and
<structname>blocks_done
</structname> contain the progress information for this phase.
6268 <entry><literal>waiting for old snapshots
</literal></entry>
6270 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6271 that can potentially see the table to release their snapshots. This
6272 phase is skipped when not in concurrent mode.
6273 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6274 and
<structname>current_locker_pid
</structname> contain the progress
6275 information for this phase.
6279 <entry><literal>waiting for readers before marking dead
</literal></entry>
6281 <command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6282 with read locks on the table to finish, before marking the old index dead.
6283 This phase is skipped when not in concurrent mode.
6284 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6285 and
<structname>current_locker_pid
</structname> contain the progress
6286 information for this phase.
6290 <entry><literal>waiting for readers before dropping
</literal></entry>
6292 <command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6293 with read locks on the table to finish, before dropping the old index.
6294 This phase is skipped when not in concurrent mode.
6295 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6296 and
<structname>current_locker_pid
</structname> contain the progress
6297 information for this phase.
6306 <sect2 id=
"vacuum-progress-reporting">
6307 <title>VACUUM Progress Reporting
</title>
6310 <primary>pg_stat_progress_vacuum
</primary>
6314 Whenever
<command>VACUUM
</command> is running, the
6315 <structname>pg_stat_progress_vacuum
</structname> view will contain
6316 one row for each backend (including autovacuum worker processes) that is
6317 currently vacuuming. The tables below describe the information
6318 that will be reported and provide information about how to interpret it.
6319 Progress for
<command>VACUUM FULL
</command> commands is reported via
6320 <structname>pg_stat_progress_cluster
</structname>
6321 because both
<command>VACUUM FULL
</command> and
<command>CLUSTER
</command>
6322 rewrite the table, while regular
<command>VACUUM
</command> only modifies it
6323 in place. See
<xref linkend=
"cluster-progress-reporting"/>.
6326 <table id=
"pg-stat-progress-vacuum-view" xreflabel=
"pg_stat_progress_vacuum">
6327 <title><structname>pg_stat_progress_vacuum
</structname> View
</title>
6331 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6342 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6343 <structfield>pid
</structfield> <type>integer
</type>
6346 Process ID of backend.
6351 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6352 <structfield>datid
</structfield> <type>oid
</type>
6355 OID of the database to which this backend is connected.
6360 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6361 <structfield>datname
</structfield> <type>name
</type>
6364 Name of the database to which this backend is connected.
6369 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6370 <structfield>relid
</structfield> <type>oid
</type>
6373 OID of the table being vacuumed.
6378 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6379 <structfield>phase
</structfield> <type>text
</type>
6382 Current processing phase of vacuum. See
<xref linkend=
"vacuum-phases"/>.
6387 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6388 <structfield>heap_blks_total
</structfield> <type>bigint
</type>
6391 Total number of heap blocks in the table. This number is reported
6392 as of the beginning of the scan; blocks added later will not be (and
6393 need not be) visited by this
<command>VACUUM
</command>.
6398 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6399 <structfield>heap_blks_scanned
</structfield> <type>bigint
</type>
6402 Number of heap blocks scanned. Because the
6403 <link linkend=
"storage-vm">visibility map
</link> is used to optimize scans,
6404 some blocks will be skipped without inspection; skipped blocks are
6405 included in this total, so that this number will eventually become
6406 equal to
<structfield>heap_blks_total
</structfield> when the vacuum is complete.
6407 This counter only advances when the phase is
<literal>scanning heap
</literal>.
6412 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6413 <structfield>heap_blks_vacuumed
</structfield> <type>bigint
</type>
6416 Number of heap blocks vacuumed. Unless the table has no indexes, this
6417 counter only advances when the phase is
<literal>vacuuming heap
</literal>.
6418 Blocks that contain no dead tuples are skipped, so the counter may
6419 sometimes skip forward in large increments.
6424 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6425 <structfield>index_vacuum_count
</structfield> <type>bigint
</type>
6428 Number of completed index vacuum cycles.
6433 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6434 <structfield>max_dead_tuple_bytes
</structfield> <type>bigint
</type>
6437 Amount of dead tuple data that we can store before needing to perform
6438 an index vacuum cycle, based on
6439 <xref linkend=
"guc-maintenance-work-mem"/>.
6444 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6445 <structfield>dead_tuple_bytes
</structfield> <type>bigint
</type>
6448 Amount of dead tuple data collected since the last index vacuum cycle.
6453 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6454 <structfield>num_dead_item_ids
</structfield> <type>bigint
</type>
6457 Number of dead item identifiers collected since the last index vacuum cycle.
6462 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6463 <structfield>indexes_total
</structfield> <type>bigint
</type>
6466 Total number of indexes that will be vacuumed or cleaned up. This
6467 number is reported at the beginning of the
6468 <literal>vacuuming indexes
</literal> phase or the
6469 <literal>cleaning up indexes
</literal> phase.
6474 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6475 <structfield>indexes_processed
</structfield> <type>bigint
</type>
6478 Number of indexes processed. This counter only advances when the
6479 phase is
<literal>vacuuming indexes
</literal> or
6480 <literal>cleaning up indexes
</literal>.
6487 <table id=
"vacuum-phases">
6488 <title>VACUUM Phases
</title>
6490 <colspec colname=
"col1" colwidth=
"1*"/>
6491 <colspec colname=
"col2" colwidth=
"2*"/>
6494 <entry>Phase
</entry>
6495 <entry>Description
</entry>
6501 <entry><literal>initializing
</literal></entry>
6503 <command>VACUUM
</command> is preparing to begin scanning the heap. This
6504 phase is expected to be very brief.
6508 <entry><literal>scanning heap
</literal></entry>
6510 <command>VACUUM
</command> is currently scanning the heap. It will prune and
6511 defragment each page if required, and possibly perform freezing
6512 activity. The
<structfield>heap_blks_scanned
</structfield> column can be used
6513 to monitor the progress of the scan.
6517 <entry><literal>vacuuming indexes
</literal></entry>
6519 <command>VACUUM
</command> is currently vacuuming the indexes. If a table has
6520 any indexes, this will happen at least once per vacuum, after the heap
6521 has been completely scanned. It may happen multiple times per vacuum
6522 if
<xref linkend=
"guc-maintenance-work-mem"/> (or, in the case of autovacuum,
6523 <xref linkend=
"guc-autovacuum-work-mem"/> if set) is insufficient to store
6524 the number of dead tuples found.
6528 <entry><literal>vacuuming heap
</literal></entry>
6530 <command>VACUUM
</command> is currently vacuuming the heap. Vacuuming the heap
6531 is distinct from scanning the heap, and occurs after each instance of
6532 vacuuming indexes. If
<structfield>heap_blks_scanned
</structfield> is less than
6533 <structfield>heap_blks_total
</structfield>, the system will return to scanning
6534 the heap after this phase is completed; otherwise, it will begin
6535 cleaning up indexes after this phase is completed.
6539 <entry><literal>cleaning up indexes
</literal></entry>
6541 <command>VACUUM
</command> is currently cleaning up indexes. This occurs after
6542 the heap has been completely scanned and all vacuuming of the indexes
6543 and the heap has been completed.
6547 <entry><literal>truncating heap
</literal></entry>
6549 <command>VACUUM
</command> is currently truncating the heap so as to return
6550 empty pages at the end of the relation to the operating system. This
6551 occurs after cleaning up indexes.
6555 <entry><literal>performing final cleanup
</literal></entry>
6557 <command>VACUUM
</command> is performing final cleanup. During this phase,
6558 <command>VACUUM
</command> will vacuum the free space map, update statistics
6559 in
<literal>pg_class
</literal>, and report statistics to the cumulative
6560 statistics system. When this phase is completed,
<command>VACUUM
</command> will end.
6568 <sect2 id=
"basebackup-progress-reporting">
6569 <title>Base Backup Progress Reporting
</title>
6572 <primary>pg_stat_progress_basebackup
</primary>
6576 Whenever an application like
<application>pg_basebackup
</application>
6577 is taking a base backup, the
6578 <structname>pg_stat_progress_basebackup
</structname>
6579 view will contain a row for each WAL sender process that is currently
6580 running the
<command>BASE_BACKUP
</command> replication command
6581 and streaming the backup. The tables below describe the information
6582 that will be reported and provide information about how to interpret it.
6585 <table id=
"pg-stat-progress-basebackup-view" xreflabel=
"pg_stat_progress_basebackup">
6586 <title><structname>pg_stat_progress_basebackup
</structname> View
</title>
6590 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6601 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6602 <structfield>pid
</structfield> <type>integer
</type>
6605 Process ID of a WAL sender process.
6610 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6611 <structfield>phase
</structfield> <type>text
</type>
6614 Current processing phase. See
<xref linkend=
"basebackup-phases"/>.
6619 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6620 <structfield>backup_total
</structfield> <type>bigint
</type>
6623 Total amount of data that will be streamed. This is estimated and
6624 reported as of the beginning of
6625 <literal>streaming database files
</literal> phase. Note that
6626 this is only an approximation since the database
6627 may change during
<literal>streaming database files
</literal> phase
6628 and WAL log may be included in the backup later. This is always
6629 the same value as
<structfield>backup_streamed
</structfield>
6630 once the amount of data streamed exceeds the estimated
6631 total size. If the estimation is disabled in
6632 <application>pg_basebackup
</application>
6633 (i.e.,
<literal>--no-estimate-size
</literal> option is specified),
6634 this is
<literal>NULL
</literal>.
6639 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6640 <structfield>backup_streamed
</structfield> <type>bigint
</type>
6643 Amount of data streamed. This counter only advances
6644 when the phase is
<literal>streaming database files
</literal> or
6645 <literal>transferring wal files
</literal>.
6650 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6651 <structfield>tablespaces_total
</structfield> <type>bigint
</type>
6654 Total number of tablespaces that will be streamed.
6659 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6660 <structfield>tablespaces_streamed
</structfield> <type>bigint
</type>
6663 Number of tablespaces streamed. This counter only
6664 advances when the phase is
<literal>streaming database files
</literal>.
6671 <table id=
"basebackup-phases">
6672 <title>Base Backup Phases
</title>
6674 <colspec colname=
"col1" colwidth=
"1*"/>
6675 <colspec colname=
"col2" colwidth=
"2*"/>
6678 <entry>Phase
</entry>
6679 <entry>Description
</entry>
6684 <entry><literal>initializing
</literal></entry>
6686 The WAL sender process is preparing to begin the backup.
6687 This phase is expected to be very brief.
6691 <entry><literal>waiting for checkpoint to finish
</literal></entry>
6693 The WAL sender process is currently performing
6694 <function>pg_backup_start
</function> to prepare to
6695 take a base backup, and waiting for the start-of-backup
6696 checkpoint to finish.
6700 <entry><literal>estimating backup size
</literal></entry>
6702 The WAL sender process is currently estimating the total amount
6703 of database files that will be streamed as a base backup.
6707 <entry><literal>streaming database files
</literal></entry>
6709 The WAL sender process is currently streaming database files
6714 <entry><literal>waiting for wal archiving to finish
</literal></entry>
6716 The WAL sender process is currently performing
6717 <function>pg_backup_stop
</function> to finish the backup,
6718 and waiting for all the WAL files required for the base backup
6719 to be successfully archived.
6720 If either
<literal>--wal-method=none
</literal> or
6721 <literal>--wal-method=stream
</literal> is specified in
6722 <application>pg_basebackup
</application>, the backup will end
6723 when this phase is completed.
6727 <entry><literal>transferring wal files
</literal></entry>
6729 The WAL sender process is currently transferring all WAL logs
6730 generated during the backup. This phase occurs after
6731 <literal>waiting for wal archiving to finish
</literal> phase if
6732 <literal>--wal-method=fetch
</literal> is specified in
6733 <application>pg_basebackup
</application>. The backup will end
6734 when this phase is completed.
6745 <sect1 id=
"dynamic-trace">
6746 <title>Dynamic Tracing
</title>
6748 <indexterm zone=
"dynamic-trace">
6749 <primary>DTrace
</primary>
6753 <productname>PostgreSQL
</productname> provides facilities to support
6754 dynamic tracing of the database server. This allows an external
6755 utility to be called at specific points in the code and thereby trace
6760 A number of probes or trace points are already inserted into the source
6761 code. These probes are intended to be used by database developers and
6762 administrators. By default the probes are not compiled into
6763 <productname>PostgreSQL
</productname>; the user needs to explicitly tell
6764 the configure script to make the probes available.
6769 <ulink url=
"https://en.wikipedia.org/wiki/DTrace">DTrace
</ulink>
6770 utility is supported, which, at the time of this writing, is available
6771 on Solaris, macOS, FreeBSD, NetBSD, and Oracle Linux. The
6772 <ulink url=
"https://sourceware.org/systemtap/">SystemTap
</ulink> project
6773 for Linux provides a DTrace equivalent and can also be used. Supporting other dynamic
6774 tracing utilities is theoretically possible by changing the definitions for
6775 the macros in
<filename>src/include/utils/probes.h
</filename>.
6778 <sect2 id=
"compiling-for-trace">
6779 <title>Compiling for Dynamic Tracing
</title>
6782 By default, probes are not available, so you will need to
6783 explicitly tell the configure script to make the probes available
6784 in
<productname>PostgreSQL
</productname>. To include DTrace support
6785 specify
<option>--enable-dtrace
</option> to configure. See
<xref
6786 linkend=
"configure-options-devel"/> for further information.
6790 <sect2 id=
"trace-points">
6791 <title>Built-in Probes
</title>
6794 A number of standard probes are provided in the source code,
6795 as shown in
<xref linkend=
"dtrace-probe-point-table"/>;
6796 <xref linkend=
"typedefs-table"/>
6797 shows the types used in the probes. More probes can certainly be
6798 added to enhance
<productname>PostgreSQL
</productname>'s observability.
6801 <table id=
"dtrace-probe-point-table">
6802 <title>Built-in DTrace Probes
</title>
6804 <colspec colname=
"col1" colwidth=
"2*"/>
6805 <colspec colname=
"col2" colwidth=
"3*"/>
6806 <colspec colname=
"col3" colwidth=
"3*"/>
6810 <entry>Parameters
</entry>
6811 <entry>Description
</entry>
6818 <entry><literal>transaction-start
</literal></entry>
6819 <entry><literal>(LocalTransactionId)
</literal></entry>
6820 <entry>Probe that fires at the start of a new transaction.
6821 arg0 is the transaction ID.
</entry>
6824 <entry><literal>transaction-commit
</literal></entry>
6825 <entry><literal>(LocalTransactionId)
</literal></entry>
6826 <entry>Probe that fires when a transaction completes successfully.
6827 arg0 is the transaction ID.
</entry>
6830 <entry><literal>transaction-abort
</literal></entry>
6831 <entry><literal>(LocalTransactionId)
</literal></entry>
6832 <entry>Probe that fires when a transaction completes unsuccessfully.
6833 arg0 is the transaction ID.
</entry>
6836 <entry><literal>query-start
</literal></entry>
6837 <entry><literal>(const char *)
</literal></entry>
6838 <entry>Probe that fires when the processing of a query is started.
6839 arg0 is the query string.
</entry>
6842 <entry><literal>query-done
</literal></entry>
6843 <entry><literal>(const char *)
</literal></entry>
6844 <entry>Probe that fires when the processing of a query is complete.
6845 arg0 is the query string.
</entry>
6848 <entry><literal>query-parse-start
</literal></entry>
6849 <entry><literal>(const char *)
</literal></entry>
6850 <entry>Probe that fires when the parsing of a query is started.
6851 arg0 is the query string.
</entry>
6854 <entry><literal>query-parse-done
</literal></entry>
6855 <entry><literal>(const char *)
</literal></entry>
6856 <entry>Probe that fires when the parsing of a query is complete.
6857 arg0 is the query string.
</entry>
6860 <entry><literal>query-rewrite-start
</literal></entry>
6861 <entry><literal>(const char *)
</literal></entry>
6862 <entry>Probe that fires when the rewriting of a query is started.
6863 arg0 is the query string.
</entry>
6866 <entry><literal>query-rewrite-done
</literal></entry>
6867 <entry><literal>(const char *)
</literal></entry>
6868 <entry>Probe that fires when the rewriting of a query is complete.
6869 arg0 is the query string.
</entry>
6872 <entry><literal>query-plan-start
</literal></entry>
6873 <entry><literal>()
</literal></entry>
6874 <entry>Probe that fires when the planning of a query is started.
</entry>
6877 <entry><literal>query-plan-done
</literal></entry>
6878 <entry><literal>()
</literal></entry>
6879 <entry>Probe that fires when the planning of a query is complete.
</entry>
6882 <entry><literal>query-execute-start
</literal></entry>
6883 <entry><literal>()
</literal></entry>
6884 <entry>Probe that fires when the execution of a query is started.
</entry>
6887 <entry><literal>query-execute-done
</literal></entry>
6888 <entry><literal>()
</literal></entry>
6889 <entry>Probe that fires when the execution of a query is complete.
</entry>
6892 <entry><literal>statement-status
</literal></entry>
6893 <entry><literal>(const char *)
</literal></entry>
6894 <entry>Probe that fires anytime the server process updates its
6895 <structname>pg_stat_activity
</structname>.
<structfield>status
</structfield>.
6896 arg0 is the new status string.
</entry>
6899 <entry><literal>checkpoint-start
</literal></entry>
6900 <entry><literal>(int)
</literal></entry>
6901 <entry>Probe that fires when a checkpoint is started.
6902 arg0 holds the bitwise flags used to distinguish different checkpoint
6903 types, such as shutdown, immediate or force.
</entry>
6906 <entry><literal>checkpoint-done
</literal></entry>
6907 <entry><literal>(int, int, int, int, int)
</literal></entry>
6908 <entry>Probe that fires when a checkpoint is complete.
6909 (The probes listed next fire in sequence during checkpoint processing.)
6910 arg0 is the number of buffers written. arg1 is the total number of
6911 buffers. arg2, arg3 and arg4 contain the number of WAL files added,
6912 removed and recycled respectively.
</entry>
6915 <entry><literal>clog-checkpoint-start
</literal></entry>
6916 <entry><literal>(bool)
</literal></entry>
6917 <entry>Probe that fires when the CLOG portion of a checkpoint is started.
6918 arg0 is true for normal checkpoint, false for shutdown
6922 <entry><literal>clog-checkpoint-done
</literal></entry>
6923 <entry><literal>(bool)
</literal></entry>
6924 <entry>Probe that fires when the CLOG portion of a checkpoint is
6925 complete. arg0 has the same meaning as for
<literal>clog-checkpoint-start
</literal>.
</entry>
6928 <entry><literal>subtrans-checkpoint-start
</literal></entry>
6929 <entry><literal>(bool)
</literal></entry>
6930 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
6932 arg0 is true for normal checkpoint, false for shutdown
6936 <entry><literal>subtrans-checkpoint-done
</literal></entry>
6937 <entry><literal>(bool)
</literal></entry>
6938 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
6939 complete. arg0 has the same meaning as for
6940 <literal>subtrans-checkpoint-start
</literal>.
</entry>
6943 <entry><literal>multixact-checkpoint-start
</literal></entry>
6944 <entry><literal>(bool)
</literal></entry>
6945 <entry>Probe that fires when the MultiXact portion of a checkpoint is
6947 arg0 is true for normal checkpoint, false for shutdown
6951 <entry><literal>multixact-checkpoint-done
</literal></entry>
6952 <entry><literal>(bool)
</literal></entry>
6953 <entry>Probe that fires when the MultiXact portion of a checkpoint is
6954 complete. arg0 has the same meaning as for
6955 <literal>multixact-checkpoint-start
</literal>.
</entry>
6958 <entry><literal>buffer-checkpoint-start
</literal></entry>
6959 <entry><literal>(int)
</literal></entry>
6960 <entry>Probe that fires when the buffer-writing portion of a checkpoint
6962 arg0 holds the bitwise flags used to distinguish different checkpoint
6963 types, such as shutdown, immediate or force.
</entry>
6966 <entry><literal>buffer-sync-start
</literal></entry>
6967 <entry><literal>(int, int)
</literal></entry>
6968 <entry>Probe that fires when we begin to write dirty buffers during
6969 checkpoint (after identifying which buffers must be written).
6970 arg0 is the total number of buffers.
6971 arg1 is the number that are currently dirty and need to be written.
</entry>
6974 <entry><literal>buffer-sync-written
</literal></entry>
6975 <entry><literal>(int)
</literal></entry>
6976 <entry>Probe that fires after each buffer is written during checkpoint.
6977 arg0 is the ID number of the buffer.
</entry>
6980 <entry><literal>buffer-sync-done
</literal></entry>
6981 <entry><literal>(int, int, int)
</literal></entry>
6982 <entry>Probe that fires when all dirty buffers have been written.
6983 arg0 is the total number of buffers.
6984 arg1 is the number of buffers actually written by the checkpoint process.
6985 arg2 is the number that were expected to be written (arg1 of
6986 <literal>buffer-sync-start
</literal>); any difference reflects other processes flushing
6987 buffers during the checkpoint.
</entry>
6990 <entry><literal>buffer-checkpoint-sync-start
</literal></entry>
6991 <entry><literal>()
</literal></entry>
6992 <entry>Probe that fires after dirty buffers have been written to the
6993 kernel, and before starting to issue fsync requests.
</entry>
6996 <entry><literal>buffer-checkpoint-done
</literal></entry>
6997 <entry><literal>()
</literal></entry>
6998 <entry>Probe that fires when syncing of buffers to disk is
7002 <entry><literal>twophase-checkpoint-start
</literal></entry>
7003 <entry><literal>()
</literal></entry>
7004 <entry>Probe that fires when the two-phase portion of a checkpoint is
7008 <entry><literal>twophase-checkpoint-done
</literal></entry>
7009 <entry><literal>()
</literal></entry>
7010 <entry>Probe that fires when the two-phase portion of a checkpoint is
7014 <entry><literal>buffer-extend-start
</literal></entry>
7015 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, unsigned int)
</literal></entry>
7016 <entry>Probe that fires when a relation extension starts.
7017 arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
7018 tablespace, database, and relation OIDs identifying the relation. arg4
7019 is the ID of the backend which created the temporary relation for a
7020 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared
7021 buffer. arg5 is the number of blocks the caller would like to extend
7025 <entry><literal>buffer-extend-done
</literal></entry>
7026 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, unsigned int, BlockNumber)
</literal></entry>
7027 <entry>Probe that fires when a relation extension is complete.
7028 arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
7029 tablespace, database, and relation OIDs identifying the relation. arg4
7030 is the ID of the backend which created the temporary relation for a
7031 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared
7032 buffer. arg5 is the number of blocks the relation was extended by, this
7033 can be less than the number in the
7034 <literal>buffer-extend-start
</literal> due to resource
7035 constraints. arg6 contains the BlockNumber of the first new
7039 <entry><literal>buffer-read-start
</literal></entry>
7040 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
7041 <entry>Probe that fires when a buffer read is started.
7042 arg0 and arg1 contain the fork and block numbers of the page.
7043 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7044 identifying the relation.
7045 arg5 is the ID of the backend which created the temporary relation for a
7046 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
7050 <entry><literal>buffer-read-done
</literal></entry>
7051 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool)
</literal></entry>
7052 <entry>Probe that fires when a buffer read is complete.
7053 arg0 and arg1 contain the fork and block numbers of the page.
7054 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7055 identifying the relation.
7056 arg5 is the ID of the backend which created the temporary relation for a
7057 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
7058 arg6 is true if the buffer was found in the pool, false if not.
</entry>
7061 <entry><literal>buffer-flush-start
</literal></entry>
7062 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)
</literal></entry>
7063 <entry>Probe that fires before issuing any write request for a shared
7065 arg0 and arg1 contain the fork and block numbers of the page.
7066 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7067 identifying the relation.
</entry>
7070 <entry><literal>buffer-flush-done
</literal></entry>
7071 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)
</literal></entry>
7072 <entry>Probe that fires when a write request is complete. (Note
7073 that this just reflects the time to pass the data to the kernel;
7074 it's typically not actually been written to disk yet.)
7075 The arguments are the same as for
<literal>buffer-flush-start
</literal>.
</entry>
7078 <entry><literal>wal-buffer-write-dirty-start
</literal></entry>
7079 <entry><literal>()
</literal></entry>
7080 <entry>Probe that fires when a server process begins to write a
7081 dirty WAL buffer because no more WAL buffer space is available.
7082 (If this happens often, it implies that
7083 <xref linkend=
"guc-wal-buffers"/> is too small.)
</entry>
7086 <entry><literal>wal-buffer-write-dirty-done
</literal></entry>
7087 <entry><literal>()
</literal></entry>
7088 <entry>Probe that fires when a dirty WAL buffer write is complete.
</entry>
7091 <entry><literal>wal-insert
</literal></entry>
7092 <entry><literal>(unsigned char, unsigned char)
</literal></entry>
7093 <entry>Probe that fires when a WAL record is inserted.
7094 arg0 is the resource manager (rmid) for the record.
7095 arg1 contains the info flags.
</entry>
7098 <entry><literal>wal-switch
</literal></entry>
7099 <entry><literal>()
</literal></entry>
7100 <entry>Probe that fires when a WAL segment switch is requested.
</entry>
7103 <entry><literal>smgr-md-read-start
</literal></entry>
7104 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
7105 <entry>Probe that fires when beginning to read a block from a relation.
7106 arg0 and arg1 contain the fork and block numbers of the page.
7107 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7108 identifying the relation.
7109 arg5 is the ID of the backend which created the temporary relation for a
7110 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
</entry>
7113 <entry><literal>smgr-md-read-done
</literal></entry>
7114 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)
</literal></entry>
7115 <entry>Probe that fires when a block read is complete.
7116 arg0 and arg1 contain the fork and block numbers of the page.
7117 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7118 identifying the relation.
7119 arg5 is the ID of the backend which created the temporary relation for a
7120 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
7121 arg6 is the number of bytes actually read, while arg7 is the number
7122 requested (if these are different it indicates a short read).
</entry>
7125 <entry><literal>smgr-md-write-start
</literal></entry>
7126 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
7127 <entry>Probe that fires when beginning to write a block to a relation.
7128 arg0 and arg1 contain the fork and block numbers of the page.
7129 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7130 identifying the relation.
7131 arg5 is the ID of the backend which created the temporary relation for a
7132 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
</entry>
7135 <entry><literal>smgr-md-write-done
</literal></entry>
7136 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)
</literal></entry>
7137 <entry>Probe that fires when a block write is complete.
7138 arg0 and arg1 contain the fork and block numbers of the page.
7139 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7140 identifying the relation.
7141 arg5 is the ID of the backend which created the temporary relation for a
7142 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
7143 arg6 is the number of bytes actually written, while arg7 is the number
7144 requested (if these are different it indicates a short write).
</entry>
7147 <entry><literal>sort-start
</literal></entry>
7148 <entry><literal>(int, bool, int, int, bool, int)
</literal></entry>
7149 <entry>Probe that fires when a sort operation is started.
7150 arg0 indicates heap, index or datum sort.
7151 arg1 is true for unique-value enforcement.
7152 arg2 is the number of key columns.
7153 arg3 is the number of kilobytes of work memory allowed.
7154 arg4 is true if random access to the sort result is required.
7155 arg5 indicates serial when
<literal>0</literal>, parallel worker when
7156 <literal>1</literal>, or parallel leader when
<literal>2</literal>.
</entry>
7159 <entry><literal>sort-done
</literal></entry>
7160 <entry><literal>(bool, long)
</literal></entry>
7161 <entry>Probe that fires when a sort is complete.
7162 arg0 is true for external sort, false for internal sort.
7163 arg1 is the number of disk blocks used for an external sort,
7164 or kilobytes of memory used for an internal sort.
</entry>
7167 <entry><literal>lwlock-acquire
</literal></entry>
7168 <entry><literal>(char *, LWLockMode)
</literal></entry>
7169 <entry>Probe that fires when an LWLock has been acquired.
7170 arg0 is the LWLock's tranche.
7171 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7174 <entry><literal>lwlock-release
</literal></entry>
7175 <entry><literal>(char *)
</literal></entry>
7176 <entry>Probe that fires when an LWLock has been released (but note
7177 that any released waiters have not yet been awakened).
7178 arg0 is the LWLock's tranche.
</entry>
7181 <entry><literal>lwlock-wait-start
</literal></entry>
7182 <entry><literal>(char *, LWLockMode)
</literal></entry>
7183 <entry>Probe that fires when an LWLock was not immediately available and
7184 a server process has begun to wait for the lock to become available.
7185 arg0 is the LWLock's tranche.
7186 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7189 <entry><literal>lwlock-wait-done
</literal></entry>
7190 <entry><literal>(char *, LWLockMode)
</literal></entry>
7191 <entry>Probe that fires when a server process has been released from its
7192 wait for an LWLock (it does not actually have the lock yet).
7193 arg0 is the LWLock's tranche.
7194 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7197 <entry><literal>lwlock-condacquire
</literal></entry>
7198 <entry><literal>(char *, LWLockMode)
</literal></entry>
7199 <entry>Probe that fires when an LWLock was successfully acquired when the
7200 caller specified no waiting.
7201 arg0 is the LWLock's tranche.
7202 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7205 <entry><literal>lwlock-condacquire-fail
</literal></entry>
7206 <entry><literal>(char *, LWLockMode)
</literal></entry>
7207 <entry>Probe that fires when an LWLock was not successfully acquired when
7208 the caller specified no waiting.
7209 arg0 is the LWLock's tranche.
7210 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7213 <entry><literal>lock-wait-start
</literal></entry>
7214 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)
</literal></entry>
7215 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
7216 has begun to wait because the lock is not available.
7217 arg0 through arg3 are the tag fields identifying the object being
7218 locked. arg4 indicates the type of object being locked.
7219 arg5 indicates the lock type being requested.
</entry>
7222 <entry><literal>lock-wait-done
</literal></entry>
7223 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)
</literal></entry>
7224 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
7225 has finished waiting (i.e., has acquired the lock).
7226 The arguments are the same as for
<literal>lock-wait-start
</literal>.
</entry>
7229 <entry><literal>deadlock-found
</literal></entry>
7230 <entry><literal>()
</literal></entry>
7231 <entry>Probe that fires when a deadlock is found by the deadlock
7239 <table id=
"typedefs-table">
7240 <title>Defined Types Used in Probe Parameters
</title>
7245 <entry>Definition
</entry>
7252 <entry><type>LocalTransactionId
</type></entry>
7253 <entry><type>unsigned int
</type></entry>
7256 <entry><type>LWLockMode
</type></entry>
7257 <entry><type>int
</type></entry>
7260 <entry><type>LOCKMODE
</type></entry>
7261 <entry><type>int
</type></entry>
7264 <entry><type>BlockNumber
</type></entry>
7265 <entry><type>unsigned int
</type></entry>
7268 <entry><type>Oid
</type></entry>
7269 <entry><type>unsigned int
</type></entry>
7272 <entry><type>ForkNumber
</type></entry>
7273 <entry><type>int
</type></entry>
7276 <entry><type>bool
</type></entry>
7277 <entry><type>unsigned char
</type></entry>
7287 <sect2 id=
"using-trace-points">
7288 <title>Using Probes
</title>
7291 The example below shows a DTrace script for analyzing transaction
7292 counts in the system, as an alternative to snapshotting
7293 <structname>pg_stat_database
</structname> before and after a performance test:
7295 #!/usr/sbin/dtrace -qs
7297 postgresql$
1:::transaction-start
7299 @start[
"Start"] = count();
7300 self-
>ts = timestamp;
7303 postgresql$
1:::transaction-abort
7305 @abort[
"Abort"] = count();
7308 postgresql$
1:::transaction-commit
7311 @commit[
"Commit"] = count();
7312 @time[
"Total time (ns)"] = sum(timestamp - self-
>ts);
7316 When executed, the example D script gives output such as:
7318 # ./txn_count.d `pgrep -n postgres` or ./txn_count.d
<PID
>
7323 Total time (ns)
2312105013
7329 SystemTap uses a different notation for trace scripts than DTrace does,
7330 even though the underlying trace points are compatible. One point worth
7331 noting is that at this writing, SystemTap scripts must reference probe
7332 names using double underscores in place of hyphens. This is expected to
7333 be fixed in future SystemTap releases.
7338 You should remember that DTrace scripts need to be carefully written and
7339 debugged, otherwise the trace information collected might
7340 be meaningless. In most cases where problems are found it is the
7341 instrumentation that is at fault, not the underlying system. When
7342 discussing information found using dynamic tracing, be sure to enclose
7343 the script used to allow that too to be checked and discussed.
7347 <sect2 id=
"defining-trace-points">
7348 <title>Defining New Probes
</title>
7351 New probes can be defined within the code wherever the developer
7352 desires, though this will require a recompilation. Below are the steps
7353 for inserting new probes:
7359 Decide on probe names and data to be made available through the probes
7365 Add the probe definitions to
<filename>src/backend/utils/probes.d
</filename>
7371 Include
<filename>pg_trace.h
</filename> if it is not already present in the
7372 module(s) containing the probe points, and insert
7373 <literal>TRACE_POSTGRESQL
</literal> probe macros at the desired locations
7380 Recompile and verify that the new probes are available
7386 <title>Example:
</title>
7388 Here is an example of how you would add a probe to trace all new
7389 transactions by transaction ID.
7396 Decide that the probe will be named
<literal>transaction-start
</literal> and
7397 requires a parameter of type
<type>LocalTransactionId
</type>
7403 Add the probe definition to
<filename>src/backend/utils/probes.d
</filename>:
7405 probe transaction__start(LocalTransactionId);
7407 Note the use of the double underline in the probe name. In a DTrace
7408 script using the probe, the double underline needs to be replaced with a
7409 hyphen, so
<literal>transaction-start
</literal> is the name to document for
7416 At compile time,
<literal>transaction__start
</literal> is converted to a macro
7417 called
<literal>TRACE_POSTGRESQL_TRANSACTION_START
</literal> (notice the
7418 underscores are single here), which is available by including
7419 <filename>pg_trace.h
</filename>. Add the macro call to the appropriate location
7420 in the source code. In this case, it looks like the following:
7423 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
7430 After recompiling and running the new binary, check that your newly added
7431 probe is available by executing the following DTrace command. You
7432 should see similar output:
7434 # dtrace -ln transaction-start
7435 ID PROVIDER MODULE FUNCTION NAME
7436 18705 postgresql49878 postgres StartTransactionCommand transaction-start
7437 18755 postgresql49877 postgres StartTransactionCommand transaction-start
7438 18805 postgresql49876 postgres StartTransactionCommand transaction-start
7439 18855 postgresql49875 postgres StartTransactionCommand transaction-start
7440 18986 postgresql49873 postgres StartTransactionCommand transaction-start
7447 There are a few things to be careful about when adding trace macros
7453 You should take care that the data types specified for a probe's
7454 parameters match the data types of the variables used in the macro.
7455 Otherwise, you will get compilation errors.
7462 On most platforms, if
<productname>PostgreSQL
</productname> is
7463 built with
<option>--enable-dtrace
</option>, the arguments to a trace
7464 macro will be evaluated whenever control passes through the
7465 macro,
<emphasis>even if no tracing is being done
</emphasis>. This is
7466 usually not worth worrying about if you are just reporting the
7467 values of a few local variables. But beware of putting expensive
7468 function calls into the arguments. If you need to do that,
7469 consider protecting the macro with a check to see if the trace
7470 is actually enabled:
7473 if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
7474 TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
7477 Each trace macro has a corresponding
<literal>ENABLED
</literal> macro.
7488 <sect1 id=
"diskusage">
7489 <title>Monitoring Disk Usage
</title>
7492 This section discusses how to monitor the disk usage of a
7493 <productname>PostgreSQL
</productname> database system.
7496 <sect2 id=
"disk-usage">
7497 <title>Determining Disk Usage
</title>
7499 <indexterm zone=
"disk-usage">
7500 <primary>disk usage
</primary>
7504 Each table has a primary heap disk file where most of the data is
7505 stored. If the table has any columns with potentially-wide values,
7506 there also might be a
<acronym>TOAST
</acronym> file associated with the table,
7507 which is used to store values too wide to fit comfortably in the main
7508 table (see
<xref linkend=
"storage-toast"/>). There will be one valid index
7509 on the
<acronym>TOAST
</acronym> table, if present. There also might be indexes
7510 associated with the base table. Each table and index is stored in a
7511 separate disk file
— possibly more than one file, if the file would
7512 exceed one gigabyte. Naming conventions for these files are described
7513 in
<xref linkend=
"storage-file-layout"/>.
7517 You can monitor disk space in three ways:
7518 using the SQL functions listed in
<xref linkend=
"functions-admin-dbsize"/>,
7519 using the
<xref linkend=
"oid2name"/> module, or
7520 using manual inspection of the system catalogs.
7521 The SQL functions are the easiest to use and are generally recommended.
7522 The remainder of this section shows how to do it by inspection of the
7527 Using
<application>psql
</application> on a recently vacuumed or analyzed
7528 database, you can issue queries to see the disk usage of any table:
7530 SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';
7532 pg_relation_filepath | relpages
7533 ----------------------+----------
7534 base/
16384/
16806 |
60
7537 Each page is typically
8 kilobytes. (Remember,
<structfield>relpages
</structfield>
7538 is only updated by
<command>VACUUM
</command>,
<command>ANALYZE
</command>, and
7539 a few DDL commands such as
<command>CREATE INDEX
</command>.) The file path name
7540 is of interest if you want to examine the table's disk file directly.
7544 To show the space used by
<acronym>TOAST
</acronym> tables, use a query
7547 SELECT relname, relpages
7549 (SELECT reltoastrelid
7551 WHERE relname = 'customer') AS ss
7552 WHERE oid = ss.reltoastrelid OR
7553 oid = (SELECT indexrelid
7555 WHERE indrelid = ss.reltoastrelid)
7559 ----------------------+----------
7561 pg_toast_16806_index |
1
7566 You can easily display index sizes, too:
7568 SELECT c2.relname, c2.relpages
7569 FROM pg_class c, pg_class c2, pg_index i
7570 WHERE c.relname = 'customer' AND
7571 c.oid = i.indrelid AND
7572 c2.oid = i.indexrelid
7573 ORDER BY c2.relname;
7576 -------------------+----------
7577 customer_id_index |
26
7582 It is easy to find your largest tables and indexes using this
7585 SELECT relname, relpages
7587 ORDER BY relpages DESC;
7590 ----------------------+----------
7597 <sect2 id=
"disk-full">
7598 <title>Disk Full Failure
</title>
7601 The most important disk monitoring task of a database administrator
7602 is to make sure the disk doesn't become full. A filled data disk will
7603 not result in data corruption, but it might prevent useful activity
7604 from occurring. If the disk holding the WAL files grows full, database
7605 server panic and consequent shutdown might occur.
7609 If you cannot free up additional space on the disk by deleting
7610 other things, you can move some of the database files to other file
7611 systems by making use of tablespaces. See
<xref
7612 linkend=
"manage-ag-tablespaces"/> for more information about that.
7617 Some file systems perform badly when they are almost full, so do
7618 not wait until the disk is completely full to take action.
7623 If your system supports per-user disk quotas, then the database
7624 will naturally be subject to whatever quota is placed on the user
7625 the server runs as. Exceeding the quota will have the same bad
7626 effects as running out of disk space entirely.