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 statistics collector,
26 but one should not neglect regular Unix monitoring programs such as
27 <command>ps</command>, <command>top</command>, <command>iostat</command>, and <command>vmstat</command>.
28 Also, once one has identified a
29 poorly-performing query, further investigation might be needed using
30 <productname>PostgreSQL</productname>'s <xref linkend="sql-explain"/> command.
31 <xref linkend="using-explain"/> discusses <command>EXPLAIN</command>
32 and other methods for understanding the behavior of an individual
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 15558 0.0 0.0 17512 1068 ? Ss 18:02 0:00 postgres: stats collector
57 postgres 15582 0.0 0.0 58772 3080 ? Ss 18:04 0:00 postgres: joe runbug 127.0.0.1 idle
58 postgres 15606 0.0 0.0 58772 3052 ? Ss 18:07 0:00 postgres: tgl regression [local] SELECT waiting
59 postgres 15610 0.0 0.0 58772 3056 ? Ss 18:07 0:00 postgres: tgl regression [local] idle in transaction
62 (The appropriate invocation of <command>ps</command> varies across different
63 platforms, as do the details of what is shown. This example is from a
64 recent Linux system.) The first process listed here is the
65 master server process. The command arguments
66 shown for it are the same ones used when it was launched. The next five
67 processes are background worker processes automatically launched by the
68 master process. (The <quote>stats collector</quote> process will not be present
69 if you have set the system not to start the statistics collector; likewise
70 the <quote>autovacuum launcher</quote> process can be disabled.)
72 processes is a server process handling one client connection. Each such
73 process sets its command line display in the form
76 postgres: <replaceable>user</replaceable> <replaceable>database</replaceable> <replaceable>host</replaceable> <replaceable>activity</replaceable>
79 The user, database, and (client) host items remain the same for
80 the life of the client connection, but the activity indicator changes.
81 The activity can be <literal>idle</literal> (i.e., waiting for a client command),
82 <literal>idle in transaction</literal> (waiting for client inside a <command>BEGIN</command> block),
83 or a command type name such as <literal>SELECT</literal>. Also,
84 <literal>waiting</literal> is appended if the server process is presently waiting
85 on a lock held by another session. In the above example we can infer
86 that process 15606 is waiting for process 15610 to complete its transaction
87 and thereby release some lock. (Process 15610 must be the blocker, because
88 there is no other active session. In more complicated cases it would be
89 necessary to look into the
90 <link linkend="view-pg-locks"><structname>pg_locks</structname></link>
91 system view to determine who is blocking whom.)
95 If <xref linkend="guc-cluster-name"/> has been configured the
96 cluster name will also be shown in <command>ps</command> output:
98 $ psql -c 'SHOW cluster_name'
104 $ ps aux|grep server1
105 postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: server1: background writer
111 If you have turned off <xref linkend="guc-update-process-title"/> then the
112 activity indicator is not updated; the process title is set only once
113 when a new process is launched. On some platforms this saves a measurable
114 amount of per-command overhead; on others it's insignificant.
119 <productname>Solaris</productname> requires special handling. You must
120 use <command>/usr/ucb/ps</command>, rather than
121 <command>/bin/ps</command>. You also must use two <option>w</option>
122 flags, not just one. In addition, your original invocation of the
123 <command>postgres</command> command must have a shorter
124 <command>ps</command> status display than that provided by each
125 server process. If you fail to do all three things, the <command>ps</command>
126 output for each server process will be the original <command>postgres</command>
132 <sect1 id="monitoring-stats">
133 <title>The Statistics Collector</title>
135 <indexterm zone="monitoring-stats">
136 <primary>statistics</primary>
140 <productname>PostgreSQL</productname>'s <firstterm>statistics collector</firstterm>
141 is a subsystem that supports collection and reporting of information about
142 server activity. Presently, the collector can count accesses to tables
143 and indexes in both disk-block and individual-row terms. It also tracks
144 the total number of rows in each table, and information about vacuum and
145 analyze actions for each table. It can also count calls to user-defined
146 functions and the total time spent in each one.
150 <productname>PostgreSQL</productname> also supports reporting dynamic
151 information about exactly what is going on in the system right now, such as
152 the exact command currently being executed by other server processes, and
153 which other connections exist in the system. This facility is independent
154 of the collector process.
157 <sect2 id="monitoring-stats-setup">
158 <title>Statistics Collection Configuration</title>
161 Since collection of statistics adds some overhead to query execution,
162 the system can be configured to collect or not collect information.
163 This is controlled by configuration parameters that are normally set in
164 <filename>postgresql.conf</filename>. (See <xref linkend="runtime-config"/> for
165 details about setting configuration parameters.)
169 The parameter <xref linkend="guc-track-activities"/> enables monitoring
170 of the current command being executed by any server process.
174 The parameter <xref linkend="guc-track-counts"/> controls whether
175 statistics are collected about table and index accesses.
179 The parameter <xref linkend="guc-track-functions"/> enables tracking of
180 usage of user-defined functions.
184 The parameter <xref linkend="guc-track-io-timing"/> enables monitoring
185 of block read and write times.
189 Normally these parameters are set in <filename>postgresql.conf</filename> so
190 that they apply to all server processes, but it is possible to turn
191 them on or off in individual sessions using the <xref
192 linkend="sql-set"/> command. (To prevent
193 ordinary users from hiding their activity from the administrator,
194 only superusers are allowed to change these parameters with
195 <command>SET</command>.)
199 The statistics collector transmits the collected information to other
200 <productname>PostgreSQL</productname> processes through temporary files.
201 These files are stored in the directory named by the
202 <xref linkend="guc-stats-temp-directory"/> parameter,
203 <filename>pg_stat_tmp</filename> by default.
204 For better performance, <varname>stats_temp_directory</varname> can be
205 pointed at a RAM-based file system, decreasing physical I/O requirements.
206 When the server shuts down cleanly, a permanent copy of the statistics
207 data is stored in the <filename>pg_stat</filename> subdirectory, so that
208 statistics can be retained across server restarts. When recovery is
209 performed at server start (e.g. after immediate shutdown, server crash,
210 and point-in-time recovery), all statistics counters are reset.
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 results
224 of statistics collection. Alternatively, one can
225 build custom views using the underlying statistics functions, as discussed
226 in <xref linkend="monitoring-stats-functions"/>.
230 When using the statistics to monitor collected data, it is important
231 to realize that the information does not update instantaneously.
232 Each individual server process transmits new statistical counts to
233 the collector just before going idle; so a query or transaction still in
234 progress does not affect the displayed totals. Also, the collector itself
235 emits a new report at most once per <varname>PGSTAT_STAT_INTERVAL</varname>
236 milliseconds (500 ms unless altered while building the server). So the
237 displayed information lags behind actual activity. However, current-query
238 information collected by <varname>track_activities</varname> is
243 Another important point is that when a server process is asked to display
244 any of these statistics, it first fetches the most recent report emitted by
245 the collector process and then continues to use this snapshot for all
246 statistical views and functions until the end of its current transaction.
247 So the statistics will show static information as long as you continue the
248 current transaction. Similarly, information about the current queries of
249 all sessions is collected when any such information is first requested
250 within a transaction, and the same information will be displayed throughout
252 This is a feature, not a bug, because it allows you to perform several
253 queries on the statistics and correlate the results without worrying that
254 the numbers are changing underneath you. But if you want to see new
255 results with each query, be sure to do the queries outside any transaction
256 block. Alternatively, you can invoke
257 <function>pg_stat_clear_snapshot</function>(), which will discard the
258 current transaction's statistics snapshot (if any). The next use of
259 statistical information will cause a new snapshot to be fetched.
263 A transaction can also see its own statistics (as yet untransmitted to the
264 collector) in the views <structname>pg_stat_xact_all_tables</structname>,
265 <structname>pg_stat_xact_sys_tables</structname>,
266 <structname>pg_stat_xact_user_tables</structname>, and
267 <structname>pg_stat_xact_user_functions</structname>. These numbers do not act as
268 stated above; instead they update continuously throughout the transaction.
272 Some of the information in the dynamic statistics views shown in <xref
273 linkend="monitoring-stats-dynamic-views-table"/> is security restricted.
274 Ordinary users can only see all the information about their own sessions
275 (sessions belonging to a role that they are a member of). In rows about
276 other sessions, many columns will be null. Note, however, that the
277 existence of a session and its general properties such as its sessions user
278 and database are visible to all users. Superusers and members of the
279 built-in role <literal>pg_read_all_stats</literal> (see also <xref
280 linkend="default-roles"/>) can see all the information about all sessions.
283 <table id="monitoring-stats-dynamic-views-table">
284 <title>Dynamic Statistics Views</title>
289 <entry>View Name</entry>
290 <entry>Description</entry>
297 <structname>pg_stat_activity</structname>
298 <indexterm><primary>pg_stat_activity</primary></indexterm>
301 One row per server process, showing information related to
302 the current activity of that process, such as state and current query.
303 See <xref linkend="pg-stat-activity-view"/> for details.
308 <entry><structname>pg_stat_replication</structname><indexterm><primary>pg_stat_replication</primary></indexterm></entry>
309 <entry>One row per WAL sender process, showing statistics about
310 replication to that sender's connected standby server.
311 See <xref linkend="pg-stat-replication-view"/> for details.
316 <entry><structname>pg_stat_wal_receiver</structname><indexterm><primary>pg_stat_wal_receiver</primary></indexterm></entry>
317 <entry>Only one row, showing statistics about the WAL receiver from
318 that receiver's connected server.
319 See <xref linkend="pg-stat-wal-receiver-view"/> for details.
324 <entry><structname>pg_stat_subscription</structname><indexterm><primary>pg_stat_subscription</primary></indexterm></entry>
325 <entry>At least one row per subscription, showing information about
326 the subscription workers.
327 See <xref linkend="pg-stat-subscription"/> for details.
332 <entry><structname>pg_stat_ssl</structname><indexterm><primary>pg_stat_ssl</primary></indexterm></entry>
333 <entry>One row per connection (regular and replication), showing information about
334 SSL used on this connection.
335 See <xref linkend="pg-stat-ssl-view"/> for details.
340 <entry><structname>pg_stat_progress_create_index</structname><indexterm><primary>pg_stat_progress_create_index</primary></indexterm></entry>
341 <entry>One row for each backend running <command>CREATE INDEX</command>, showing
343 See <xref linkend='create-index-progress-reporting'/>.
348 <entry><structname>pg_stat_progress_vacuum</structname><indexterm><primary>pg_stat_progress_vacuum</primary></indexterm></entry>
349 <entry>One row for each backend (including autovacuum worker processes) running
350 <command>VACUUM</command>, showing current progress.
351 See <xref linkend='vacuum-progress-reporting'/>.
356 <entry><structname>pg_stat_progress_cluster</structname><indexterm><primary>pg_stat_progress_cluster</primary></indexterm></entry>
357 <entry>One row for each backend running
358 <command>CLUSTER</command> or <command>VACUUM FULL</command>, showing current progress.
359 See <xref linkend='cluster-progress-reporting'/>.
367 <table id="monitoring-stats-views-table">
368 <title>Collected Statistics Views</title>
373 <entry>View Name</entry>
374 <entry>Description</entry>
380 <entry><structname>pg_stat_archiver</structname><indexterm><primary>pg_stat_archiver</primary></indexterm></entry>
381 <entry>One row only, showing statistics about the
382 WAL archiver process's activity. See
383 <xref linkend="pg-stat-archiver-view"/> for details.
388 <entry><structname>pg_stat_bgwriter</structname><indexterm><primary>pg_stat_bgwriter</primary></indexterm></entry>
389 <entry>One row only, showing statistics about the
390 background writer process's activity. See
391 <xref linkend="pg-stat-bgwriter-view"/> for details.
396 <entry><structname>pg_stat_database</structname><indexterm><primary>pg_stat_database</primary></indexterm></entry>
397 <entry>One row per database, showing database-wide statistics. See
398 <xref linkend="pg-stat-database-view"/> for details.
403 <entry><structname>pg_stat_database_conflicts</structname><indexterm><primary>pg_stat_database_conflicts</primary></indexterm></entry>
405 One row per database, showing database-wide statistics about
406 query cancels due to conflict with recovery on standby servers.
407 See <xref linkend="pg-stat-database-conflicts-view"/> for details.
412 <entry><structname>pg_stat_all_tables</structname><indexterm><primary>pg_stat_all_tables</primary></indexterm></entry>
414 One row for each table in the current database, showing statistics
415 about accesses to that specific table.
416 See <xref linkend="pg-stat-all-tables-view"/> for details.
421 <entry><structname>pg_stat_sys_tables</structname><indexterm><primary>pg_stat_sys_tables</primary></indexterm></entry>
422 <entry>Same as <structname>pg_stat_all_tables</structname>, except that only
423 system tables are shown.</entry>
427 <entry><structname>pg_stat_user_tables</structname><indexterm><primary>pg_stat_user_tables</primary></indexterm></entry>
428 <entry>Same as <structname>pg_stat_all_tables</structname>, except that only user
429 tables are shown.</entry>
433 <entry><structname>pg_stat_xact_all_tables</structname><indexterm><primary>pg_stat_xact_all_tables</primary></indexterm></entry>
434 <entry>Similar to <structname>pg_stat_all_tables</structname>, but counts actions
435 taken so far within the current transaction (which are <emphasis>not</emphasis>
436 yet included in <structname>pg_stat_all_tables</structname> and related views).
437 The columns for numbers of live and dead rows and vacuum and
438 analyze actions are not present in this view.</entry>
442 <entry><structname>pg_stat_xact_sys_tables</structname><indexterm><primary>pg_stat_xact_sys_tables</primary></indexterm></entry>
443 <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
444 system tables are shown.</entry>
448 <entry><structname>pg_stat_xact_user_tables</structname><indexterm><primary>pg_stat_xact_user_tables</primary></indexterm></entry>
449 <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
450 user tables are shown.</entry>
454 <entry><structname>pg_stat_all_indexes</structname><indexterm><primary>pg_stat_all_indexes</primary></indexterm></entry>
456 One row for each index in the current database, showing statistics
457 about accesses to that specific index.
458 See <xref linkend="pg-stat-all-indexes-view"/> for details.
463 <entry><structname>pg_stat_sys_indexes</structname><indexterm><primary>pg_stat_sys_indexes</primary></indexterm></entry>
464 <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
465 indexes on system tables are shown.</entry>
469 <entry><structname>pg_stat_user_indexes</structname><indexterm><primary>pg_stat_user_indexes</primary></indexterm></entry>
470 <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
471 indexes on user tables are shown.</entry>
475 <entry><structname>pg_statio_all_tables</structname><indexterm><primary>pg_statio_all_tables</primary></indexterm></entry>
477 One row for each table in the current database, showing statistics
478 about I/O on that specific table.
479 See <xref linkend="pg-statio-all-tables-view"/> for details.
484 <entry><structname>pg_statio_sys_tables</structname><indexterm><primary>pg_statio_sys_tables</primary></indexterm></entry>
485 <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
486 system tables are shown.</entry>
490 <entry><structname>pg_statio_user_tables</structname><indexterm><primary>pg_statio_user_tables</primary></indexterm></entry>
491 <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
492 user tables are shown.</entry>
496 <entry><structname>pg_statio_all_indexes</structname><indexterm><primary>pg_statio_all_indexes</primary></indexterm></entry>
498 One row for each index in the current database,
499 showing statistics about I/O on that specific index.
500 See <xref linkend="pg-statio-all-indexes-view"/> for details.
505 <entry><structname>pg_statio_sys_indexes</structname><indexterm><primary>pg_statio_sys_indexes</primary></indexterm></entry>
506 <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
507 indexes on system tables are shown.</entry>
511 <entry><structname>pg_statio_user_indexes</structname><indexterm><primary>pg_statio_user_indexes</primary></indexterm></entry>
512 <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
513 indexes on user tables are shown.</entry>
517 <entry><structname>pg_statio_all_sequences</structname><indexterm><primary>pg_statio_all_sequences</primary></indexterm></entry>
519 One row for each sequence in the current database,
520 showing statistics about I/O on that specific sequence.
521 See <xref linkend="pg-statio-all-sequences-view"/> for details.
526 <entry><structname>pg_statio_sys_sequences</structname><indexterm><primary>pg_statio_sys_sequences</primary></indexterm></entry>
527 <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
528 system sequences are shown. (Presently, no system sequences are defined,
529 so this view is always empty.)</entry>
533 <entry><structname>pg_statio_user_sequences</structname><indexterm><primary>pg_statio_user_sequences</primary></indexterm></entry>
534 <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
535 user sequences are shown.</entry>
539 <entry><structname>pg_stat_user_functions</structname><indexterm><primary>pg_stat_user_functions</primary></indexterm></entry>
541 One row for each tracked function, showing statistics
542 about executions of that function. See
543 <xref linkend="pg-stat-user-functions-view"/> for details.
548 <entry><structname>pg_stat_xact_user_functions</structname><indexterm><primary>pg_stat_xact_user_functions</primary></indexterm></entry>
549 <entry>Similar to <structname>pg_stat_user_functions</structname>, but counts only
550 calls during the current transaction (which are <emphasis>not</emphasis>
551 yet included in <structname>pg_stat_user_functions</structname>).</entry>
559 The per-index statistics are particularly useful to determine which
560 indexes are being used and how effective they are.
564 The <structname>pg_statio_</structname> views are primarily useful to
565 determine the effectiveness of the buffer cache. When the number
566 of actual disk reads is much smaller than the number of buffer
567 hits, then the cache is satisfying most read requests without
568 invoking a kernel call. However, these statistics do not give the
569 entire story: due to the way in which <productname>PostgreSQL</productname>
570 handles disk I/O, data that is not in the
571 <productname>PostgreSQL</productname> buffer cache might still reside in the
572 kernel's I/O cache, and might therefore still be fetched without
573 requiring a physical read. Users interested in obtaining more
574 detailed information on <productname>PostgreSQL</productname> I/O behavior are
575 advised to use the <productname>PostgreSQL</productname> statistics collector
576 in combination with operating system utilities that allow insight
577 into the kernel's handling of I/O.
581 <table id="pg-stat-activity-view" xreflabel="pg_stat_activity">
582 <title><structname>pg_stat_activity</structname> View</title>
587 <entry>Column</entry>
589 <entry>Description</entry>
595 <entry><structfield>datid</structfield></entry>
596 <entry><type>oid</type></entry>
597 <entry>OID of the database this backend is connected to</entry>
600 <entry><structfield>datname</structfield></entry>
601 <entry><type>name</type></entry>
602 <entry>Name of the database this backend is connected to</entry>
605 <entry><structfield>pid</structfield></entry>
606 <entry><type>integer</type></entry>
607 <entry>Process ID of this backend</entry>
610 <entry><structfield>usesysid</structfield></entry>
611 <entry><type>oid</type></entry>
612 <entry>OID of the user logged into this backend</entry>
615 <entry><structfield>usename</structfield></entry>
616 <entry><type>name</type></entry>
617 <entry>Name of the user logged into this backend</entry>
620 <entry><structfield>application_name</structfield></entry>
621 <entry><type>text</type></entry>
622 <entry>Name of the application that is connected
623 to this backend</entry>
626 <entry><structfield>client_addr</structfield></entry>
627 <entry><type>inet</type></entry>
628 <entry>IP address of the client connected to this backend.
629 If this field is null, it indicates either that the client is
630 connected via a Unix socket on the server machine or that this is an
631 internal process such as autovacuum.
635 <entry><structfield>client_hostname</structfield></entry>
636 <entry><type>text</type></entry>
637 <entry>Host name of the connected client, as reported by a
638 reverse DNS lookup of <structfield>client_addr</structfield>. This field will
639 only be non-null for IP connections, and only when <xref
640 linkend="guc-log-hostname"/> is enabled.
644 <entry><structfield>client_port</structfield></entry>
645 <entry><type>integer</type></entry>
646 <entry>TCP port number that the client is using for communication
647 with this backend, or <literal>-1</literal> if a Unix socket is used
651 <entry><structfield>backend_start</structfield></entry>
652 <entry><type>timestamp with time zone</type></entry>
653 <entry>Time when this process was started. For client backends,
654 this is the time the client connected to the server.
658 <entry><structfield>xact_start</structfield></entry>
659 <entry><type>timestamp with time zone</type></entry>
660 <entry>Time when this process' current transaction was started, or null
661 if no transaction is active. If the current
662 query is the first of its transaction, this column is equal to the
663 <structfield>query_start</structfield> column.
667 <entry><structfield>query_start</structfield></entry>
668 <entry><type>timestamp with time zone</type></entry>
669 <entry>Time when the currently active query was started, or if
670 <structfield>state</structfield> is not <literal>active</literal>, when the last query
675 <entry><structfield>state_change</structfield></entry>
676 <entry><type>timestamp with time zone</type></entry>
677 <entry>Time when the <structfield>state</structfield> was last changed</entry>
680 <entry><structfield>wait_event_type</structfield></entry>
681 <entry><type>text</type></entry>
682 <entry>The type of event for which the backend is waiting, if any;
683 otherwise NULL. Possible values are:
687 <literal>LWLock</literal>: The backend is waiting for a lightweight lock.
688 Each such lock protects a particular data structure in shared memory.
689 <literal>wait_event</literal> will contain a name identifying the purpose
690 of the lightweight lock. (Some locks have specific names; others
691 are part of a group of locks each with a similar purpose.)
696 <literal>Lock</literal>: The backend is waiting for a heavyweight lock.
697 Heavyweight locks, also known as lock manager locks or simply locks,
698 primarily protect SQL-visible objects such as tables. However,
699 they are also used to ensure mutual exclusion for certain internal
700 operations such as relation extension. <literal>wait_event</literal> will
701 identify the type of lock awaited.
706 <literal>BufferPin</literal>: The server process is waiting to access to
707 a data buffer during a period when no other process can be
708 examining that buffer. Buffer pin waits can be protracted if
709 another process holds an open cursor which last read data from the
715 <literal>Activity</literal>: The server process is idle. This is used by
716 system processes waiting for activity in their main processing loop.
717 <literal>wait_event</literal> will identify the specific wait point.
722 <literal>Extension</literal>: The server process is waiting for activity
723 in an extension module. This category is useful for modules to
724 track custom waiting points.
729 <literal>Client</literal>: The server process is waiting for some activity
730 on a socket from user applications, and that the server expects
731 something to happen that is independent from its internal processes.
732 <literal>wait_event</literal> will identify the specific wait point.
737 <literal>IPC</literal>: The server process is waiting for some activity
738 from another process in the server. <literal>wait_event</literal> will
739 identify the specific wait point.
744 <literal>Timeout</literal>: The server process is waiting for a timeout
745 to expire. <literal>wait_event</literal> will identify the specific wait
751 <literal>IO</literal>: The server process is waiting for a IO to complete.
752 <literal>wait_event</literal> will identify the specific wait point.
759 <entry><structfield>wait_event</structfield></entry>
760 <entry><type>text</type></entry>
761 <entry>Wait event name if backend is currently waiting, otherwise NULL.
762 See <xref linkend="wait-event-table"/> for details.
766 <entry><structfield>state</structfield></entry>
767 <entry><type>text</type></entry>
768 <entry>Current overall state of this backend.
773 <literal>active</literal>: The backend is executing a query.
778 <literal>idle</literal>: The backend is waiting for a new client command.
783 <literal>idle in transaction</literal>: The backend is in a transaction,
784 but is not currently executing a query.
789 <literal>idle in transaction (aborted)</literal>: This state is similar to
790 <literal>idle in transaction</literal>, except one of the statements in
791 the transaction caused an error.
796 <literal>fastpath function call</literal>: The backend is executing a
802 <literal>disabled</literal>: This state is reported if <xref
803 linkend="guc-track-activities"/> is disabled in this backend.
810 <entry><structfield>backend_xid</structfield></entry>
811 <entry><type>xid</type></entry>
812 <entry>Top-level transaction identifier of this backend, if any.</entry>
815 <entry><structfield>backend_xmin</structfield></entry>
816 <entry><type>xid</type></entry>
817 <entry>The current backend's <literal>xmin</literal> horizon.</entry>
820 <entry><structfield>query</structfield></entry>
821 <entry><type>text</type></entry>
822 <entry>Text of this backend's most recent query. If
823 <structfield>state</structfield> is <literal>active</literal> this field shows the
824 currently executing query. In all other states, it shows the last query
825 that was executed. By default the query text is truncated at 1024
826 characters; this value can be changed via the parameter
827 <xref linkend="guc-track-activity-query-size"/>.
831 <entry><structfield>backend_type</structfield></entry>
832 <entry><type>text</type></entry>
833 <entry>Type of current backend. Possible types are
834 <literal>autovacuum launcher</literal>, <literal>autovacuum worker</literal>,
835 <literal>logical replication launcher</literal>,
836 <literal>logical replication worker</literal>,
837 <literal>parallel worker</literal>, <literal>background writer</literal>,
838 <literal>client backend</literal>, <literal>checkpointer</literal>,
839 <literal>startup</literal>, <literal>walreceiver</literal>,
840 <literal>walsender</literal> and <literal>walwriter</literal>.
841 In addition, background workers registered by extensions may have
850 The <structname>pg_stat_activity</structname> view will have one row
851 per server process, showing information related to
852 the current activity of that process.
857 The <structfield>wait_event</structfield> and <structfield>state</structfield> columns are
858 independent. If a backend is in the <literal>active</literal> state,
859 it may or may not be <literal>waiting</literal> on some event. If the state
860 is <literal>active</literal> and <structfield>wait_event</structfield> is non-null, it
861 means that a query is being executed, but is being blocked somewhere
866 <table id="wait-event-table">
867 <title><structname>wait_event</structname> Description</title>
872 <entry>Wait Event Type</entry>
873 <entry>Wait Event Name</entry>
874 <entry>Description</entry>
880 <entry morerows="64"><literal>LWLock</literal></entry>
881 <entry><literal>ShmemIndexLock</literal></entry>
882 <entry>Waiting to find or allocate space in shared memory.</entry>
885 <entry><literal>OidGenLock</literal></entry>
886 <entry>Waiting to allocate or assign an OID.</entry>
889 <entry><literal>XidGenLock</literal></entry>
890 <entry>Waiting to allocate or assign a transaction id.</entry>
893 <entry><literal>ProcArrayLock</literal></entry>
894 <entry>Waiting to get a snapshot or clearing a transaction id at
895 transaction end.</entry>
898 <entry><literal>SInvalReadLock</literal></entry>
899 <entry>Waiting to retrieve or remove messages from shared invalidation
903 <entry><literal>SInvalWriteLock</literal></entry>
904 <entry>Waiting to add a message in shared invalidation queue.</entry>
907 <entry><literal>WALBufMappingLock</literal></entry>
908 <entry>Waiting to replace a page in WAL buffers.</entry>
911 <entry><literal>WALWriteLock</literal></entry>
912 <entry>Waiting for WAL buffers to be written to disk.</entry>
915 <entry><literal>ControlFileLock</literal></entry>
916 <entry>Waiting to read or update the control file or creation of a
917 new WAL file.</entry>
920 <entry><literal>CheckpointLock</literal></entry>
921 <entry>Waiting to perform checkpoint.</entry>
924 <entry><literal>CLogControlLock</literal></entry>
925 <entry>Waiting to read or update transaction status.</entry>
928 <entry><literal>SubtransControlLock</literal></entry>
929 <entry>Waiting to read or update sub-transaction information.</entry>
932 <entry><literal>MultiXactGenLock</literal></entry>
933 <entry>Waiting to read or update shared multixact state.</entry>
936 <entry><literal>MultiXactOffsetControlLock</literal></entry>
937 <entry>Waiting to read or update multixact offset mappings.</entry>
940 <entry><literal>MultiXactMemberControlLock</literal></entry>
941 <entry>Waiting to read or update multixact member mappings.</entry>
944 <entry><literal>RelCacheInitLock</literal></entry>
945 <entry>Waiting to read or write relation cache initialization
949 <entry><literal>CheckpointerCommLock</literal></entry>
950 <entry>Waiting to manage fsync requests.</entry>
953 <entry><literal>TwoPhaseStateLock</literal></entry>
954 <entry>Waiting to read or update the state of prepared transactions.</entry>
957 <entry><literal>TablespaceCreateLock</literal></entry>
958 <entry>Waiting to create or drop the tablespace.</entry>
961 <entry><literal>BtreeVacuumLock</literal></entry>
962 <entry>Waiting to read or update vacuum-related information for a
963 B-tree index.</entry>
966 <entry><literal>AddinShmemInitLock</literal></entry>
967 <entry>Waiting to manage space allocation in shared memory.</entry>
970 <entry><literal>AutovacuumLock</literal></entry>
971 <entry>Autovacuum worker or launcher waiting to update or
972 read the current state of autovacuum workers.</entry>
975 <entry><literal>AutovacuumScheduleLock</literal></entry>
976 <entry>Waiting to ensure that the table it has selected for a vacuum
977 still needs vacuuming.
981 <entry><literal>SyncScanLock</literal></entry>
982 <entry>Waiting to get the start location of a scan on a table for
983 synchronized scans.</entry>
986 <entry><literal>RelationMappingLock</literal></entry>
987 <entry>Waiting to update the relation map file used to store catalog
992 <entry><literal>AsyncCtlLock</literal></entry>
993 <entry>Waiting to read or update shared notification state.</entry>
996 <entry><literal>AsyncQueueLock</literal></entry>
997 <entry>Waiting to read or update notification messages.</entry>
1000 <entry><literal>SerializableXactHashLock</literal></entry>
1001 <entry>Waiting to retrieve or store information about serializable
1002 transactions.</entry>
1005 <entry><literal>SerializableFinishedListLock</literal></entry>
1006 <entry>Waiting to access the list of finished serializable
1007 transactions.</entry>
1010 <entry><literal>SerializablePredicateLockListLock</literal></entry>
1011 <entry>Waiting to perform an operation on a list of locks held by
1012 serializable transactions.</entry>
1015 <entry><literal>OldSerXidLock</literal></entry>
1016 <entry>Waiting to read or record conflicting serializable
1017 transactions.</entry>
1020 <entry><literal>SyncRepLock</literal></entry>
1021 <entry>Waiting to read or update information about synchronous
1025 <entry><literal>BackgroundWorkerLock</literal></entry>
1026 <entry>Waiting to read or update background worker state.</entry>
1029 <entry><literal>DynamicSharedMemoryControlLock</literal></entry>
1030 <entry>Waiting to read or update dynamic shared memory state.</entry>
1033 <entry><literal>AutoFileLock</literal></entry>
1034 <entry>Waiting to update the <filename>postgresql.auto.conf</filename> file.</entry>
1037 <entry><literal>ReplicationSlotAllocationLock</literal></entry>
1038 <entry>Waiting to allocate or free a replication slot.</entry>
1041 <entry><literal>ReplicationSlotControlLock</literal></entry>
1042 <entry>Waiting to read or update replication slot state.</entry>
1045 <entry><literal>CommitTsControlLock</literal></entry>
1046 <entry>Waiting to read or update transaction commit timestamps.</entry>
1049 <entry><literal>CommitTsLock</literal></entry>
1050 <entry>Waiting to read or update the last value set for the
1051 transaction timestamp.</entry>
1054 <entry><literal>ReplicationOriginLock</literal></entry>
1055 <entry>Waiting to setup, drop or use replication origin.</entry>
1058 <entry><literal>MultiXactTruncationLock</literal></entry>
1059 <entry>Waiting to read or truncate multixact information.</entry>
1062 <entry><literal>OldSnapshotTimeMapLock</literal></entry>
1063 <entry>Waiting to read or update old snapshot control information.</entry>
1066 <entry><literal>LogicalRepWorkerLock</literal></entry>
1067 <entry>Waiting for action on logical replication worker to finish.</entry>
1070 <entry><literal>CLogTruncationLock</literal></entry>
1071 <entry>Waiting to execute <function>txid_status</function> or update
1072 the oldest transaction id available to it.</entry>
1075 <entry><literal>clog</literal></entry>
1076 <entry>Waiting for I/O on a clog (transaction status) buffer.</entry>
1079 <entry><literal>commit_timestamp</literal></entry>
1080 <entry>Waiting for I/O on commit timestamp buffer.</entry>
1083 <entry><literal>subtrans</literal></entry>
1084 <entry>Waiting for I/O a subtransaction buffer.</entry>
1087 <entry><literal>multixact_offset</literal></entry>
1088 <entry>Waiting for I/O on a multixact offset buffer.</entry>
1091 <entry><literal>multixact_member</literal></entry>
1092 <entry>Waiting for I/O on a multixact_member buffer.</entry>
1095 <entry><literal>async</literal></entry>
1096 <entry>Waiting for I/O on an async (notify) buffer.</entry>
1099 <entry><literal>oldserxid</literal></entry>
1100 <entry>Waiting for I/O on an oldserxid buffer.</entry>
1103 <entry><literal>wal_insert</literal></entry>
1104 <entry>Waiting to insert WAL into a memory buffer.</entry>
1107 <entry><literal>buffer_content</literal></entry>
1108 <entry>Waiting to read or write a data page in memory.</entry>
1111 <entry><literal>buffer_io</literal></entry>
1112 <entry>Waiting for I/O on a data page.</entry>
1115 <entry><literal>replication_origin</literal></entry>
1116 <entry>Waiting to read or update the replication progress.</entry>
1119 <entry><literal>replication_slot_io</literal></entry>
1120 <entry>Waiting for I/O on a replication slot.</entry>
1123 <entry><literal>proc</literal></entry>
1124 <entry>Waiting to read or update the fast-path lock information.</entry>
1127 <entry><literal>buffer_mapping</literal></entry>
1128 <entry>Waiting to associate a data block with a buffer in the buffer
1132 <entry><literal>lock_manager</literal></entry>
1133 <entry>Waiting to add or examine locks for backends, or waiting to
1134 join or exit a locking group (used by parallel query).</entry>
1137 <entry><literal>predicate_lock_manager</literal></entry>
1138 <entry>Waiting to add or examine predicate lock information.</entry>
1141 <entry><literal>serializable_xact</literal></entry>
1142 <entry>Waiting to perform an operation on a serializable transaction
1143 in a parallel query.</entry>
1146 <entry><literal>parallel_query_dsa</literal></entry>
1147 <entry>Waiting for parallel query dynamic shared memory allocation lock.</entry>
1150 <entry><literal>tbm</literal></entry>
1151 <entry>Waiting for TBM shared iterator lock.</entry>
1154 <entry><literal>parallel_append</literal></entry>
1155 <entry>Waiting to choose the next subplan during Parallel Append plan
1159 <entry><literal>parallel_hash_join</literal></entry>
1160 <entry>Waiting to allocate or exchange a chunk of memory or update
1161 counters during Parallel Hash plan execution.</entry>
1164 <entry morerows="9"><literal>Lock</literal></entry>
1165 <entry><literal>relation</literal></entry>
1166 <entry>Waiting to acquire a lock on a relation.</entry>
1169 <entry><literal>extend</literal></entry>
1170 <entry>Waiting to extend a relation.</entry>
1173 <entry><literal>page</literal></entry>
1174 <entry>Waiting to acquire a lock on page of a relation.</entry>
1177 <entry><literal>tuple</literal></entry>
1178 <entry>Waiting to acquire a lock on a tuple.</entry>
1181 <entry><literal>transactionid</literal></entry>
1182 <entry>Waiting for a transaction to finish.</entry>
1185 <entry><literal>virtualxid</literal></entry>
1186 <entry>Waiting to acquire a virtual xid lock.</entry>
1189 <entry><literal>speculative token</literal></entry>
1190 <entry>Waiting to acquire a speculative insertion lock.</entry>
1193 <entry><literal>object</literal></entry>
1194 <entry>Waiting to acquire a lock on a non-relation database object.</entry>
1197 <entry><literal>userlock</literal></entry>
1198 <entry>Waiting to acquire a user lock.</entry>
1201 <entry><literal>advisory</literal></entry>
1202 <entry>Waiting to acquire an advisory user lock.</entry>
1205 <entry><literal>BufferPin</literal></entry>
1206 <entry><literal>BufferPin</literal></entry>
1207 <entry>Waiting to acquire a pin on a buffer.</entry>
1210 <entry morerows="13"><literal>Activity</literal></entry>
1211 <entry><literal>ArchiverMain</literal></entry>
1212 <entry>Waiting in main loop of the archiver process.</entry>
1215 <entry><literal>AutoVacuumMain</literal></entry>
1216 <entry>Waiting in main loop of autovacuum launcher process.</entry>
1219 <entry><literal>BgWriterHibernate</literal></entry>
1220 <entry>Waiting in background writer process, hibernating.</entry>
1223 <entry><literal>BgWriterMain</literal></entry>
1224 <entry>Waiting in main loop of background writer process background worker.</entry>
1227 <entry><literal>CheckpointerMain</literal></entry>
1228 <entry>Waiting in main loop of checkpointer process.</entry>
1231 <entry><literal>LogicalApplyMain</literal></entry>
1232 <entry>Waiting in main loop of logical apply process.</entry>
1235 <entry><literal>LogicalLauncherMain</literal></entry>
1236 <entry>Waiting in main loop of logical launcher process.</entry>
1239 <entry><literal>PgStatMain</literal></entry>
1240 <entry>Waiting in main loop of the statistics collector process.</entry>
1243 <entry><literal>RecoveryWalAll</literal></entry>
1244 <entry>Waiting for WAL from any kind of source (local, archive or stream) at recovery.</entry>
1247 <entry><literal>RecoveryWalStream</literal></entry>
1248 <entry>Waiting for WAL from a stream at recovery.</entry>
1251 <entry><literal>SysLoggerMain</literal></entry>
1252 <entry>Waiting in main loop of syslogger process.</entry>
1255 <entry><literal>WalReceiverMain</literal></entry>
1256 <entry>Waiting in main loop of WAL receiver process.</entry>
1259 <entry><literal>WalSenderMain</literal></entry>
1260 <entry>Waiting in main loop of WAL sender process.</entry>
1263 <entry><literal>WalWriterMain</literal></entry>
1264 <entry>Waiting in main loop of WAL writer process.</entry>
1267 <entry morerows="7"><literal>Client</literal></entry>
1268 <entry><literal>ClientRead</literal></entry>
1269 <entry>Waiting to read data from the client.</entry>
1272 <entry><literal>ClientWrite</literal></entry>
1273 <entry>Waiting to write data to the client.</entry>
1276 <entry><literal>LibPQWalReceiverConnect</literal></entry>
1277 <entry>Waiting in WAL receiver to establish connection to remote server.</entry>
1280 <entry><literal>LibPQWalReceiverReceive</literal></entry>
1281 <entry>Waiting in WAL receiver to receive data from remote server.</entry>
1284 <entry><literal>SSLOpenServer</literal></entry>
1285 <entry>Waiting for SSL while attempting connection.</entry>
1288 <entry><literal>WalReceiverWaitStart</literal></entry>
1289 <entry>Waiting for startup process to send initial data for streaming replication.</entry>
1292 <entry><literal>WalSenderWaitForWAL</literal></entry>
1293 <entry>Waiting for WAL to be flushed in WAL sender process.</entry>
1296 <entry><literal>WalSenderWriteData</literal></entry>
1297 <entry>Waiting for any activity when processing replies from WAL receiver in WAL sender process.</entry>
1300 <entry><literal>Extension</literal></entry>
1301 <entry><literal>Extension</literal></entry>
1302 <entry>Waiting in an extension.</entry>
1305 <entry morerows="36"><literal>IPC</literal></entry>
1306 <entry><literal>BgWorkerShutdown</literal></entry>
1307 <entry>Waiting for background worker to shut down.</entry>
1310 <entry><literal>BgWorkerStartup</literal></entry>
1311 <entry>Waiting for background worker to start up.</entry>
1314 <entry><literal>BtreePage</literal></entry>
1315 <entry>Waiting for the page number needed to continue a parallel B-tree scan to become available.</entry>
1318 <entry><literal>CheckpointDone</literal></entry>
1319 <entry>Waiting for a checkpoint to complete.</entry>
1322 <entry><literal>CheckpointStart</literal></entry>
1323 <entry>Waiting for a checkpoint to start.</entry>
1326 <entry><literal>ClogGroupUpdate</literal></entry>
1327 <entry>Waiting for group leader to update transaction status at transaction end.</entry>
1330 <entry><literal>ExecuteGather</literal></entry>
1331 <entry>Waiting for activity from child process when executing <literal>Gather</literal> node.</entry>
1334 <entry><literal>Hash/Batch/Allocating</literal></entry>
1335 <entry>Waiting for an elected Parallel Hash participant to allocate a hash table.</entry>
1338 <entry><literal>Hash/Batch/Electing</literal></entry>
1339 <entry>Electing a Parallel Hash participant to allocate a hash table.</entry>
1342 <entry><literal>Hash/Batch/Loading</literal></entry>
1343 <entry>Waiting for other Parallel Hash participants to finish loading a hash table.</entry>
1346 <entry><literal>Hash/Build/Allocating</literal></entry>
1347 <entry>Waiting for an elected Parallel Hash participant to allocate the initial hash table.</entry>
1350 <entry><literal>Hash/Build/Electing</literal></entry>
1351 <entry>Electing a Parallel Hash participant to allocate the initial hash table.</entry>
1354 <entry><literal>Hash/Build/HashingInner</literal></entry>
1355 <entry>Waiting for other Parallel Hash participants to finish hashing the inner relation.</entry>
1358 <entry><literal>Hash/Build/HashingOuter</literal></entry>
1359 <entry>Waiting for other Parallel Hash participants to finish partitioning the outer relation.</entry>
1362 <entry><literal>Hash/GrowBatches/Allocating</literal></entry>
1363 <entry>Waiting for an elected Parallel Hash participant to allocate more batches.</entry>
1366 <entry><literal>Hash/GrowBatches/Deciding</literal></entry>
1367 <entry>Electing a Parallel Hash participant to decide on future batch growth.</entry>
1370 <entry><literal>Hash/GrowBatches/Electing</literal></entry>
1371 <entry>Electing a Parallel Hash participant to allocate more batches.</entry>
1374 <entry><literal>Hash/GrowBatches/Finishing</literal></entry>
1375 <entry>Waiting for an elected Parallel Hash participant to decide on future batch growth.</entry>
1378 <entry><literal>Hash/GrowBatches/Repartitioning</literal></entry>
1379 <entry>Waiting for other Parallel Hash participants to finishing repartitioning.</entry>
1382 <entry><literal>Hash/GrowBuckets/Allocating</literal></entry>
1383 <entry>Waiting for an elected Parallel Hash participant to finish allocating more buckets.</entry>
1386 <entry><literal>Hash/GrowBuckets/Electing</literal></entry>
1387 <entry>Electing a Parallel Hash participant to allocate more buckets.</entry>
1390 <entry><literal>Hash/GrowBuckets/Reinserting</literal></entry>
1391 <entry>Waiting for other Parallel Hash participants to finish inserting tuples into new buckets.</entry>
1394 <entry><literal>LogicalSyncData</literal></entry>
1395 <entry>Waiting for logical replication remote server to send data for initial table synchronization.</entry>
1398 <entry><literal>LogicalSyncStateChange</literal></entry>
1399 <entry>Waiting for logical replication remote server to change state.</entry>
1402 <entry><literal>MessageQueueInternal</literal></entry>
1403 <entry>Waiting for other process to be attached in shared message queue.</entry>
1406 <entry><literal>MessageQueuePutMessage</literal></entry>
1407 <entry>Waiting to write a protocol message to a shared message queue.</entry>
1410 <entry><literal>MessageQueueReceive</literal></entry>
1411 <entry>Waiting to receive bytes from a shared message queue.</entry>
1414 <entry><literal>MessageQueueSend</literal></entry>
1415 <entry>Waiting to send bytes to a shared message queue.</entry>
1418 <entry><literal>ParallelBitmapScan</literal></entry>
1419 <entry>Waiting for parallel bitmap scan to become initialized.</entry>
1422 <entry><literal>ParallelCreateIndexScan</literal></entry>
1423 <entry>Waiting for parallel <command>CREATE INDEX</command> workers to finish heap scan.</entry>
1426 <entry><literal>ParallelFinish</literal></entry>
1427 <entry>Waiting for parallel workers to finish computing.</entry>
1430 <entry><literal>ProcArrayGroupUpdate</literal></entry>
1431 <entry>Waiting for group leader to clear transaction id at transaction end.</entry>
1434 <entry><literal>Promote</literal></entry>
1435 <entry>Waiting for standby promotion.</entry>
1438 <entry><literal>ReplicationOriginDrop</literal></entry>
1439 <entry>Waiting for a replication origin to become inactive to be dropped.</entry>
1442 <entry><literal>ReplicationSlotDrop</literal></entry>
1443 <entry>Waiting for a replication slot to become inactive to be dropped.</entry>
1446 <entry><literal>SafeSnapshot</literal></entry>
1447 <entry>Waiting for a snapshot for a <literal>READ ONLY DEFERRABLE</literal> transaction.</entry>
1450 <entry><literal>SyncRep</literal></entry>
1451 <entry>Waiting for confirmation from remote server during synchronous replication.</entry>
1454 <entry morerows="2"><literal>Timeout</literal></entry>
1455 <entry><literal>BaseBackupThrottle</literal></entry>
1456 <entry>Waiting during base backup when throttling activity.</entry>
1459 <entry><literal>PgSleep</literal></entry>
1460 <entry>Waiting in process that called <function>pg_sleep</function>.</entry>
1463 <entry><literal>RecoveryApplyDelay</literal></entry>
1464 <entry>Waiting to apply WAL at recovery because it is delayed.</entry>
1467 <entry morerows="66"><literal>IO</literal></entry>
1468 <entry><literal>BufFileRead</literal></entry>
1469 <entry>Waiting for a read from a buffered file.</entry>
1472 <entry><literal>BufFileWrite</literal></entry>
1473 <entry>Waiting for a write to a buffered file.</entry>
1476 <entry><literal>ControlFileRead</literal></entry>
1477 <entry>Waiting for a read from the control file.</entry>
1480 <entry><literal>ControlFileSync</literal></entry>
1481 <entry>Waiting for the control file to reach stable storage.</entry>
1484 <entry><literal>ControlFileSyncUpdate</literal></entry>
1485 <entry>Waiting for an update to the control file to reach stable storage.</entry>
1488 <entry><literal>ControlFileWrite</literal></entry>
1489 <entry>Waiting for a write to the control file.</entry>
1492 <entry><literal>ControlFileWriteUpdate</literal></entry>
1493 <entry>Waiting for a write to update the control file.</entry>
1496 <entry><literal>CopyFileRead</literal></entry>
1497 <entry>Waiting for a read during a file copy operation.</entry>
1500 <entry><literal>CopyFileWrite</literal></entry>
1501 <entry>Waiting for a write during a file copy operation.</entry>
1504 <entry><literal>DataFileExtend</literal></entry>
1505 <entry>Waiting for a relation data file to be extended.</entry>
1508 <entry><literal>DataFileFlush</literal></entry>
1509 <entry>Waiting for a relation data file to reach stable storage.</entry>
1512 <entry><literal>DataFileImmediateSync</literal></entry>
1513 <entry>Waiting for an immediate synchronization of a relation data file to stable storage.</entry>
1516 <entry><literal>DataFilePrefetch</literal></entry>
1517 <entry>Waiting for an asynchronous prefetch from a relation data file.</entry>
1520 <entry><literal>DataFileRead</literal></entry>
1521 <entry>Waiting for a read from a relation data file.</entry>
1524 <entry><literal>DataFileSync</literal></entry>
1525 <entry>Waiting for changes to a relation data file to reach stable storage.</entry>
1528 <entry><literal>DataFileTruncate</literal></entry>
1529 <entry>Waiting for a relation data file to be truncated.</entry>
1532 <entry><literal>DataFileWrite</literal></entry>
1533 <entry>Waiting for a write to a relation data file.</entry>
1536 <entry><literal>DSMFillZeroWrite</literal></entry>
1537 <entry>Waiting to write zero bytes to a dynamic shared memory backing file.</entry>
1540 <entry><literal>LockFileAddToDataDirRead</literal></entry>
1541 <entry>Waiting for a read while adding a line to the data directory lock file.</entry>
1544 <entry><literal>LockFileAddToDataDirSync</literal></entry>
1545 <entry>Waiting for data to reach stable storage while adding a line to the data directory lock file.</entry>
1548 <entry><literal>LockFileAddToDataDirWrite</literal></entry>
1549 <entry>Waiting for a write while adding a line to the data directory lock file.</entry>
1552 <entry><literal>LockFileCreateRead</literal></entry>
1553 <entry>Waiting to read while creating the data directory lock file.</entry>
1556 <entry><literal>LockFileCreateSync</literal></entry>
1557 <entry>Waiting for data to reach stable storage while creating the data directory lock file.</entry>
1560 <entry><literal>LockFileCreateWrite</literal></entry>
1561 <entry>Waiting for a write while creating the data directory lock file.</entry>
1564 <entry><literal>LockFileReCheckDataDirRead</literal></entry>
1565 <entry>Waiting for a read during recheck of the data directory lock file.</entry>
1568 <entry><literal>LogicalRewriteCheckpointSync</literal></entry>
1569 <entry>Waiting for logical rewrite mappings to reach stable storage during a checkpoint.</entry>
1572 <entry><literal>LogicalRewriteMappingSync</literal></entry>
1573 <entry>Waiting for mapping data to reach stable storage during a logical rewrite.</entry>
1576 <entry><literal>LogicalRewriteMappingWrite</literal></entry>
1577 <entry>Waiting for a write of mapping data during a logical rewrite.</entry>
1580 <entry><literal>LogicalRewriteSync</literal></entry>
1581 <entry>Waiting for logical rewrite mappings to reach stable storage.</entry>
1584 <entry><literal>LogicalRewriteWrite</literal></entry>
1585 <entry>Waiting for a write of logical rewrite mappings.</entry>
1588 <entry><literal>RelationMapRead</literal></entry>
1589 <entry>Waiting for a read of the relation map file.</entry>
1592 <entry><literal>RelationMapSync</literal></entry>
1593 <entry>Waiting for the relation map file to reach stable storage.</entry>
1596 <entry><literal>RelationMapWrite</literal></entry>
1597 <entry>Waiting for a write to the relation map file.</entry>
1600 <entry><literal>ReorderBufferRead</literal></entry>
1601 <entry>Waiting for a read during reorder buffer management.</entry>
1604 <entry><literal>ReorderBufferWrite</literal></entry>
1605 <entry>Waiting for a write during reorder buffer management.</entry>
1608 <entry><literal>ReorderLogicalMappingRead</literal></entry>
1609 <entry>Waiting for a read of a logical mapping during reorder buffer management.</entry>
1612 <entry><literal>ReplicationSlotRead</literal></entry>
1613 <entry>Waiting for a read from a replication slot control file.</entry>
1616 <entry><literal>ReplicationSlotRestoreSync</literal></entry>
1617 <entry>Waiting for a replication slot control file to reach stable storage while restoring it to memory.</entry>
1620 <entry><literal>ReplicationSlotSync</literal></entry>
1621 <entry>Waiting for a replication slot control file to reach stable storage.</entry>
1624 <entry><literal>ReplicationSlotWrite</literal></entry>
1625 <entry>Waiting for a write to a replication slot control file.</entry>
1628 <entry><literal>SLRUFlushSync</literal></entry>
1629 <entry>Waiting for SLRU data to reach stable storage during a checkpoint or database shutdown.</entry>
1632 <entry><literal>SLRURead</literal></entry>
1633 <entry>Waiting for a read of an SLRU page.</entry>
1636 <entry><literal>SLRUSync</literal></entry>
1637 <entry>Waiting for SLRU data to reach stable storage following a page write.</entry>
1640 <entry><literal>SLRUWrite</literal></entry>
1641 <entry>Waiting for a write of an SLRU page.</entry>
1644 <entry><literal>SnapbuildRead</literal></entry>
1645 <entry>Waiting for a read of a serialized historical catalog snapshot.</entry>
1648 <entry><literal>SnapbuildSync</literal></entry>
1649 <entry>Waiting for a serialized historical catalog snapshot to reach stable storage.</entry>
1652 <entry><literal>SnapbuildWrite</literal></entry>
1653 <entry>Waiting for a write of a serialized historical catalog snapshot.</entry>
1656 <entry><literal>TimelineHistoryFileSync</literal></entry>
1657 <entry>Waiting for a timeline history file received via streaming replication to reach stable storage.</entry>
1660 <entry><literal>TimelineHistoryFileWrite</literal></entry>
1661 <entry>Waiting for a write of a timeline history file received via streaming replication.</entry>
1664 <entry><literal>TimelineHistoryRead</literal></entry>
1665 <entry>Waiting for a read of a timeline history file.</entry>
1668 <entry><literal>TimelineHistorySync</literal></entry>
1669 <entry>Waiting for a newly created timeline history file to reach stable storage.</entry>
1672 <entry><literal>TimelineHistoryWrite</literal></entry>
1673 <entry>Waiting for a write of a newly created timeline history file.</entry>
1676 <entry><literal>TwophaseFileRead</literal></entry>
1677 <entry>Waiting for a read of a two phase state file.</entry>
1680 <entry><literal>TwophaseFileSync</literal></entry>
1681 <entry>Waiting for a two phase state file to reach stable storage.</entry>
1684 <entry><literal>TwophaseFileWrite</literal></entry>
1685 <entry>Waiting for a write of a two phase state file.</entry>
1688 <entry><literal>WALBootstrapSync</literal></entry>
1689 <entry>Waiting for WAL to reach stable storage during bootstrapping.</entry>
1692 <entry><literal>WALBootstrapWrite</literal></entry>
1693 <entry>Waiting for a write of a WAL page during bootstrapping.</entry>
1696 <entry><literal>WALCopyRead</literal></entry>
1697 <entry>Waiting for a read when creating a new WAL segment by copying an existing one.</entry>
1700 <entry><literal>WALCopySync</literal></entry>
1701 <entry>Waiting a new WAL segment created by copying an existing one to reach stable storage.</entry>
1704 <entry><literal>WALCopyWrite</literal></entry>
1705 <entry>Waiting for a write when creating a new WAL segment by copying an existing one.</entry>
1708 <entry><literal>WALInitSync</literal></entry>
1709 <entry>Waiting for a newly initialized WAL file to reach stable storage.</entry>
1712 <entry><literal>WALInitWrite</literal></entry>
1713 <entry>Waiting for a write while initializing a new WAL file.</entry>
1716 <entry><literal>WALRead</literal></entry>
1717 <entry>Waiting for a read from a WAL file.</entry>
1720 <entry><literal>WALSenderTimelineHistoryRead</literal></entry>
1721 <entry>Waiting for a read from a timeline history file during walsender timeline command.</entry>
1724 <entry><literal>WALSync</literal></entry>
1725 <entry>Waiting for a WAL file to reach stable storage.</entry>
1728 <entry><literal>WALSyncMethodAssign</literal></entry>
1729 <entry>Waiting for data to reach stable storage while assigning WAL sync method.</entry>
1732 <entry><literal>WALWrite</literal></entry>
1733 <entry>Waiting for a write to a WAL file.</entry>
1741 For tranches registered by extensions, the name is specified by extension
1742 and this will be displayed as <structfield>wait_event</structfield>. It is quite
1743 possible that user has registered the tranche in one of the backends (by
1744 having allocation in dynamic shared memory) in which case other backends
1745 won't have that information, so we display <literal>extension</literal> for such
1751 Here is an example of how wait events can be viewed
1754 SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
1755 pid | wait_event_type | wait_event
1756 ------+-----------------+---------------
1757 2540 | Lock | relation
1758 6644 | LWLock | ProcArrayLock
1763 <table id="pg-stat-replication-view" xreflabel="pg_stat_replication">
1764 <title><structname>pg_stat_replication</structname> View</title>
1768 <entry>Column</entry>
1770 <entry>Description</entry>
1776 <entry><structfield>pid</structfield></entry>
1777 <entry><type>integer</type></entry>
1778 <entry>Process ID of a WAL sender process</entry>
1781 <entry><structfield>usesysid</structfield></entry>
1782 <entry><type>oid</type></entry>
1783 <entry>OID of the user logged into this WAL sender process</entry>
1786 <entry><structfield>usename</structfield></entry>
1787 <entry><type>name</type></entry>
1788 <entry>Name of the user logged into this WAL sender process</entry>
1791 <entry><structfield>application_name</structfield></entry>
1792 <entry><type>text</type></entry>
1793 <entry>Name of the application that is connected
1794 to this WAL sender</entry>
1797 <entry><structfield>client_addr</structfield></entry>
1798 <entry><type>inet</type></entry>
1799 <entry>IP address of the client connected to this WAL sender.
1800 If this field is null, it indicates that the client is
1801 connected via a Unix socket on the server machine.
1805 <entry><structfield>client_hostname</structfield></entry>
1806 <entry><type>text</type></entry>
1807 <entry>Host name of the connected client, as reported by a
1808 reverse DNS lookup of <structfield>client_addr</structfield>. This field will
1809 only be non-null for IP connections, and only when <xref
1810 linkend="guc-log-hostname"/> is enabled.
1814 <entry><structfield>client_port</structfield></entry>
1815 <entry><type>integer</type></entry>
1816 <entry>TCP port number that the client is using for communication
1817 with this WAL sender, or <literal>-1</literal> if a Unix socket is used
1821 <entry><structfield>backend_start</structfield></entry>
1822 <entry><type>timestamp with time zone</type></entry>
1823 <entry>Time when this process was started, i.e., when the
1824 client connected to this WAL sender
1828 <entry><structfield>backend_xmin</structfield></entry>
1829 <entry><type>xid</type></entry>
1830 <entry>This standby's <literal>xmin</literal> horizon reported
1831 by <xref linkend="guc-hot-standby-feedback"/>.</entry>
1834 <entry><structfield>state</structfield></entry>
1835 <entry><type>text</type></entry>
1836 <entry>Current WAL sender state.
1837 Possible values are:
1841 <literal>startup</literal>: This WAL sender is starting up.
1846 <literal>catchup</literal>: This WAL sender's connected standby is
1847 catching up with the primary.
1852 <literal>streaming</literal>: This WAL sender is streaming changes
1853 after its connected standby server has caught up with the primary.
1858 <literal>backup</literal>: This WAL sender is sending a backup.
1863 <literal>stopping</literal>: This WAL sender is stopping.
1870 <entry><structfield>sent_lsn</structfield></entry>
1871 <entry><type>pg_lsn</type></entry>
1872 <entry>Last write-ahead log location sent on this connection</entry>
1875 <entry><structfield>write_lsn</structfield></entry>
1876 <entry><type>pg_lsn</type></entry>
1877 <entry>Last write-ahead log location written to disk by this standby
1881 <entry><structfield>flush_lsn</structfield></entry>
1882 <entry><type>pg_lsn</type></entry>
1883 <entry>Last write-ahead log location flushed to disk by this standby
1887 <entry><structfield>replay_lsn</structfield></entry>
1888 <entry><type>pg_lsn</type></entry>
1889 <entry>Last write-ahead log location replayed into the database on this
1890 standby server</entry>
1893 <entry><structfield>write_lag</structfield></entry>
1894 <entry><type>interval</type></entry>
1895 <entry>Time elapsed between flushing recent WAL locally and receiving
1896 notification that this standby server has written it (but not yet
1897 flushed it or applied it). This can be used to gauge the delay that
1898 <literal>synchronous_commit</literal> level
1899 <literal>remote_write</literal> incurred while committing if this
1900 server was configured as a synchronous standby.</entry>
1903 <entry><structfield>flush_lag</structfield></entry>
1904 <entry><type>interval</type></entry>
1905 <entry>Time elapsed between flushing recent WAL locally and receiving
1906 notification that this standby server has written and flushed it
1907 (but not yet applied it). This can be used to gauge the delay that
1908 <literal>synchronous_commit</literal> level
1909 <literal>on</literal> incurred while committing if this
1910 server was configured as a synchronous standby.</entry>
1913 <entry><structfield>replay_lag</structfield></entry>
1914 <entry><type>interval</type></entry>
1915 <entry>Time elapsed between flushing recent WAL locally and receiving
1916 notification that this standby server has written, flushed and
1917 applied it. This can be used to gauge the delay that
1918 <literal>synchronous_commit</literal> level
1919 <literal>remote_apply</literal> incurred while committing if this
1920 server was configured as a synchronous standby.</entry>
1923 <entry><structfield>sync_priority</structfield></entry>
1924 <entry><type>integer</type></entry>
1925 <entry>Priority of this standby server for being chosen as the
1926 synchronous standby in a priority-based synchronous replication.
1927 This has no effect in a quorum-based synchronous replication.</entry>
1930 <entry><structfield>sync_state</structfield></entry>
1931 <entry><type>text</type></entry>
1932 <entry>Synchronous state of this standby server.
1933 Possible values are:
1937 <literal>async</literal>: This standby server is asynchronous.
1942 <literal>potential</literal>: This standby server is now asynchronous,
1943 but can potentially become synchronous if one of current
1944 synchronous ones fails.
1949 <literal>sync</literal>: This standby server is synchronous.
1954 <literal>quorum</literal>: This standby server is considered as a candidate
1955 for quorum standbys.
1962 <entry><structfield>reply_time</structfield></entry>
1963 <entry><type>timestamp with time zone</type></entry>
1964 <entry>Send time of last reply message received from standby server</entry>
1971 The <structname>pg_stat_replication</structname> view will contain one row
1972 per WAL sender process, showing statistics about replication to that
1973 sender's connected standby server. Only directly connected standbys are
1974 listed; no information is available about downstream standby servers.
1978 The lag times reported in the <structname>pg_stat_replication</structname>
1979 view are measurements of the time taken for recent WAL to be written,
1980 flushed and replayed and for the sender to know about it. These times
1981 represent the commit delay that was (or would have been) introduced by each
1982 synchronous commit level, if the remote server was configured as a
1983 synchronous standby. For an asynchronous standby, the
1984 <structfield>replay_lag</structfield> column approximates the delay
1985 before recent transactions became visible to queries. If the standby
1986 server has entirely caught up with the sending server and there is no more
1987 WAL activity, the most recently measured lag times will continue to be
1988 displayed for a short time and then show NULL.
1992 Lag times work automatically for physical replication. Logical decoding
1993 plugins may optionally emit tracking messages; if they do not, the tracking
1994 mechanism will simply display NULL lag.
1999 The reported lag times are not predictions of how long it will take for
2000 the standby to catch up with the sending server assuming the current
2001 rate of replay. Such a system would show similar times while new WAL is
2002 being generated, but would differ when the sender becomes idle. In
2003 particular, when the standby has caught up completely,
2004 <structname>pg_stat_replication</structname> shows the time taken to
2005 write, flush and replay the most recent reported WAL location rather than
2006 zero as some users might expect. This is consistent with the goal of
2007 measuring synchronous commit and transaction visibility delays for
2008 recent write transactions.
2009 To reduce confusion for users expecting a different model of lag, the
2010 lag columns revert to NULL after a short time on a fully replayed idle
2011 system. Monitoring systems should choose whether to represent this
2012 as missing data, zero or continue to display the last known value.
2016 <table id="pg-stat-wal-receiver-view" xreflabel="pg_stat_wal_receiver">
2017 <title><structname>pg_stat_wal_receiver</structname> View</title>
2021 <entry>Column</entry>
2023 <entry>Description</entry>
2029 <entry><structfield>pid</structfield></entry>
2030 <entry><type>integer</type></entry>
2031 <entry>Process ID of the WAL receiver process</entry>
2034 <entry><structfield>status</structfield></entry>
2035 <entry><type>text</type></entry>
2036 <entry>Activity status of the WAL receiver process</entry>
2039 <entry><structfield>receive_start_lsn</structfield></entry>
2040 <entry><type>pg_lsn</type></entry>
2041 <entry>First write-ahead log location used when WAL receiver is
2045 <entry><structfield>receive_start_tli</structfield></entry>
2046 <entry><type>integer</type></entry>
2047 <entry>First timeline number used when WAL receiver is started</entry>
2050 <entry><structfield>received_lsn</structfield></entry>
2051 <entry><type>pg_lsn</type></entry>
2052 <entry>Last write-ahead log location already received and flushed to
2053 disk, the initial value of this field being the first log location used
2054 when WAL receiver is started</entry>
2057 <entry><structfield>received_tli</structfield></entry>
2058 <entry><type>integer</type></entry>
2059 <entry>Timeline number of last write-ahead log location received and
2060 flushed to disk, the initial value of this field being the timeline
2061 number of the first log location used when WAL receiver is started
2065 <entry><structfield>last_msg_send_time</structfield></entry>
2066 <entry><type>timestamp with time zone</type></entry>
2067 <entry>Send time of last message received from origin WAL sender</entry>
2070 <entry><structfield>last_msg_receipt_time</structfield></entry>
2071 <entry><type>timestamp with time zone</type></entry>
2072 <entry>Receipt time of last message received from origin WAL sender</entry>
2075 <entry><structfield>latest_end_lsn</structfield></entry>
2076 <entry><type>pg_lsn</type></entry>
2077 <entry>Last write-ahead log location reported to origin WAL sender</entry>
2080 <entry><structfield>latest_end_time</structfield></entry>
2081 <entry><type>timestamp with time zone</type></entry>
2082 <entry>Time of last write-ahead log location reported to origin WAL sender</entry>
2085 <entry><structfield>slot_name</structfield></entry>
2086 <entry><type>text</type></entry>
2087 <entry>Replication slot name used by this WAL receiver</entry>
2090 <entry><structfield>sender_host</structfield></entry>
2091 <entry><type>text</type></entry>
2093 Host of the <productname>PostgreSQL</productname> instance
2094 this WAL receiver is connected to. This can be a host name,
2095 an IP address, or a directory path if the connection is via
2096 Unix socket. (The path case can be distinguished because it
2097 will always be an absolute path, beginning with <literal>/</literal>.)
2101 <entry><structfield>sender_port</structfield></entry>
2102 <entry><type>integer</type></entry>
2104 Port number of the <productname>PostgreSQL</productname> instance
2105 this WAL receiver is connected to.
2109 <entry><structfield>conninfo</structfield></entry>
2110 <entry><type>text</type></entry>
2112 Connection string used by this WAL receiver,
2113 with security-sensitive fields obfuscated.
2121 The <structname>pg_stat_wal_receiver</structname> view will contain only
2122 one row, showing statistics about the WAL receiver from that receiver's
2126 <table id="pg-stat-subscription" xreflabel="pg_stat_subscription">
2127 <title><structname>pg_stat_subscription</structname> View</title>
2131 <entry>Column</entry>
2133 <entry>Description</entry>
2139 <entry><structfield>subid</structfield></entry>
2140 <entry><type>oid</type></entry>
2141 <entry>OID of the subscription</entry>
2144 <entry><structfield>subname</structfield></entry>
2145 <entry><type>text</type></entry>
2146 <entry>Name of the subscription</entry>
2149 <entry><structfield>pid</structfield></entry>
2150 <entry><type>integer</type></entry>
2151 <entry>Process ID of the subscription worker process</entry>
2154 <entry><structfield>relid</structfield></entry>
2155 <entry><type>Oid</type></entry>
2156 <entry>OID of the relation that the worker is synchronizing; null for the
2157 main apply worker</entry>
2160 <entry><structfield>received_lsn</structfield></entry>
2161 <entry><type>pg_lsn</type></entry>
2162 <entry>Last write-ahead log location received, the initial value of
2163 this field being 0</entry>
2166 <entry><structfield>last_msg_send_time</structfield></entry>
2167 <entry><type>timestamp with time zone</type></entry>
2168 <entry>Send time of last message received from origin WAL sender</entry>
2171 <entry><structfield>last_msg_receipt_time</structfield></entry>
2172 <entry><type>timestamp with time zone</type></entry>
2173 <entry>Receipt time of last message received from origin WAL sender
2177 <entry><structfield>latest_end_lsn</structfield></entry>
2178 <entry><type>pg_lsn</type></entry>
2179 <entry>Last write-ahead log location reported to origin WAL sender
2183 <entry><structfield>latest_end_time</structfield></entry>
2184 <entry><type>timestamp with time zone</type></entry>
2185 <entry>Time of last write-ahead log location reported to origin WAL
2193 The <structname>pg_stat_subscription</structname> view will contain one
2194 row per subscription for main worker (with null PID if the worker is
2195 not running), and additional rows for workers handling the initial data
2196 copy of the subscribed tables.
2199 <table id="pg-stat-ssl-view" xreflabel="pg_stat_ssl">
2200 <title><structname>pg_stat_ssl</structname> View</title>
2204 <entry>Column</entry>
2206 <entry>Description</entry>
2212 <entry><structfield>pid</structfield></entry>
2213 <entry><type>integer</type></entry>
2214 <entry>Process ID of a backend or WAL sender process</entry>
2217 <entry><structfield>ssl</structfield></entry>
2218 <entry><type>boolean</type></entry>
2219 <entry>True if SSL is used on this connection</entry>
2222 <entry><structfield>version</structfield></entry>
2223 <entry><type>text</type></entry>
2224 <entry>Version of SSL in use, or NULL if SSL is not in use
2225 on this connection</entry>
2228 <entry><structfield>cipher</structfield></entry>
2229 <entry><type>text</type></entry>
2230 <entry>Name of SSL cipher in use, or NULL if SSL is not in use
2231 on this connection</entry>
2234 <entry><structfield>bits</structfield></entry>
2235 <entry><type>integer</type></entry>
2236 <entry>Number of bits in the encryption algorithm used, or NULL
2237 if SSL is not used on this connection</entry>
2240 <entry><structfield>compression</structfield></entry>
2241 <entry><type>boolean</type></entry>
2242 <entry>True if SSL compression is in use, false if not,
2243 or NULL if SSL is not in use on this connection</entry>
2246 <entry><structfield>client_dn</structfield></entry>
2247 <entry><type>text</type></entry>
2248 <entry>Distinguished Name (DN) field from the client certificate
2249 used, or NULL if no client certificate was supplied or if SSL
2250 is not in use on this connection. This field is truncated if the
2251 DN field is longer than <symbol>NAMEDATALEN</symbol> (64 characters
2252 in a standard build).
2256 <entry><structfield>client_serial</structfield></entry>
2257 <entry><type>numeric</type></entry>
2258 <entry>Serial number of the client certificate, or NULL if no client
2259 certificate was supplied or if SSL is not in use on this connection. The
2260 combination of certificate serial number and certificate issuer uniquely
2261 identifies a certificate (unless the issuer erroneously reuses serial
2265 <entry><structfield>issuer_dn</structfield></entry>
2266 <entry><type>text</type></entry>
2267 <entry>DN of the issuer of the client certificate, or NULL if no client
2268 certificate was supplied or if SSL is not in use on this connection.
2269 This field is truncated like <structfield>client_dn</structfield>.</entry>
2276 The <structname>pg_stat_ssl</structname> view will contain one row per
2277 backend or WAL sender process, showing statistics about SSL usage on
2278 this connection. It can be joined to <structname>pg_stat_activity</structname>
2279 or <structname>pg_stat_replication</structname> on the
2280 <structfield>pid</structfield> column to get more details about the
2285 <table id="pg-stat-archiver-view" xreflabel="pg_stat_archiver">
2286 <title><structname>pg_stat_archiver</structname> View</title>
2291 <entry>Column</entry>
2293 <entry>Description</entry>
2299 <entry><structfield>archived_count</structfield></entry>
2300 <entry><type>bigint</type></entry>
2301 <entry>Number of WAL files that have been successfully archived</entry>
2304 <entry><structfield>last_archived_wal</structfield></entry>
2305 <entry><type>text</type></entry>
2306 <entry>Name of the last WAL file successfully archived</entry>
2309 <entry><structfield>last_archived_time</structfield></entry>
2310 <entry><type>timestamp with time zone</type></entry>
2311 <entry>Time of the last successful archive operation</entry>
2314 <entry><structfield>failed_count</structfield></entry>
2315 <entry><type>bigint</type></entry>
2316 <entry>Number of failed attempts for archiving WAL files</entry>
2319 <entry><structfield>last_failed_wal</structfield></entry>
2320 <entry><type>text</type></entry>
2321 <entry>Name of the WAL file of the last failed archival operation</entry>
2324 <entry><structfield>last_failed_time</structfield></entry>
2325 <entry><type>timestamp with time zone</type></entry>
2326 <entry>Time of the last failed archival operation</entry>
2329 <entry><structfield>stats_reset</structfield></entry>
2330 <entry><type>timestamp with time zone</type></entry>
2331 <entry>Time at which these statistics were last reset</entry>
2338 The <structname>pg_stat_archiver</structname> view will always have a
2339 single row, containing data about the archiver process of the cluster.
2342 <table id="pg-stat-bgwriter-view" xreflabel="pg_stat_bgwriter">
2343 <title><structname>pg_stat_bgwriter</structname> View</title>
2348 <entry>Column</entry>
2350 <entry>Description</entry>
2356 <entry><structfield>checkpoints_timed</structfield></entry>
2357 <entry><type>bigint</type></entry>
2358 <entry>Number of scheduled checkpoints that have been performed</entry>
2361 <entry><structfield>checkpoints_req</structfield></entry>
2362 <entry><type>bigint</type></entry>
2363 <entry>Number of requested checkpoints that have been performed</entry>
2366 <entry><structfield>checkpoint_write_time</structfield></entry>
2367 <entry><type>double precision</type></entry>
2369 Total amount of time that has been spent in the portion of
2370 checkpoint processing where files are written to disk, in milliseconds
2374 <entry><structfield>checkpoint_sync_time</structfield></entry>
2375 <entry><type>double precision</type></entry>
2377 Total amount of time that has been spent in the portion of
2378 checkpoint processing where files are synchronized to disk, in
2383 <entry><structfield>buffers_checkpoint</structfield></entry>
2384 <entry><type>bigint</type></entry>
2385 <entry>Number of buffers written during checkpoints</entry>
2388 <entry><structfield>buffers_clean</structfield></entry>
2389 <entry><type>bigint</type></entry>
2390 <entry>Number of buffers written by the background writer</entry>
2393 <entry><structfield>maxwritten_clean</structfield></entry>
2394 <entry><type>bigint</type></entry>
2395 <entry>Number of times the background writer stopped a cleaning
2396 scan because it had written too many buffers</entry>
2399 <entry><structfield>buffers_backend</structfield></entry>
2400 <entry><type>bigint</type></entry>
2401 <entry>Number of buffers written directly by a backend</entry>
2404 <entry><structfield>buffers_backend_fsync</structfield></entry>
2405 <entry><type>bigint</type></entry>
2406 <entry>Number of times a backend had to execute its own
2407 <function>fsync</function> call (normally the background writer handles those
2408 even when the backend does its own write)</entry>
2411 <entry><structfield>buffers_alloc</structfield></entry>
2412 <entry><type>bigint</type></entry>
2413 <entry>Number of buffers allocated</entry>
2416 <entry><structfield>stats_reset</structfield></entry>
2417 <entry><type>timestamp with time zone</type></entry>
2418 <entry>Time at which these statistics were last reset</entry>
2425 The <structname>pg_stat_bgwriter</structname> view will always have a
2426 single row, containing global data for the cluster.
2429 <table id="pg-stat-database-view" xreflabel="pg_stat_database">
2430 <title><structname>pg_stat_database</structname> View</title>
2434 <entry>Column</entry>
2436 <entry>Description</entry>
2442 <entry><structfield>datid</structfield></entry>
2443 <entry><type>oid</type></entry>
2444 <entry>OID of a database</entry>
2447 <entry><structfield>datname</structfield></entry>
2448 <entry><type>name</type></entry>
2449 <entry>Name of this database</entry>
2452 <entry><structfield>numbackends</structfield></entry>
2453 <entry><type>integer</type></entry>
2454 <entry>Number of backends currently connected to this database.
2455 This is the only column in this view that returns a value reflecting
2456 current state; all other columns return the accumulated values since
2457 the last reset.</entry>
2460 <entry><structfield>xact_commit</structfield></entry>
2461 <entry><type>bigint</type></entry>
2462 <entry>Number of transactions in this database that have been
2466 <entry><structfield>xact_rollback</structfield></entry>
2467 <entry><type>bigint</type></entry>
2468 <entry>Number of transactions in this database that have been
2472 <entry><structfield>blks_read</structfield></entry>
2473 <entry><type>bigint</type></entry>
2474 <entry>Number of disk blocks read in this database</entry>
2477 <entry><structfield>blks_hit</structfield></entry>
2478 <entry><type>bigint</type></entry>
2479 <entry>Number of times disk blocks were found already in the buffer
2480 cache, so that a read was not necessary (this only includes hits in the
2481 PostgreSQL buffer cache, not the operating system's file system cache)
2485 <entry><structfield>tup_returned</structfield></entry>
2486 <entry><type>bigint</type></entry>
2487 <entry>Number of rows returned by queries in this database</entry>
2490 <entry><structfield>tup_fetched</structfield></entry>
2491 <entry><type>bigint</type></entry>
2492 <entry>Number of rows fetched by queries in this database</entry>
2495 <entry><structfield>tup_inserted</structfield></entry>
2496 <entry><type>bigint</type></entry>
2497 <entry>Number of rows inserted by queries in this database</entry>
2500 <entry><structfield>tup_updated</structfield></entry>
2501 <entry><type>bigint</type></entry>
2502 <entry>Number of rows updated by queries in this database</entry>
2505 <entry><structfield>tup_deleted</structfield></entry>
2506 <entry><type>bigint</type></entry>
2507 <entry>Number of rows deleted by queries in this database</entry>
2510 <entry><structfield>conflicts</structfield></entry>
2511 <entry><type>bigint</type></entry>
2512 <entry>Number of queries canceled due to conflicts with recovery
2513 in this database. (Conflicts occur only on standby servers; see
2514 <xref linkend="pg-stat-database-conflicts-view"/> for details.)
2518 <entry><structfield>temp_files</structfield></entry>
2519 <entry><type>bigint</type></entry>
2520 <entry>Number of temporary files created by queries in this database.
2521 All temporary files are counted, regardless of why the temporary file
2522 was created (e.g., sorting or hashing), and regardless of the
2523 <xref linkend="guc-log-temp-files"/> setting.
2527 <entry><structfield>temp_bytes</structfield></entry>
2528 <entry><type>bigint</type></entry>
2529 <entry>Total amount of data written to temporary files by queries in
2530 this database. All temporary files are counted, regardless of why
2531 the temporary file was created, and
2532 regardless of the <xref linkend="guc-log-temp-files"/> setting.
2536 <entry><structfield>deadlocks</structfield></entry>
2537 <entry><type>bigint</type></entry>
2538 <entry>Number of deadlocks detected in this database</entry>
2541 <entry><structfield>checksum_failures</structfield></entry>
2542 <entry><type>bigint</type></entry>
2543 <entry>Number of data page checksum failures detected in this database</entry>
2546 <entry><structfield>blk_read_time</structfield></entry>
2547 <entry><type>double precision</type></entry>
2548 <entry>Time spent reading data file blocks by backends in this database,
2549 in milliseconds</entry>
2552 <entry><structfield>blk_write_time</structfield></entry>
2553 <entry><type>double precision</type></entry>
2554 <entry>Time spent writing data file blocks by backends in this database,
2555 in milliseconds</entry>
2558 <entry><structfield>stats_reset</structfield></entry>
2559 <entry><type>timestamp with time zone</type></entry>
2560 <entry>Time at which these statistics were last reset</entry>
2567 The <structname>pg_stat_database</structname> view will contain one row
2568 for each database in the cluster, showing database-wide statistics.
2571 <table id="pg-stat-database-conflicts-view" xreflabel="pg_stat_database_conflicts">
2572 <title><structname>pg_stat_database_conflicts</structname> View</title>
2576 <entry>Column</entry>
2578 <entry>Description</entry>
2584 <entry><structfield>datid</structfield></entry>
2585 <entry><type>oid</type></entry>
2586 <entry>OID of a database</entry>
2589 <entry><structfield>datname</structfield></entry>
2590 <entry><type>name</type></entry>
2591 <entry>Name of this database</entry>
2594 <entry><structfield>confl_tablespace</structfield></entry>
2595 <entry><type>bigint</type></entry>
2596 <entry>Number of queries in this database that have been canceled due to
2597 dropped tablespaces</entry>
2600 <entry><structfield>confl_lock</structfield></entry>
2601 <entry><type>bigint</type></entry>
2602 <entry>Number of queries in this database that have been canceled due to
2603 lock timeouts</entry>
2606 <entry><structfield>confl_snapshot</structfield></entry>
2607 <entry><type>bigint</type></entry>
2608 <entry>Number of queries in this database that have been canceled due to
2609 old snapshots</entry>
2612 <entry><structfield>confl_bufferpin</structfield></entry>
2613 <entry><type>bigint</type></entry>
2614 <entry>Number of queries in this database that have been canceled due to
2615 pinned buffers</entry>
2618 <entry><structfield>confl_deadlock</structfield></entry>
2619 <entry><type>bigint</type></entry>
2620 <entry>Number of queries in this database that have been canceled due to
2628 The <structname>pg_stat_database_conflicts</structname> view will contain
2629 one row per database, showing database-wide statistics about
2630 query cancels occurring due to conflicts with recovery on standby servers.
2631 This view will only contain information on standby servers, since
2632 conflicts do not occur on master servers.
2635 <table id="pg-stat-all-tables-view" xreflabel="pg_stat_all_tables">
2636 <title><structname>pg_stat_all_tables</structname> View</title>
2640 <entry>Column</entry>
2642 <entry>Description</entry>
2648 <entry><structfield>relid</structfield></entry>
2649 <entry><type>oid</type></entry>
2650 <entry>OID of a table</entry>
2653 <entry><structfield>schemaname</structfield></entry>
2654 <entry><type>name</type></entry>
2655 <entry>Name of the schema that this table is in</entry>
2658 <entry><structfield>relname</structfield></entry>
2659 <entry><type>name</type></entry>
2660 <entry>Name of this table</entry>
2663 <entry><structfield>seq_scan</structfield></entry>
2664 <entry><type>bigint</type></entry>
2665 <entry>Number of sequential scans initiated on this table</entry>
2668 <entry><structfield>seq_tup_read</structfield></entry>
2669 <entry><type>bigint</type></entry>
2670 <entry>Number of live rows fetched by sequential scans</entry>
2673 <entry><structfield>idx_scan</structfield></entry>
2674 <entry><type>bigint</type></entry>
2675 <entry>Number of index scans initiated on this table</entry>
2678 <entry><structfield>idx_tup_fetch</structfield></entry>
2679 <entry><type>bigint</type></entry>
2680 <entry>Number of live rows fetched by index scans</entry>
2683 <entry><structfield>n_tup_ins</structfield></entry>
2684 <entry><type>bigint</type></entry>
2685 <entry>Number of rows inserted</entry>
2688 <entry><structfield>n_tup_upd</structfield></entry>
2689 <entry><type>bigint</type></entry>
2690 <entry>Number of rows updated (includes HOT updated rows)</entry>
2693 <entry><structfield>n_tup_del</structfield></entry>
2694 <entry><type>bigint</type></entry>
2695 <entry>Number of rows deleted</entry>
2698 <entry><structfield>n_tup_hot_upd</structfield></entry>
2699 <entry><type>bigint</type></entry>
2700 <entry>Number of rows HOT updated (i.e., with no separate index
2701 update required)</entry>
2704 <entry><structfield>n_live_tup</structfield></entry>
2705 <entry><type>bigint</type></entry>
2706 <entry>Estimated number of live rows</entry>
2709 <entry><structfield>n_dead_tup</structfield></entry>
2710 <entry><type>bigint</type></entry>
2711 <entry>Estimated number of dead rows</entry>
2714 <entry><structfield>n_mod_since_analyze</structfield></entry>
2715 <entry><type>bigint</type></entry>
2716 <entry>Estimated number of rows modified since this table was last analyzed</entry>
2719 <entry><structfield>last_vacuum</structfield></entry>
2720 <entry><type>timestamp with time zone</type></entry>
2721 <entry>Last time at which this table was manually vacuumed
2722 (not counting <command>VACUUM FULL</command>)</entry>
2725 <entry><structfield>last_autovacuum</structfield></entry>
2726 <entry><type>timestamp with time zone</type></entry>
2727 <entry>Last time at which this table was vacuumed by the autovacuum
2731 <entry><structfield>last_analyze</structfield></entry>
2732 <entry><type>timestamp with time zone</type></entry>
2733 <entry>Last time at which this table was manually analyzed</entry>
2736 <entry><structfield>last_autoanalyze</structfield></entry>
2737 <entry><type>timestamp with time zone</type></entry>
2738 <entry>Last time at which this table was analyzed by the autovacuum
2742 <entry><structfield>vacuum_count</structfield></entry>
2743 <entry><type>bigint</type></entry>
2744 <entry>Number of times this table has been manually vacuumed
2745 (not counting <command>VACUUM FULL</command>)</entry>
2748 <entry><structfield>autovacuum_count</structfield></entry>
2749 <entry><type>bigint</type></entry>
2750 <entry>Number of times this table has been vacuumed by the autovacuum
2754 <entry><structfield>analyze_count</structfield></entry>
2755 <entry><type>bigint</type></entry>
2756 <entry>Number of times this table has been manually analyzed</entry>
2759 <entry><structfield>autoanalyze_count</structfield></entry>
2760 <entry><type>bigint</type></entry>
2761 <entry>Number of times this table has been analyzed by the autovacuum
2769 The <structname>pg_stat_all_tables</structname> view will contain
2770 one row for each table in the current database (including TOAST
2771 tables), showing statistics about accesses to that specific table. The
2772 <structname>pg_stat_user_tables</structname> and
2773 <structname>pg_stat_sys_tables</structname> views
2774 contain the same information,
2775 but filtered to only show user and system tables respectively.
2778 <table id="pg-stat-all-indexes-view" xreflabel="pg_stat_all_indexes">
2779 <title><structname>pg_stat_all_indexes</structname> View</title>
2783 <entry>Column</entry>
2785 <entry>Description</entry>
2791 <entry><structfield>relid</structfield></entry>
2792 <entry><type>oid</type></entry>
2793 <entry>OID of the table for this index</entry>
2796 <entry><structfield>indexrelid</structfield></entry>
2797 <entry><type>oid</type></entry>
2798 <entry>OID of this index</entry>
2801 <entry><structfield>schemaname</structfield></entry>
2802 <entry><type>name</type></entry>
2803 <entry>Name of the schema this index is in</entry>
2806 <entry><structfield>relname</structfield></entry>
2807 <entry><type>name</type></entry>
2808 <entry>Name of the table for this index</entry>
2811 <entry><structfield>indexrelname</structfield></entry>
2812 <entry><type>name</type></entry>
2813 <entry>Name of this index</entry>
2816 <entry><structfield>idx_scan</structfield></entry>
2817 <entry><type>bigint</type></entry>
2818 <entry>Number of index scans initiated on this index</entry>
2821 <entry><structfield>idx_tup_read</structfield></entry>
2822 <entry><type>bigint</type></entry>
2823 <entry>Number of index entries returned by scans on this index</entry>
2826 <entry><structfield>idx_tup_fetch</structfield></entry>
2827 <entry><type>bigint</type></entry>
2828 <entry>Number of live table rows fetched by simple index scans using this
2836 The <structname>pg_stat_all_indexes</structname> view will contain
2837 one row for each index in the current database,
2838 showing statistics about accesses to that specific index. The
2839 <structname>pg_stat_user_indexes</structname> and
2840 <structname>pg_stat_sys_indexes</structname> views
2841 contain the same information,
2842 but filtered to only show user and system indexes respectively.
2846 Indexes can be used by simple index scans, <quote>bitmap</quote> index scans,
2847 and the optimizer. In a bitmap scan
2848 the output of several indexes can be combined via AND or OR rules,
2849 so it is difficult to associate individual heap row fetches
2850 with specific indexes when a bitmap scan is used. Therefore, a bitmap
2852 <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_read</structfield>
2853 count(s) for the index(es) it uses, and it increments the
2854 <structname>pg_stat_all_tables</structname>.<structfield>idx_tup_fetch</structfield>
2855 count for the table, but it does not affect
2856 <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_fetch</structfield>.
2857 The optimizer also accesses indexes to check for supplied constants
2858 whose values are outside the recorded range of the optimizer statistics
2859 because the optimizer statistics might be stale.
2864 The <structfield>idx_tup_read</structfield> and <structfield>idx_tup_fetch</structfield> counts
2865 can be different even without any use of bitmap scans,
2866 because <structfield>idx_tup_read</structfield> counts
2867 index entries retrieved from the index while <structfield>idx_tup_fetch</structfield>
2868 counts live rows fetched from the table. The latter will be less if any
2869 dead or not-yet-committed rows are fetched using the index, or if any
2870 heap fetches are avoided by means of an index-only scan.
2874 <table id="pg-statio-all-tables-view" xreflabel="pg_statio_all_tables">
2875 <title><structname>pg_statio_all_tables</structname> View</title>
2879 <entry>Column</entry>
2881 <entry>Description</entry>
2887 <entry><structfield>relid</structfield></entry>
2888 <entry><type>oid</type></entry>
2889 <entry>OID of a table</entry>
2892 <entry><structfield>schemaname</structfield></entry>
2893 <entry><type>name</type></entry>
2894 <entry>Name of the schema that this table is in</entry>
2897 <entry><structfield>relname</structfield></entry>
2898 <entry><type>name</type></entry>
2899 <entry>Name of this table</entry>
2902 <entry><structfield>heap_blks_read</structfield></entry>
2903 <entry><type>bigint</type></entry>
2904 <entry>Number of disk blocks read from this table</entry>
2907 <entry><structfield>heap_blks_hit</structfield></entry>
2908 <entry><type>bigint</type></entry>
2909 <entry>Number of buffer hits in this table</entry>
2912 <entry><structfield>idx_blks_read</structfield></entry>
2913 <entry><type>bigint</type></entry>
2914 <entry>Number of disk blocks read from all indexes on this table</entry>
2917 <entry><structfield>idx_blks_hit</structfield></entry>
2918 <entry><type>bigint</type></entry>
2919 <entry>Number of buffer hits in all indexes on this table</entry>
2922 <entry><structfield>toast_blks_read</structfield></entry>
2923 <entry><type>bigint</type></entry>
2924 <entry>Number of disk blocks read from this table's TOAST table (if any)</entry>
2927 <entry><structfield>toast_blks_hit</structfield></entry>
2928 <entry><type>bigint</type></entry>
2929 <entry>Number of buffer hits in this table's TOAST table (if any)</entry>
2932 <entry><structfield>tidx_blks_read</structfield></entry>
2933 <entry><type>bigint</type></entry>
2934 <entry>Number of disk blocks read from this table's TOAST table indexes (if any)</entry>
2937 <entry><structfield>tidx_blks_hit</structfield></entry>
2938 <entry><type>bigint</type></entry>
2939 <entry>Number of buffer hits in this table's TOAST table indexes (if any)</entry>
2946 The <structname>pg_statio_all_tables</structname> view will contain
2947 one row for each table in the current database (including TOAST
2948 tables), showing statistics about I/O on that specific table. The
2949 <structname>pg_statio_user_tables</structname> and
2950 <structname>pg_statio_sys_tables</structname> views
2951 contain the same information,
2952 but filtered to only show user and system tables respectively.
2955 <table id="pg-statio-all-indexes-view" xreflabel="pg_statio_all_indexes">
2956 <title><structname>pg_statio_all_indexes</structname> View</title>
2960 <entry>Column</entry>
2962 <entry>Description</entry>
2968 <entry><structfield>relid</structfield></entry>
2969 <entry><type>oid</type></entry>
2970 <entry>OID of the table for this index</entry>
2973 <entry><structfield>indexrelid</structfield></entry>
2974 <entry><type>oid</type></entry>
2975 <entry>OID of this index</entry>
2978 <entry><structfield>schemaname</structfield></entry>
2979 <entry><type>name</type></entry>
2980 <entry>Name of the schema this index is in</entry>
2983 <entry><structfield>relname</structfield></entry>
2984 <entry><type>name</type></entry>
2985 <entry>Name of the table for this index</entry>
2988 <entry><structfield>indexrelname</structfield></entry>
2989 <entry><type>name</type></entry>
2990 <entry>Name of this index</entry>
2993 <entry><structfield>idx_blks_read</structfield></entry>
2994 <entry><type>bigint</type></entry>
2995 <entry>Number of disk blocks read from this index</entry>
2998 <entry><structfield>idx_blks_hit</structfield></entry>
2999 <entry><type>bigint</type></entry>
3000 <entry>Number of buffer hits in this index</entry>
3007 The <structname>pg_statio_all_indexes</structname> view will contain
3008 one row for each index in the current database,
3009 showing statistics about I/O on that specific index. The
3010 <structname>pg_statio_user_indexes</structname> and
3011 <structname>pg_statio_sys_indexes</structname> views
3012 contain the same information,
3013 but filtered to only show user and system indexes respectively.
3016 <table id="pg-statio-all-sequences-view" xreflabel="pg_statio_all_sequences">
3017 <title><structname>pg_statio_all_sequences</structname> View</title>
3021 <entry>Column</entry>
3023 <entry>Description</entry>
3029 <entry><structfield>relid</structfield></entry>
3030 <entry><type>oid</type></entry>
3031 <entry>OID of a sequence</entry>
3034 <entry><structfield>schemaname</structfield></entry>
3035 <entry><type>name</type></entry>
3036 <entry>Name of the schema this sequence is in</entry>
3039 <entry><structfield>relname</structfield></entry>
3040 <entry><type>name</type></entry>
3041 <entry>Name of this sequence</entry>
3044 <entry><structfield>blks_read</structfield></entry>
3045 <entry><type>bigint</type></entry>
3046 <entry>Number of disk blocks read from this sequence</entry>
3049 <entry><structfield>blks_hit</structfield></entry>
3050 <entry><type>bigint</type></entry>
3051 <entry>Number of buffer hits in this sequence</entry>
3058 The <structname>pg_statio_all_sequences</structname> view will contain
3059 one row for each sequence in the current database,
3060 showing statistics about I/O on that specific sequence.
3063 <table id="pg-stat-user-functions-view" xreflabel="pg_stat_user_functions">
3064 <title><structname>pg_stat_user_functions</structname> View</title>
3068 <entry>Column</entry>
3070 <entry>Description</entry>
3076 <entry><structfield>funcid</structfield></entry>
3077 <entry><type>oid</type></entry>
3078 <entry>OID of a function</entry>
3081 <entry><structfield>schemaname</structfield></entry>
3082 <entry><type>name</type></entry>
3083 <entry>Name of the schema this function is in</entry>
3086 <entry><structfield>funcname</structfield></entry>
3087 <entry><type>name</type></entry>
3088 <entry>Name of this function</entry>
3091 <entry><structfield>calls</structfield></entry>
3092 <entry><type>bigint</type></entry>
3093 <entry>Number of times this function has been called</entry>
3096 <entry><structfield>total_time</structfield></entry>
3097 <entry><type>double precision</type></entry>
3098 <entry>Total time spent in this function and all other functions
3099 called by it, in milliseconds</entry>
3102 <entry><structfield>self_time</structfield></entry>
3103 <entry><type>double precision</type></entry>
3104 <entry>Total time spent in this function itself, not including
3105 other functions called by it, in milliseconds</entry>
3112 The <structname>pg_stat_user_functions</structname> view will contain
3113 one row for each tracked function, showing statistics about executions of
3114 that function. The <xref linkend="guc-track-functions"/> parameter
3115 controls exactly which functions are tracked.
3120 <sect2 id="monitoring-stats-functions">
3121 <title>Statistics Functions</title>
3124 Other ways of looking at the statistics can be set up by writing
3125 queries that use the same underlying statistics access functions used by
3126 the standard views shown above. For details such as the functions' names,
3127 consult the definitions of the standard views. (For example, in
3128 <application>psql</application> you could issue <literal>\d+ pg_stat_activity</literal>.)
3129 The access functions for per-database statistics take a database OID as an
3130 argument to identify which database to report on.
3131 The per-table and per-index functions take a table or index OID.
3132 The functions for per-function statistics take a function OID.
3133 Note that only tables, indexes, and functions in the current database
3134 can be seen with these functions.
3138 Additional functions related to statistics collection are listed in <xref
3139 linkend="monitoring-stats-funcs-table"/>.
3142 <table id="monitoring-stats-funcs-table">
3143 <title>Additional Statistics Functions</title>
3148 <entry>Function</entry>
3149 <entry>Return Type</entry>
3150 <entry>Description</entry>
3157 <!-- See also the entry for this in func.sgml -->
3158 <entry><literal><function>pg_backend_pid()</function></literal></entry>
3159 <entry><type>integer</type></entry>
3161 Process ID of the server process handling the current session
3166 <entry><literal><function>pg_stat_get_activity</function>(<type>integer</type>)</literal><indexterm><primary>pg_stat_get_activity</primary></indexterm></entry>
3167 <entry><type>setof record</type></entry>
3169 Returns a record of information about the backend with the specified PID, or
3170 one record for each active backend in the system if <symbol>NULL</symbol> is
3171 specified. The fields returned are a subset of those in the
3172 <structname>pg_stat_activity</structname> view.
3177 <entry><literal><function>pg_stat_get_snapshot_timestamp()</function></literal><indexterm><primary>pg_stat_get_snapshot_timestamp</primary></indexterm></entry>
3178 <entry><type>timestamp with time zone</type></entry>
3180 Returns the timestamp of the current statistics snapshot
3185 <entry><literal><function>pg_stat_clear_snapshot()</function></literal><indexterm><primary>pg_stat_clear_snapshot</primary></indexterm></entry>
3186 <entry><type>void</type></entry>
3188 Discard the current statistics snapshot
3193 <entry><literal><function>pg_stat_reset()</function></literal><indexterm><primary>pg_stat_reset</primary></indexterm></entry>
3194 <entry><type>void</type></entry>
3196 Reset all statistics counters for the current database to zero
3197 (requires superuser privileges by default, but EXECUTE for this
3198 function can be granted to others.)
3203 <entry><literal><function>pg_stat_reset_shared</function>(text)</literal><indexterm><primary>pg_stat_reset_shared</primary></indexterm></entry>
3204 <entry><type>void</type></entry>
3206 Reset some cluster-wide statistics counters to zero, depending on the
3207 argument (requires superuser privileges by default, but EXECUTE for
3208 this function can be granted to others).
3209 Calling <literal>pg_stat_reset_shared('bgwriter')</literal> will zero all the
3210 counters shown in the <structname>pg_stat_bgwriter</structname> view.
3211 Calling <literal>pg_stat_reset_shared('archiver')</literal> will zero all the
3212 counters shown in the <structname>pg_stat_archiver</structname> view.
3217 <entry><literal><function>pg_stat_reset_single_table_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_table_counters</primary></indexterm></entry>
3218 <entry><type>void</type></entry>
3220 Reset statistics for a single table or index in the current database to
3221 zero (requires superuser privileges by default, but EXECUTE for this
3222 function can be granted to others)
3227 <entry><literal><function>pg_stat_reset_single_function_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_function_counters</primary></indexterm></entry>
3228 <entry><type>void</type></entry>
3230 Reset statistics for a single function in the current database to
3231 zero (requires superuser privileges by default, but EXECUTE for this
3232 function can be granted to others)
3240 <function>pg_stat_get_activity</function>, the underlying function of
3241 the <structname>pg_stat_activity</structname> view, returns a set of records
3242 containing all the available information about each backend process.
3243 Sometimes it may be more convenient to obtain just a subset of this
3244 information. In such cases, an older set of per-backend statistics
3245 access functions can be used; these are shown in <xref
3246 linkend="monitoring-stats-backend-funcs-table"/>.
3247 These access functions use a backend ID number, which ranges from one
3248 to the number of currently active backends.
3249 The function <function>pg_stat_get_backend_idset</function> provides a
3250 convenient way to generate one row for each active backend for
3251 invoking these functions. For example, to show the <acronym>PID</acronym>s and
3252 current queries of all backends:
3255 SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
3256 pg_stat_get_backend_activity(s.backendid) AS query
3257 FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
3261 <table id="monitoring-stats-backend-funcs-table">
3262 <title>Per-Backend Statistics Functions</title>
3267 <entry>Function</entry>
3268 <entry>Return Type</entry>
3269 <entry>Description</entry>
3276 <entry><literal><function>pg_stat_get_backend_idset()</function></literal></entry>
3277 <entry><type>setof integer</type></entry>
3278 <entry>Set of currently active backend ID numbers (from 1 to the
3279 number of active backends)</entry>
3283 <entry><literal><function>pg_stat_get_backend_activity(integer)</function></literal></entry>
3284 <entry><type>text</type></entry>
3285 <entry>Text of this backend's most recent query</entry>
3289 <entry><literal><function>pg_stat_get_backend_activity_start(integer)</function></literal></entry>
3290 <entry><type>timestamp with time zone</type></entry>
3291 <entry>Time when the most recent query was started</entry>
3295 <entry><literal><function>pg_stat_get_backend_client_addr(integer)</function></literal></entry>
3296 <entry><type>inet</type></entry>
3297 <entry>IP address of the client connected to this backend</entry>
3301 <entry><literal><function>pg_stat_get_backend_client_port(integer)</function></literal></entry>
3302 <entry><type>integer</type></entry>
3303 <entry>TCP port number that the client is using for communication</entry>
3307 <entry><literal><function>pg_stat_get_backend_dbid(integer)</function></literal></entry>
3308 <entry><type>oid</type></entry>
3309 <entry>OID of the database this backend is connected to</entry>
3313 <entry><literal><function>pg_stat_get_backend_pid(integer)</function></literal></entry>
3314 <entry><type>integer</type></entry>
3315 <entry>Process ID of this backend</entry>
3319 <entry><literal><function>pg_stat_get_backend_start(integer)</function></literal></entry>
3320 <entry><type>timestamp with time zone</type></entry>
3321 <entry>Time when this process was started</entry>
3325 <entry><literal><function>pg_stat_get_backend_userid(integer)</function></literal></entry>
3326 <entry><type>oid</type></entry>
3327 <entry>OID of the user logged into this backend</entry>
3331 <entry><literal><function>pg_stat_get_backend_wait_event_type(integer)</function></literal></entry>
3332 <entry><type>text</type></entry>
3333 <entry>Wait event type name if backend is currently waiting, otherwise NULL.
3334 See <xref linkend="wait-event-table"/> for details.
3339 <entry><literal><function>pg_stat_get_backend_wait_event(integer)</function></literal></entry>
3340 <entry><type>text</type></entry>
3341 <entry>Wait event name if backend is currently waiting, otherwise NULL.
3342 See <xref linkend="wait-event-table"/> for details.
3347 <entry><literal><function>pg_stat_get_backend_xact_start(integer)</function></literal></entry>
3348 <entry><type>timestamp with time zone</type></entry>
3349 <entry>Time when the current transaction was started</entry>
3359 <sect1 id="monitoring-locks">
3360 <title>Viewing Locks</title>
3362 <indexterm zone="monitoring-locks">
3363 <primary>lock</primary>
3364 <secondary>monitoring</secondary>
3368 Another useful tool for monitoring database activity is the
3369 <structname>pg_locks</structname> system table. It allows the
3370 database administrator to view information about the outstanding
3371 locks in the lock manager. For example, this capability can be used
3377 View all the locks currently outstanding, all the locks on
3378 relations in a particular database, all the locks on a
3379 particular relation, or all the locks held by a particular
3380 <productname>PostgreSQL</productname> session.
3386 Determine the relation in the current database with the most
3387 ungranted locks (which might be a source of contention among
3394 Determine the effect of lock contention on overall database
3395 performance, as well as the extent to which contention varies
3396 with overall database traffic.
3401 Details of the <structname>pg_locks</structname> view appear in
3402 <xref linkend="view-pg-locks"/>.
3403 For more information on locking and managing concurrency with
3404 <productname>PostgreSQL</productname>, refer to <xref linkend="mvcc"/>.
3408 <sect1 id="progress-reporting">
3409 <title>Progress Reporting</title>
3412 <productname>PostgreSQL</productname> has the ability to report the progress of
3413 certain commands during command execution. Currently, the only commands
3414 which support progress reporting are <command>CREATE INDEX</command>,
3415 <command>VACUUM</command> and
3416 <command>CLUSTER</command>. This may be expanded in the future.
3419 <sect2 id="create-index-progress-reporting">
3420 <title>CREATE INDEX Progress Reporting</title>
3423 Whenever <command>CREATE INDEX</command> is running, the
3424 <structname>pg_stat_progress_create_index</structname> view will contain
3425 one row for each backend that is currently creating indexes. The tables
3426 below describe the information that will be reported and provide information
3427 about how to interpret it.
3430 <table id="pg-stat-progress-create-index-view" xreflabel="pg_stat_progress_create_index">
3431 <title><structname>pg_stat_progress_create_index</structname> View</title>
3435 <entry>Column</entry>
3437 <entry>Description</entry>
3443 <entry><structfield>pid</structfield></entry>
3444 <entry><type>integer</type></entry>
3445 <entry>Process ID of backend.</entry>
3448 <entry><structfield>datid</structfield></entry>
3449 <entry><type>oid</type></entry>
3450 <entry>OID of the database to which this backend is connected.</entry>
3453 <entry><structfield>datname</structfield></entry>
3454 <entry><type>name</type></entry>
3455 <entry>Name of the database to which this backend is connected.</entry>
3458 <entry><structfield>relid</structfield></entry>
3459 <entry><type>oid</type></entry>
3460 <entry>OID of the table on which the index is being created.</entry>
3463 <entry><structfield>phase</structfield></entry>
3464 <entry><type>text</type></entry>
3466 Current processing phase of index creation. See <xref linkend='create-index-phases'/>.
3470 <entry><structfield>lockers_total</structfield></entry>
3471 <entry><type>bigint</type></entry>
3473 Total number of lockers to wait for, when applicable.
3477 <entry><structfield>lockers_done</structfield></entry>
3478 <entry><type>bigint</type></entry>
3480 Number of lockers already waited for.
3484 <entry><structfield>current_locked_pid</structfield></entry>
3485 <entry><type>bigint</type></entry>
3487 Process ID of the locker currently being waited for.
3491 <entry><structfield>blocks_total</structfield></entry>
3492 <entry><type>bigint</type></entry>
3494 Total number of blocks to be processed in the current phase.
3498 <entry><structfield>blocks_done</structfield></entry>
3499 <entry><type>bigint</type></entry>
3501 Number of blocks already processed in the current phase.
3505 <entry><structfield>tuples_total</structfield></entry>
3506 <entry><type>bigint</type></entry>
3508 Total number of tuples to be processed in the current phase.
3512 <entry><structfield>tuples_done</structfield></entry>
3513 <entry><type>bigint</type></entry>
3515 Number of tuples already processed in the current phase.
3519 <entry><structfield>partitions_total</structfield></entry>
3520 <entry><type>bigint</type></entry>
3522 When creating an index on a partitioned table, this column is set to
3523 the total number of partitions on which the index is to be created.
3527 <entry><structfield>partitions_done</structfield></entry>
3528 <entry><type>bigint</type></entry>
3530 When creating an index on a partitioned table, this column is set to
3531 the number of partitions on which the index has been completed.
3538 <table id="create-index-phases">
3539 <title>CREATE INDEX phases</title>
3543 <entry>Phase</entry>
3544 <entry>Description</entry>
3549 <entry><literal>initializing</literal></entry>
3551 <command>CREATE INDEX</command> is preparing to create the index. This
3552 phase is expected to be very brief.
3556 <entry><literal>waiting for old snapshots</literal></entry>
3558 <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3559 that can potentially see the table to release their snapshots.
3560 This phase is skipped when not in concurrent mode.
3561 Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3562 and <structname>current_locker_pid</structname> contain the progress
3563 information for this phase.
3567 <entry><literal>building index</literal></entry>
3569 The index is being built by the access method-specific code. In this phase,
3570 access methods that support progress reporting fill in their own progress data,
3571 and the subphase is indicated in this column. Typically,
3572 <structname>blocks_total</structname> and <structname>blocks_done</structname>
3573 will contain progress data, as well as potentially
3574 <structname>tuples_total</structname> and <structname>tuples_done</structname>.
3578 <entry><literal>waiting for writer snapshots</literal></entry>
3580 <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3581 that can potentially write into the table to release their snapshots.
3582 This phase is skipped when not in concurrent mode.
3583 Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3584 and <structname>current_locker_pid</structname> contain the progress
3585 information for this phase.
3589 <entry><literal>index validation: scanning index</literal></entry>
3591 <command>CREATE INDEX CONCURRENTLY</command> is scanning the index searching
3592 for tuples that need to be validated.
3593 This phase is skipped when not in concurrent mode.
3594 Columns <structname>blocks_total</structname> (set to the total size of the index)
3595 and <structname>blocks_done</structname> contain the progress information for this phase.
3599 <entry><literal>index validation: sorting tuples</literal></entry>
3601 <command>CREATE INDEX CONCURRENTLY</command> is sorting the output of the
3602 index scanning phase.
3606 <entry><literal>index validation: scanning table</literal></entry>
3608 <command>CREATE INDEX CONCURRENTLY</command> is scanning the table
3609 to validate the index tuples collected in the previous two phases.
3610 This phase is skipped when not in concurrent mode.
3611 Columns <structname>blocks_total</structname> (set to the total size of the table)
3612 and <structname>blocks_done</structname> contain the progress information for this phase.
3616 <entry><literal>waiting for reader snapshots</literal></entry>
3618 <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3619 that can potentially see the table to release their snapshots. This
3620 phase is skipped when not in concurrent mode.
3621 Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3622 and <structname>current_locker_pid</structname> contain the progress
3623 information for this phase.
3632 <sect2 id="vacuum-progress-reporting">
3633 <title>VACUUM Progress Reporting</title>
3636 Whenever <command>VACUUM</command> is running, the
3637 <structname>pg_stat_progress_vacuum</structname> view will contain
3638 one row for each backend (including autovacuum worker processes) that is
3639 currently vacuuming. The tables below describe the information
3640 that will be reported and provide information about how to interpret it.
3641 Progress for <command>VACUUM FULL</command> commands is reported via
3642 <structname>pg_stat_progress_cluster</structname>
3643 because both <command>VACUUM FULL</command> and <command>CLUSTER</command>
3644 rewrite the table, while regular <command>VACUUM</command> only modifies it
3645 in place. See <xref linkend='cluster-progress-reporting'/>.
3648 <table id="pg-stat-progress-vacuum-view" xreflabel="pg_stat_progress_vacuum">
3649 <title><structname>pg_stat_progress_vacuum</structname> View</title>
3653 <entry>Column</entry>
3655 <entry>Description</entry>
3661 <entry><structfield>pid</structfield></entry>
3662 <entry><type>integer</type></entry>
3663 <entry>Process ID of backend.</entry>
3666 <entry><structfield>datid</structfield></entry>
3667 <entry><type>oid</type></entry>
3668 <entry>OID of the database to which this backend is connected.</entry>
3671 <entry><structfield>datname</structfield></entry>
3672 <entry><type>name</type></entry>
3673 <entry>Name of the database to which this backend is connected.</entry>
3676 <entry><structfield>relid</structfield></entry>
3677 <entry><type>oid</type></entry>
3678 <entry>OID of the table being vacuumed.</entry>
3681 <entry><structfield>phase</structfield></entry>
3682 <entry><type>text</type></entry>
3684 Current processing phase of vacuum. See <xref linkend='vacuum-phases'/>.
3688 <entry><structfield>heap_blks_total</structfield></entry>
3689 <entry><type>bigint</type></entry>
3691 Total number of heap blocks in the table. This number is reported
3692 as of the beginning of the scan; blocks added later will not be (and
3693 need not be) visited by this <command>VACUUM</command>.
3697 <entry><structfield>heap_blks_scanned</structfield></entry>
3698 <entry><type>bigint</type></entry>
3700 Number of heap blocks scanned. Because the
3701 <link linkend="storage-vm">visibility map</link> is used to optimize scans,
3702 some blocks will be skipped without inspection; skipped blocks are
3703 included in this total, so that this number will eventually become
3704 equal to <structfield>heap_blks_total</structfield> when the vacuum is complete.
3705 This counter only advances when the phase is <literal>scanning heap</literal>.
3709 <entry><structfield>heap_blks_vacuumed</structfield></entry>
3710 <entry><type>bigint</type></entry>
3712 Number of heap blocks vacuumed. Unless the table has no indexes, this
3713 counter only advances when the phase is <literal>vacuuming heap</literal>.
3714 Blocks that contain no dead tuples are skipped, so the counter may
3715 sometimes skip forward in large increments.
3719 <entry><structfield>index_vacuum_count</structfield></entry>
3720 <entry><type>bigint</type></entry>
3722 Number of completed index vacuum cycles.
3726 <entry><structfield>max_dead_tuples</structfield></entry>
3727 <entry><type>bigint</type></entry>
3729 Number of dead tuples that we can store before needing to perform
3730 an index vacuum cycle, based on
3731 <xref linkend="guc-maintenance-work-mem"/>.
3735 <entry><structfield>num_dead_tuples</structfield></entry>
3736 <entry><type>bigint</type></entry>
3738 Number of dead tuples collected since the last index vacuum cycle.
3745 <table id="vacuum-phases">
3746 <title>VACUUM phases</title>
3750 <entry>Phase</entry>
3751 <entry>Description</entry>
3757 <entry><literal>initializing</literal></entry>
3759 <command>VACUUM</command> is preparing to begin scanning the heap. This
3760 phase is expected to be very brief.
3764 <entry><literal>scanning heap</literal></entry>
3766 <command>VACUUM</command> is currently scanning the heap. It will prune and
3767 defragment each page if required, and possibly perform freezing
3768 activity. The <structfield>heap_blks_scanned</structfield> column can be used
3769 to monitor the progress of the scan.
3773 <entry><literal>vacuuming indexes</literal></entry>
3775 <command>VACUUM</command> is currently vacuuming the indexes. If a table has
3776 any indexes, this will happen at least once per vacuum, after the heap
3777 has been completely scanned. It may happen multiple times per vacuum
3778 if <xref linkend="guc-maintenance-work-mem"/> is insufficient to
3779 store the number of dead tuples found.
3783 <entry><literal>vacuuming heap</literal></entry>
3785 <command>VACUUM</command> is currently vacuuming the heap. Vacuuming the heap
3786 is distinct from scanning the heap, and occurs after each instance of
3787 vacuuming indexes. If <structfield>heap_blks_scanned</structfield> is less than
3788 <structfield>heap_blks_total</structfield>, the system will return to scanning
3789 the heap after this phase is completed; otherwise, it will begin
3790 cleaning up indexes after this phase is completed.
3794 <entry><literal>cleaning up indexes</literal></entry>
3796 <command>VACUUM</command> is currently cleaning up indexes. This occurs after
3797 the heap has been completely scanned and all vacuuming of the indexes
3798 and the heap has been completed.
3802 <entry><literal>truncating heap</literal></entry>
3804 <command>VACUUM</command> is currently truncating the heap so as to return
3805 empty pages at the end of the relation to the operating system. This
3806 occurs after cleaning up indexes.
3810 <entry><literal>performing final cleanup</literal></entry>
3812 <command>VACUUM</command> is performing final cleanup. During this phase,
3813 <command>VACUUM</command> will vacuum the free space map, update statistics
3814 in <literal>pg_class</literal>, and report statistics to the statistics
3815 collector. When this phase is completed, <command>VACUUM</command> will end.
3824 <sect2 id="cluster-progress-reporting">
3825 <title>CLUSTER Progress Reporting</title>
3828 Whenever <command>CLUSTER</command> or <command>VACUUM FULL</command> is
3829 running, the <structname>pg_stat_progress_cluster</structname> view will
3830 contain a row for each backend that is currently running either command.
3831 The tables below describe the information that will be reported and
3832 provide information about how to interpret it.
3835 <table id="pg-stat-progress-cluster-view" xreflabel="pg_stat_progress_cluster">
3836 <title><structname>pg_stat_progress_cluster</structname> View</title>
3840 <entry>Column</entry>
3842 <entry>Description</entry>
3848 <entry><structfield>pid</structfield></entry>
3849 <entry><type>integer</type></entry>
3850 <entry>Process ID of backend.</entry>
3853 <entry><structfield>datid</structfield></entry>
3854 <entry><type>oid</type></entry>
3855 <entry>OID of the database to which this backend is connected.</entry>
3858 <entry><structfield>datname</structfield></entry>
3859 <entry><type>name</type></entry>
3860 <entry>Name of the database to which this backend is connected.</entry>
3863 <entry><structfield>relid</structfield></entry>
3864 <entry><type>oid</type></entry>
3865 <entry>OID of the table being clustered.</entry>
3868 <entry><structfield>command</structfield></entry>
3869 <entry><type>text</type></entry>
3871 The command that is running. Either CLUSTER or VACUUM FULL.
3875 <entry><structfield>phase</structfield></entry>
3876 <entry><type>text</type></entry>
3878 Current processing phase. See <xref linkend='cluster-phases' />.
3882 <entry><structfield>cluster_index_relid</structfield></entry>
3883 <entry><type>bigint</type></entry>
3885 If the table is being scanned using an index, this is the OID of the
3886 index being used; otherwise, it is zero.
3890 <entry><structfield>heap_tuples_scanned</structfield></entry>
3891 <entry><type>bigint</type></entry>
3893 Number of heap tuples scanned.
3894 This counter only advances when the phase is
3895 <literal>seq scanning heap</literal>,
3896 <literal>index scanning heap</literal>
3897 or <literal>writing new heap</literal>.
3901 <entry><structfield>heap_tuples_written</structfield></entry>
3902 <entry><type>bigint</type></entry>
3904 Number of heap tuples written.
3905 This counter only advances when the phase is
3906 <literal>seq scanning heap</literal>,
3907 <literal>index scanning heap</literal>
3908 or <literal>writing new heap</literal>.
3912 <entry><structfield>heap_blks_total</structfield></entry>
3913 <entry><type>bigint</type></entry>
3915 Total number of heap blocks in the table. This number is reported
3916 as of the beginning of <literal>seq scanning heap</literal>.
3920 <entry><structfield>heap_blks_scanned</structfield></entry>
3921 <entry><type>bigint</type></entry>
3923 Number of heap blocks scanned. This counter only advances when the
3924 phase is <literal>seq scanning heap</literal>.
3928 <entry><structfield>index_rebuild_count</structfield></entry>
3929 <entry><type>bigint</type></entry>
3931 Number of indexes rebuilt. This counter only advances when the phase
3932 is <literal>rebuilding index</literal>.
3939 <table id="cluster-phases">
3940 <title>CLUSTER and VACUUM FULL phases</title>
3944 <entry>Phase</entry>
3945 <entry>Description</entry>
3951 <entry><literal>initializing</literal></entry>
3953 The command is preparing to begin scanning the heap. This phase is
3954 expected to be very brief.
3958 <entry><literal>seq scanning heap</literal></entry>
3960 The command is currently scanning the table using a sequential scan.
3964 <entry><literal>index scanning heap</literal></entry>
3966 <command>CLUSTER</command> is currently scanning the table using an index scan.
3970 <entry><literal>sorting tuples</literal></entry>
3972 <command>CLUSTER</command> is currently sorting tuples.
3976 <entry><literal>swapping relation files</literal></entry>
3978 The command is currently swapping newly-built files into place.
3982 <entry><literal>rebuilding index</literal></entry>
3984 The command is currently rebuilding an index.
3988 <entry><literal>performing final cleanup</literal></entry>
3990 The command is performing final cleanup. When this phase is
3991 completed, <command>CLUSTER</command>
3992 or <command>VACUUM FULL</command> will end.
4002 <sect1 id="dynamic-trace">
4003 <title>Dynamic Tracing</title>
4005 <indexterm zone="dynamic-trace">
4006 <primary>DTrace</primary>
4010 <productname>PostgreSQL</productname> provides facilities to support
4011 dynamic tracing of the database server. This allows an external
4012 utility to be called at specific points in the code and thereby trace
4017 A number of probes or trace points are already inserted into the source
4018 code. These probes are intended to be used by database developers and
4019 administrators. By default the probes are not compiled into
4020 <productname>PostgreSQL</productname>; the user needs to explicitly tell
4021 the configure script to make the probes available.
4026 <ulink url="https://en.wikipedia.org/wiki/DTrace">DTrace</ulink>
4027 utility is supported, which, at the time of this writing, is available
4028 on Solaris, macOS, FreeBSD, NetBSD, and Oracle Linux. The
4029 <ulink url="http://sourceware.org/systemtap/">SystemTap</ulink> project
4030 for Linux provides a DTrace equivalent and can also be used. Supporting other dynamic
4031 tracing utilities is theoretically possible by changing the definitions for
4032 the macros in <filename>src/include/utils/probes.h</filename>.
4035 <sect2 id="compiling-for-trace">
4036 <title>Compiling for Dynamic Tracing</title>
4039 By default, probes are not available, so you will need to
4040 explicitly tell the configure script to make the probes available
4041 in <productname>PostgreSQL</productname>. To include DTrace support
4042 specify <option>--enable-dtrace</option> to configure. See <xref
4043 linkend="install-procedure"/> for further information.
4047 <sect2 id="trace-points">
4048 <title>Built-in Probes</title>
4051 A number of standard probes are provided in the source code,
4052 as shown in <xref linkend="dtrace-probe-point-table"/>;
4053 <xref linkend="typedefs-table"/>
4054 shows the types used in the probes. More probes can certainly be
4055 added to enhance <productname>PostgreSQL</productname>'s observability.
4058 <table id="dtrace-probe-point-table">
4059 <title>Built-in DTrace Probes</title>
4064 <entry>Parameters</entry>
4065 <entry>Description</entry>
4072 <entry><literal>transaction-start</literal></entry>
4073 <entry><literal>(LocalTransactionId)</literal></entry>
4074 <entry>Probe that fires at the start of a new transaction.
4075 arg0 is the transaction ID.</entry>
4078 <entry><literal>transaction-commit</literal></entry>
4079 <entry><literal>(LocalTransactionId)</literal></entry>
4080 <entry>Probe that fires when a transaction completes successfully.
4081 arg0 is the transaction ID.</entry>
4084 <entry><literal>transaction-abort</literal></entry>
4085 <entry><literal>(LocalTransactionId)</literal></entry>
4086 <entry>Probe that fires when a transaction completes unsuccessfully.
4087 arg0 is the transaction ID.</entry>
4090 <entry><literal>query-start</literal></entry>
4091 <entry><literal>(const char *)</literal></entry>
4092 <entry>Probe that fires when the processing of a query is started.
4093 arg0 is the query string.</entry>
4096 <entry><literal>query-done</literal></entry>
4097 <entry><literal>(const char *)</literal></entry>
4098 <entry>Probe that fires when the processing of a query is complete.
4099 arg0 is the query string.</entry>
4102 <entry><literal>query-parse-start</literal></entry>
4103 <entry><literal>(const char *)</literal></entry>
4104 <entry>Probe that fires when the parsing of a query is started.
4105 arg0 is the query string.</entry>
4108 <entry><literal>query-parse-done</literal></entry>
4109 <entry><literal>(const char *)</literal></entry>
4110 <entry>Probe that fires when the parsing of a query is complete.
4111 arg0 is the query string.</entry>
4114 <entry><literal>query-rewrite-start</literal></entry>
4115 <entry><literal>(const char *)</literal></entry>
4116 <entry>Probe that fires when the rewriting of a query is started.
4117 arg0 is the query string.</entry>
4120 <entry><literal>query-rewrite-done</literal></entry>
4121 <entry><literal>(const char *)</literal></entry>
4122 <entry>Probe that fires when the rewriting of a query is complete.
4123 arg0 is the query string.</entry>
4126 <entry><literal>query-plan-start</literal></entry>
4127 <entry><literal>()</literal></entry>
4128 <entry>Probe that fires when the planning of a query is started.</entry>
4131 <entry><literal>query-plan-done</literal></entry>
4132 <entry><literal>()</literal></entry>
4133 <entry>Probe that fires when the planning of a query is complete.</entry>
4136 <entry><literal>query-execute-start</literal></entry>
4137 <entry><literal>()</literal></entry>
4138 <entry>Probe that fires when the execution of a query is started.</entry>
4141 <entry><literal>query-execute-done</literal></entry>
4142 <entry><literal>()</literal></entry>
4143 <entry>Probe that fires when the execution of a query is complete.</entry>
4146 <entry><literal>statement-status</literal></entry>
4147 <entry><literal>(const char *)</literal></entry>
4148 <entry>Probe that fires anytime the server process updates its
4149 <structname>pg_stat_activity</structname>.<structfield>status</structfield>.
4150 arg0 is the new status string.</entry>
4153 <entry><literal>checkpoint-start</literal></entry>
4154 <entry><literal>(int)</literal></entry>
4155 <entry>Probe that fires when a checkpoint is started.
4156 arg0 holds the bitwise flags used to distinguish different checkpoint
4157 types, such as shutdown, immediate or force.</entry>
4160 <entry><literal>checkpoint-done</literal></entry>
4161 <entry><literal>(int, int, int, int, int)</literal></entry>
4162 <entry>Probe that fires when a checkpoint is complete.
4163 (The probes listed next fire in sequence during checkpoint processing.)
4164 arg0 is the number of buffers written. arg1 is the total number of
4165 buffers. arg2, arg3 and arg4 contain the number of WAL files added,
4166 removed and recycled respectively.</entry>
4169 <entry><literal>clog-checkpoint-start</literal></entry>
4170 <entry><literal>(bool)</literal></entry>
4171 <entry>Probe that fires when the CLOG portion of a checkpoint is started.
4172 arg0 is true for normal checkpoint, false for shutdown
4176 <entry><literal>clog-checkpoint-done</literal></entry>
4177 <entry><literal>(bool)</literal></entry>
4178 <entry>Probe that fires when the CLOG portion of a checkpoint is
4179 complete. arg0 has the same meaning as for <literal>clog-checkpoint-start</literal>.</entry>
4182 <entry><literal>subtrans-checkpoint-start</literal></entry>
4183 <entry><literal>(bool)</literal></entry>
4184 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
4186 arg0 is true for normal checkpoint, false for shutdown
4190 <entry><literal>subtrans-checkpoint-done</literal></entry>
4191 <entry><literal>(bool)</literal></entry>
4192 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
4193 complete. arg0 has the same meaning as for
4194 <literal>subtrans-checkpoint-start</literal>.</entry>
4197 <entry><literal>multixact-checkpoint-start</literal></entry>
4198 <entry><literal>(bool)</literal></entry>
4199 <entry>Probe that fires when the MultiXact portion of a checkpoint is
4201 arg0 is true for normal checkpoint, false for shutdown
4205 <entry><literal>multixact-checkpoint-done</literal></entry>
4206 <entry><literal>(bool)</literal></entry>
4207 <entry>Probe that fires when the MultiXact portion of a checkpoint is
4208 complete. arg0 has the same meaning as for
4209 <literal>multixact-checkpoint-start</literal>.</entry>
4212 <entry><literal>buffer-checkpoint-start</literal></entry>
4213 <entry><literal>(int)</literal></entry>
4214 <entry>Probe that fires when the buffer-writing portion of a checkpoint
4216 arg0 holds the bitwise flags used to distinguish different checkpoint
4217 types, such as shutdown, immediate or force.</entry>
4220 <entry><literal>buffer-sync-start</literal></entry>
4221 <entry><literal>(int, int)</literal></entry>
4222 <entry>Probe that fires when we begin to write dirty buffers during
4223 checkpoint (after identifying which buffers must be written).
4224 arg0 is the total number of buffers.
4225 arg1 is the number that are currently dirty and need to be written.</entry>
4228 <entry><literal>buffer-sync-written</literal></entry>
4229 <entry><literal>(int)</literal></entry>
4230 <entry>Probe that fires after each buffer is written during checkpoint.
4231 arg0 is the ID number of the buffer.</entry>
4234 <entry><literal>buffer-sync-done</literal></entry>
4235 <entry><literal>(int, int, int)</literal></entry>
4236 <entry>Probe that fires when all dirty buffers have been written.
4237 arg0 is the total number of buffers.
4238 arg1 is the number of buffers actually written by the checkpoint process.
4239 arg2 is the number that were expected to be written (arg1 of
4240 <literal>buffer-sync-start</literal>); any difference reflects other processes flushing
4241 buffers during the checkpoint.</entry>
4244 <entry><literal>buffer-checkpoint-sync-start</literal></entry>
4245 <entry><literal>()</literal></entry>
4246 <entry>Probe that fires after dirty buffers have been written to the
4247 kernel, and before starting to issue fsync requests.</entry>
4250 <entry><literal>buffer-checkpoint-done</literal></entry>
4251 <entry><literal>()</literal></entry>
4252 <entry>Probe that fires when syncing of buffers to disk is
4256 <entry><literal>twophase-checkpoint-start</literal></entry>
4257 <entry><literal>()</literal></entry>
4258 <entry>Probe that fires when the two-phase portion of a checkpoint is
4262 <entry><literal>twophase-checkpoint-done</literal></entry>
4263 <entry><literal>()</literal></entry>
4264 <entry>Probe that fires when the two-phase portion of a checkpoint is
4268 <entry><literal>buffer-read-start</literal></entry>
4269 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool)</literal></entry>
4270 <entry>Probe that fires when a buffer read is started.
4271 arg0 and arg1 contain the fork and block numbers of the page (but
4272 arg1 will be -1 if this is a relation extension request).
4273 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4274 identifying the relation.
4275 arg5 is the ID of the backend which created the temporary relation for a
4276 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
4277 arg6 is true for a relation extension request, false for normal
4281 <entry><literal>buffer-read-done</literal></entry>
4282 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool, bool)</literal></entry>
4283 <entry>Probe that fires when a buffer read is complete.
4284 arg0 and arg1 contain the fork and block numbers of the page (if this
4285 is a relation extension request, arg1 now contains the block number
4286 of the newly added block).
4287 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4288 identifying the relation.
4289 arg5 is the ID of the backend which created the temporary relation for a
4290 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
4291 arg6 is true for a relation extension request, false for normal
4293 arg7 is true if the buffer was found in the pool, false if not.</entry>
4296 <entry><literal>buffer-flush-start</literal></entry>
4297 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
4298 <entry>Probe that fires before issuing any write request for a shared
4300 arg0 and arg1 contain the fork and block numbers of the page.
4301 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4302 identifying the relation.</entry>
4305 <entry><literal>buffer-flush-done</literal></entry>
4306 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
4307 <entry>Probe that fires when a write request is complete. (Note
4308 that this just reflects the time to pass the data to the kernel;
4309 it's typically not actually been written to disk yet.)
4310 The arguments are the same as for <literal>buffer-flush-start</literal>.</entry>
4313 <entry><literal>buffer-write-dirty-start</literal></entry>
4314 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
4315 <entry>Probe that fires when a server process begins to write a dirty
4316 buffer. (If this happens often, it implies that
4317 <xref linkend="guc-shared-buffers"/> is too
4318 small or the background writer control parameters need adjustment.)
4319 arg0 and arg1 contain the fork and block numbers of the page.
4320 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4321 identifying the relation.</entry>
4324 <entry><literal>buffer-write-dirty-done</literal></entry>
4325 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
4326 <entry>Probe that fires when a dirty-buffer write is complete.
4327 The arguments are the same as for <literal>buffer-write-dirty-start</literal>.</entry>
4330 <entry><literal>wal-buffer-write-dirty-start</literal></entry>
4331 <entry><literal>()</literal></entry>
4332 <entry>Probe that fires when a server process begins to write a
4333 dirty WAL buffer because no more WAL buffer space is available.
4334 (If this happens often, it implies that
4335 <xref linkend="guc-wal-buffers"/> is too small.)</entry>
4338 <entry><literal>wal-buffer-write-dirty-done</literal></entry>
4339 <entry><literal>()</literal></entry>
4340 <entry>Probe that fires when a dirty WAL buffer write is complete.</entry>
4343 <entry><literal>wal-insert</literal></entry>
4344 <entry><literal>(unsigned char, unsigned char)</literal></entry>
4345 <entry>Probe that fires when a WAL record is inserted.
4346 arg0 is the resource manager (rmid) for the record.
4347 arg1 contains the info flags.</entry>
4350 <entry><literal>wal-switch</literal></entry>
4351 <entry><literal>()</literal></entry>
4352 <entry>Probe that fires when a WAL segment switch is requested.</entry>
4355 <entry><literal>smgr-md-read-start</literal></entry>
4356 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
4357 <entry>Probe that fires when beginning to read a block from a relation.
4358 arg0 and arg1 contain the fork and block numbers of the page.
4359 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4360 identifying the relation.
4361 arg5 is the ID of the backend which created the temporary relation for a
4362 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
4365 <entry><literal>smgr-md-read-done</literal></entry>
4366 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
4367 <entry>Probe that fires when a block read is complete.
4368 arg0 and arg1 contain the fork and block numbers of the page.
4369 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4370 identifying the relation.
4371 arg5 is the ID of the backend which created the temporary relation for a
4372 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
4373 arg6 is the number of bytes actually read, while arg7 is the number
4374 requested (if these are different it indicates trouble).</entry>
4377 <entry><literal>smgr-md-write-start</literal></entry>
4378 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
4379 <entry>Probe that fires when beginning to write a block to a relation.
4380 arg0 and arg1 contain the fork and block numbers of the page.
4381 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4382 identifying the relation.
4383 arg5 is the ID of the backend which created the temporary relation for a
4384 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
4387 <entry><literal>smgr-md-write-done</literal></entry>
4388 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
4389 <entry>Probe that fires when a block write is complete.
4390 arg0 and arg1 contain the fork and block numbers of the page.
4391 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
4392 identifying the relation.
4393 arg5 is the ID of the backend which created the temporary relation for a
4394 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
4395 arg6 is the number of bytes actually written, while arg7 is the number
4396 requested (if these are different it indicates trouble).</entry>
4399 <entry><literal>sort-start</literal></entry>
4400 <entry><literal>(int, bool, int, int, bool, int)</literal></entry>
4401 <entry>Probe that fires when a sort operation is started.
4402 arg0 indicates heap, index or datum sort.
4403 arg1 is true for unique-value enforcement.
4404 arg2 is the number of key columns.
4405 arg3 is the number of kilobytes of work memory allowed.
4406 arg4 is true if random access to the sort result is required.
4407 arg5 indicates serial when <literal>0</literal>, parallel worker when
4408 <literal>1</literal>, or parallel leader when <literal>2</literal>.</entry>
4411 <entry><literal>sort-done</literal></entry>
4412 <entry><literal>(bool, long)</literal></entry>
4413 <entry>Probe that fires when a sort is complete.
4414 arg0 is true for external sort, false for internal sort.
4415 arg1 is the number of disk blocks used for an external sort,
4416 or kilobytes of memory used for an internal sort.</entry>
4419 <entry><literal>lwlock-acquire</literal></entry>
4420 <entry><literal>(char *, LWLockMode)</literal></entry>
4421 <entry>Probe that fires when an LWLock has been acquired.
4422 arg0 is the LWLock's tranche.
4423 arg1 is the requested lock mode, either exclusive or shared.</entry>
4426 <entry><literal>lwlock-release</literal></entry>
4427 <entry><literal>(char *)</literal></entry>
4428 <entry>Probe that fires when an LWLock has been released (but note
4429 that any released waiters have not yet been awakened).
4430 arg0 is the LWLock's tranche.</entry>
4433 <entry><literal>lwlock-wait-start</literal></entry>
4434 <entry><literal>(char *, LWLockMode)</literal></entry>
4435 <entry>Probe that fires when an LWLock was not immediately available and
4436 a server process has begun to wait for the lock to become available.
4437 arg0 is the LWLock's tranche.
4438 arg1 is the requested lock mode, either exclusive or shared.</entry>
4441 <entry><literal>lwlock-wait-done</literal></entry>
4442 <entry><literal>(char *, LWLockMode)</literal></entry>
4443 <entry>Probe that fires when a server process has been released from its
4444 wait for an LWLock (it does not actually have the lock yet).
4445 arg0 is the LWLock's tranche.
4446 arg1 is the requested lock mode, either exclusive or shared.</entry>
4449 <entry><literal>lwlock-condacquire</literal></entry>
4450 <entry><literal>(char *, LWLockMode)</literal></entry>
4451 <entry>Probe that fires when an LWLock was successfully acquired when the
4452 caller specified no waiting.
4453 arg0 is the LWLock's tranche.
4454 arg1 is the requested lock mode, either exclusive or shared.</entry>
4457 <entry><literal>lwlock-condacquire-fail</literal></entry>
4458 <entry><literal>(char *, LWLockMode)</literal></entry>
4459 <entry>Probe that fires when an LWLock was not successfully acquired when
4460 the caller specified no waiting.
4461 arg0 is the LWLock's tranche.
4462 arg1 is the requested lock mode, either exclusive or shared.</entry>
4465 <entry><literal>lock-wait-start</literal></entry>
4466 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4467 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4468 has begun to wait because the lock is not available.
4469 arg0 through arg3 are the tag fields identifying the object being
4470 locked. arg4 indicates the type of object being locked.
4471 arg5 indicates the lock type being requested.</entry>
4474 <entry><literal>lock-wait-done</literal></entry>
4475 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4476 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4477 has finished waiting (i.e., has acquired the lock).
4478 The arguments are the same as for <literal>lock-wait-start</literal>.</entry>
4481 <entry><literal>deadlock-found</literal></entry>
4482 <entry><literal>()</literal></entry>
4483 <entry>Probe that fires when a deadlock is found by the deadlock
4491 <table id="typedefs-table">
4492 <title>Defined Types Used in Probe Parameters</title>
4497 <entry>Definition</entry>
4504 <entry><type>LocalTransactionId</type></entry>
4505 <entry><type>unsigned int</type></entry>
4508 <entry><type>LWLockMode</type></entry>
4509 <entry><type>int</type></entry>
4512 <entry><type>LOCKMODE</type></entry>
4513 <entry><type>int</type></entry>
4516 <entry><type>BlockNumber</type></entry>
4517 <entry><type>unsigned int</type></entry>
4520 <entry><type>Oid</type></entry>
4521 <entry><type>unsigned int</type></entry>
4524 <entry><type>ForkNumber</type></entry>
4525 <entry><type>int</type></entry>
4528 <entry><type>bool</type></entry>
4529 <entry><type>char</type></entry>
4539 <sect2 id="using-trace-points">
4540 <title>Using Probes</title>
4543 The example below shows a DTrace script for analyzing transaction
4544 counts in the system, as an alternative to snapshotting
4545 <structname>pg_stat_database</structname> before and after a performance test:
4547 #!/usr/sbin/dtrace -qs
4549 postgresql$1:::transaction-start
4551 @start["Start"] = count();
4552 self->ts = timestamp;
4555 postgresql$1:::transaction-abort
4557 @abort["Abort"] = count();
4560 postgresql$1:::transaction-commit
4563 @commit["Commit"] = count();
4564 @time["Total time (ns)"] = sum(timestamp - self->ts);
4568 When executed, the example D script gives output such as:
4570 # ./txn_count.d `pgrep -n postgres` or ./txn_count.d <PID>
4575 Total time (ns) 2312105013
4581 SystemTap uses a different notation for trace scripts than DTrace does,
4582 even though the underlying trace points are compatible. One point worth
4583 noting is that at this writing, SystemTap scripts must reference probe
4584 names using double underscores in place of hyphens. This is expected to
4585 be fixed in future SystemTap releases.
4590 You should remember that DTrace scripts need to be carefully written and
4591 debugged, otherwise the trace information collected might
4592 be meaningless. In most cases where problems are found it is the
4593 instrumentation that is at fault, not the underlying system. When
4594 discussing information found using dynamic tracing, be sure to enclose
4595 the script used to allow that too to be checked and discussed.
4599 <sect2 id="defining-trace-points">
4600 <title>Defining New Probes</title>
4603 New probes can be defined within the code wherever the developer
4604 desires, though this will require a recompilation. Below are the steps
4605 for inserting new probes:
4611 Decide on probe names and data to be made available through the probes
4617 Add the probe definitions to <filename>src/backend/utils/probes.d</filename>
4623 Include <filename>pg_trace.h</filename> if it is not already present in the
4624 module(s) containing the probe points, and insert
4625 <literal>TRACE_POSTGRESQL</literal> probe macros at the desired locations
4632 Recompile and verify that the new probes are available
4638 <title>Example:</title>
4640 Here is an example of how you would add a probe to trace all new
4641 transactions by transaction ID.
4648 Decide that the probe will be named <literal>transaction-start</literal> and
4649 requires a parameter of type <type>LocalTransactionId</type>
4655 Add the probe definition to <filename>src/backend/utils/probes.d</filename>:
4657 probe transaction__start(LocalTransactionId);
4659 Note the use of the double underline in the probe name. In a DTrace
4660 script using the probe, the double underline needs to be replaced with a
4661 hyphen, so <literal>transaction-start</literal> is the name to document for
4668 At compile time, <literal>transaction__start</literal> is converted to a macro
4669 called <literal>TRACE_POSTGRESQL_TRANSACTION_START</literal> (notice the
4670 underscores are single here), which is available by including
4671 <filename>pg_trace.h</filename>. Add the macro call to the appropriate location
4672 in the source code. In this case, it looks like the following:
4675 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
4682 After recompiling and running the new binary, check that your newly added
4683 probe is available by executing the following DTrace command. You
4684 should see similar output:
4686 # dtrace -ln transaction-start
4687 ID PROVIDER MODULE FUNCTION NAME
4688 18705 postgresql49878 postgres StartTransactionCommand transaction-start
4689 18755 postgresql49877 postgres StartTransactionCommand transaction-start
4690 18805 postgresql49876 postgres StartTransactionCommand transaction-start
4691 18855 postgresql49875 postgres StartTransactionCommand transaction-start
4692 18986 postgresql49873 postgres StartTransactionCommand transaction-start
4699 There are a few things to be careful about when adding trace macros
4705 You should take care that the data types specified for a probe's
4706 parameters match the data types of the variables used in the macro.
4707 Otherwise, you will get compilation errors.
4714 On most platforms, if <productname>PostgreSQL</productname> is
4715 built with <option>--enable-dtrace</option>, the arguments to a trace
4716 macro will be evaluated whenever control passes through the
4717 macro, <emphasis>even if no tracing is being done</emphasis>. This is
4718 usually not worth worrying about if you are just reporting the
4719 values of a few local variables. But beware of putting expensive
4720 function calls into the arguments. If you need to do that,
4721 consider protecting the macro with a check to see if the trace
4722 is actually enabled:
4725 if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
4726 TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
4729 Each trace macro has a corresponding <literal>ENABLED</literal> macro.