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, each of the size specified in
2696 <varname>op_bytes
</varname>.
2702 <entry role=
"catalog_table_entry">
2703 <para role=
"column_definition">
2704 <structfield>read_time
</structfield> <type>double precision
</type>
2707 Time spent in read operations in milliseconds (if
2708 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2714 <entry role=
"catalog_table_entry">
2715 <para role=
"column_definition">
2716 <structfield>writes
</structfield> <type>bigint
</type>
2719 Number of write operations, each of the size specified in
2720 <varname>op_bytes
</varname>.
2726 <entry role=
"catalog_table_entry">
2727 <para role=
"column_definition">
2728 <structfield>write_time
</structfield> <type>double precision
</type>
2731 Time spent in write operations in milliseconds (if
2732 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2738 <entry role=
"catalog_table_entry">
2739 <para role=
"column_definition">
2740 <structfield>writebacks
</structfield> <type>bigint
</type>
2743 Number of units of size
<varname>op_bytes
</varname> which the process
2744 requested the kernel write out to permanent storage.
2750 <entry role=
"catalog_table_entry">
2751 <para role=
"column_definition">
2752 <structfield>writeback_time
</structfield> <type>double precision
</type>
2755 Time spent in writeback operations in milliseconds (if
2756 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero). This
2757 includes the time spent queueing write-out requests and, potentially,
2758 the time spent to write out the dirty data.
2764 <entry role=
"catalog_table_entry">
2765 <para role=
"column_definition">
2766 <structfield>extends
</structfield> <type>bigint
</type>
2769 Number of relation extend operations, each of the size specified in
2770 <varname>op_bytes
</varname>.
2776 <entry role=
"catalog_table_entry">
2777 <para role=
"column_definition">
2778 <structfield>extend_time
</structfield> <type>double precision
</type>
2781 Time spent in extend operations in milliseconds (if
2782 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2788 <entry role=
"catalog_table_entry">
2789 <para role=
"column_definition">
2790 <structfield>op_bytes
</structfield> <type>bigint
</type>
2793 The number of bytes per unit of I/O read, written, or extended.
2796 Relation data reads, writes, and extends are done in
2797 <varname>block_size
</varname> units, derived from the build-time
2798 parameter
<symbol>BLCKSZ
</symbol>, which is
<literal>8192</literal> by
2805 <entry role=
"catalog_table_entry">
2806 <para role=
"column_definition">
2807 <structfield>hits
</structfield> <type>bigint
</type>
2810 The number of times a desired block was found in a shared buffer.
2816 <entry role=
"catalog_table_entry">
2817 <para role=
"column_definition">
2818 <structfield>evictions
</structfield> <type>bigint
</type>
2821 Number of times a block has been written out from a shared or local
2822 buffer in order to make it available for another use.
2825 In
<varname>context
</varname> <literal>normal
</literal>, this counts
2826 the number of times a block was evicted from a buffer and replaced with
2827 another block. In
<varname>context
</varname>s
2828 <literal>bulkwrite
</literal>,
<literal>bulkread
</literal>, and
2829 <literal>vacuum
</literal>, this counts the number of times a block was
2830 evicted from shared buffers in order to add the shared buffer to a
2831 separate, size-limited ring buffer for use in a bulk I/O operation.
2837 <entry role=
"catalog_table_entry">
2838 <para role=
"column_definition">
2839 <structfield>reuses
</structfield> <type>bigint
</type>
2842 The number of times an existing buffer in a size-limited ring buffer
2843 outside of shared buffers was reused as part of an I/O operation in the
2844 <literal>bulkread
</literal>,
<literal>bulkwrite
</literal>, or
2845 <literal>vacuum
</literal> <varname>context
</varname>s.
2851 <entry role=
"catalog_table_entry">
2852 <para role=
"column_definition">
2853 <structfield>fsyncs
</structfield> <type>bigint
</type>
2856 Number of
<literal>fsync
</literal> calls. These are only tracked in
2857 <varname>context
</varname> <literal>normal
</literal>.
2863 <entry role=
"catalog_table_entry">
2864 <para role=
"column_definition">
2865 <structfield>fsync_time
</structfield> <type>double precision
</type>
2868 Time spent in fsync operations in milliseconds (if
2869 <xref linkend=
"guc-track-io-timing"/> is enabled, otherwise zero)
2875 <entry role=
"catalog_table_entry">
2876 <para role=
"column_definition">
2877 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
2880 Time at which these statistics were last reset.
2889 Some backend types never perform I/O operations on some I/O objects and/or
2890 in some I/O contexts. These rows are omitted from the view. For example, the
2891 checkpointer does not checkpoint temporary tables, so there will be no rows
2892 for
<varname>backend_type
</varname> <literal>checkpointer
</literal> and
2893 <varname>object
</varname> <literal>temp relation
</literal>.
2897 In addition, some I/O operations will never be performed either by certain
2898 backend types or on certain I/O objects and/or in certain I/O contexts.
2899 These cells will be NULL. For example, temporary tables are not
2900 <literal>fsync
</literal>ed, so
<varname>fsyncs
</varname> will be NULL for
2901 <varname>object
</varname> <literal>temp relation
</literal>. Also, the
2902 background writer does not perform reads, so
<varname>reads
</varname> will
2903 be NULL in rows for
<varname>backend_type
</varname> <literal>background
2908 <structname>pg_stat_io
</structname> can be used to inform database tuning.
2913 A high
<varname>evictions
</varname> count can indicate that shared
2914 buffers should be increased.
2919 Client backends rely on the checkpointer to ensure data is persisted to
2920 permanent storage. Large numbers of
<varname>fsyncs
</varname> by
2921 <literal>client backend
</literal>s could indicate a misconfiguration of
2922 shared buffers or of the checkpointer. More information on configuring
2923 the checkpointer can be found in
<xref linkend=
"wal-configuration"/>.
2928 Normally, client backends should be able to rely on auxiliary processes
2929 like the checkpointer and the background writer to write out dirty data
2930 as much as possible. Large numbers of writes by client backends could
2931 indicate a misconfiguration of shared buffers or of the checkpointer.
2932 More information on configuring the checkpointer can be found in
<xref
2933 linkend=
"wal-configuration"/>.
2941 Columns tracking I/O time will only be non-zero when
2942 <xref linkend=
"guc-track-io-timing"/> is enabled. The user should be
2943 careful when referencing these columns in combination with their
2944 corresponding I/O operations in case
<varname>track_io_timing
</varname>
2945 was not enabled for the entire time since the last stats reset.
2953 <sect2 id=
"monitoring-pg-stat-bgwriter-view">
2954 <title><structname>pg_stat_bgwriter
</structname></title>
2957 <primary>pg_stat_bgwriter
</primary>
2961 The
<structname>pg_stat_bgwriter
</structname> view will always have a
2962 single row, containing data about the background writer of the cluster.
2965 <table id=
"pg-stat-bgwriter-view" xreflabel=
"pg_stat_bgwriter">
2966 <title><structname>pg_stat_bgwriter
</structname> View
</title>
2970 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2981 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2982 <structfield>buffers_clean
</structfield> <type>bigint
</type>
2985 Number of buffers written by the background writer
2990 <entry role=
"catalog_table_entry"><para role=
"column_definition">
2991 <structfield>maxwritten_clean
</structfield> <type>bigint
</type>
2994 Number of times the background writer stopped a cleaning
2995 scan because it had written too many buffers
3000 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3001 <structfield>buffers_alloc
</structfield> <type>bigint
</type>
3004 Number of buffers allocated
3009 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3010 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3013 Time at which these statistics were last reset
3022 <sect2 id=
"monitoring-pg-stat-checkpointer-view">
3023 <title><structname>pg_stat_checkpointer
</structname></title>
3026 <primary>pg_stat_checkpointer
</primary>
3030 The
<structname>pg_stat_checkpointer
</structname> view will always have a
3031 single row, containing data about the checkpointer process of the cluster.
3034 <table id=
"pg-stat-checkpointer-view" xreflabel=
"pg_stat_checkpointer">
3035 <title><structname>pg_stat_checkpointer
</structname> View
</title>
3039 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3050 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3051 <structfield>num_timed
</structfield> <type>bigint
</type>
3054 Number of scheduled checkpoints that have been performed
3059 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3060 <structfield>num_requested
</structfield> <type>bigint
</type>
3063 Number of requested checkpoints that have been performed
3068 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3069 <structfield>restartpoints_timed
</structfield> <type>bigint
</type>
3072 Number of scheduled restartpoints due to timeout or after a failed attempt to perform it
3077 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3078 <structfield>restartpoints_req
</structfield> <type>bigint
</type>
3081 Number of requested restartpoints
3086 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3087 <structfield>restartpoints_done
</structfield> <type>bigint
</type>
3090 Number of restartpoints that have been performed
3095 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3096 <structfield>write_time
</structfield> <type>double precision
</type>
3099 Total amount of time that has been spent in the portion of
3100 processing checkpoints and restartpoints where files are written to disk,
3106 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3107 <structfield>sync_time
</structfield> <type>double precision
</type>
3110 Total amount of time that has been spent in the portion of
3111 processing checkpoints and restartpoints where files are synchronized to
3112 disk, in milliseconds
3117 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3118 <structfield>buffers_written
</structfield> <type>bigint
</type>
3121 Number of buffers written during checkpoints and restartpoints
3126 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3127 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3130 Time at which these statistics were last reset
3139 <sect2 id=
"monitoring-pg-stat-wal-view">
3140 <title><structname>pg_stat_wal
</structname></title>
3143 <primary>pg_stat_wal
</primary>
3147 The
<structname>pg_stat_wal
</structname> view will always have a
3148 single row, containing data about WAL activity of the cluster.
3151 <table id=
"pg-stat-wal-view" xreflabel=
"pg_stat_wal">
3152 <title><structname>pg_stat_wal
</structname> View
</title>
3156 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3167 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3168 <structfield>wal_records
</structfield> <type>bigint
</type>
3171 Total number of WAL records generated
3176 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3177 <structfield>wal_fpi
</structfield> <type>bigint
</type>
3180 Total number of WAL full page images generated
3185 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3186 <structfield>wal_bytes
</structfield> <type>numeric
</type>
3189 Total amount of WAL generated in bytes
3194 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3195 <structfield>wal_buffers_full
</structfield> <type>bigint
</type>
3198 Number of times WAL data was written to disk because WAL buffers became full
3203 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3204 <structfield>wal_write
</structfield> <type>bigint
</type>
3207 Number of times WAL buffers were written out to disk via
3208 <function>XLogWrite
</function> request.
3209 See
<xref linkend=
"wal-configuration"/> for more information about
3210 the internal WAL function
<function>XLogWrite
</function>.
3215 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3216 <structfield>wal_sync
</structfield> <type>bigint
</type>
3219 Number of times WAL files were synced to disk via
3220 <function>issue_xlog_fsync
</function> request
3221 (if
<xref linkend=
"guc-fsync"/> is
<literal>on
</literal> and
3222 <xref linkend=
"guc-wal-sync-method"/> is either
3223 <literal>fdatasync
</literal>,
<literal>fsync
</literal> or
3224 <literal>fsync_writethrough
</literal>, otherwise zero).
3225 See
<xref linkend=
"wal-configuration"/> for more information about
3226 the internal WAL function
<function>issue_xlog_fsync
</function>.
3231 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3232 <structfield>wal_write_time
</structfield> <type>double precision
</type>
3235 Total amount of time spent writing WAL buffers to disk via
3236 <function>XLogWrite
</function> request, in milliseconds
3237 (if
<xref linkend=
"guc-track-wal-io-timing"/> is enabled,
3238 otherwise zero). This includes the sync time when
3239 <varname>wal_sync_method
</varname> is either
3240 <literal>open_datasync
</literal> or
<literal>open_sync
</literal>.
3245 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3246 <structfield>wal_sync_time
</structfield> <type>double precision
</type>
3249 Total amount of time spent syncing WAL files to disk via
3250 <function>issue_xlog_fsync
</function> request, in milliseconds
3251 (if
<varname>track_wal_io_timing
</varname> is enabled,
3252 <varname>fsync
</varname> is
<literal>on
</literal>, and
3253 <varname>wal_sync_method
</varname> is either
3254 <literal>fdatasync
</literal>,
<literal>fsync
</literal> or
3255 <literal>fsync_writethrough
</literal>, otherwise zero).
3260 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3261 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3264 Time at which these statistics were last reset
3273 <sect2 id=
"monitoring-pg-stat-database-view">
3274 <title><structname>pg_stat_database
</structname></title>
3277 <primary>pg_stat_database
</primary>
3281 The
<structname>pg_stat_database
</structname> view will contain one row
3282 for each database in the cluster, plus one for shared objects, showing
3283 database-wide statistics.
3286 <table id=
"pg-stat-database-view" xreflabel=
"pg_stat_database">
3287 <title><structname>pg_stat_database
</structname> View
</title>
3291 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3302 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3303 <structfield>datid
</structfield> <type>oid
</type>
3306 OID of this database, or
0 for objects belonging to a shared
3312 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3313 <structfield>datname
</structfield> <type>name
</type>
3316 Name of this database, or
<literal>NULL
</literal> for shared
3322 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3323 <structfield>numbackends
</structfield> <type>integer
</type>
3326 Number of backends currently connected to this database, or
3327 <literal>NULL
</literal> for shared objects. This is the only column
3328 in this view that returns a value reflecting current state; all other
3329 columns return the accumulated values since the last reset.
3334 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3335 <structfield>xact_commit
</structfield> <type>bigint
</type>
3338 Number of transactions in this database that have been
3344 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3345 <structfield>xact_rollback
</structfield> <type>bigint
</type>
3348 Number of transactions in this database that have been
3354 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3355 <structfield>blks_read
</structfield> <type>bigint
</type>
3358 Number of disk blocks read in this database
3363 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3364 <structfield>blks_hit
</structfield> <type>bigint
</type>
3367 Number of times disk blocks were found already in the buffer
3368 cache, so that a read was not necessary (this only includes hits in the
3369 PostgreSQL buffer cache, not the operating system's file system cache)
3374 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3375 <structfield>tup_returned
</structfield> <type>bigint
</type>
3378 Number of live rows fetched by sequential scans and index entries returned by index scans in this database
3383 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3384 <structfield>tup_fetched
</structfield> <type>bigint
</type>
3387 Number of live rows fetched by index scans in this database
3392 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3393 <structfield>tup_inserted
</structfield> <type>bigint
</type>
3396 Number of rows inserted by queries in this database
3401 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3402 <structfield>tup_updated
</structfield> <type>bigint
</type>
3405 Number of rows updated by queries in this database
3410 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3411 <structfield>tup_deleted
</structfield> <type>bigint
</type>
3414 Number of rows deleted by queries in this database
3419 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3420 <structfield>conflicts
</structfield> <type>bigint
</type>
3423 Number of queries canceled due to conflicts with recovery
3424 in this database. (Conflicts occur only on standby servers; see
3425 <link linkend=
"monitoring-pg-stat-database-conflicts-view">
3426 <structname>pg_stat_database_conflicts
</structname></link> for details.)
3431 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3432 <structfield>temp_files
</structfield> <type>bigint
</type>
3435 Number of temporary files created by queries in this database.
3436 All temporary files are counted, regardless of why the temporary file
3437 was created (e.g., sorting or hashing), and regardless of the
3438 <xref linkend=
"guc-log-temp-files"/> setting.
3443 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3444 <structfield>temp_bytes
</structfield> <type>bigint
</type>
3447 Total amount of data written to temporary files by queries in
3448 this database. All temporary files are counted, regardless of why
3449 the temporary file was created, and
3450 regardless of the
<xref linkend=
"guc-log-temp-files"/> setting.
3455 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3456 <structfield>deadlocks
</structfield> <type>bigint
</type>
3459 Number of deadlocks detected in this database
3464 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3465 <structfield>checksum_failures
</structfield> <type>bigint
</type>
3468 Number of data page checksum failures detected in this
3469 database (or on a shared object), or NULL if data checksums are not
3475 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3476 <structfield>checksum_last_failure
</structfield> <type>timestamp with time zone
</type>
3479 Time at which the last data page checksum failure was detected in
3480 this database (or on a shared object), or NULL if data checksums are not
3486 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3487 <structfield>blk_read_time
</structfield> <type>double precision
</type>
3490 Time spent reading data file blocks by backends in this database,
3491 in milliseconds (if
<xref linkend=
"guc-track-io-timing"/> is enabled,
3497 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3498 <structfield>blk_write_time
</structfield> <type>double precision
</type>
3501 Time spent writing data file blocks by backends in this database,
3502 in milliseconds (if
<xref linkend=
"guc-track-io-timing"/> is enabled,
3508 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3509 <structfield>session_time
</structfield> <type>double precision
</type>
3512 Time spent by database sessions in this database, in milliseconds
3513 (note that statistics are only updated when the state of a session
3514 changes, so if sessions have been idle for a long time, this idle time
3520 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3521 <structfield>active_time
</structfield> <type>double precision
</type>
3524 Time spent executing SQL statements in this database, in milliseconds
3525 (this corresponds to the states
<literal>active
</literal> and
3526 <literal>fastpath function call
</literal> in
3527 <link linkend=
"monitoring-pg-stat-activity-view">
3528 <structname>pg_stat_activity
</structname></link>)
3533 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3534 <structfield>idle_in_transaction_time
</structfield> <type>double precision
</type>
3537 Time spent idling while in a transaction in this database, in milliseconds
3538 (this corresponds to the states
<literal>idle in transaction
</literal> and
3539 <literal>idle in transaction (aborted)
</literal> in
3540 <link linkend=
"monitoring-pg-stat-activity-view">
3541 <structname>pg_stat_activity
</structname></link>)
3546 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3547 <structfield>sessions
</structfield> <type>bigint
</type>
3550 Total number of sessions established to this database
3555 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3556 <structfield>sessions_abandoned
</structfield> <type>bigint
</type>
3559 Number of database sessions to this database that were terminated
3560 because connection to the client was lost
3565 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3566 <structfield>sessions_fatal
</structfield> <type>bigint
</type>
3569 Number of database sessions to this database that were terminated
3575 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3576 <structfield>sessions_killed
</structfield> <type>bigint
</type>
3579 Number of database sessions to this database that were terminated
3580 by operator intervention
3585 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3586 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
3589 Time at which these statistics were last reset
3598 <sect2 id=
"monitoring-pg-stat-database-conflicts-view">
3599 <title><structname>pg_stat_database_conflicts
</structname></title>
3602 <primary>pg_stat_database_conflicts
</primary>
3606 The
<structname>pg_stat_database_conflicts
</structname> view will contain
3607 one row per database, showing database-wide statistics about
3608 query cancels occurring due to conflicts with recovery on standby servers.
3609 This view will only contain information on standby servers, since
3610 conflicts do not occur on primary servers.
3613 <table id=
"pg-stat-database-conflicts-view" xreflabel=
"pg_stat_database_conflicts">
3614 <title><structname>pg_stat_database_conflicts
</structname> View
</title>
3618 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3629 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3630 <structfield>datid
</structfield> <type>oid
</type>
3638 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3639 <structfield>datname
</structfield> <type>name
</type>
3642 Name of this database
3647 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3648 <structfield>confl_tablespace
</structfield> <type>bigint
</type>
3651 Number of queries in this database that have been canceled due to
3657 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3658 <structfield>confl_lock
</structfield> <type>bigint
</type>
3661 Number of queries in this database that have been canceled due to
3667 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3668 <structfield>confl_snapshot
</structfield> <type>bigint
</type>
3671 Number of queries in this database that have been canceled due to
3677 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3678 <structfield>confl_bufferpin
</structfield> <type>bigint
</type>
3681 Number of queries in this database that have been canceled due to
3687 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3688 <structfield>confl_deadlock
</structfield> <type>bigint
</type>
3691 Number of queries in this database that have been canceled due to
3697 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3698 <structfield>confl_active_logicalslot
</structfield> <type>bigint
</type>
3701 Number of uses of logical slots in this database that have been
3702 canceled due to old snapshots or too low a
<xref linkend=
"guc-wal-level"/>
3712 <sect2 id=
"monitoring-pg-stat-all-tables-view">
3713 <title><structname>pg_stat_all_tables
</structname></title>
3716 <primary>pg_stat_all_tables
</primary>
3720 The
<structname>pg_stat_all_tables
</structname> view will contain
3721 one row for each table in the current database (including TOAST
3722 tables), showing statistics about accesses to that specific table. The
3723 <structname>pg_stat_user_tables
</structname> and
3724 <structname>pg_stat_sys_tables
</structname> views
3725 contain the same information,
3726 but filtered to only show user and system tables respectively.
3729 <table id=
"pg-stat-all-tables-view" xreflabel=
"pg_stat_all_tables">
3730 <title><structname>pg_stat_all_tables
</structname> View
</title>
3734 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3745 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3746 <structfield>relid
</structfield> <type>oid
</type>
3754 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3755 <structfield>schemaname
</structfield> <type>name
</type>
3758 Name of the schema that this table is in
3763 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3764 <structfield>relname
</structfield> <type>name
</type>
3772 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3773 <structfield>seq_scan
</structfield> <type>bigint
</type>
3776 Number of sequential scans initiated on this table
3781 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3782 <structfield>last_seq_scan
</structfield> <type>timestamp with time zone
</type>
3785 The time of the last sequential scan on this table, based on the
3786 most recent transaction stop time
3791 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3792 <structfield>seq_tup_read
</structfield> <type>bigint
</type>
3795 Number of live rows fetched by sequential scans
3800 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3801 <structfield>idx_scan
</structfield> <type>bigint
</type>
3804 Number of index scans initiated on this table
3809 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3810 <structfield>last_idx_scan
</structfield> <type>timestamp with time zone
</type>
3813 The time of the last index scan on this table, based on the
3814 most recent transaction stop time
3819 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3820 <structfield>idx_tup_fetch
</structfield> <type>bigint
</type>
3823 Number of live rows fetched by index scans
3828 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3829 <structfield>n_tup_ins
</structfield> <type>bigint
</type>
3832 Total number of rows inserted
3837 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3838 <structfield>n_tup_upd
</structfield> <type>bigint
</type>
3841 Total number of rows updated. (This includes row updates
3842 counted in
<structfield>n_tup_hot_upd
</structfield> and
3843 <structfield>n_tup_newpage_upd
</structfield>, and remaining
3844 non-
<acronym>HOT
</acronym> updates.)
3849 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3850 <structfield>n_tup_del
</structfield> <type>bigint
</type>
3853 Total number of rows deleted
3858 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3859 <structfield>n_tup_hot_upd
</structfield> <type>bigint
</type>
3862 Number of rows
<link linkend=
"storage-hot">HOT updated
</link>.
3863 These are updates where no successor versions are required in
3869 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3870 <structfield>n_tup_newpage_upd
</structfield> <type>bigint
</type>
3873 Number of rows updated where the successor version goes onto a
3874 <emphasis>new
</emphasis> heap page, leaving behind an original
3876 <link linkend=
"storage-tuple-layout"><structfield>t_ctid
</structfield>
3877 field
</link> that points to a different heap page. These are
3878 always non-
<acronym>HOT
</acronym> updates.
3883 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3884 <structfield>n_live_tup
</structfield> <type>bigint
</type>
3887 Estimated number of live rows
3892 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3893 <structfield>n_dead_tup
</structfield> <type>bigint
</type>
3896 Estimated number of dead rows
3901 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3902 <structfield>n_mod_since_analyze
</structfield> <type>bigint
</type>
3905 Estimated number of rows modified since this table was last analyzed
3910 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3911 <structfield>n_ins_since_vacuum
</structfield> <type>bigint
</type>
3914 Estimated number of rows inserted since this table was last vacuumed
3919 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3920 <structfield>last_vacuum
</structfield> <type>timestamp with time zone
</type>
3923 Last time at which this table was manually vacuumed
3924 (not counting
<command>VACUUM FULL
</command>)
3929 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3930 <structfield>last_autovacuum
</structfield> <type>timestamp with time zone
</type>
3933 Last time at which this table was vacuumed by the autovacuum
3939 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3940 <structfield>last_analyze
</structfield> <type>timestamp with time zone
</type>
3943 Last time at which this table was manually analyzed
3948 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3949 <structfield>last_autoanalyze
</structfield> <type>timestamp with time zone
</type>
3952 Last time at which this table was analyzed by the autovacuum
3958 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3959 <structfield>vacuum_count
</structfield> <type>bigint
</type>
3962 Number of times this table has been manually vacuumed
3963 (not counting
<command>VACUUM FULL
</command>)
3968 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3969 <structfield>autovacuum_count
</structfield> <type>bigint
</type>
3972 Number of times this table has been vacuumed by the autovacuum
3978 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3979 <structfield>analyze_count
</structfield> <type>bigint
</type>
3982 Number of times this table has been manually analyzed
3987 <entry role=
"catalog_table_entry"><para role=
"column_definition">
3988 <structfield>autoanalyze_count
</structfield> <type>bigint
</type>
3991 Number of times this table has been analyzed by the autovacuum
4001 <sect2 id=
"monitoring-pg-stat-all-indexes-view">
4002 <title><structname>pg_stat_all_indexes
</structname></title>
4005 <primary>pg_stat_all_indexes
</primary>
4009 The
<structname>pg_stat_all_indexes
</structname> view will contain
4010 one row for each index in the current database,
4011 showing statistics about accesses to that specific index. The
4012 <structname>pg_stat_user_indexes
</structname> and
4013 <structname>pg_stat_sys_indexes
</structname> views
4014 contain the same information,
4015 but filtered to only show user and system indexes respectively.
4018 <table id=
"pg-stat-all-indexes-view" xreflabel=
"pg_stat_all_indexes">
4019 <title><structname>pg_stat_all_indexes
</structname> View
</title>
4023 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4034 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4035 <structfield>relid
</structfield> <type>oid
</type>
4038 OID of the table for this index
4043 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4044 <structfield>indexrelid
</structfield> <type>oid
</type>
4052 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4053 <structfield>schemaname
</structfield> <type>name
</type>
4056 Name of the schema this index is in
4061 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4062 <structfield>relname
</structfield> <type>name
</type>
4065 Name of the table for this index
4070 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4071 <structfield>indexrelname
</structfield> <type>name
</type>
4079 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4080 <structfield>idx_scan
</structfield> <type>bigint
</type>
4083 Number of index scans initiated on this index
4088 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4089 <structfield>last_idx_scan
</structfield> <type>timestamp with time zone
</type>
4092 The time of the last scan on this index, based on the
4093 most recent transaction stop time
4098 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4099 <structfield>idx_tup_read
</structfield> <type>bigint
</type>
4102 Number of index entries returned by scans on this index
4107 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4108 <structfield>idx_tup_fetch
</structfield> <type>bigint
</type>
4111 Number of live table rows fetched by simple index scans using this
4120 Indexes can be used by simple index scans,
<quote>bitmap
</quote> index scans,
4121 and the optimizer. In a bitmap scan
4122 the output of several indexes can be combined via AND or OR rules,
4123 so it is difficult to associate individual heap row fetches
4124 with specific indexes when a bitmap scan is used. Therefore, a bitmap
4126 <structname>pg_stat_all_indexes
</structname>.
<structfield>idx_tup_read
</structfield>
4127 count(s) for the index(es) it uses, and it increments the
4128 <structname>pg_stat_all_tables
</structname>.
<structfield>idx_tup_fetch
</structfield>
4129 count for the table, but it does not affect
4130 <structname>pg_stat_all_indexes
</structname>.
<structfield>idx_tup_fetch
</structfield>.
4131 The optimizer also accesses indexes to check for supplied constants
4132 whose values are outside the recorded range of the optimizer statistics
4133 because the optimizer statistics might be stale.
4138 The
<structfield>idx_tup_read
</structfield> and
<structfield>idx_tup_fetch
</structfield> counts
4139 can be different even without any use of bitmap scans,
4140 because
<structfield>idx_tup_read
</structfield> counts
4141 index entries retrieved from the index while
<structfield>idx_tup_fetch
</structfield>
4142 counts live rows fetched from the table. The latter will be less if any
4143 dead or not-yet-committed rows are fetched using the index, or if any
4144 heap fetches are avoided by means of an index-only scan.
4150 Queries that use certain
<acronym>SQL
</acronym> constructs to search for
4151 rows matching any value out of a list or array of multiple scalar values
4152 (see
<xref linkend=
"functions-comparisons"/>) perform multiple
4153 <quote>primitive
</quote> index scans (up to one primitive scan per scalar
4154 value) during query execution. Each internal primitive index scan
4155 increments
<structname>pg_stat_all_indexes
</structname>.
<structfield>idx_scan
</structfield>,
4156 so it's possible for the count of index scans to significantly exceed the
4157 total number of index scan executor node executions.
4163 <sect2 id=
"monitoring-pg-statio-all-tables-view">
4164 <title><structname>pg_statio_all_tables
</structname></title>
4167 <primary>pg_statio_all_tables
</primary>
4171 The
<structname>pg_statio_all_tables
</structname> view will contain
4172 one row for each table in the current database (including TOAST
4173 tables), showing statistics about I/O on that specific table. The
4174 <structname>pg_statio_user_tables
</structname> and
4175 <structname>pg_statio_sys_tables
</structname> views
4176 contain the same information,
4177 but filtered to only show user and system tables respectively.
4180 <table id=
"pg-statio-all-tables-view" xreflabel=
"pg_statio_all_tables">
4181 <title><structname>pg_statio_all_tables
</structname> View
</title>
4185 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4196 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4197 <structfield>relid
</structfield> <type>oid
</type>
4205 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4206 <structfield>schemaname
</structfield> <type>name
</type>
4209 Name of the schema that this table is in
4214 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4215 <structfield>relname
</structfield> <type>name
</type>
4223 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4224 <structfield>heap_blks_read
</structfield> <type>bigint
</type>
4227 Number of disk blocks read from this table
4232 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4233 <structfield>heap_blks_hit
</structfield> <type>bigint
</type>
4236 Number of buffer hits in this table
4241 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4242 <structfield>idx_blks_read
</structfield> <type>bigint
</type>
4245 Number of disk blocks read from all indexes on this table
4250 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4251 <structfield>idx_blks_hit
</structfield> <type>bigint
</type>
4254 Number of buffer hits in all indexes on this table
4259 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4260 <structfield>toast_blks_read
</structfield> <type>bigint
</type>
4263 Number of disk blocks read from this table's TOAST table (if any)
4268 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4269 <structfield>toast_blks_hit
</structfield> <type>bigint
</type>
4272 Number of buffer hits in this table's TOAST table (if any)
4277 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4278 <structfield>tidx_blks_read
</structfield> <type>bigint
</type>
4281 Number of disk blocks read from this table's TOAST table indexes (if any)
4286 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4287 <structfield>tidx_blks_hit
</structfield> <type>bigint
</type>
4290 Number of buffer hits in this table's TOAST table indexes (if any)
4299 <sect2 id=
"monitoring-pg-statio-all-indexes-view">
4300 <title><structname>pg_statio_all_indexes
</structname></title>
4303 <primary>pg_statio_all_indexes
</primary>
4307 The
<structname>pg_statio_all_indexes
</structname> view will contain
4308 one row for each index in the current database,
4309 showing statistics about I/O on that specific index. The
4310 <structname>pg_statio_user_indexes
</structname> and
4311 <structname>pg_statio_sys_indexes
</structname> views
4312 contain the same information,
4313 but filtered to only show user and system indexes respectively.
4316 <table id=
"pg-statio-all-indexes-view" xreflabel=
"pg_statio_all_indexes">
4317 <title><structname>pg_statio_all_indexes
</structname> View
</title>
4321 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4332 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4333 <structfield>relid
</structfield> <type>oid
</type>
4336 OID of the table for this index
4341 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4342 <structfield>indexrelid
</structfield> <type>oid
</type>
4350 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4351 <structfield>schemaname
</structfield> <type>name
</type>
4354 Name of the schema this index is in
4359 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4360 <structfield>relname
</structfield> <type>name
</type>
4363 Name of the table for this index
4368 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4369 <structfield>indexrelname
</structfield> <type>name
</type>
4377 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4378 <structfield>idx_blks_read
</structfield> <type>bigint
</type>
4381 Number of disk blocks read from this index
4386 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4387 <structfield>idx_blks_hit
</structfield> <type>bigint
</type>
4390 Number of buffer hits in this index
4399 <sect2 id=
"monitoring-pg-statio-all-sequences-view">
4400 <title><structname>pg_statio_all_sequences
</structname></title>
4403 <primary>pg_statio_all_sequences
</primary>
4407 The
<structname>pg_statio_all_sequences
</structname> view will contain
4408 one row for each sequence in the current database,
4409 showing statistics about I/O on that specific sequence.
4412 <table id=
"pg-statio-all-sequences-view" xreflabel=
"pg_statio_all_sequences">
4413 <title><structname>pg_statio_all_sequences
</structname> View
</title>
4417 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4428 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4429 <structfield>relid
</structfield> <type>oid
</type>
4437 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4438 <structfield>schemaname
</structfield> <type>name
</type>
4441 Name of the schema this sequence is in
4446 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4447 <structfield>relname
</structfield> <type>name
</type>
4450 Name of this sequence
4455 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4456 <structfield>blks_read
</structfield> <type>bigint
</type>
4459 Number of disk blocks read from this sequence
4464 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4465 <structfield>blks_hit
</structfield> <type>bigint
</type>
4468 Number of buffer hits in this sequence
4477 <sect2 id=
"monitoring-pg-stat-user-functions-view">
4478 <title><structname>pg_stat_user_functions
</structname></title>
4481 <primary>pg_stat_user_functions
</primary>
4485 The
<structname>pg_stat_user_functions
</structname> view will contain
4486 one row for each tracked function, showing statistics about executions of
4487 that function. The
<xref linkend=
"guc-track-functions"/> parameter
4488 controls exactly which functions are tracked.
4491 <table id=
"pg-stat-user-functions-view" xreflabel=
"pg_stat_user_functions">
4492 <title><structname>pg_stat_user_functions
</structname> View
</title>
4496 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4507 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4508 <structfield>funcid
</structfield> <type>oid
</type>
4516 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4517 <structfield>schemaname
</structfield> <type>name
</type>
4520 Name of the schema this function is in
4525 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4526 <structfield>funcname
</structfield> <type>name
</type>
4529 Name of this function
4534 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4535 <structfield>calls
</structfield> <type>bigint
</type>
4538 Number of times this function has been called
4543 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4544 <structfield>total_time
</structfield> <type>double precision
</type>
4547 Total time spent in this function and all other functions
4548 called by it, in milliseconds
4553 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4554 <structfield>self_time
</structfield> <type>double precision
</type>
4557 Total time spent in this function itself, not including
4558 other functions called by it, in milliseconds
4567 <sect2 id=
"monitoring-pg-stat-slru-view">
4568 <title><structname>pg_stat_slru
</structname></title>
4571 <primary>SLRU
</primary>
4575 <primary>pg_stat_slru
</primary>
4579 <productname>PostgreSQL
</productname> accesses certain on-disk information
4580 via
<literal>SLRU
</literal> (
<firstterm>simple least-recently-used
</firstterm>)
4582 The
<structname>pg_stat_slru
</structname> view will contain
4583 one row for each tracked SLRU cache, showing statistics about access
4588 For each
<literal>SLRU
</literal> cache that's part of the core server,
4589 there is a configuration parameter that controls its size, with the suffix
4590 <literal>_buffers
</literal> appended.
4593 <table id=
"pg-stat-slru-view" xreflabel=
"pg_stat_slru">
4594 <title><structname>pg_stat_slru
</structname> View
</title>
4598 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4609 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4610 <structfield>name
</structfield> <type>text
</type>
4618 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4619 <structfield>blks_zeroed
</structfield> <type>bigint
</type>
4622 Number of blocks zeroed during initializations
4627 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4628 <structfield>blks_hit
</structfield> <type>bigint
</type>
4631 Number of times disk blocks were found already in the SLRU,
4632 so that a read was not necessary (this only includes hits in the
4633 SLRU, not the operating system's file system cache)
4638 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4639 <structfield>blks_read
</structfield> <type>bigint
</type>
4642 Number of disk blocks read for this SLRU
4647 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4648 <structfield>blks_written
</structfield> <type>bigint
</type>
4651 Number of disk blocks written for this SLRU
4656 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4657 <structfield>blks_exists
</structfield> <type>bigint
</type>
4660 Number of blocks checked for existence for this SLRU
4665 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4666 <structfield>flushes
</structfield> <type>bigint
</type>
4669 Number of flushes of dirty data for this SLRU
4674 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4675 <structfield>truncates
</structfield> <type>bigint
</type>
4678 Number of truncates for this SLRU
4683 <entry role=
"catalog_table_entry"><para role=
"column_definition">
4684 <structfield>stats_reset
</structfield> <type>timestamp with time zone
</type>
4687 Time at which these statistics were last reset
4696 <sect2 id=
"monitoring-stats-functions">
4697 <title>Statistics Functions
</title>
4700 Other ways of looking at the statistics can be set up by writing
4701 queries that use the same underlying statistics access functions used by
4702 the standard views shown above. For details such as the functions' names,
4703 consult the definitions of the standard views. (For example, in
4704 <application>psql
</application> you could issue
<literal>\d+ pg_stat_activity
</literal>.)
4705 The access functions for per-database statistics take a database OID as an
4706 argument to identify which database to report on.
4707 The per-table and per-index functions take a table or index OID.
4708 The functions for per-function statistics take a function OID.
4709 Note that only tables, indexes, and functions in the current database
4710 can be seen with these functions.
4714 Additional functions related to the cumulative statistics system are listed
4715 in
<xref linkend=
"monitoring-stats-funcs-table"/>.
4718 <table id=
"monitoring-stats-funcs-table">
4719 <title>Additional Statistics Functions
</title>
4723 <entry role=
"func_table_entry"><para role=
"func_signature">
4734 <!-- See also the entry for this in func.sgml -->
4735 <entry role=
"func_table_entry"><para role=
"func_signature">
4736 <function>pg_backend_pid
</function> ()
4737 <returnvalue>integer
</returnvalue>
4740 Returns the process ID of the server process attached to the current
4746 <entry role=
"func_table_entry"><para role=
"func_signature">
4748 <primary>pg_stat_get_activity
</primary>
4750 <function>pg_stat_get_activity
</function> (
<type>integer
</type> )
4751 <returnvalue>setof record
</returnvalue>
4754 Returns a record of information about the backend with the specified
4755 process ID, or one record for each active backend in the system
4756 if
<literal>NULL
</literal> is specified. The fields returned are a
4757 subset of those in the
<structname>pg_stat_activity
</structname> view.
4762 <entry role=
"func_table_entry"><para role=
"func_signature">
4764 <primary>pg_stat_get_snapshot_timestamp
</primary>
4766 <function>pg_stat_get_snapshot_timestamp
</function> ()
4767 <returnvalue>timestamp with time zone
</returnvalue>
4770 Returns the timestamp of the current statistics snapshot, or NULL if
4771 no statistics snapshot has been taken. A snapshot is taken the first
4772 time cumulative statistics are accessed in a transaction if
4773 <varname>stats_fetch_consistency
</varname> is set to
4774 <literal>snapshot
</literal>
4779 <entry role=
"func_table_entry"><para role=
"func_signature">
4781 <primary>pg_stat_get_xact_blocks_fetched
</primary>
4783 <function>pg_stat_get_xact_blocks_fetched
</function> (
<type>oid
</type> )
4784 <returnvalue>bigint
</returnvalue>
4787 Returns the number of block read requests for table or index, in the
4788 current transaction. This number minus
4789 <function>pg_stat_get_xact_blocks_hit
</function> gives the number of
4790 kernel
<function>read()
</function> calls; the number of actual
4791 physical reads is usually lower due to kernel-level buffering.
4796 <entry role=
"func_table_entry"><para role=
"func_signature">
4798 <primary>pg_stat_get_xact_blocks_hit
</primary>
4800 <function>pg_stat_get_xact_blocks_hit
</function> (
<type>oid
</type> )
4801 <returnvalue>bigint
</returnvalue>
4804 Returns the number of block read requests for table or index, in the
4805 current transaction, found in cache (not triggering kernel
4806 <function>read()
</function> calls).
4811 <entry role=
"func_table_entry"><para role=
"func_signature">
4813 <primary>pg_stat_clear_snapshot
</primary>
4815 <function>pg_stat_clear_snapshot
</function> ()
4816 <returnvalue>void
</returnvalue>
4819 Discards the current statistics snapshot or cached information.
4824 <entry role=
"func_table_entry"><para role=
"func_signature">
4826 <primary>pg_stat_reset
</primary>
4828 <function>pg_stat_reset
</function> ()
4829 <returnvalue>void
</returnvalue>
4832 Resets all statistics counters for the current database to zero.
4835 This function is restricted to superusers by default, but other users
4836 can be granted EXECUTE to run the function.
4841 <entry role=
"func_table_entry"><para role=
"func_signature">
4843 <primary>pg_stat_reset_shared
</primary>
4845 <function>pg_stat_reset_shared
</function> ( [
<parameter>target
</parameter> <type>text
</type> <literal>DEFAULT
</literal> <literal>NULL
</literal> ] )
4846 <returnvalue>void
</returnvalue>
4849 Resets some cluster-wide statistics counters to zero, depending on the
4850 argument.
<parameter>target
</parameter> can be:
4854 <literal>archiver
</literal>: Reset all the counters shown in the
4855 <structname>pg_stat_archiver
</structname> view.
4860 <literal>bgwriter
</literal>: Reset all the counters shown in the
4861 <structname>pg_stat_bgwriter
</structname> view.
4866 <literal>checkpointer
</literal>: Reset all the counters shown in the
4867 <structname>pg_stat_checkpointer
</structname> view.
4872 <literal>io
</literal>: Reset all the counters shown in the
4873 <structname>pg_stat_io
</structname> view.
4878 <literal>recovery_prefetch
</literal>: Reset all the counters shown in
4879 the
<structname>pg_stat_recovery_prefetch
</structname> view.
4884 <literal>slru
</literal>: Reset all the counters shown in the
4885 <structname>pg_stat_slru
</structname> view.
4890 <literal>wal
</literal>: Reset all the counters shown in the
4891 <structname>pg_stat_wal
</structname> view.
4896 <literal>NULL
</literal> or not specified: All the counters from the
4897 views listed above are reset.
4903 This function is restricted to superusers by default, but other users
4904 can be granted EXECUTE to run the function.
4909 <entry role=
"func_table_entry"><para role=
"func_signature">
4911 <primary>pg_stat_reset_single_table_counters
</primary>
4913 <function>pg_stat_reset_single_table_counters
</function> (
<type>oid
</type> )
4914 <returnvalue>void
</returnvalue>
4917 Resets statistics for a single table or index in the current database
4918 or shared across all databases in the cluster to zero.
4921 This function is restricted to superusers by default, but other users
4922 can be granted EXECUTE to run the function.
4927 <entry role=
"func_table_entry"><para role=
"func_signature">
4929 <primary>pg_stat_reset_single_function_counters
</primary>
4931 <function>pg_stat_reset_single_function_counters
</function> (
<type>oid
</type> )
4932 <returnvalue>void
</returnvalue>
4935 Resets statistics for a single function in the current database to
4939 This function is restricted to superusers by default, but other users
4940 can be granted EXECUTE to run the function.
4945 <entry role=
"func_table_entry"><para role=
"func_signature">
4947 <primary>pg_stat_reset_slru
</primary>
4949 <function>pg_stat_reset_slru
</function> ( [
<parameter>target
</parameter> <type>text
</type> <literal>DEFAULT
</literal> <literal>NULL
</literal> ] )
4950 <returnvalue>void
</returnvalue>
4953 Resets statistics to zero for a single SLRU cache, or for all SLRUs in
4954 the cluster. If
<parameter>target
</parameter> is
4955 <literal>NULL
</literal> or is not specified, all the counters shown in
4956 the
<structname>pg_stat_slru
</structname> view for all SLRU caches are
4957 reset. The argument can be one of
4958 <literal>commit_timestamp
</literal>,
4959 <literal>multixact_member
</literal>,
4960 <literal>multixact_offset
</literal>,
4961 <literal>notify
</literal>,
4962 <literal>serializable
</literal>,
4963 <literal>subtransaction
</literal>, or
4964 <literal>transaction
</literal>
4965 to reset the counters for only that entry.
4966 If the argument is
<literal>other
</literal> (or indeed, any
4967 unrecognized name), then the counters for all other SLRU caches, such
4968 as extension-defined caches, are reset.
4971 This function is restricted to superusers by default, but other users
4972 can be granted EXECUTE to run the function.
4977 <entry role=
"func_table_entry"><para role=
"func_signature">
4979 <primary>pg_stat_reset_replication_slot
</primary>
4981 <function>pg_stat_reset_replication_slot
</function> (
<type>text
</type> )
4982 <returnvalue>void
</returnvalue>
4985 Resets statistics of the replication slot defined by the argument. If
4986 the argument is
<literal>NULL
</literal>, resets statistics for all
4987 the replication slots.
4990 This function is restricted to superusers by default, but other users
4991 can be granted EXECUTE to run the function.
4996 <entry role=
"func_table_entry"><para role=
"func_signature">
4998 <primary>pg_stat_reset_subscription_stats
</primary>
5000 <function>pg_stat_reset_subscription_stats
</function> (
<type>oid
</type> )
5001 <returnvalue>void
</returnvalue>
5004 Resets statistics for a single subscription shown in the
5005 <structname>pg_stat_subscription_stats
</structname> view to zero. If
5006 the argument is
<literal>NULL
</literal>, reset statistics for all
5010 This function is restricted to superusers by default, but other users
5011 can be granted EXECUTE to run the function.
5020 Using
<function>pg_stat_reset()
</function> also resets counters that
5021 autovacuum uses to determine when to trigger a vacuum or an analyze.
5022 Resetting these counters can cause autovacuum to not perform necessary
5023 work, which can cause problems such as table bloat or out-dated
5024 table statistics. A database-wide
<command>ANALYZE
</command> is
5025 recommended after the statistics have been reset.
5030 <function>pg_stat_get_activity
</function>, the underlying function of
5031 the
<structname>pg_stat_activity
</structname> view, returns a set of records
5032 containing all the available information about each backend process.
5033 Sometimes it may be more convenient to obtain just a subset of this
5034 information. In such cases, another set of per-backend statistics
5035 access functions can be used; these are shown in
<xref
5036 linkend=
"monitoring-stats-backend-funcs-table"/>.
5037 These access functions use the session's backend ID number, which is a
5038 small integer (
>=
0) that is distinct from the backend ID of any
5039 concurrent session, although a session's ID can be recycled as soon as
5040 it exits. The backend ID is used, among other things, to identify the
5041 session's temporary schema if it has one.
5042 The function
<function>pg_stat_get_backend_idset
</function> provides a
5043 convenient way to list all the active backends' ID numbers for
5044 invoking these functions. For example, to show the
<acronym>PID
</acronym>s and
5045 current queries of all backends:
5048 SELECT pg_stat_get_backend_pid(backendid) AS pid,
5049 pg_stat_get_backend_activity(backendid) AS query
5050 FROM pg_stat_get_backend_idset() AS backendid;
5054 <table id=
"monitoring-stats-backend-funcs-table">
5055 <title>Per-Backend Statistics Functions
</title>
5059 <entry role=
"func_table_entry"><para role=
"func_signature">
5070 <entry role=
"func_table_entry"><para role=
"func_signature">
5072 <primary>pg_stat_get_backend_activity
</primary>
5074 <function>pg_stat_get_backend_activity
</function> (
<type>integer
</type> )
5075 <returnvalue>text
</returnvalue>
5078 Returns the text of this backend's most recent query.
5083 <entry role=
"func_table_entry"><para role=
"func_signature">
5085 <primary>pg_stat_get_backend_activity_start
</primary>
5087 <function>pg_stat_get_backend_activity_start
</function> (
<type>integer
</type> )
5088 <returnvalue>timestamp with time zone
</returnvalue>
5091 Returns the time when the backend's most recent query was started.
5096 <entry role=
"func_table_entry"><para role=
"func_signature">
5098 <primary>pg_stat_get_backend_client_addr
</primary>
5100 <function>pg_stat_get_backend_client_addr
</function> (
<type>integer
</type> )
5101 <returnvalue>inet
</returnvalue>
5104 Returns the IP address of the client connected to this backend.
5109 <entry role=
"func_table_entry"><para role=
"func_signature">
5111 <primary>pg_stat_get_backend_client_port
</primary>
5113 <function>pg_stat_get_backend_client_port
</function> (
<type>integer
</type> )
5114 <returnvalue>integer
</returnvalue>
5117 Returns the TCP port number that the client is using for communication.
5122 <entry role=
"func_table_entry"><para role=
"func_signature">
5124 <primary>pg_stat_get_backend_dbid
</primary>
5126 <function>pg_stat_get_backend_dbid
</function> (
<type>integer
</type> )
5127 <returnvalue>oid
</returnvalue>
5130 Returns the OID of the database this backend is connected to.
5135 <entry role=
"func_table_entry"><para role=
"func_signature">
5137 <primary>pg_stat_get_backend_idset
</primary>
5139 <function>pg_stat_get_backend_idset
</function> ()
5140 <returnvalue>setof integer
</returnvalue>
5143 Returns the set of currently active backend ID numbers.
5148 <entry role=
"func_table_entry"><para role=
"func_signature">
5150 <primary>pg_stat_get_backend_pid
</primary>
5152 <function>pg_stat_get_backend_pid
</function> (
<type>integer
</type> )
5153 <returnvalue>integer
</returnvalue>
5156 Returns the process ID of this backend.
5161 <entry role=
"func_table_entry"><para role=
"func_signature">
5163 <primary>pg_stat_get_backend_start
</primary>
5165 <function>pg_stat_get_backend_start
</function> (
<type>integer
</type> )
5166 <returnvalue>timestamp with time zone
</returnvalue>
5169 Returns the time when this process was started.
5174 <entry role=
"func_table_entry"><para role=
"func_signature">
5176 <primary>pg_stat_get_backend_subxact
</primary>
5178 <function>pg_stat_get_backend_subxact
</function> (
<type>integer
</type> )
5179 <returnvalue>record
</returnvalue>
5182 Returns a record of information about the subtransactions of the
5183 backend with the specified ID.
5184 The fields returned are
<parameter>subxact_count
</parameter>, which
5185 is the number of subtransactions in the backend's subtransaction cache,
5186 and
<parameter>subxact_overflow
</parameter>, which indicates whether
5187 the backend's subtransaction cache is overflowed or not.
5192 <entry role=
"func_table_entry"><para role=
"func_signature">
5194 <primary>pg_stat_get_backend_userid
</primary>
5196 <function>pg_stat_get_backend_userid
</function> (
<type>integer
</type> )
5197 <returnvalue>oid
</returnvalue>
5200 Returns the OID of the user logged into this backend.
5205 <entry role=
"func_table_entry"><para role=
"func_signature">
5207 <primary>pg_stat_get_backend_wait_event
</primary>
5209 <function>pg_stat_get_backend_wait_event
</function> (
<type>integer
</type> )
5210 <returnvalue>text
</returnvalue>
5213 Returns the wait event name if this backend is currently waiting,
5214 otherwise NULL. See
<xref linkend=
"wait-event-activity-table"/> through
5215 <xref linkend=
"wait-event-timeout-table"/>.
5220 <entry role=
"func_table_entry"><para role=
"func_signature">
5222 <primary>pg_stat_get_backend_wait_event_type
</primary>
5224 <function>pg_stat_get_backend_wait_event_type
</function> (
<type>integer
</type> )
5225 <returnvalue>text
</returnvalue>
5228 Returns the wait event type name if this backend is currently waiting,
5229 otherwise NULL. See
<xref linkend=
"wait-event-table"/> for details.
5234 <entry role=
"func_table_entry"><para role=
"func_signature">
5236 <primary>pg_stat_get_backend_xact_start
</primary>
5238 <function>pg_stat_get_backend_xact_start
</function> (
<type>integer
</type> )
5239 <returnvalue>timestamp with time zone
</returnvalue>
5242 Returns the time when the backend's current transaction was started.
5252 <sect1 id=
"monitoring-locks">
5253 <title>Viewing Locks
</title>
5255 <indexterm zone=
"monitoring-locks">
5256 <primary>lock
</primary>
5257 <secondary>monitoring
</secondary>
5261 Another useful tool for monitoring database activity is the
5262 <structname>pg_locks
</structname> system table. It allows the
5263 database administrator to view information about the outstanding
5264 locks in the lock manager. For example, this capability can be used
5270 View all the locks currently outstanding, all the locks on
5271 relations in a particular database, all the locks on a
5272 particular relation, or all the locks held by a particular
5273 <productname>PostgreSQL
</productname> session.
5279 Determine the relation in the current database with the most
5280 ungranted locks (which might be a source of contention among
5287 Determine the effect of lock contention on overall database
5288 performance, as well as the extent to which contention varies
5289 with overall database traffic.
5294 Details of the
<structname>pg_locks
</structname> view appear in
5295 <xref linkend=
"view-pg-locks"/>.
5296 For more information on locking and managing concurrency with
5297 <productname>PostgreSQL
</productname>, refer to
<xref linkend=
"mvcc"/>.
5301 <sect1 id=
"progress-reporting">
5302 <title>Progress Reporting
</title>
5305 <productname>PostgreSQL
</productname> has the ability to report the progress of
5306 certain commands during command execution. Currently, the only commands
5307 which support progress reporting are
<command>ANALYZE
</command>,
5308 <command>CLUSTER
</command>,
5309 <command>CREATE INDEX
</command>,
<command>VACUUM
</command>,
5310 <command>COPY
</command>,
5311 and
<xref linkend=
"protocol-replication-base-backup"/> (i.e., replication
5312 command that
<xref linkend=
"app-pgbasebackup"/> issues to take
5314 This may be expanded in the future.
5317 <sect2 id=
"analyze-progress-reporting">
5318 <title>ANALYZE Progress Reporting
</title>
5321 <primary>pg_stat_progress_analyze
</primary>
5325 Whenever
<command>ANALYZE
</command> is running, the
5326 <structname>pg_stat_progress_analyze
</structname> view will contain a
5327 row for each backend that is currently running that command. The tables
5328 below describe the information that will be reported and provide
5329 information about how to interpret it.
5332 <table id=
"pg-stat-progress-analyze-view" xreflabel=
"pg_stat_progress_analyze">
5333 <title><structname>pg_stat_progress_analyze
</structname> View
</title>
5337 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5348 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5349 <structfield>pid
</structfield> <type>integer
</type>
5352 Process ID of backend.
5357 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5358 <structfield>datid
</structfield> <type>oid
</type>
5361 OID of the database to which this backend is connected.
5366 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5367 <structfield>datname
</structfield> <type>name
</type>
5370 Name of the database to which this backend is connected.
5375 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5376 <structfield>relid
</structfield> <type>oid
</type>
5379 OID of the table being analyzed.
5384 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5385 <structfield>phase
</structfield> <type>text
</type>
5388 Current processing phase. See
<xref linkend=
"analyze-phases"/>.
5393 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5394 <structfield>sample_blks_total
</structfield> <type>bigint
</type>
5397 Total number of heap blocks that will be sampled.
5402 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5403 <structfield>sample_blks_scanned
</structfield> <type>bigint
</type>
5406 Number of heap blocks scanned.
5411 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5412 <structfield>ext_stats_total
</structfield> <type>bigint
</type>
5415 Number of extended statistics.
5420 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5421 <structfield>ext_stats_computed
</structfield> <type>bigint
</type>
5424 Number of extended statistics computed. This counter only advances
5425 when the phase is
<literal>computing extended statistics
</literal>.
5430 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5431 <structfield>child_tables_total
</structfield> <type>bigint
</type>
5434 Number of child tables.
5439 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5440 <structfield>child_tables_done
</structfield> <type>bigint
</type>
5443 Number of child tables scanned. This counter only advances when the
5444 phase is
<literal>acquiring inherited sample rows
</literal>.
5449 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5450 <structfield>current_child_table_relid
</structfield> <type>oid
</type>
5453 OID of the child table currently being scanned. This field is
5454 only valid when the phase is
5455 <literal>acquiring inherited sample rows
</literal>.
5462 <table id=
"analyze-phases">
5463 <title>ANALYZE Phases
</title>
5465 <colspec colname=
"col1" colwidth=
"1*"/>
5466 <colspec colname=
"col2" colwidth=
"2*"/>
5469 <entry>Phase
</entry>
5470 <entry>Description
</entry>
5475 <entry><literal>initializing
</literal></entry>
5477 The command is preparing to begin scanning the heap. This phase is
5478 expected to be very brief.
5482 <entry><literal>acquiring sample rows
</literal></entry>
5484 The command is currently scanning the table given by
5485 <structfield>relid
</structfield> to obtain sample rows.
5489 <entry><literal>acquiring inherited sample rows
</literal></entry>
5491 The command is currently scanning child tables to obtain sample rows.
5492 Columns
<structfield>child_tables_total
</structfield>,
5493 <structfield>child_tables_done
</structfield>, and
5494 <structfield>current_child_table_relid
</structfield> contain the
5495 progress information for this phase.
5499 <entry><literal>computing statistics
</literal></entry>
5501 The command is computing statistics from the sample rows obtained
5502 during the table scan.
5506 <entry><literal>computing extended statistics
</literal></entry>
5508 The command is computing extended statistics from the sample rows
5509 obtained during the table scan.
5513 <entry><literal>finalizing analyze
</literal></entry>
5515 The command is updating
<structname>pg_class
</structname>. When this
5516 phase is completed,
<command>ANALYZE
</command> will end.
5525 Note that when
<command>ANALYZE
</command> is run on a partitioned table,
5526 all of its partitions are also recursively analyzed.
5527 In that case,
<command>ANALYZE
</command>
5528 progress is reported first for the parent table, whereby its inheritance
5529 statistics are collected, followed by that for each partition.
5534 <sect2 id=
"cluster-progress-reporting">
5535 <title>CLUSTER Progress Reporting
</title>
5538 <primary>pg_stat_progress_cluster
</primary>
5542 Whenever
<command>CLUSTER
</command> or
<command>VACUUM FULL
</command> is
5543 running, the
<structname>pg_stat_progress_cluster
</structname> view will
5544 contain a row for each backend that is currently running either command.
5545 The tables below describe the information that will be reported and
5546 provide information about how to interpret it.
5549 <table id=
"pg-stat-progress-cluster-view" xreflabel=
"pg_stat_progress_cluster">
5550 <title><structname>pg_stat_progress_cluster
</structname> View
</title>
5554 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5565 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5566 <structfield>pid
</structfield> <type>integer
</type>
5569 Process ID of backend.
5574 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5575 <structfield>datid
</structfield> <type>oid
</type>
5578 OID of the database to which this backend is connected.
5583 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5584 <structfield>datname
</structfield> <type>name
</type>
5587 Name of the database to which this backend is connected.
5592 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5593 <structfield>relid
</structfield> <type>oid
</type>
5596 OID of the table being clustered.
5601 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5602 <structfield>command
</structfield> <type>text
</type>
5605 The command that is running. Either
<literal>CLUSTER
</literal> or
<literal>VACUUM FULL
</literal>.
5610 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5611 <structfield>phase
</structfield> <type>text
</type>
5614 Current processing phase. See
<xref linkend=
"cluster-phases"/>.
5619 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5620 <structfield>cluster_index_relid
</structfield> <type>oid
</type>
5623 If the table is being scanned using an index, this is the OID of the
5624 index being used; otherwise, it is zero.
5629 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5630 <structfield>heap_tuples_scanned
</structfield> <type>bigint
</type>
5633 Number of heap tuples scanned.
5634 This counter only advances when the phase is
5635 <literal>seq scanning heap
</literal>,
5636 <literal>index scanning heap
</literal>
5637 or
<literal>writing new heap
</literal>.
5642 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5643 <structfield>heap_tuples_written
</structfield> <type>bigint
</type>
5646 Number of heap tuples written.
5647 This counter only advances when the phase is
5648 <literal>seq scanning heap
</literal>,
5649 <literal>index scanning heap
</literal>
5650 or
<literal>writing new heap
</literal>.
5655 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5656 <structfield>heap_blks_total
</structfield> <type>bigint
</type>
5659 Total number of heap blocks in the table. This number is reported
5660 as of the beginning of
<literal>seq scanning heap
</literal>.
5665 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5666 <structfield>heap_blks_scanned
</structfield> <type>bigint
</type>
5669 Number of heap blocks scanned. This counter only advances when the
5670 phase is
<literal>seq scanning heap
</literal>.
5675 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5676 <structfield>index_rebuild_count
</structfield> <type>bigint
</type>
5679 Number of indexes rebuilt. This counter only advances when the phase
5680 is
<literal>rebuilding index
</literal>.
5687 <table id=
"cluster-phases">
5688 <title>CLUSTER and VACUUM FULL Phases
</title>
5690 <colspec colname=
"col1" colwidth=
"1*"/>
5691 <colspec colname=
"col2" colwidth=
"2*"/>
5694 <entry>Phase
</entry>
5695 <entry>Description
</entry>
5701 <entry><literal>initializing
</literal></entry>
5703 The command is preparing to begin scanning the heap. This phase is
5704 expected to be very brief.
5708 <entry><literal>seq scanning heap
</literal></entry>
5710 The command is currently scanning the table using a sequential scan.
5714 <entry><literal>index scanning heap
</literal></entry>
5716 <command>CLUSTER
</command> is currently scanning the table using an index scan.
5720 <entry><literal>sorting tuples
</literal></entry>
5722 <command>CLUSTER
</command> is currently sorting tuples.
5726 <entry><literal>writing new heap
</literal></entry>
5728 <command>CLUSTER
</command> is currently writing the new heap.
5732 <entry><literal>swapping relation files
</literal></entry>
5734 The command is currently swapping newly-built files into place.
5738 <entry><literal>rebuilding index
</literal></entry>
5740 The command is currently rebuilding an index.
5744 <entry><literal>performing final cleanup
</literal></entry>
5746 The command is performing final cleanup. When this phase is
5747 completed,
<command>CLUSTER
</command>
5748 or
<command>VACUUM FULL
</command> will end.
5756 <sect2 id=
"copy-progress-reporting">
5757 <title>COPY Progress Reporting
</title>
5760 <primary>pg_stat_progress_copy
</primary>
5764 Whenever
<command>COPY
</command> is running, the
5765 <structname>pg_stat_progress_copy
</structname> view will contain one row
5766 for each backend that is currently running a
<command>COPY
</command> command.
5767 The table below describes the information that will be reported and provides
5768 information about how to interpret it.
5771 <table id=
"pg-stat-progress-copy-view" xreflabel=
"pg_stat_progress_copy">
5772 <title><structname>pg_stat_progress_copy
</structname> View
</title>
5776 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5787 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5788 <structfield>pid
</structfield> <type>integer
</type>
5791 Process ID of backend.
5796 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5797 <structfield>datid
</structfield> <type>oid
</type>
5800 OID of the database to which this backend is connected.
5805 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5806 <structfield>datname
</structfield> <type>name
</type>
5809 Name of the database to which this backend is connected.
5814 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5815 <structfield>relid
</structfield> <type>oid
</type>
5818 OID of the table on which the
<command>COPY
</command> command is
5819 executed. It is set to
<literal>0</literal> if copying from a
5820 <command>SELECT
</command> query.
5825 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5826 <structfield>command
</structfield> <type>text
</type>
5829 The command that is running:
<literal>COPY FROM
</literal>, or
5830 <literal>COPY TO
</literal>.
5835 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5836 <structfield>type
</structfield> <type>text
</type>
5839 The I/O type that the data is read from or written to:
5840 <literal>FILE
</literal>,
<literal>PROGRAM
</literal>,
5841 <literal>PIPE
</literal> (for
<command>COPY FROM STDIN
</command> and
5842 <command>COPY TO STDOUT
</command>), or
<literal>CALLBACK
</literal>
5843 (used for example during the initial table synchronization in
5844 logical replication).
5849 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5850 <structfield>bytes_processed
</structfield> <type>bigint
</type>
5853 Number of bytes already processed by
<command>COPY
</command> command.
5858 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5859 <structfield>bytes_total
</structfield> <type>bigint
</type>
5862 Size of source file for
<command>COPY FROM
</command> command in bytes.
5863 It is set to
<literal>0</literal> if not available.
5868 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5869 <structfield>tuples_processed
</structfield> <type>bigint
</type>
5872 Number of tuples already processed by
<command>COPY
</command> command.
5877 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5878 <structfield>tuples_excluded
</structfield> <type>bigint
</type>
5881 Number of tuples not processed because they were excluded by the
5882 <command>WHERE
</command> clause of the
<command>COPY
</command> command.
5887 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5888 <structfield>tuples_skipped
</structfield> <type>bigint
</type>
5891 Number of tuples skipped because they contain malformed data.
5892 This counter only advances when a value other than
5893 <literal>stop
</literal> is specified to the
<literal>ON_ERROR
</literal>
5902 <sect2 id=
"create-index-progress-reporting">
5903 <title>CREATE INDEX Progress Reporting
</title>
5906 <primary>pg_stat_progress_create_index
</primary>
5910 Whenever
<command>CREATE INDEX
</command> or
<command>REINDEX
</command> is running, the
5911 <structname>pg_stat_progress_create_index
</structname> view will contain
5912 one row for each backend that is currently creating indexes. The tables
5913 below describe the information that will be reported and provide information
5914 about how to interpret it.
5917 <table id=
"pg-stat-progress-create-index-view" xreflabel=
"pg_stat_progress_create_index">
5918 <title><structname>pg_stat_progress_create_index
</structname> View
</title>
5922 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5933 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5934 <structfield>pid
</structfield> <type>integer
</type>
5937 Process ID of the backend creating indexes.
5942 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5943 <structfield>datid
</structfield> <type>oid
</type>
5946 OID of the database to which this backend is connected.
5951 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5952 <structfield>datname
</structfield> <type>name
</type>
5955 Name of the database to which this backend is connected.
5960 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5961 <structfield>relid
</structfield> <type>oid
</type>
5964 OID of the table on which the index is being created.
5969 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5970 <structfield>index_relid
</structfield> <type>oid
</type>
5973 OID of the index being created or reindexed. During a
5974 non-concurrent
<command>CREATE INDEX
</command>, this is
0.
5979 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5980 <structfield>command
</structfield> <type>text
</type>
5983 Specific command type:
<literal>CREATE INDEX
</literal>,
5984 <literal>CREATE INDEX CONCURRENTLY
</literal>,
5985 <literal>REINDEX
</literal>, or
<literal>REINDEX CONCURRENTLY
</literal>.
5990 <entry role=
"catalog_table_entry"><para role=
"column_definition">
5991 <structfield>phase
</structfield> <type>text
</type>
5994 Current processing phase of index creation. See
<xref linkend=
"create-index-phases"/>.
5999 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6000 <structfield>lockers_total
</structfield> <type>bigint
</type>
6003 Total number of lockers to wait for, when applicable.
6008 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6009 <structfield>lockers_done
</structfield> <type>bigint
</type>
6012 Number of lockers already waited for.
6017 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6018 <structfield>current_locker_pid
</structfield> <type>bigint
</type>
6021 Process ID of the locker currently being waited for.
6026 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6027 <structfield>blocks_total
</structfield> <type>bigint
</type>
6030 Total number of blocks to be processed in the current phase.
6035 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6036 <structfield>blocks_done
</structfield> <type>bigint
</type>
6039 Number of blocks already processed in the current phase.
6044 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6045 <structfield>tuples_total
</structfield> <type>bigint
</type>
6048 Total number of tuples to be processed in the current phase.
6053 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6054 <structfield>tuples_done
</structfield> <type>bigint
</type>
6057 Number of tuples already processed in the current phase.
6062 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6063 <structfield>partitions_total
</structfield> <type>bigint
</type>
6066 Total number of partitions on which the index is to be created
6067 or attached, including both direct and indirect partitions.
6068 <literal>0</literal> during a
<literal>REINDEX
</literal>, or when
6069 the index is not partitioned.
6074 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6075 <structfield>partitions_done
</structfield> <type>bigint
</type>
6078 Number of partitions on which the index has already been created
6079 or attached, including both direct and indirect partitions.
6080 <literal>0</literal> during a
<literal>REINDEX
</literal>, or when
6081 the index is not partitioned.
6088 <table id=
"create-index-phases">
6089 <title>CREATE INDEX Phases
</title>
6091 <colspec colname=
"col1" colwidth=
"1*"/>
6092 <colspec colname=
"col2" colwidth=
"2*"/>
6095 <entry>Phase
</entry>
6096 <entry>Description
</entry>
6101 <entry><literal>initializing
</literal></entry>
6103 <command>CREATE INDEX
</command> or
<command>REINDEX
</command> is preparing to create the index. This
6104 phase is expected to be very brief.
6108 <entry><literal>waiting for writers before build
</literal></entry>
6110 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6111 with write locks that can potentially see the table to finish.
6112 This phase is skipped when not in concurrent mode.
6113 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6114 and
<structname>current_locker_pid
</structname> contain the progress
6115 information for this phase.
6119 <entry><literal>building index
</literal></entry>
6121 The index is being built by the access method-specific code. In this phase,
6122 access methods that support progress reporting fill in their own progress data,
6123 and the subphase is indicated in this column. Typically,
6124 <structname>blocks_total
</structname> and
<structname>blocks_done
</structname>
6125 will contain progress data, as well as potentially
6126 <structname>tuples_total
</structname> and
<structname>tuples_done
</structname>.
6130 <entry><literal>waiting for writers before validation
</literal></entry>
6132 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6133 with write locks that can potentially write into the table to finish.
6134 This phase is skipped when not in concurrent mode.
6135 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6136 and
<structname>current_locker_pid
</structname> contain the progress
6137 information for this phase.
6141 <entry><literal>index validation: scanning index
</literal></entry>
6143 <command>CREATE INDEX CONCURRENTLY
</command> is scanning the index searching
6144 for tuples that need to be validated.
6145 This phase is skipped when not in concurrent mode.
6146 Columns
<structname>blocks_total
</structname> (set to the total size of the index)
6147 and
<structname>blocks_done
</structname> contain the progress information for this phase.
6151 <entry><literal>index validation: sorting tuples
</literal></entry>
6153 <command>CREATE INDEX CONCURRENTLY
</command> is sorting the output of the
6154 index scanning phase.
6158 <entry><literal>index validation: scanning table
</literal></entry>
6160 <command>CREATE INDEX CONCURRENTLY
</command> is scanning the table
6161 to validate the index tuples collected in the previous two phases.
6162 This phase is skipped when not in concurrent mode.
6163 Columns
<structname>blocks_total
</structname> (set to the total size of the table)
6164 and
<structname>blocks_done
</structname> contain the progress information for this phase.
6168 <entry><literal>waiting for old snapshots
</literal></entry>
6170 <command>CREATE INDEX CONCURRENTLY
</command> or
<command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6171 that can potentially see the table to release their snapshots. This
6172 phase is skipped when not in concurrent mode.
6173 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6174 and
<structname>current_locker_pid
</structname> contain the progress
6175 information for this phase.
6179 <entry><literal>waiting for readers before marking dead
</literal></entry>
6181 <command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6182 with read locks on the table to finish, before marking the old index dead.
6183 This phase is skipped when not in concurrent mode.
6184 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6185 and
<structname>current_locker_pid
</structname> contain the progress
6186 information for this phase.
6190 <entry><literal>waiting for readers before dropping
</literal></entry>
6192 <command>REINDEX CONCURRENTLY
</command> is waiting for transactions
6193 with read locks on the table to finish, before dropping the old index.
6194 This phase is skipped when not in concurrent mode.
6195 Columns
<structname>lockers_total
</structname>,
<structname>lockers_done
</structname>
6196 and
<structname>current_locker_pid
</structname> contain the progress
6197 information for this phase.
6206 <sect2 id=
"vacuum-progress-reporting">
6207 <title>VACUUM Progress Reporting
</title>
6210 <primary>pg_stat_progress_vacuum
</primary>
6214 Whenever
<command>VACUUM
</command> is running, the
6215 <structname>pg_stat_progress_vacuum
</structname> view will contain
6216 one row for each backend (including autovacuum worker processes) that is
6217 currently vacuuming. The tables below describe the information
6218 that will be reported and provide information about how to interpret it.
6219 Progress for
<command>VACUUM FULL
</command> commands is reported via
6220 <structname>pg_stat_progress_cluster
</structname>
6221 because both
<command>VACUUM FULL
</command> and
<command>CLUSTER
</command>
6222 rewrite the table, while regular
<command>VACUUM
</command> only modifies it
6223 in place. See
<xref linkend=
"cluster-progress-reporting"/>.
6226 <table id=
"pg-stat-progress-vacuum-view" xreflabel=
"pg_stat_progress_vacuum">
6227 <title><structname>pg_stat_progress_vacuum
</structname> View
</title>
6231 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6242 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6243 <structfield>pid
</structfield> <type>integer
</type>
6246 Process ID of backend.
6251 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6252 <structfield>datid
</structfield> <type>oid
</type>
6255 OID of the database to which this backend is connected.
6260 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6261 <structfield>datname
</structfield> <type>name
</type>
6264 Name of the database to which this backend is connected.
6269 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6270 <structfield>relid
</structfield> <type>oid
</type>
6273 OID of the table being vacuumed.
6278 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6279 <structfield>phase
</structfield> <type>text
</type>
6282 Current processing phase of vacuum. See
<xref linkend=
"vacuum-phases"/>.
6287 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6288 <structfield>heap_blks_total
</structfield> <type>bigint
</type>
6291 Total number of heap blocks in the table. This number is reported
6292 as of the beginning of the scan; blocks added later will not be (and
6293 need not be) visited by this
<command>VACUUM
</command>.
6298 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6299 <structfield>heap_blks_scanned
</structfield> <type>bigint
</type>
6302 Number of heap blocks scanned. Because the
6303 <link linkend=
"storage-vm">visibility map
</link> is used to optimize scans,
6304 some blocks will be skipped without inspection; skipped blocks are
6305 included in this total, so that this number will eventually become
6306 equal to
<structfield>heap_blks_total
</structfield> when the vacuum is complete.
6307 This counter only advances when the phase is
<literal>scanning heap
</literal>.
6312 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6313 <structfield>heap_blks_vacuumed
</structfield> <type>bigint
</type>
6316 Number of heap blocks vacuumed. Unless the table has no indexes, this
6317 counter only advances when the phase is
<literal>vacuuming heap
</literal>.
6318 Blocks that contain no dead tuples are skipped, so the counter may
6319 sometimes skip forward in large increments.
6324 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6325 <structfield>index_vacuum_count
</structfield> <type>bigint
</type>
6328 Number of completed index vacuum cycles.
6333 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6334 <structfield>max_dead_tuple_bytes
</structfield> <type>bigint
</type>
6337 Amount of dead tuple data that we can store before needing to perform
6338 an index vacuum cycle, based on
6339 <xref linkend=
"guc-maintenance-work-mem"/>.
6344 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6345 <structfield>dead_tuple_bytes
</structfield> <type>bigint
</type>
6348 Amount of dead tuple data collected since the last index vacuum cycle.
6353 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6354 <structfield>num_dead_item_ids
</structfield> <type>bigint
</type>
6357 Number of dead item identifiers collected since the last index vacuum cycle.
6362 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6363 <structfield>indexes_total
</structfield> <type>bigint
</type>
6366 Total number of indexes that will be vacuumed or cleaned up. This
6367 number is reported at the beginning of the
6368 <literal>vacuuming indexes
</literal> phase or the
6369 <literal>cleaning up indexes
</literal> phase.
6374 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6375 <structfield>indexes_processed
</structfield> <type>bigint
</type>
6378 Number of indexes processed. This counter only advances when the
6379 phase is
<literal>vacuuming indexes
</literal> or
6380 <literal>cleaning up indexes
</literal>.
6387 <table id=
"vacuum-phases">
6388 <title>VACUUM Phases
</title>
6390 <colspec colname=
"col1" colwidth=
"1*"/>
6391 <colspec colname=
"col2" colwidth=
"2*"/>
6394 <entry>Phase
</entry>
6395 <entry>Description
</entry>
6401 <entry><literal>initializing
</literal></entry>
6403 <command>VACUUM
</command> is preparing to begin scanning the heap. This
6404 phase is expected to be very brief.
6408 <entry><literal>scanning heap
</literal></entry>
6410 <command>VACUUM
</command> is currently scanning the heap. It will prune and
6411 defragment each page if required, and possibly perform freezing
6412 activity. The
<structfield>heap_blks_scanned
</structfield> column can be used
6413 to monitor the progress of the scan.
6417 <entry><literal>vacuuming indexes
</literal></entry>
6419 <command>VACUUM
</command> is currently vacuuming the indexes. If a table has
6420 any indexes, this will happen at least once per vacuum, after the heap
6421 has been completely scanned. It may happen multiple times per vacuum
6422 if
<xref linkend=
"guc-maintenance-work-mem"/> (or, in the case of autovacuum,
6423 <xref linkend=
"guc-autovacuum-work-mem"/> if set) is insufficient to store
6424 the number of dead tuples found.
6428 <entry><literal>vacuuming heap
</literal></entry>
6430 <command>VACUUM
</command> is currently vacuuming the heap. Vacuuming the heap
6431 is distinct from scanning the heap, and occurs after each instance of
6432 vacuuming indexes. If
<structfield>heap_blks_scanned
</structfield> is less than
6433 <structfield>heap_blks_total
</structfield>, the system will return to scanning
6434 the heap after this phase is completed; otherwise, it will begin
6435 cleaning up indexes after this phase is completed.
6439 <entry><literal>cleaning up indexes
</literal></entry>
6441 <command>VACUUM
</command> is currently cleaning up indexes. This occurs after
6442 the heap has been completely scanned and all vacuuming of the indexes
6443 and the heap has been completed.
6447 <entry><literal>truncating heap
</literal></entry>
6449 <command>VACUUM
</command> is currently truncating the heap so as to return
6450 empty pages at the end of the relation to the operating system. This
6451 occurs after cleaning up indexes.
6455 <entry><literal>performing final cleanup
</literal></entry>
6457 <command>VACUUM
</command> is performing final cleanup. During this phase,
6458 <command>VACUUM
</command> will vacuum the free space map, update statistics
6459 in
<literal>pg_class
</literal>, and report statistics to the cumulative
6460 statistics system. When this phase is completed,
<command>VACUUM
</command> will end.
6468 <sect2 id=
"basebackup-progress-reporting">
6469 <title>Base Backup Progress Reporting
</title>
6472 <primary>pg_stat_progress_basebackup
</primary>
6476 Whenever an application like
<application>pg_basebackup
</application>
6477 is taking a base backup, the
6478 <structname>pg_stat_progress_basebackup
</structname>
6479 view will contain a row for each WAL sender process that is currently
6480 running the
<command>BASE_BACKUP
</command> replication command
6481 and streaming the backup. The tables below describe the information
6482 that will be reported and provide information about how to interpret it.
6485 <table id=
"pg-stat-progress-basebackup-view" xreflabel=
"pg_stat_progress_basebackup">
6486 <title><structname>pg_stat_progress_basebackup
</structname> View
</title>
6490 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6501 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6502 <structfield>pid
</structfield> <type>integer
</type>
6505 Process ID of a WAL sender process.
6510 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6511 <structfield>phase
</structfield> <type>text
</type>
6514 Current processing phase. See
<xref linkend=
"basebackup-phases"/>.
6519 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6520 <structfield>backup_total
</structfield> <type>bigint
</type>
6523 Total amount of data that will be streamed. This is estimated and
6524 reported as of the beginning of
6525 <literal>streaming database files
</literal> phase. Note that
6526 this is only an approximation since the database
6527 may change during
<literal>streaming database files
</literal> phase
6528 and WAL log may be included in the backup later. This is always
6529 the same value as
<structfield>backup_streamed
</structfield>
6530 once the amount of data streamed exceeds the estimated
6531 total size. If the estimation is disabled in
6532 <application>pg_basebackup
</application>
6533 (i.e.,
<literal>--no-estimate-size
</literal> option is specified),
6534 this is
<literal>NULL
</literal>.
6539 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6540 <structfield>backup_streamed
</structfield> <type>bigint
</type>
6543 Amount of data streamed. This counter only advances
6544 when the phase is
<literal>streaming database files
</literal> or
6545 <literal>transferring wal files
</literal>.
6550 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6551 <structfield>tablespaces_total
</structfield> <type>bigint
</type>
6554 Total number of tablespaces that will be streamed.
6559 <entry role=
"catalog_table_entry"><para role=
"column_definition">
6560 <structfield>tablespaces_streamed
</structfield> <type>bigint
</type>
6563 Number of tablespaces streamed. This counter only
6564 advances when the phase is
<literal>streaming database files
</literal>.
6571 <table id=
"basebackup-phases">
6572 <title>Base Backup Phases
</title>
6574 <colspec colname=
"col1" colwidth=
"1*"/>
6575 <colspec colname=
"col2" colwidth=
"2*"/>
6578 <entry>Phase
</entry>
6579 <entry>Description
</entry>
6584 <entry><literal>initializing
</literal></entry>
6586 The WAL sender process is preparing to begin the backup.
6587 This phase is expected to be very brief.
6591 <entry><literal>waiting for checkpoint to finish
</literal></entry>
6593 The WAL sender process is currently performing
6594 <function>pg_backup_start
</function> to prepare to
6595 take a base backup, and waiting for the start-of-backup
6596 checkpoint to finish.
6600 <entry><literal>estimating backup size
</literal></entry>
6602 The WAL sender process is currently estimating the total amount
6603 of database files that will be streamed as a base backup.
6607 <entry><literal>streaming database files
</literal></entry>
6609 The WAL sender process is currently streaming database files
6614 <entry><literal>waiting for wal archiving to finish
</literal></entry>
6616 The WAL sender process is currently performing
6617 <function>pg_backup_stop
</function> to finish the backup,
6618 and waiting for all the WAL files required for the base backup
6619 to be successfully archived.
6620 If either
<literal>--wal-method=none
</literal> or
6621 <literal>--wal-method=stream
</literal> is specified in
6622 <application>pg_basebackup
</application>, the backup will end
6623 when this phase is completed.
6627 <entry><literal>transferring wal files
</literal></entry>
6629 The WAL sender process is currently transferring all WAL logs
6630 generated during the backup. This phase occurs after
6631 <literal>waiting for wal archiving to finish
</literal> phase if
6632 <literal>--wal-method=fetch
</literal> is specified in
6633 <application>pg_basebackup
</application>. The backup will end
6634 when this phase is completed.
6645 <sect1 id=
"dynamic-trace">
6646 <title>Dynamic Tracing
</title>
6648 <indexterm zone=
"dynamic-trace">
6649 <primary>DTrace
</primary>
6653 <productname>PostgreSQL
</productname> provides facilities to support
6654 dynamic tracing of the database server. This allows an external
6655 utility to be called at specific points in the code and thereby trace
6660 A number of probes or trace points are already inserted into the source
6661 code. These probes are intended to be used by database developers and
6662 administrators. By default the probes are not compiled into
6663 <productname>PostgreSQL
</productname>; the user needs to explicitly tell
6664 the configure script to make the probes available.
6669 <ulink url=
"https://en.wikipedia.org/wiki/DTrace">DTrace
</ulink>
6670 utility is supported, which, at the time of this writing, is available
6671 on Solaris, macOS, FreeBSD, NetBSD, and Oracle Linux. The
6672 <ulink url=
"https://sourceware.org/systemtap/">SystemTap
</ulink> project
6673 for Linux provides a DTrace equivalent and can also be used. Supporting other dynamic
6674 tracing utilities is theoretically possible by changing the definitions for
6675 the macros in
<filename>src/include/utils/probes.h
</filename>.
6678 <sect2 id=
"compiling-for-trace">
6679 <title>Compiling for Dynamic Tracing
</title>
6682 By default, probes are not available, so you will need to
6683 explicitly tell the configure script to make the probes available
6684 in
<productname>PostgreSQL
</productname>. To include DTrace support
6685 specify
<option>--enable-dtrace
</option> to configure. See
<xref
6686 linkend=
"configure-options-devel"/> for further information.
6690 <sect2 id=
"trace-points">
6691 <title>Built-in Probes
</title>
6694 A number of standard probes are provided in the source code,
6695 as shown in
<xref linkend=
"dtrace-probe-point-table"/>;
6696 <xref linkend=
"typedefs-table"/>
6697 shows the types used in the probes. More probes can certainly be
6698 added to enhance
<productname>PostgreSQL
</productname>'s observability.
6701 <table id=
"dtrace-probe-point-table">
6702 <title>Built-in DTrace Probes
</title>
6704 <colspec colname=
"col1" colwidth=
"2*"/>
6705 <colspec colname=
"col2" colwidth=
"3*"/>
6706 <colspec colname=
"col3" colwidth=
"3*"/>
6710 <entry>Parameters
</entry>
6711 <entry>Description
</entry>
6718 <entry><literal>transaction-start
</literal></entry>
6719 <entry><literal>(LocalTransactionId)
</literal></entry>
6720 <entry>Probe that fires at the start of a new transaction.
6721 arg0 is the transaction ID.
</entry>
6724 <entry><literal>transaction-commit
</literal></entry>
6725 <entry><literal>(LocalTransactionId)
</literal></entry>
6726 <entry>Probe that fires when a transaction completes successfully.
6727 arg0 is the transaction ID.
</entry>
6730 <entry><literal>transaction-abort
</literal></entry>
6731 <entry><literal>(LocalTransactionId)
</literal></entry>
6732 <entry>Probe that fires when a transaction completes unsuccessfully.
6733 arg0 is the transaction ID.
</entry>
6736 <entry><literal>query-start
</literal></entry>
6737 <entry><literal>(const char *)
</literal></entry>
6738 <entry>Probe that fires when the processing of a query is started.
6739 arg0 is the query string.
</entry>
6742 <entry><literal>query-done
</literal></entry>
6743 <entry><literal>(const char *)
</literal></entry>
6744 <entry>Probe that fires when the processing of a query is complete.
6745 arg0 is the query string.
</entry>
6748 <entry><literal>query-parse-start
</literal></entry>
6749 <entry><literal>(const char *)
</literal></entry>
6750 <entry>Probe that fires when the parsing of a query is started.
6751 arg0 is the query string.
</entry>
6754 <entry><literal>query-parse-done
</literal></entry>
6755 <entry><literal>(const char *)
</literal></entry>
6756 <entry>Probe that fires when the parsing of a query is complete.
6757 arg0 is the query string.
</entry>
6760 <entry><literal>query-rewrite-start
</literal></entry>
6761 <entry><literal>(const char *)
</literal></entry>
6762 <entry>Probe that fires when the rewriting of a query is started.
6763 arg0 is the query string.
</entry>
6766 <entry><literal>query-rewrite-done
</literal></entry>
6767 <entry><literal>(const char *)
</literal></entry>
6768 <entry>Probe that fires when the rewriting of a query is complete.
6769 arg0 is the query string.
</entry>
6772 <entry><literal>query-plan-start
</literal></entry>
6773 <entry><literal>()
</literal></entry>
6774 <entry>Probe that fires when the planning of a query is started.
</entry>
6777 <entry><literal>query-plan-done
</literal></entry>
6778 <entry><literal>()
</literal></entry>
6779 <entry>Probe that fires when the planning of a query is complete.
</entry>
6782 <entry><literal>query-execute-start
</literal></entry>
6783 <entry><literal>()
</literal></entry>
6784 <entry>Probe that fires when the execution of a query is started.
</entry>
6787 <entry><literal>query-execute-done
</literal></entry>
6788 <entry><literal>()
</literal></entry>
6789 <entry>Probe that fires when the execution of a query is complete.
</entry>
6792 <entry><literal>statement-status
</literal></entry>
6793 <entry><literal>(const char *)
</literal></entry>
6794 <entry>Probe that fires anytime the server process updates its
6795 <structname>pg_stat_activity
</structname>.
<structfield>status
</structfield>.
6796 arg0 is the new status string.
</entry>
6799 <entry><literal>checkpoint-start
</literal></entry>
6800 <entry><literal>(int)
</literal></entry>
6801 <entry>Probe that fires when a checkpoint is started.
6802 arg0 holds the bitwise flags used to distinguish different checkpoint
6803 types, such as shutdown, immediate or force.
</entry>
6806 <entry><literal>checkpoint-done
</literal></entry>
6807 <entry><literal>(int, int, int, int, int)
</literal></entry>
6808 <entry>Probe that fires when a checkpoint is complete.
6809 (The probes listed next fire in sequence during checkpoint processing.)
6810 arg0 is the number of buffers written. arg1 is the total number of
6811 buffers. arg2, arg3 and arg4 contain the number of WAL files added,
6812 removed and recycled respectively.
</entry>
6815 <entry><literal>clog-checkpoint-start
</literal></entry>
6816 <entry><literal>(bool)
</literal></entry>
6817 <entry>Probe that fires when the CLOG portion of a checkpoint is started.
6818 arg0 is true for normal checkpoint, false for shutdown
6822 <entry><literal>clog-checkpoint-done
</literal></entry>
6823 <entry><literal>(bool)
</literal></entry>
6824 <entry>Probe that fires when the CLOG portion of a checkpoint is
6825 complete. arg0 has the same meaning as for
<literal>clog-checkpoint-start
</literal>.
</entry>
6828 <entry><literal>subtrans-checkpoint-start
</literal></entry>
6829 <entry><literal>(bool)
</literal></entry>
6830 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
6832 arg0 is true for normal checkpoint, false for shutdown
6836 <entry><literal>subtrans-checkpoint-done
</literal></entry>
6837 <entry><literal>(bool)
</literal></entry>
6838 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
6839 complete. arg0 has the same meaning as for
6840 <literal>subtrans-checkpoint-start
</literal>.
</entry>
6843 <entry><literal>multixact-checkpoint-start
</literal></entry>
6844 <entry><literal>(bool)
</literal></entry>
6845 <entry>Probe that fires when the MultiXact portion of a checkpoint is
6847 arg0 is true for normal checkpoint, false for shutdown
6851 <entry><literal>multixact-checkpoint-done
</literal></entry>
6852 <entry><literal>(bool)
</literal></entry>
6853 <entry>Probe that fires when the MultiXact portion of a checkpoint is
6854 complete. arg0 has the same meaning as for
6855 <literal>multixact-checkpoint-start
</literal>.
</entry>
6858 <entry><literal>buffer-checkpoint-start
</literal></entry>
6859 <entry><literal>(int)
</literal></entry>
6860 <entry>Probe that fires when the buffer-writing portion of a checkpoint
6862 arg0 holds the bitwise flags used to distinguish different checkpoint
6863 types, such as shutdown, immediate or force.
</entry>
6866 <entry><literal>buffer-sync-start
</literal></entry>
6867 <entry><literal>(int, int)
</literal></entry>
6868 <entry>Probe that fires when we begin to write dirty buffers during
6869 checkpoint (after identifying which buffers must be written).
6870 arg0 is the total number of buffers.
6871 arg1 is the number that are currently dirty and need to be written.
</entry>
6874 <entry><literal>buffer-sync-written
</literal></entry>
6875 <entry><literal>(int)
</literal></entry>
6876 <entry>Probe that fires after each buffer is written during checkpoint.
6877 arg0 is the ID number of the buffer.
</entry>
6880 <entry><literal>buffer-sync-done
</literal></entry>
6881 <entry><literal>(int, int, int)
</literal></entry>
6882 <entry>Probe that fires when all dirty buffers have been written.
6883 arg0 is the total number of buffers.
6884 arg1 is the number of buffers actually written by the checkpoint process.
6885 arg2 is the number that were expected to be written (arg1 of
6886 <literal>buffer-sync-start
</literal>); any difference reflects other processes flushing
6887 buffers during the checkpoint.
</entry>
6890 <entry><literal>buffer-checkpoint-sync-start
</literal></entry>
6891 <entry><literal>()
</literal></entry>
6892 <entry>Probe that fires after dirty buffers have been written to the
6893 kernel, and before starting to issue fsync requests.
</entry>
6896 <entry><literal>buffer-checkpoint-done
</literal></entry>
6897 <entry><literal>()
</literal></entry>
6898 <entry>Probe that fires when syncing of buffers to disk is
6902 <entry><literal>twophase-checkpoint-start
</literal></entry>
6903 <entry><literal>()
</literal></entry>
6904 <entry>Probe that fires when the two-phase portion of a checkpoint is
6908 <entry><literal>twophase-checkpoint-done
</literal></entry>
6909 <entry><literal>()
</literal></entry>
6910 <entry>Probe that fires when the two-phase portion of a checkpoint is
6914 <entry><literal>buffer-extend-start
</literal></entry>
6915 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, unsigned int)
</literal></entry>
6916 <entry>Probe that fires when a relation extension starts.
6917 arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
6918 tablespace, database, and relation OIDs identifying the relation. arg4
6919 is the ID of the backend which created the temporary relation for a
6920 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared
6921 buffer. arg5 is the number of blocks the caller would like to extend
6925 <entry><literal>buffer-extend-done
</literal></entry>
6926 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, unsigned int, BlockNumber)
</literal></entry>
6927 <entry>Probe that fires when a relation extension is complete.
6928 arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
6929 tablespace, database, and relation OIDs identifying the relation. arg4
6930 is the ID of the backend which created the temporary relation for a
6931 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared
6932 buffer. arg5 is the number of blocks the relation was extended by, this
6933 can be less than the number in the
6934 <literal>buffer-extend-start
</literal> due to resource
6935 constraints. arg6 contains the BlockNumber of the first new
6939 <entry><literal>buffer-read-start
</literal></entry>
6940 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
6941 <entry>Probe that fires when a buffer read is started.
6942 arg0 and arg1 contain the fork and block numbers of the page.
6943 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
6944 identifying the relation.
6945 arg5 is the ID of the backend which created the temporary relation for a
6946 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
6950 <entry><literal>buffer-read-done
</literal></entry>
6951 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool)
</literal></entry>
6952 <entry>Probe that fires when a buffer read is complete.
6953 arg0 and arg1 contain the fork and block numbers of the page.
6954 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
6955 identifying the relation.
6956 arg5 is the ID of the backend which created the temporary relation for a
6957 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
6958 arg6 is true if the buffer was found in the pool, false if not.
</entry>
6961 <entry><literal>buffer-flush-start
</literal></entry>
6962 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)
</literal></entry>
6963 <entry>Probe that fires before issuing any write request for a shared
6965 arg0 and arg1 contain the fork and block numbers of the page.
6966 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
6967 identifying the relation.
</entry>
6970 <entry><literal>buffer-flush-done
</literal></entry>
6971 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)
</literal></entry>
6972 <entry>Probe that fires when a write request is complete. (Note
6973 that this just reflects the time to pass the data to the kernel;
6974 it's typically not actually been written to disk yet.)
6975 The arguments are the same as for
<literal>buffer-flush-start
</literal>.
</entry>
6978 <entry><literal>wal-buffer-write-dirty-start
</literal></entry>
6979 <entry><literal>()
</literal></entry>
6980 <entry>Probe that fires when a server process begins to write a
6981 dirty WAL buffer because no more WAL buffer space is available.
6982 (If this happens often, it implies that
6983 <xref linkend=
"guc-wal-buffers"/> is too small.)
</entry>
6986 <entry><literal>wal-buffer-write-dirty-done
</literal></entry>
6987 <entry><literal>()
</literal></entry>
6988 <entry>Probe that fires when a dirty WAL buffer write is complete.
</entry>
6991 <entry><literal>wal-insert
</literal></entry>
6992 <entry><literal>(unsigned char, unsigned char)
</literal></entry>
6993 <entry>Probe that fires when a WAL record is inserted.
6994 arg0 is the resource manager (rmid) for the record.
6995 arg1 contains the info flags.
</entry>
6998 <entry><literal>wal-switch
</literal></entry>
6999 <entry><literal>()
</literal></entry>
7000 <entry>Probe that fires when a WAL segment switch is requested.
</entry>
7003 <entry><literal>smgr-md-read-start
</literal></entry>
7004 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
7005 <entry>Probe that fires when beginning to read a block from a relation.
7006 arg0 and arg1 contain the fork and block numbers of the page.
7007 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7008 identifying the relation.
7009 arg5 is the ID of the backend which created the temporary relation for a
7010 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
</entry>
7013 <entry><literal>smgr-md-read-done
</literal></entry>
7014 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)
</literal></entry>
7015 <entry>Probe that fires when a block read is complete.
7016 arg0 and arg1 contain the fork and block numbers of the page.
7017 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7018 identifying the relation.
7019 arg5 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 buffer.
7021 arg6 is the number of bytes actually read, while arg7 is the number
7022 requested (if these are different it indicates a short read).
</entry>
7025 <entry><literal>smgr-md-write-start
</literal></entry>
7026 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)
</literal></entry>
7027 <entry>Probe that fires when beginning to write a block to a relation.
7028 arg0 and arg1 contain the fork and block numbers of the page.
7029 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7030 identifying the relation.
7031 arg5 is the ID of the backend which created the temporary relation for a
7032 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
</entry>
7035 <entry><literal>smgr-md-write-done
</literal></entry>
7036 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)
</literal></entry>
7037 <entry>Probe that fires when a block write is complete.
7038 arg0 and arg1 contain the fork and block numbers of the page.
7039 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
7040 identifying the relation.
7041 arg5 is the ID of the backend which created the temporary relation for a
7042 local buffer, or
<symbol>INVALID_PROC_NUMBER
</symbol> (-
1) for a shared buffer.
7043 arg6 is the number of bytes actually written, while arg7 is the number
7044 requested (if these are different it indicates a short write).
</entry>
7047 <entry><literal>sort-start
</literal></entry>
7048 <entry><literal>(int, bool, int, int, bool, int)
</literal></entry>
7049 <entry>Probe that fires when a sort operation is started.
7050 arg0 indicates heap, index or datum sort.
7051 arg1 is true for unique-value enforcement.
7052 arg2 is the number of key columns.
7053 arg3 is the number of kilobytes of work memory allowed.
7054 arg4 is true if random access to the sort result is required.
7055 arg5 indicates serial when
<literal>0</literal>, parallel worker when
7056 <literal>1</literal>, or parallel leader when
<literal>2</literal>.
</entry>
7059 <entry><literal>sort-done
</literal></entry>
7060 <entry><literal>(bool, long)
</literal></entry>
7061 <entry>Probe that fires when a sort is complete.
7062 arg0 is true for external sort, false for internal sort.
7063 arg1 is the number of disk blocks used for an external sort,
7064 or kilobytes of memory used for an internal sort.
</entry>
7067 <entry><literal>lwlock-acquire
</literal></entry>
7068 <entry><literal>(char *, LWLockMode)
</literal></entry>
7069 <entry>Probe that fires when an LWLock has been acquired.
7070 arg0 is the LWLock's tranche.
7071 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7074 <entry><literal>lwlock-release
</literal></entry>
7075 <entry><literal>(char *)
</literal></entry>
7076 <entry>Probe that fires when an LWLock has been released (but note
7077 that any released waiters have not yet been awakened).
7078 arg0 is the LWLock's tranche.
</entry>
7081 <entry><literal>lwlock-wait-start
</literal></entry>
7082 <entry><literal>(char *, LWLockMode)
</literal></entry>
7083 <entry>Probe that fires when an LWLock was not immediately available and
7084 a server process has begun to wait for the lock to become available.
7085 arg0 is the LWLock's tranche.
7086 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7089 <entry><literal>lwlock-wait-done
</literal></entry>
7090 <entry><literal>(char *, LWLockMode)
</literal></entry>
7091 <entry>Probe that fires when a server process has been released from its
7092 wait for an LWLock (it does not actually have the lock yet).
7093 arg0 is the LWLock's tranche.
7094 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7097 <entry><literal>lwlock-condacquire
</literal></entry>
7098 <entry><literal>(char *, LWLockMode)
</literal></entry>
7099 <entry>Probe that fires when an LWLock was successfully acquired when the
7100 caller specified no waiting.
7101 arg0 is the LWLock's tranche.
7102 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7105 <entry><literal>lwlock-condacquire-fail
</literal></entry>
7106 <entry><literal>(char *, LWLockMode)
</literal></entry>
7107 <entry>Probe that fires when an LWLock was not successfully acquired when
7108 the caller specified no waiting.
7109 arg0 is the LWLock's tranche.
7110 arg1 is the requested lock mode, either exclusive or shared.
</entry>
7113 <entry><literal>lock-wait-start
</literal></entry>
7114 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)
</literal></entry>
7115 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
7116 has begun to wait because the lock is not available.
7117 arg0 through arg3 are the tag fields identifying the object being
7118 locked. arg4 indicates the type of object being locked.
7119 arg5 indicates the lock type being requested.
</entry>
7122 <entry><literal>lock-wait-done
</literal></entry>
7123 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)
</literal></entry>
7124 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
7125 has finished waiting (i.e., has acquired the lock).
7126 The arguments are the same as for
<literal>lock-wait-start
</literal>.
</entry>
7129 <entry><literal>deadlock-found
</literal></entry>
7130 <entry><literal>()
</literal></entry>
7131 <entry>Probe that fires when a deadlock is found by the deadlock
7139 <table id=
"typedefs-table">
7140 <title>Defined Types Used in Probe Parameters
</title>
7145 <entry>Definition
</entry>
7152 <entry><type>LocalTransactionId
</type></entry>
7153 <entry><type>unsigned int
</type></entry>
7156 <entry><type>LWLockMode
</type></entry>
7157 <entry><type>int
</type></entry>
7160 <entry><type>LOCKMODE
</type></entry>
7161 <entry><type>int
</type></entry>
7164 <entry><type>BlockNumber
</type></entry>
7165 <entry><type>unsigned int
</type></entry>
7168 <entry><type>Oid
</type></entry>
7169 <entry><type>unsigned int
</type></entry>
7172 <entry><type>ForkNumber
</type></entry>
7173 <entry><type>int
</type></entry>
7176 <entry><type>bool
</type></entry>
7177 <entry><type>unsigned char
</type></entry>
7187 <sect2 id=
"using-trace-points">
7188 <title>Using Probes
</title>
7191 The example below shows a DTrace script for analyzing transaction
7192 counts in the system, as an alternative to snapshotting
7193 <structname>pg_stat_database
</structname> before and after a performance test:
7195 #!/usr/sbin/dtrace -qs
7197 postgresql$
1:::transaction-start
7199 @start[
"Start"] = count();
7200 self-
>ts = timestamp;
7203 postgresql$
1:::transaction-abort
7205 @abort[
"Abort"] = count();
7208 postgresql$
1:::transaction-commit
7211 @commit[
"Commit"] = count();
7212 @time[
"Total time (ns)"] = sum(timestamp - self-
>ts);
7216 When executed, the example D script gives output such as:
7218 # ./txn_count.d `pgrep -n postgres` or ./txn_count.d
<PID
>
7223 Total time (ns)
2312105013
7229 SystemTap uses a different notation for trace scripts than DTrace does,
7230 even though the underlying trace points are compatible. One point worth
7231 noting is that at this writing, SystemTap scripts must reference probe
7232 names using double underscores in place of hyphens. This is expected to
7233 be fixed in future SystemTap releases.
7238 You should remember that DTrace scripts need to be carefully written and
7239 debugged, otherwise the trace information collected might
7240 be meaningless. In most cases where problems are found it is the
7241 instrumentation that is at fault, not the underlying system. When
7242 discussing information found using dynamic tracing, be sure to enclose
7243 the script used to allow that too to be checked and discussed.
7247 <sect2 id=
"defining-trace-points">
7248 <title>Defining New Probes
</title>
7251 New probes can be defined within the code wherever the developer
7252 desires, though this will require a recompilation. Below are the steps
7253 for inserting new probes:
7259 Decide on probe names and data to be made available through the probes
7265 Add the probe definitions to
<filename>src/backend/utils/probes.d
</filename>
7271 Include
<filename>pg_trace.h
</filename> if it is not already present in the
7272 module(s) containing the probe points, and insert
7273 <literal>TRACE_POSTGRESQL
</literal> probe macros at the desired locations
7280 Recompile and verify that the new probes are available
7286 <title>Example:
</title>
7288 Here is an example of how you would add a probe to trace all new
7289 transactions by transaction ID.
7296 Decide that the probe will be named
<literal>transaction-start
</literal> and
7297 requires a parameter of type
<type>LocalTransactionId
</type>
7303 Add the probe definition to
<filename>src/backend/utils/probes.d
</filename>:
7305 probe transaction__start(LocalTransactionId);
7307 Note the use of the double underline in the probe name. In a DTrace
7308 script using the probe, the double underline needs to be replaced with a
7309 hyphen, so
<literal>transaction-start
</literal> is the name to document for
7316 At compile time,
<literal>transaction__start
</literal> is converted to a macro
7317 called
<literal>TRACE_POSTGRESQL_TRANSACTION_START
</literal> (notice the
7318 underscores are single here), which is available by including
7319 <filename>pg_trace.h
</filename>. Add the macro call to the appropriate location
7320 in the source code. In this case, it looks like the following:
7323 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
7330 After recompiling and running the new binary, check that your newly added
7331 probe is available by executing the following DTrace command. You
7332 should see similar output:
7334 # dtrace -ln transaction-start
7335 ID PROVIDER MODULE FUNCTION NAME
7336 18705 postgresql49878 postgres StartTransactionCommand transaction-start
7337 18755 postgresql49877 postgres StartTransactionCommand transaction-start
7338 18805 postgresql49876 postgres StartTransactionCommand transaction-start
7339 18855 postgresql49875 postgres StartTransactionCommand transaction-start
7340 18986 postgresql49873 postgres StartTransactionCommand transaction-start
7347 There are a few things to be careful about when adding trace macros
7353 You should take care that the data types specified for a probe's
7354 parameters match the data types of the variables used in the macro.
7355 Otherwise, you will get compilation errors.
7362 On most platforms, if
<productname>PostgreSQL
</productname> is
7363 built with
<option>--enable-dtrace
</option>, the arguments to a trace
7364 macro will be evaluated whenever control passes through the
7365 macro,
<emphasis>even if no tracing is being done
</emphasis>. This is
7366 usually not worth worrying about if you are just reporting the
7367 values of a few local variables. But beware of putting expensive
7368 function calls into the arguments. If you need to do that,
7369 consider protecting the macro with a check to see if the trace
7370 is actually enabled:
7373 if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
7374 TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
7377 Each trace macro has a corresponding
<literal>ENABLED
</literal> macro.
7388 <sect1 id=
"diskusage">
7389 <title>Monitoring Disk Usage
</title>
7392 This section discusses how to monitor the disk usage of a
7393 <productname>PostgreSQL
</productname> database system.
7396 <sect2 id=
"disk-usage">
7397 <title>Determining Disk Usage
</title>
7399 <indexterm zone=
"disk-usage">
7400 <primary>disk usage
</primary>
7404 Each table has a primary heap disk file where most of the data is
7405 stored. If the table has any columns with potentially-wide values,
7406 there also might be a
<acronym>TOAST
</acronym> file associated with the table,
7407 which is used to store values too wide to fit comfortably in the main
7408 table (see
<xref linkend=
"storage-toast"/>). There will be one valid index
7409 on the
<acronym>TOAST
</acronym> table, if present. There also might be indexes
7410 associated with the base table. Each table and index is stored in a
7411 separate disk file
— possibly more than one file, if the file would
7412 exceed one gigabyte. Naming conventions for these files are described
7413 in
<xref linkend=
"storage-file-layout"/>.
7417 You can monitor disk space in three ways:
7418 using the SQL functions listed in
<xref linkend=
"functions-admin-dbsize"/>,
7419 using the
<xref linkend=
"oid2name"/> module, or
7420 using manual inspection of the system catalogs.
7421 The SQL functions are the easiest to use and are generally recommended.
7422 The remainder of this section shows how to do it by inspection of the
7427 Using
<application>psql
</application> on a recently vacuumed or analyzed
7428 database, you can issue queries to see the disk usage of any table:
7430 SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';
7432 pg_relation_filepath | relpages
7433 ----------------------+----------
7434 base/
16384/
16806 |
60
7437 Each page is typically
8 kilobytes. (Remember,
<structfield>relpages
</structfield>
7438 is only updated by
<command>VACUUM
</command>,
<command>ANALYZE
</command>, and
7439 a few DDL commands such as
<command>CREATE INDEX
</command>.) The file path name
7440 is of interest if you want to examine the table's disk file directly.
7444 To show the space used by
<acronym>TOAST
</acronym> tables, use a query
7447 SELECT relname, relpages
7449 (SELECT reltoastrelid
7451 WHERE relname = 'customer') AS ss
7452 WHERE oid = ss.reltoastrelid OR
7453 oid = (SELECT indexrelid
7455 WHERE indrelid = ss.reltoastrelid)
7459 ----------------------+----------
7461 pg_toast_16806_index |
1
7466 You can easily display index sizes, too:
7468 SELECT c2.relname, c2.relpages
7469 FROM pg_class c, pg_class c2, pg_index i
7470 WHERE c.relname = 'customer' AND
7471 c.oid = i.indrelid AND
7472 c2.oid = i.indexrelid
7473 ORDER BY c2.relname;
7476 -------------------+----------
7477 customer_id_index |
26
7482 It is easy to find your largest tables and indexes using this
7485 SELECT relname, relpages
7487 ORDER BY relpages DESC;
7490 ----------------------+----------
7497 <sect2 id=
"disk-full">
7498 <title>Disk Full Failure
</title>
7501 The most important disk monitoring task of a database administrator
7502 is to make sure the disk doesn't become full. A filled data disk will
7503 not result in data corruption, but it might prevent useful activity
7504 from occurring. If the disk holding the WAL files grows full, database
7505 server panic and consequent shutdown might occur.
7509 If you cannot free up additional space on the disk by deleting
7510 other things, you can move some of the database files to other file
7511 systems by making use of tablespaces. See
<xref
7512 linkend=
"manage-ag-tablespaces"/> for more information about that.
7517 Some file systems perform badly when they are almost full, so do
7518 not wait until the disk is completely full to take action.
7523 If your system supports per-user disk quotas, then the database
7524 will naturally be subject to whatever quota is placed on the user
7525 the server runs as. Exceeding the quota will have the same bad
7526 effects as running out of disk space entirely.