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_vacuum</structname><indexterm><primary>pg_stat_progress_vacuum</primary></indexterm></entry>
341 <entry>One row for each backend (including autovacuum worker processes) running
342 <command>VACUUM</command>, showing current progress.
343 See <xref linkend='vacuum-progress-reporting'/>.
351 <table id="monitoring-stats-views-table">
352 <title>Collected Statistics Views</title>
357 <entry>View Name</entry>
358 <entry>Description</entry>
364 <entry><structname>pg_stat_archiver</structname><indexterm><primary>pg_stat_archiver</primary></indexterm></entry>
365 <entry>One row only, showing statistics about the
366 WAL archiver process's activity. See
367 <xref linkend="pg-stat-archiver-view"/> for details.
372 <entry><structname>pg_stat_bgwriter</structname><indexterm><primary>pg_stat_bgwriter</primary></indexterm></entry>
373 <entry>One row only, showing statistics about the
374 background writer process's activity. See
375 <xref linkend="pg-stat-bgwriter-view"/> for details.
380 <entry><structname>pg_stat_database</structname><indexterm><primary>pg_stat_database</primary></indexterm></entry>
381 <entry>One row per database, showing database-wide statistics. See
382 <xref linkend="pg-stat-database-view"/> for details.
387 <entry><structname>pg_stat_database_conflicts</structname><indexterm><primary>pg_stat_database_conflicts</primary></indexterm></entry>
389 One row per database, showing database-wide statistics about
390 query cancels due to conflict with recovery on standby servers.
391 See <xref linkend="pg-stat-database-conflicts-view"/> for details.
396 <entry><structname>pg_stat_all_tables</structname><indexterm><primary>pg_stat_all_tables</primary></indexterm></entry>
398 One row for each table in the current database, showing statistics
399 about accesses to that specific table.
400 See <xref linkend="pg-stat-all-tables-view"/> for details.
405 <entry><structname>pg_stat_sys_tables</structname><indexterm><primary>pg_stat_sys_tables</primary></indexterm></entry>
406 <entry>Same as <structname>pg_stat_all_tables</structname>, except that only
407 system tables are shown.</entry>
411 <entry><structname>pg_stat_user_tables</structname><indexterm><primary>pg_stat_user_tables</primary></indexterm></entry>
412 <entry>Same as <structname>pg_stat_all_tables</structname>, except that only user
413 tables are shown.</entry>
417 <entry><structname>pg_stat_xact_all_tables</structname><indexterm><primary>pg_stat_xact_all_tables</primary></indexterm></entry>
418 <entry>Similar to <structname>pg_stat_all_tables</structname>, but counts actions
419 taken so far within the current transaction (which are <emphasis>not</emphasis>
420 yet included in <structname>pg_stat_all_tables</structname> and related views).
421 The columns for numbers of live and dead rows and vacuum and
422 analyze actions are not present in this view.</entry>
426 <entry><structname>pg_stat_xact_sys_tables</structname><indexterm><primary>pg_stat_xact_sys_tables</primary></indexterm></entry>
427 <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
428 system tables are shown.</entry>
432 <entry><structname>pg_stat_xact_user_tables</structname><indexterm><primary>pg_stat_xact_user_tables</primary></indexterm></entry>
433 <entry>Same as <structname>pg_stat_xact_all_tables</structname>, except that only
434 user tables are shown.</entry>
438 <entry><structname>pg_stat_all_indexes</structname><indexterm><primary>pg_stat_all_indexes</primary></indexterm></entry>
440 One row for each index in the current database, showing statistics
441 about accesses to that specific index.
442 See <xref linkend="pg-stat-all-indexes-view"/> for details.
447 <entry><structname>pg_stat_sys_indexes</structname><indexterm><primary>pg_stat_sys_indexes</primary></indexterm></entry>
448 <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
449 indexes on system tables are shown.</entry>
453 <entry><structname>pg_stat_user_indexes</structname><indexterm><primary>pg_stat_user_indexes</primary></indexterm></entry>
454 <entry>Same as <structname>pg_stat_all_indexes</structname>, except that only
455 indexes on user tables are shown.</entry>
459 <entry><structname>pg_statio_all_tables</structname><indexterm><primary>pg_statio_all_tables</primary></indexterm></entry>
461 One row for each table in the current database, showing statistics
462 about I/O on that specific table.
463 See <xref linkend="pg-statio-all-tables-view"/> for details.
468 <entry><structname>pg_statio_sys_tables</structname><indexterm><primary>pg_statio_sys_tables</primary></indexterm></entry>
469 <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
470 system tables are shown.</entry>
474 <entry><structname>pg_statio_user_tables</structname><indexterm><primary>pg_statio_user_tables</primary></indexterm></entry>
475 <entry>Same as <structname>pg_statio_all_tables</structname>, except that only
476 user tables are shown.</entry>
480 <entry><structname>pg_statio_all_indexes</structname><indexterm><primary>pg_statio_all_indexes</primary></indexterm></entry>
482 One row for each index in the current database,
483 showing statistics about I/O on that specific index.
484 See <xref linkend="pg-statio-all-indexes-view"/> for details.
489 <entry><structname>pg_statio_sys_indexes</structname><indexterm><primary>pg_statio_sys_indexes</primary></indexterm></entry>
490 <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
491 indexes on system tables are shown.</entry>
495 <entry><structname>pg_statio_user_indexes</structname><indexterm><primary>pg_statio_user_indexes</primary></indexterm></entry>
496 <entry>Same as <structname>pg_statio_all_indexes</structname>, except that only
497 indexes on user tables are shown.</entry>
501 <entry><structname>pg_statio_all_sequences</structname><indexterm><primary>pg_statio_all_sequences</primary></indexterm></entry>
503 One row for each sequence in the current database,
504 showing statistics about I/O on that specific sequence.
505 See <xref linkend="pg-statio-all-sequences-view"/> for details.
510 <entry><structname>pg_statio_sys_sequences</structname><indexterm><primary>pg_statio_sys_sequences</primary></indexterm></entry>
511 <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
512 system sequences are shown. (Presently, no system sequences are defined,
513 so this view is always empty.)</entry>
517 <entry><structname>pg_statio_user_sequences</structname><indexterm><primary>pg_statio_user_sequences</primary></indexterm></entry>
518 <entry>Same as <structname>pg_statio_all_sequences</structname>, except that only
519 user sequences are shown.</entry>
523 <entry><structname>pg_stat_user_functions</structname><indexterm><primary>pg_stat_user_functions</primary></indexterm></entry>
525 One row for each tracked function, showing statistics
526 about executions of that function. See
527 <xref linkend="pg-stat-user-functions-view"/> for details.
532 <entry><structname>pg_stat_xact_user_functions</structname><indexterm><primary>pg_stat_xact_user_functions</primary></indexterm></entry>
533 <entry>Similar to <structname>pg_stat_user_functions</structname>, but counts only
534 calls during the current transaction (which are <emphasis>not</emphasis>
535 yet included in <structname>pg_stat_user_functions</structname>).</entry>
543 The per-index statistics are particularly useful to determine which
544 indexes are being used and how effective they are.
548 The <structname>pg_statio_</structname> views are primarily useful to
549 determine the effectiveness of the buffer cache. When the number
550 of actual disk reads is much smaller than the number of buffer
551 hits, then the cache is satisfying most read requests without
552 invoking a kernel call. However, these statistics do not give the
553 entire story: due to the way in which <productname>PostgreSQL</productname>
554 handles disk I/O, data that is not in the
555 <productname>PostgreSQL</productname> buffer cache might still reside in the
556 kernel's I/O cache, and might therefore still be fetched without
557 requiring a physical read. Users interested in obtaining more
558 detailed information on <productname>PostgreSQL</productname> I/O behavior are
559 advised to use the <productname>PostgreSQL</productname> statistics collector
560 in combination with operating system utilities that allow insight
561 into the kernel's handling of I/O.
565 <table id="pg-stat-activity-view" xreflabel="pg_stat_activity">
566 <title><structname>pg_stat_activity</structname> View</title>
571 <entry>Column</entry>
573 <entry>Description</entry>
579 <entry><structfield>datid</structfield></entry>
580 <entry><type>oid</type></entry>
581 <entry>OID of the database this backend is connected to</entry>
584 <entry><structfield>datname</structfield></entry>
585 <entry><type>name</type></entry>
586 <entry>Name of the database this backend is connected to</entry>
589 <entry><structfield>pid</structfield></entry>
590 <entry><type>integer</type></entry>
591 <entry>Process ID of this backend</entry>
594 <entry><structfield>usesysid</structfield></entry>
595 <entry><type>oid</type></entry>
596 <entry>OID of the user logged into this backend</entry>
599 <entry><structfield>usename</structfield></entry>
600 <entry><type>name</type></entry>
601 <entry>Name of the user logged into this backend</entry>
604 <entry><structfield>application_name</structfield></entry>
605 <entry><type>text</type></entry>
606 <entry>Name of the application that is connected
607 to this backend</entry>
610 <entry><structfield>client_addr</structfield></entry>
611 <entry><type>inet</type></entry>
612 <entry>IP address of the client connected to this backend.
613 If this field is null, it indicates either that the client is
614 connected via a Unix socket on the server machine or that this is an
615 internal process such as autovacuum.
619 <entry><structfield>client_hostname</structfield></entry>
620 <entry><type>text</type></entry>
621 <entry>Host name of the connected client, as reported by a
622 reverse DNS lookup of <structfield>client_addr</structfield>. This field will
623 only be non-null for IP connections, and only when <xref
624 linkend="guc-log-hostname"/> is enabled.
628 <entry><structfield>client_port</structfield></entry>
629 <entry><type>integer</type></entry>
630 <entry>TCP port number that the client is using for communication
631 with this backend, or <literal>-1</literal> if a Unix socket is used
635 <entry><structfield>backend_start</structfield></entry>
636 <entry><type>timestamp with time zone</type></entry>
637 <entry>Time when this process was started. For client backends,
638 this is the time the client connected to the server.
642 <entry><structfield>xact_start</structfield></entry>
643 <entry><type>timestamp with time zone</type></entry>
644 <entry>Time when this process' current transaction was started, or null
645 if no transaction is active. If the current
646 query is the first of its transaction, this column is equal to the
647 <structfield>query_start</structfield> column.
651 <entry><structfield>query_start</structfield></entry>
652 <entry><type>timestamp with time zone</type></entry>
653 <entry>Time when the currently active query was started, or if
654 <structfield>state</structfield> is not <literal>active</literal>, when the last query
659 <entry><structfield>state_change</structfield></entry>
660 <entry><type>timestamp with time zone</type></entry>
661 <entry>Time when the <structfield>state</structfield> was last changed</entry>
664 <entry><structfield>wait_event_type</structfield></entry>
665 <entry><type>text</type></entry>
666 <entry>The type of event for which the backend is waiting, if any;
667 otherwise NULL. Possible values are:
671 <literal>LWLock</literal>: The backend is waiting for a lightweight lock.
672 Each such lock protects a particular data structure in shared memory.
673 <literal>wait_event</literal> will contain a name identifying the purpose
674 of the lightweight lock. (Some locks have specific names; others
675 are part of a group of locks each with a similar purpose.)
680 <literal>Lock</literal>: The backend is waiting for a heavyweight lock.
681 Heavyweight locks, also known as lock manager locks or simply locks,
682 primarily protect SQL-visible objects such as tables. However,
683 they are also used to ensure mutual exclusion for certain internal
684 operations such as relation extension. <literal>wait_event</literal> will
685 identify the type of lock awaited.
690 <literal>BufferPin</literal>: The server process is waiting to access to
691 a data buffer during a period when no other process can be
692 examining that buffer. Buffer pin waits can be protracted if
693 another process holds an open cursor which last read data from the
699 <literal>Activity</literal>: The server process is idle. This is used by
700 system processes waiting for activity in their main processing loop.
701 <literal>wait_event</literal> will identify the specific wait point.
706 <literal>Extension</literal>: The server process is waiting for activity
707 in an extension module. This category is useful for modules to
708 track custom waiting points.
713 <literal>Client</literal>: The server process is waiting for some activity
714 on a socket from user applications, and that the server expects
715 something to happen that is independent from its internal processes.
716 <literal>wait_event</literal> will identify the specific wait point.
721 <literal>IPC</literal>: The server process is waiting for some activity
722 from another process in the server. <literal>wait_event</literal> will
723 identify the specific wait point.
728 <literal>Timeout</literal>: The server process is waiting for a timeout
729 to expire. <literal>wait_event</literal> will identify the specific wait
735 <literal>IO</literal>: The server process is waiting for a IO to complete.
736 <literal>wait_event</literal> will identify the specific wait point.
743 <entry><structfield>wait_event</structfield></entry>
744 <entry><type>text</type></entry>
745 <entry>Wait event name if backend is currently waiting, otherwise NULL.
746 See <xref linkend="wait-event-table"/> for details.
750 <entry><structfield>state</structfield></entry>
751 <entry><type>text</type></entry>
752 <entry>Current overall state of this backend.
757 <literal>active</literal>: The backend is executing a query.
762 <literal>idle</literal>: The backend is waiting for a new client command.
767 <literal>idle in transaction</literal>: The backend is in a transaction,
768 but is not currently executing a query.
773 <literal>idle in transaction (aborted)</literal>: This state is similar to
774 <literal>idle in transaction</literal>, except one of the statements in
775 the transaction caused an error.
780 <literal>fastpath function call</literal>: The backend is executing a
786 <literal>disabled</literal>: This state is reported if <xref
787 linkend="guc-track-activities"/> is disabled in this backend.
794 <entry><structfield>backend_xid</structfield></entry>
795 <entry><type>xid</type></entry>
796 <entry>Top-level transaction identifier of this backend, if any.</entry>
799 <entry><structfield>backend_xmin</structfield></entry>
800 <entry><type>xid</type></entry>
801 <entry>The current backend's <literal>xmin</literal> horizon.</entry>
804 <entry><structfield>query</structfield></entry>
805 <entry><type>text</type></entry>
806 <entry>Text of this backend's most recent query. If
807 <structfield>state</structfield> is <literal>active</literal> this field shows the
808 currently executing query. In all other states, it shows the last query
809 that was executed. By default the query text is truncated at 1024
810 characters; this value can be changed via the parameter
811 <xref linkend="guc-track-activity-query-size"/>.
815 <entry><structfield>backend_type</structfield></entry>
816 <entry><type>text</type></entry>
817 <entry>Type of current backend. Possible types are
818 <literal>autovacuum launcher</literal>, <literal>autovacuum worker</literal>,
819 <literal>logical replication launcher</literal>,
820 <literal>logical replication worker</literal>,
821 <literal>parallel worker</literal>, <literal>background writer</literal>,
822 <literal>client backend</literal>, <literal>checkpointer</literal>,
823 <literal>startup</literal>, <literal>walreceiver</literal>,
824 <literal>walsender</literal> and <literal>walwriter</literal>.
825 In addition, background workers registered by extensions may have
834 The <structname>pg_stat_activity</structname> view will have one row
835 per server process, showing information related to
836 the current activity of that process.
841 The <structfield>wait_event</structfield> and <structfield>state</structfield> columns are
842 independent. If a backend is in the <literal>active</literal> state,
843 it may or may not be <literal>waiting</literal> on some event. If the state
844 is <literal>active</literal> and <structfield>wait_event</structfield> is non-null, it
845 means that a query is being executed, but is being blocked somewhere
850 <table id="wait-event-table">
851 <title><structname>wait_event</structname> Description</title>
856 <entry>Wait Event Type</entry>
857 <entry>Wait Event Name</entry>
858 <entry>Description</entry>
864 <entry morerows="63"><literal>LWLock</literal></entry>
865 <entry><literal>ShmemIndexLock</literal></entry>
866 <entry>Waiting to find or allocate space in shared memory.</entry>
869 <entry><literal>OidGenLock</literal></entry>
870 <entry>Waiting to allocate or assign an OID.</entry>
873 <entry><literal>XidGenLock</literal></entry>
874 <entry>Waiting to allocate or assign a transaction id.</entry>
877 <entry><literal>ProcArrayLock</literal></entry>
878 <entry>Waiting to get a snapshot or clearing a transaction id at
879 transaction end.</entry>
882 <entry><literal>SInvalReadLock</literal></entry>
883 <entry>Waiting to retrieve or remove messages from shared invalidation
887 <entry><literal>SInvalWriteLock</literal></entry>
888 <entry>Waiting to add a message in shared invalidation queue.</entry>
891 <entry><literal>WALBufMappingLock</literal></entry>
892 <entry>Waiting to replace a page in WAL buffers.</entry>
895 <entry><literal>WALWriteLock</literal></entry>
896 <entry>Waiting for WAL buffers to be written to disk.</entry>
899 <entry><literal>ControlFileLock</literal></entry>
900 <entry>Waiting to read or update the control file or creation of a
901 new WAL file.</entry>
904 <entry><literal>CheckpointLock</literal></entry>
905 <entry>Waiting to perform checkpoint.</entry>
908 <entry><literal>CLogControlLock</literal></entry>
909 <entry>Waiting to read or update transaction status.</entry>
912 <entry><literal>SubtransControlLock</literal></entry>
913 <entry>Waiting to read or update sub-transaction information.</entry>
916 <entry><literal>MultiXactGenLock</literal></entry>
917 <entry>Waiting to read or update shared multixact state.</entry>
920 <entry><literal>MultiXactOffsetControlLock</literal></entry>
921 <entry>Waiting to read or update multixact offset mappings.</entry>
924 <entry><literal>MultiXactMemberControlLock</literal></entry>
925 <entry>Waiting to read or update multixact member mappings.</entry>
928 <entry><literal>RelCacheInitLock</literal></entry>
929 <entry>Waiting to read or write relation cache initialization
933 <entry><literal>CheckpointerCommLock</literal></entry>
934 <entry>Waiting to manage fsync requests.</entry>
937 <entry><literal>TwoPhaseStateLock</literal></entry>
938 <entry>Waiting to read or update the state of prepared transactions.</entry>
941 <entry><literal>TablespaceCreateLock</literal></entry>
942 <entry>Waiting to create or drop the tablespace.</entry>
945 <entry><literal>BtreeVacuumLock</literal></entry>
946 <entry>Waiting to read or update vacuum-related information for a
947 B-tree index.</entry>
950 <entry><literal>AddinShmemInitLock</literal></entry>
951 <entry>Waiting to manage space allocation in shared memory.</entry>
954 <entry><literal>AutovacuumLock</literal></entry>
955 <entry>Autovacuum worker or launcher waiting to update or
956 read the current state of autovacuum workers.</entry>
959 <entry><literal>AutovacuumScheduleLock</literal></entry>
960 <entry>Waiting to ensure that the table it has selected for a vacuum
961 still needs vacuuming.
965 <entry><literal>SyncScanLock</literal></entry>
966 <entry>Waiting to get the start location of a scan on a table for
967 synchronized scans.</entry>
970 <entry><literal>RelationMappingLock</literal></entry>
971 <entry>Waiting to update the relation map file used to store catalog
976 <entry><literal>AsyncCtlLock</literal></entry>
977 <entry>Waiting to read or update shared notification state.</entry>
980 <entry><literal>AsyncQueueLock</literal></entry>
981 <entry>Waiting to read or update notification messages.</entry>
984 <entry><literal>SerializableXactHashLock</literal></entry>
985 <entry>Waiting to retrieve or store information about serializable
986 transactions.</entry>
989 <entry><literal>SerializableFinishedListLock</literal></entry>
990 <entry>Waiting to access the list of finished serializable
991 transactions.</entry>
994 <entry><literal>SerializablePredicateLockListLock</literal></entry>
995 <entry>Waiting to perform an operation on a list of locks held by
996 serializable transactions.</entry>
999 <entry><literal>OldSerXidLock</literal></entry>
1000 <entry>Waiting to read or record conflicting serializable
1001 transactions.</entry>
1004 <entry><literal>SyncRepLock</literal></entry>
1005 <entry>Waiting to read or update information about synchronous
1009 <entry><literal>BackgroundWorkerLock</literal></entry>
1010 <entry>Waiting to read or update background worker state.</entry>
1013 <entry><literal>DynamicSharedMemoryControlLock</literal></entry>
1014 <entry>Waiting to read or update dynamic shared memory state.</entry>
1017 <entry><literal>AutoFileLock</literal></entry>
1018 <entry>Waiting to update the <filename>postgresql.auto.conf</filename> file.</entry>
1021 <entry><literal>ReplicationSlotAllocationLock</literal></entry>
1022 <entry>Waiting to allocate or free a replication slot.</entry>
1025 <entry><literal>ReplicationSlotControlLock</literal></entry>
1026 <entry>Waiting to read or update replication slot state.</entry>
1029 <entry><literal>CommitTsControlLock</literal></entry>
1030 <entry>Waiting to read or update transaction commit timestamps.</entry>
1033 <entry><literal>CommitTsLock</literal></entry>
1034 <entry>Waiting to read or update the last value set for the
1035 transaction timestamp.</entry>
1038 <entry><literal>ReplicationOriginLock</literal></entry>
1039 <entry>Waiting to setup, drop or use replication origin.</entry>
1042 <entry><literal>MultiXactTruncationLock</literal></entry>
1043 <entry>Waiting to read or truncate multixact information.</entry>
1046 <entry><literal>OldSnapshotTimeMapLock</literal></entry>
1047 <entry>Waiting to read or update old snapshot control information.</entry>
1050 <entry><literal>LogicalRepWorkerLock</literal></entry>
1051 <entry>Waiting for action on logical replication worker to finish.</entry>
1054 <entry><literal>CLogTruncationLock</literal></entry>
1055 <entry>Waiting to execute <function>txid_status</function> or update
1056 the oldest transaction id available to it.</entry>
1059 <entry><literal>clog</literal></entry>
1060 <entry>Waiting for I/O on a clog (transaction status) buffer.</entry>
1063 <entry><literal>commit_timestamp</literal></entry>
1064 <entry>Waiting for I/O on commit timestamp buffer.</entry>
1067 <entry><literal>subtrans</literal></entry>
1068 <entry>Waiting for I/O a subtransaction buffer.</entry>
1071 <entry><literal>multixact_offset</literal></entry>
1072 <entry>Waiting for I/O on a multixact offset buffer.</entry>
1075 <entry><literal>multixact_member</literal></entry>
1076 <entry>Waiting for I/O on a multixact_member buffer.</entry>
1079 <entry><literal>async</literal></entry>
1080 <entry>Waiting for I/O on an async (notify) buffer.</entry>
1083 <entry><literal>oldserxid</literal></entry>
1084 <entry>Waiting for I/O on an oldserxid buffer.</entry>
1087 <entry><literal>wal_insert</literal></entry>
1088 <entry>Waiting to insert WAL into a memory buffer.</entry>
1091 <entry><literal>buffer_content</literal></entry>
1092 <entry>Waiting to read or write a data page in memory.</entry>
1095 <entry><literal>buffer_io</literal></entry>
1096 <entry>Waiting for I/O on a data page.</entry>
1099 <entry><literal>replication_origin</literal></entry>
1100 <entry>Waiting to read or update the replication progress.</entry>
1103 <entry><literal>replication_slot_io</literal></entry>
1104 <entry>Waiting for I/O on a replication slot.</entry>
1107 <entry><literal>proc</literal></entry>
1108 <entry>Waiting to read or update the fast-path lock information.</entry>
1111 <entry><literal>buffer_mapping</literal></entry>
1112 <entry>Waiting to associate a data block with a buffer in the buffer
1116 <entry><literal>lock_manager</literal></entry>
1117 <entry>Waiting to add or examine locks for backends, or waiting to
1118 join or exit a locking group (used by parallel query).</entry>
1121 <entry><literal>predicate_lock_manager</literal></entry>
1122 <entry>Waiting to add or examine predicate lock information.</entry>
1125 <entry><literal>parallel_query_dsa</literal></entry>
1126 <entry>Waiting for parallel query dynamic shared memory allocation lock.</entry>
1129 <entry><literal>tbm</literal></entry>
1130 <entry>Waiting for TBM shared iterator lock.</entry>
1133 <entry><literal>parallel_append</literal></entry>
1134 <entry>Waiting to choose the next subplan during Parallel Append plan
1138 <entry><literal>parallel_hash_join</literal></entry>
1139 <entry>Waiting to allocate or exchange a chunk of memory or update
1140 counters during Parallel Hash plan execution.</entry>
1143 <entry morerows="9"><literal>Lock</literal></entry>
1144 <entry><literal>relation</literal></entry>
1145 <entry>Waiting to acquire a lock on a relation.</entry>
1148 <entry><literal>extend</literal></entry>
1149 <entry>Waiting to extend a relation.</entry>
1152 <entry><literal>page</literal></entry>
1153 <entry>Waiting to acquire a lock on page of a relation.</entry>
1156 <entry><literal>tuple</literal></entry>
1157 <entry>Waiting to acquire a lock on a tuple.</entry>
1160 <entry><literal>transactionid</literal></entry>
1161 <entry>Waiting for a transaction to finish.</entry>
1164 <entry><literal>virtualxid</literal></entry>
1165 <entry>Waiting to acquire a virtual xid lock.</entry>
1168 <entry><literal>speculative token</literal></entry>
1169 <entry>Waiting to acquire a speculative insertion lock.</entry>
1172 <entry><literal>object</literal></entry>
1173 <entry>Waiting to acquire a lock on a non-relation database object.</entry>
1176 <entry><literal>userlock</literal></entry>
1177 <entry>Waiting to acquire a user lock.</entry>
1180 <entry><literal>advisory</literal></entry>
1181 <entry>Waiting to acquire an advisory user lock.</entry>
1184 <entry><literal>BufferPin</literal></entry>
1185 <entry><literal>BufferPin</literal></entry>
1186 <entry>Waiting to acquire a pin on a buffer.</entry>
1189 <entry morerows="13"><literal>Activity</literal></entry>
1190 <entry><literal>ArchiverMain</literal></entry>
1191 <entry>Waiting in main loop of the archiver process.</entry>
1194 <entry><literal>AutoVacuumMain</literal></entry>
1195 <entry>Waiting in main loop of autovacuum launcher process.</entry>
1198 <entry><literal>BgWriterHibernate</literal></entry>
1199 <entry>Waiting in background writer process, hibernating.</entry>
1202 <entry><literal>BgWriterMain</literal></entry>
1203 <entry>Waiting in main loop of background writer process background worker.</entry>
1206 <entry><literal>CheckpointerMain</literal></entry>
1207 <entry>Waiting in main loop of checkpointer process.</entry>
1210 <entry><literal>LogicalApplyMain</literal></entry>
1211 <entry>Waiting in main loop of logical apply process.</entry>
1214 <entry><literal>LogicalLauncherMain</literal></entry>
1215 <entry>Waiting in main loop of logical launcher process.</entry>
1218 <entry><literal>PgStatMain</literal></entry>
1219 <entry>Waiting in main loop of the statistics collector process.</entry>
1222 <entry><literal>RecoveryWalAll</literal></entry>
1223 <entry>Waiting for WAL from any kind of source (local, archive or stream) at recovery.</entry>
1226 <entry><literal>RecoveryWalStream</literal></entry>
1227 <entry>Waiting for WAL from a stream at recovery.</entry>
1230 <entry><literal>SysLoggerMain</literal></entry>
1231 <entry>Waiting in main loop of syslogger process.</entry>
1234 <entry><literal>WalReceiverMain</literal></entry>
1235 <entry>Waiting in main loop of WAL receiver process.</entry>
1238 <entry><literal>WalSenderMain</literal></entry>
1239 <entry>Waiting in main loop of WAL sender process.</entry>
1242 <entry><literal>WalWriterMain</literal></entry>
1243 <entry>Waiting in main loop of WAL writer process.</entry>
1246 <entry morerows="7"><literal>Client</literal></entry>
1247 <entry><literal>ClientRead</literal></entry>
1248 <entry>Waiting to read data from the client.</entry>
1251 <entry><literal>ClientWrite</literal></entry>
1252 <entry>Waiting to write data to the client.</entry>
1255 <entry><literal>LibPQWalReceiverConnect</literal></entry>
1256 <entry>Waiting in WAL receiver to establish connection to remote server.</entry>
1259 <entry><literal>LibPQWalReceiverReceive</literal></entry>
1260 <entry>Waiting in WAL receiver to receive data from remote server.</entry>
1263 <entry><literal>SSLOpenServer</literal></entry>
1264 <entry>Waiting for SSL while attempting connection.</entry>
1267 <entry><literal>WalReceiverWaitStart</literal></entry>
1268 <entry>Waiting for startup process to send initial data for streaming replication.</entry>
1271 <entry><literal>WalSenderWaitForWAL</literal></entry>
1272 <entry>Waiting for WAL to be flushed in WAL sender process.</entry>
1275 <entry><literal>WalSenderWriteData</literal></entry>
1276 <entry>Waiting for any activity when processing replies from WAL receiver in WAL sender process.</entry>
1279 <entry><literal>Extension</literal></entry>
1280 <entry><literal>Extension</literal></entry>
1281 <entry>Waiting in an extension.</entry>
1284 <entry morerows="34"><literal>IPC</literal></entry>
1285 <entry><literal>BgWorkerShutdown</literal></entry>
1286 <entry>Waiting for background worker to shut down.</entry>
1289 <entry><literal>BgWorkerStartup</literal></entry>
1290 <entry>Waiting for background worker to start up.</entry>
1293 <entry><literal>BtreePage</literal></entry>
1294 <entry>Waiting for the page number needed to continue a parallel B-tree scan to become available.</entry>
1297 <entry><literal>ClogGroupUpdate</literal></entry>
1298 <entry>Waiting for group leader to update transaction status at transaction end.</entry>
1301 <entry><literal>ExecuteGather</literal></entry>
1302 <entry>Waiting for activity from child process when executing <literal>Gather</literal> node.</entry>
1305 <entry><literal>Hash/Batch/Allocating</literal></entry>
1306 <entry>Waiting for an elected Parallel Hash participant to allocate a hash table.</entry>
1309 <entry><literal>Hash/Batch/Electing</literal></entry>
1310 <entry>Electing a Parallel Hash participant to allocate a hash table.</entry>
1313 <entry><literal>Hash/Batch/Loading</literal></entry>
1314 <entry>Waiting for other Parallel Hash participants to finish loading a hash table.</entry>
1317 <entry><literal>Hash/Build/Allocating</literal></entry>
1318 <entry>Waiting for an elected Parallel Hash participant to allocate the initial hash table.</entry>
1321 <entry><literal>Hash/Build/Electing</literal></entry>
1322 <entry>Electing a Parallel Hash participant to allocate the initial hash table.</entry>
1325 <entry><literal>Hash/Build/HashingInner</literal></entry>
1326 <entry>Waiting for other Parallel Hash participants to finish hashing the inner relation.</entry>
1329 <entry><literal>Hash/Build/HashingOuter</literal></entry>
1330 <entry>Waiting for other Parallel Hash participants to finish partitioning the outer relation.</entry>
1333 <entry><literal>Hash/GrowBatches/Allocating</literal></entry>
1334 <entry>Waiting for an elected Parallel Hash participant to allocate more batches.</entry>
1337 <entry><literal>Hash/GrowBatches/Deciding</literal></entry>
1338 <entry>Electing a Parallel Hash participant to decide on future batch growth.</entry>
1341 <entry><literal>Hash/GrowBatches/Electing</literal></entry>
1342 <entry>Electing a Parallel Hash participant to allocate more batches.</entry>
1345 <entry><literal>Hash/GrowBatches/Finishing</literal></entry>
1346 <entry>Waiting for an elected Parallel Hash participant to decide on future batch growth.</entry>
1349 <entry><literal>Hash/GrowBatches/Repartitioning</literal></entry>
1350 <entry>Waiting for other Parallel Hash participants to finishing repartitioning.</entry>
1353 <entry><literal>Hash/GrowBuckets/Allocating</literal></entry>
1354 <entry>Waiting for an elected Parallel Hash participant to finish allocating more buckets.</entry>
1357 <entry><literal>Hash/GrowBuckets/Electing</literal></entry>
1358 <entry>Electing a Parallel Hash participant to allocate more buckets.</entry>
1361 <entry><literal>Hash/GrowBuckets/Reinserting</literal></entry>
1362 <entry>Waiting for other Parallel Hash participants to finish inserting tuples into new buckets.</entry>
1365 <entry><literal>LogicalSyncData</literal></entry>
1366 <entry>Waiting for logical replication remote server to send data for initial table synchronization.</entry>
1369 <entry><literal>LogicalSyncStateChange</literal></entry>
1370 <entry>Waiting for logical replication remote server to change state.</entry>
1373 <entry><literal>MessageQueueInternal</literal></entry>
1374 <entry>Waiting for other process to be attached in shared message queue.</entry>
1377 <entry><literal>MessageQueuePutMessage</literal></entry>
1378 <entry>Waiting to write a protocol message to a shared message queue.</entry>
1381 <entry><literal>MessageQueueReceive</literal></entry>
1382 <entry>Waiting to receive bytes from a shared message queue.</entry>
1385 <entry><literal>MessageQueueSend</literal></entry>
1386 <entry>Waiting to send bytes to a shared message queue.</entry>
1389 <entry><literal>ParallelBitmapScan</literal></entry>
1390 <entry>Waiting for parallel bitmap scan to become initialized.</entry>
1393 <entry><literal>ParallelCreateIndexScan</literal></entry>
1394 <entry>Waiting for parallel <command>CREATE INDEX</command> workers to finish heap scan.</entry>
1397 <entry><literal>ParallelFinish</literal></entry>
1398 <entry>Waiting for parallel workers to finish computing.</entry>
1401 <entry><literal>ProcArrayGroupUpdate</literal></entry>
1402 <entry>Waiting for group leader to clear transaction id at transaction end.</entry>
1405 <entry><literal>Promote</literal></entry>
1406 <entry>Waiting for standby promotion.</entry>
1409 <entry><literal>ReplicationOriginDrop</literal></entry>
1410 <entry>Waiting for a replication origin to become inactive to be dropped.</entry>
1413 <entry><literal>ReplicationSlotDrop</literal></entry>
1414 <entry>Waiting for a replication slot to become inactive to be dropped.</entry>
1417 <entry><literal>SafeSnapshot</literal></entry>
1418 <entry>Waiting for a snapshot for a <literal>READ ONLY DEFERRABLE</literal> transaction.</entry>
1421 <entry><literal>SyncRep</literal></entry>
1422 <entry>Waiting for confirmation from remote server during synchronous replication.</entry>
1425 <entry morerows="2"><literal>Timeout</literal></entry>
1426 <entry><literal>BaseBackupThrottle</literal></entry>
1427 <entry>Waiting during base backup when throttling activity.</entry>
1430 <entry><literal>PgSleep</literal></entry>
1431 <entry>Waiting in process that called <function>pg_sleep</function>.</entry>
1434 <entry><literal>RecoveryApplyDelay</literal></entry>
1435 <entry>Waiting to apply WAL at recovery because it is delayed.</entry>
1438 <entry morerows="66"><literal>IO</literal></entry>
1439 <entry><literal>BufFileRead</literal></entry>
1440 <entry>Waiting for a read from a buffered file.</entry>
1443 <entry><literal>BufFileWrite</literal></entry>
1444 <entry>Waiting for a write to a buffered file.</entry>
1447 <entry><literal>ControlFileRead</literal></entry>
1448 <entry>Waiting for a read from the control file.</entry>
1451 <entry><literal>ControlFileSync</literal></entry>
1452 <entry>Waiting for the control file to reach stable storage.</entry>
1455 <entry><literal>ControlFileSyncUpdate</literal></entry>
1456 <entry>Waiting for an update to the control file to reach stable storage.</entry>
1459 <entry><literal>ControlFileWrite</literal></entry>
1460 <entry>Waiting for a write to the control file.</entry>
1463 <entry><literal>ControlFileWriteUpdate</literal></entry>
1464 <entry>Waiting for a write to update the control file.</entry>
1467 <entry><literal>CopyFileRead</literal></entry>
1468 <entry>Waiting for a read during a file copy operation.</entry>
1471 <entry><literal>CopyFileWrite</literal></entry>
1472 <entry>Waiting for a write during a file copy operation.</entry>
1475 <entry><literal>DataFileExtend</literal></entry>
1476 <entry>Waiting for a relation data file to be extended.</entry>
1479 <entry><literal>DataFileFlush</literal></entry>
1480 <entry>Waiting for a relation data file to reach stable storage.</entry>
1483 <entry><literal>DataFileImmediateSync</literal></entry>
1484 <entry>Waiting for an immediate synchronization of a relation data file to stable storage.</entry>
1487 <entry><literal>DataFilePrefetch</literal></entry>
1488 <entry>Waiting for an asynchronous prefetch from a relation data file.</entry>
1491 <entry><literal>DataFileRead</literal></entry>
1492 <entry>Waiting for a read from a relation data file.</entry>
1495 <entry><literal>DataFileSync</literal></entry>
1496 <entry>Waiting for changes to a relation data file to reach stable storage.</entry>
1499 <entry><literal>DataFileTruncate</literal></entry>
1500 <entry>Waiting for a relation data file to be truncated.</entry>
1503 <entry><literal>DataFileWrite</literal></entry>
1504 <entry>Waiting for a write to a relation data file.</entry>
1507 <entry><literal>DSMFillZeroWrite</literal></entry>
1508 <entry>Waiting to write zero bytes to a dynamic shared memory backing file.</entry>
1511 <entry><literal>LockFileAddToDataDirRead</literal></entry>
1512 <entry>Waiting for a read while adding a line to the data directory lock file.</entry>
1515 <entry><literal>LockFileAddToDataDirSync</literal></entry>
1516 <entry>Waiting for data to reach stable storage while adding a line to the data directory lock file.</entry>
1519 <entry><literal>LockFileAddToDataDirWrite</literal></entry>
1520 <entry>Waiting for a write while adding a line to the data directory lock file.</entry>
1523 <entry><literal>LockFileCreateRead</literal></entry>
1524 <entry>Waiting to read while creating the data directory lock file.</entry>
1527 <entry><literal>LockFileCreateSync</literal></entry>
1528 <entry>Waiting for data to reach stable storage while creating the data directory lock file.</entry>
1531 <entry><literal>LockFileCreateWrite</literal></entry>
1532 <entry>Waiting for a write while creating the data directory lock file.</entry>
1535 <entry><literal>LockFileReCheckDataDirRead</literal></entry>
1536 <entry>Waiting for a read during recheck of the data directory lock file.</entry>
1539 <entry><literal>LogicalRewriteCheckpointSync</literal></entry>
1540 <entry>Waiting for logical rewrite mappings to reach stable storage during a checkpoint.</entry>
1543 <entry><literal>LogicalRewriteMappingSync</literal></entry>
1544 <entry>Waiting for mapping data to reach stable storage during a logical rewrite.</entry>
1547 <entry><literal>LogicalRewriteMappingWrite</literal></entry>
1548 <entry>Waiting for a write of mapping data during a logical rewrite.</entry>
1551 <entry><literal>LogicalRewriteSync</literal></entry>
1552 <entry>Waiting for logical rewrite mappings to reach stable storage.</entry>
1555 <entry><literal>LogicalRewriteWrite</literal></entry>
1556 <entry>Waiting for a write of logical rewrite mappings.</entry>
1559 <entry><literal>RelationMapRead</literal></entry>
1560 <entry>Waiting for a read of the relation map file.</entry>
1563 <entry><literal>RelationMapSync</literal></entry>
1564 <entry>Waiting for the relation map file to reach stable storage.</entry>
1567 <entry><literal>RelationMapWrite</literal></entry>
1568 <entry>Waiting for a write to the relation map file.</entry>
1571 <entry><literal>ReorderBufferRead</literal></entry>
1572 <entry>Waiting for a read during reorder buffer management.</entry>
1575 <entry><literal>ReorderBufferWrite</literal></entry>
1576 <entry>Waiting for a write during reorder buffer management.</entry>
1579 <entry><literal>ReorderLogicalMappingRead</literal></entry>
1580 <entry>Waiting for a read of a logical mapping during reorder buffer management.</entry>
1583 <entry><literal>ReplicationSlotRead</literal></entry>
1584 <entry>Waiting for a read from a replication slot control file.</entry>
1587 <entry><literal>ReplicationSlotRestoreSync</literal></entry>
1588 <entry>Waiting for a replication slot control file to reach stable storage while restoring it to memory.</entry>
1591 <entry><literal>ReplicationSlotSync</literal></entry>
1592 <entry>Waiting for a replication slot control file to reach stable storage.</entry>
1595 <entry><literal>ReplicationSlotWrite</literal></entry>
1596 <entry>Waiting for a write to a replication slot control file.</entry>
1599 <entry><literal>SLRUFlushSync</literal></entry>
1600 <entry>Waiting for SLRU data to reach stable storage during a checkpoint or database shutdown.</entry>
1603 <entry><literal>SLRURead</literal></entry>
1604 <entry>Waiting for a read of an SLRU page.</entry>
1607 <entry><literal>SLRUSync</literal></entry>
1608 <entry>Waiting for SLRU data to reach stable storage following a page write.</entry>
1611 <entry><literal>SLRUWrite</literal></entry>
1612 <entry>Waiting for a write of an SLRU page.</entry>
1615 <entry><literal>SnapbuildRead</literal></entry>
1616 <entry>Waiting for a read of a serialized historical catalog snapshot.</entry>
1619 <entry><literal>SnapbuildSync</literal></entry>
1620 <entry>Waiting for a serialized historical catalog snapshot to reach stable storage.</entry>
1623 <entry><literal>SnapbuildWrite</literal></entry>
1624 <entry>Waiting for a write of a serialized historical catalog snapshot.</entry>
1627 <entry><literal>TimelineHistoryFileSync</literal></entry>
1628 <entry>Waiting for a timeline history file received via streaming replication to reach stable storage.</entry>
1631 <entry><literal>TimelineHistoryFileWrite</literal></entry>
1632 <entry>Waiting for a write of a timeline history file received via streaming replication.</entry>
1635 <entry><literal>TimelineHistoryRead</literal></entry>
1636 <entry>Waiting for a read of a timeline history file.</entry>
1639 <entry><literal>TimelineHistorySync</literal></entry>
1640 <entry>Waiting for a newly created timeline history file to reach stable storage.</entry>
1643 <entry><literal>TimelineHistoryWrite</literal></entry>
1644 <entry>Waiting for a write of a newly created timeline history file.</entry>
1647 <entry><literal>TwophaseFileRead</literal></entry>
1648 <entry>Waiting for a read of a two phase state file.</entry>
1651 <entry><literal>TwophaseFileSync</literal></entry>
1652 <entry>Waiting for a two phase state file to reach stable storage.</entry>
1655 <entry><literal>TwophaseFileWrite</literal></entry>
1656 <entry>Waiting for a write of a two phase state file.</entry>
1659 <entry><literal>WALBootstrapSync</literal></entry>
1660 <entry>Waiting for WAL to reach stable storage during bootstrapping.</entry>
1663 <entry><literal>WALBootstrapWrite</literal></entry>
1664 <entry>Waiting for a write of a WAL page during bootstrapping.</entry>
1667 <entry><literal>WALCopyRead</literal></entry>
1668 <entry>Waiting for a read when creating a new WAL segment by copying an existing one.</entry>
1671 <entry><literal>WALCopySync</literal></entry>
1672 <entry>Waiting a new WAL segment created by copying an existing one to reach stable storage.</entry>
1675 <entry><literal>WALCopyWrite</literal></entry>
1676 <entry>Waiting for a write when creating a new WAL segment by copying an existing one.</entry>
1679 <entry><literal>WALInitSync</literal></entry>
1680 <entry>Waiting for a newly initialized WAL file to reach stable storage.</entry>
1683 <entry><literal>WALInitWrite</literal></entry>
1684 <entry>Waiting for a write while initializing a new WAL file.</entry>
1687 <entry><literal>WALRead</literal></entry>
1688 <entry>Waiting for a read from a WAL file.</entry>
1691 <entry><literal>WALSenderTimelineHistoryRead</literal></entry>
1692 <entry>Waiting for a read from a timeline history file during walsender timeline command.</entry>
1695 <entry><literal>WALSync</literal></entry>
1696 <entry>Waiting for a WAL file to reach stable storage.</entry>
1699 <entry><literal>WALSyncMethodAssign</literal></entry>
1700 <entry>Waiting for data to reach stable storage while assigning WAL sync method.</entry>
1703 <entry><literal>WALWrite</literal></entry>
1704 <entry>Waiting for a write to a WAL file.</entry>
1712 For tranches registered by extensions, the name is specified by extension
1713 and this will be displayed as <structfield>wait_event</structfield>. It is quite
1714 possible that user has registered the tranche in one of the backends (by
1715 having allocation in dynamic shared memory) in which case other backends
1716 won't have that information, so we display <literal>extension</literal> for such
1722 Here is an example of how wait events can be viewed
1725 SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
1726 pid | wait_event_type | wait_event
1727 ------+-----------------+---------------
1728 2540 | Lock | relation
1729 6644 | LWLock | ProcArrayLock
1734 <table id="pg-stat-replication-view" xreflabel="pg_stat_replication">
1735 <title><structname>pg_stat_replication</structname> View</title>
1739 <entry>Column</entry>
1741 <entry>Description</entry>
1747 <entry><structfield>pid</structfield></entry>
1748 <entry><type>integer</type></entry>
1749 <entry>Process ID of a WAL sender process</entry>
1752 <entry><structfield>usesysid</structfield></entry>
1753 <entry><type>oid</type></entry>
1754 <entry>OID of the user logged into this WAL sender process</entry>
1757 <entry><structfield>usename</structfield></entry>
1758 <entry><type>name</type></entry>
1759 <entry>Name of the user logged into this WAL sender process</entry>
1762 <entry><structfield>application_name</structfield></entry>
1763 <entry><type>text</type></entry>
1764 <entry>Name of the application that is connected
1765 to this WAL sender</entry>
1768 <entry><structfield>client_addr</structfield></entry>
1769 <entry><type>inet</type></entry>
1770 <entry>IP address of the client connected to this WAL sender.
1771 If this field is null, it indicates that the client is
1772 connected via a Unix socket on the server machine.
1776 <entry><structfield>client_hostname</structfield></entry>
1777 <entry><type>text</type></entry>
1778 <entry>Host name of the connected client, as reported by a
1779 reverse DNS lookup of <structfield>client_addr</structfield>. This field will
1780 only be non-null for IP connections, and only when <xref
1781 linkend="guc-log-hostname"/> is enabled.
1785 <entry><structfield>client_port</structfield></entry>
1786 <entry><type>integer</type></entry>
1787 <entry>TCP port number that the client is using for communication
1788 with this WAL sender, or <literal>-1</literal> if a Unix socket is used
1792 <entry><structfield>backend_start</structfield></entry>
1793 <entry><type>timestamp with time zone</type></entry>
1794 <entry>Time when this process was started, i.e., when the
1795 client connected to this WAL sender
1799 <entry><structfield>backend_xmin</structfield></entry>
1800 <entry><type>xid</type></entry>
1801 <entry>This standby's <literal>xmin</literal> horizon reported
1802 by <xref linkend="guc-hot-standby-feedback"/>.</entry>
1805 <entry><structfield>state</structfield></entry>
1806 <entry><type>text</type></entry>
1807 <entry>Current WAL sender state.
1808 Possible values are:
1812 <literal>startup</literal>: This WAL sender is starting up.
1817 <literal>catchup</literal>: This WAL sender's connected standby is
1818 catching up with the primary.
1823 <literal>streaming</literal>: This WAL sender is streaming changes
1824 after its connected standby server has caught up with the primary.
1829 <literal>backup</literal>: This WAL sender is sending a backup.
1834 <literal>stopping</literal>: This WAL sender is stopping.
1841 <entry><structfield>sent_lsn</structfield></entry>
1842 <entry><type>pg_lsn</type></entry>
1843 <entry>Last write-ahead log location sent on this connection</entry>
1846 <entry><structfield>write_lsn</structfield></entry>
1847 <entry><type>pg_lsn</type></entry>
1848 <entry>Last write-ahead log location written to disk by this standby
1852 <entry><structfield>flush_lsn</structfield></entry>
1853 <entry><type>pg_lsn</type></entry>
1854 <entry>Last write-ahead log location flushed to disk by this standby
1858 <entry><structfield>replay_lsn</structfield></entry>
1859 <entry><type>pg_lsn</type></entry>
1860 <entry>Last write-ahead log location replayed into the database on this
1861 standby server</entry>
1864 <entry><structfield>write_lag</structfield></entry>
1865 <entry><type>interval</type></entry>
1866 <entry>Time elapsed between flushing recent WAL locally and receiving
1867 notification that this standby server has written it (but not yet
1868 flushed it or applied it). This can be used to gauge the delay that
1869 <literal>synchronous_commit</literal> level
1870 <literal>remote_write</literal> incurred while committing if this
1871 server was configured as a synchronous standby.</entry>
1874 <entry><structfield>flush_lag</structfield></entry>
1875 <entry><type>interval</type></entry>
1876 <entry>Time elapsed between flushing recent WAL locally and receiving
1877 notification that this standby server has written and flushed it
1878 (but not yet applied it). This can be used to gauge the delay that
1879 <literal>synchronous_commit</literal> level
1880 <literal>on</literal> incurred while committing if this
1881 server was configured as a synchronous standby.</entry>
1884 <entry><structfield>replay_lag</structfield></entry>
1885 <entry><type>interval</type></entry>
1886 <entry>Time elapsed between flushing recent WAL locally and receiving
1887 notification that this standby server has written, flushed and
1888 applied it. This can be used to gauge the delay that
1889 <literal>synchronous_commit</literal> level
1890 <literal>remote_apply</literal> incurred while committing if this
1891 server was configured as a synchronous standby.</entry>
1894 <entry><structfield>sync_priority</structfield></entry>
1895 <entry><type>integer</type></entry>
1896 <entry>Priority of this standby server for being chosen as the
1897 synchronous standby in a priority-based synchronous replication.
1898 This has no effect in a quorum-based synchronous replication.</entry>
1901 <entry><structfield>sync_state</structfield></entry>
1902 <entry><type>text</type></entry>
1903 <entry>Synchronous state of this standby server.
1904 Possible values are:
1908 <literal>async</literal>: This standby server is asynchronous.
1913 <literal>potential</literal>: This standby server is now asynchronous,
1914 but can potentially become synchronous if one of current
1915 synchronous ones fails.
1920 <literal>sync</literal>: This standby server is synchronous.
1925 <literal>quorum</literal>: This standby server is considered as a candidate
1926 for quorum standbys.
1933 <entry><structfield>reply_time</structfield></entry>
1934 <entry><type>timestamp with time zone</type></entry>
1935 <entry>Send time of last reply message received from standby server</entry>
1942 The <structname>pg_stat_replication</structname> view will contain one row
1943 per WAL sender process, showing statistics about replication to that
1944 sender's connected standby server. Only directly connected standbys are
1945 listed; no information is available about downstream standby servers.
1949 The lag times reported in the <structname>pg_stat_replication</structname>
1950 view are measurements of the time taken for recent WAL to be written,
1951 flushed and replayed and for the sender to know about it. These times
1952 represent the commit delay that was (or would have been) introduced by each
1953 synchronous commit level, if the remote server was configured as a
1954 synchronous standby. For an asynchronous standby, the
1955 <structfield>replay_lag</structfield> column approximates the delay
1956 before recent transactions became visible to queries. If the standby
1957 server has entirely caught up with the sending server and there is no more
1958 WAL activity, the most recently measured lag times will continue to be
1959 displayed for a short time and then show NULL.
1963 Lag times work automatically for physical replication. Logical decoding
1964 plugins may optionally emit tracking messages; if they do not, the tracking
1965 mechanism will simply display NULL lag.
1970 The reported lag times are not predictions of how long it will take for
1971 the standby to catch up with the sending server assuming the current
1972 rate of replay. Such a system would show similar times while new WAL is
1973 being generated, but would differ when the sender becomes idle. In
1974 particular, when the standby has caught up completely,
1975 <structname>pg_stat_replication</structname> shows the time taken to
1976 write, flush and replay the most recent reported WAL location rather than
1977 zero as some users might expect. This is consistent with the goal of
1978 measuring synchronous commit and transaction visibility delays for
1979 recent write transactions.
1980 To reduce confusion for users expecting a different model of lag, the
1981 lag columns revert to NULL after a short time on a fully replayed idle
1982 system. Monitoring systems should choose whether to represent this
1983 as missing data, zero or continue to display the last known value.
1987 <table id="pg-stat-wal-receiver-view" xreflabel="pg_stat_wal_receiver">
1988 <title><structname>pg_stat_wal_receiver</structname> View</title>
1992 <entry>Column</entry>
1994 <entry>Description</entry>
2000 <entry><structfield>pid</structfield></entry>
2001 <entry><type>integer</type></entry>
2002 <entry>Process ID of the WAL receiver process</entry>
2005 <entry><structfield>status</structfield></entry>
2006 <entry><type>text</type></entry>
2007 <entry>Activity status of the WAL receiver process</entry>
2010 <entry><structfield>receive_start_lsn</structfield></entry>
2011 <entry><type>pg_lsn</type></entry>
2012 <entry>First write-ahead log location used when WAL receiver is
2016 <entry><structfield>receive_start_tli</structfield></entry>
2017 <entry><type>integer</type></entry>
2018 <entry>First timeline number used when WAL receiver is started</entry>
2021 <entry><structfield>received_lsn</structfield></entry>
2022 <entry><type>pg_lsn</type></entry>
2023 <entry>Last write-ahead log location already received and flushed to
2024 disk, the initial value of this field being the first log location used
2025 when WAL receiver is started</entry>
2028 <entry><structfield>received_tli</structfield></entry>
2029 <entry><type>integer</type></entry>
2030 <entry>Timeline number of last write-ahead log location received and
2031 flushed to disk, the initial value of this field being the timeline
2032 number of the first log location used when WAL receiver is started
2036 <entry><structfield>last_msg_send_time</structfield></entry>
2037 <entry><type>timestamp with time zone</type></entry>
2038 <entry>Send time of last message received from origin WAL sender</entry>
2041 <entry><structfield>last_msg_receipt_time</structfield></entry>
2042 <entry><type>timestamp with time zone</type></entry>
2043 <entry>Receipt time of last message received from origin WAL sender</entry>
2046 <entry><structfield>latest_end_lsn</structfield></entry>
2047 <entry><type>pg_lsn</type></entry>
2048 <entry>Last write-ahead log location reported to origin WAL sender</entry>
2051 <entry><structfield>latest_end_time</structfield></entry>
2052 <entry><type>timestamp with time zone</type></entry>
2053 <entry>Time of last write-ahead log location reported to origin WAL sender</entry>
2056 <entry><structfield>slot_name</structfield></entry>
2057 <entry><type>text</type></entry>
2058 <entry>Replication slot name used by this WAL receiver</entry>
2061 <entry><structfield>sender_host</structfield></entry>
2062 <entry><type>text</type></entry>
2064 Host of the <productname>PostgreSQL</productname> instance
2065 this WAL receiver is connected to. This can be a host name,
2066 an IP address, or a directory path if the connection is via
2067 Unix socket. (The path case can be distinguished because it
2068 will always be an absolute path, beginning with <literal>/</literal>.)
2072 <entry><structfield>sender_port</structfield></entry>
2073 <entry><type>integer</type></entry>
2075 Port number of the <productname>PostgreSQL</productname> instance
2076 this WAL receiver is connected to.
2080 <entry><structfield>conninfo</structfield></entry>
2081 <entry><type>text</type></entry>
2083 Connection string used by this WAL receiver,
2084 with security-sensitive fields obfuscated.
2092 The <structname>pg_stat_wal_receiver</structname> view will contain only
2093 one row, showing statistics about the WAL receiver from that receiver's
2097 <table id="pg-stat-subscription" xreflabel="pg_stat_subscription">
2098 <title><structname>pg_stat_subscription</structname> View</title>
2102 <entry>Column</entry>
2104 <entry>Description</entry>
2110 <entry><structfield>subid</structfield></entry>
2111 <entry><type>oid</type></entry>
2112 <entry>OID of the subscription</entry>
2115 <entry><structfield>subname</structfield></entry>
2116 <entry><type>text</type></entry>
2117 <entry>Name of the subscription</entry>
2120 <entry><structfield>pid</structfield></entry>
2121 <entry><type>integer</type></entry>
2122 <entry>Process ID of the subscription worker process</entry>
2125 <entry><structfield>relid</structfield></entry>
2126 <entry><type>Oid</type></entry>
2127 <entry>OID of the relation that the worker is synchronizing; null for the
2128 main apply worker</entry>
2131 <entry><structfield>received_lsn</structfield></entry>
2132 <entry><type>pg_lsn</type></entry>
2133 <entry>Last write-ahead log location received, the initial value of
2134 this field being 0</entry>
2137 <entry><structfield>last_msg_send_time</structfield></entry>
2138 <entry><type>timestamp with time zone</type></entry>
2139 <entry>Send time of last message received from origin WAL sender</entry>
2142 <entry><structfield>last_msg_receipt_time</structfield></entry>
2143 <entry><type>timestamp with time zone</type></entry>
2144 <entry>Receipt time of last message received from origin WAL sender
2148 <entry><structfield>latest_end_lsn</structfield></entry>
2149 <entry><type>pg_lsn</type></entry>
2150 <entry>Last write-ahead log location reported to origin WAL sender
2154 <entry><structfield>latest_end_time</structfield></entry>
2155 <entry><type>timestamp with time zone</type></entry>
2156 <entry>Time of last write-ahead log location reported to origin WAL
2164 The <structname>pg_stat_subscription</structname> view will contain one
2165 row per subscription for main worker (with null PID if the worker is
2166 not running), and additional rows for workers handling the initial data
2167 copy of the subscribed tables.
2170 <table id="pg-stat-ssl-view" xreflabel="pg_stat_ssl">
2171 <title><structname>pg_stat_ssl</structname> View</title>
2175 <entry>Column</entry>
2177 <entry>Description</entry>
2183 <entry><structfield>pid</structfield></entry>
2184 <entry><type>integer</type></entry>
2185 <entry>Process ID of a backend or WAL sender process</entry>
2188 <entry><structfield>ssl</structfield></entry>
2189 <entry><type>boolean</type></entry>
2190 <entry>True if SSL is used on this connection</entry>
2193 <entry><structfield>version</structfield></entry>
2194 <entry><type>text</type></entry>
2195 <entry>Version of SSL in use, or NULL if SSL is not in use
2196 on this connection</entry>
2199 <entry><structfield>cipher</structfield></entry>
2200 <entry><type>text</type></entry>
2201 <entry>Name of SSL cipher in use, or NULL if SSL is not in use
2202 on this connection</entry>
2205 <entry><structfield>bits</structfield></entry>
2206 <entry><type>integer</type></entry>
2207 <entry>Number of bits in the encryption algorithm used, or NULL
2208 if SSL is not used on this connection</entry>
2211 <entry><structfield>compression</structfield></entry>
2212 <entry><type>boolean</type></entry>
2213 <entry>True if SSL compression is in use, false if not,
2214 or NULL if SSL is not in use on this connection</entry>
2217 <entry><structfield>client_dn</structfield></entry>
2218 <entry><type>text</type></entry>
2219 <entry>Distinguished Name (DN) field from the client certificate
2220 used, or NULL if no client certificate was supplied or if SSL
2221 is not in use on this connection. This field is truncated if the
2222 DN field is longer than <symbol>NAMEDATALEN</symbol> (64 characters
2223 in a standard build).
2227 <entry><structfield>client_serial</structfield></entry>
2228 <entry><type>numeric</type></entry>
2229 <entry>Serial number of the client certificate, or NULL if no client
2230 certificate was supplied or if SSL is not in use on this connection. The
2231 combination of certificate serial number and certificate issuer uniquely
2232 identifies a certificate (unless the issuer erroneously reuses serial
2236 <entry><structfield>issuer_dn</structfield></entry>
2237 <entry><type>text</type></entry>
2238 <entry>DN of the issuer of the client certificate, or NULL if no client
2239 certificate was supplied or if SSL is not in use on this connection.
2240 This field is truncated like <structfield>client_dn</structfield>.</entry>
2247 The <structname>pg_stat_ssl</structname> view will contain one row per
2248 backend or WAL sender process, showing statistics about SSL usage on
2249 this connection. It can be joined to <structname>pg_stat_activity</structname>
2250 or <structname>pg_stat_replication</structname> on the
2251 <structfield>pid</structfield> column to get more details about the
2256 <table id="pg-stat-archiver-view" xreflabel="pg_stat_archiver">
2257 <title><structname>pg_stat_archiver</structname> View</title>
2262 <entry>Column</entry>
2264 <entry>Description</entry>
2270 <entry><structfield>archived_count</structfield></entry>
2271 <entry><type>bigint</type></entry>
2272 <entry>Number of WAL files that have been successfully archived</entry>
2275 <entry><structfield>last_archived_wal</structfield></entry>
2276 <entry><type>text</type></entry>
2277 <entry>Name of the last WAL file successfully archived</entry>
2280 <entry><structfield>last_archived_time</structfield></entry>
2281 <entry><type>timestamp with time zone</type></entry>
2282 <entry>Time of the last successful archive operation</entry>
2285 <entry><structfield>failed_count</structfield></entry>
2286 <entry><type>bigint</type></entry>
2287 <entry>Number of failed attempts for archiving WAL files</entry>
2290 <entry><structfield>last_failed_wal</structfield></entry>
2291 <entry><type>text</type></entry>
2292 <entry>Name of the WAL file of the last failed archival operation</entry>
2295 <entry><structfield>last_failed_time</structfield></entry>
2296 <entry><type>timestamp with time zone</type></entry>
2297 <entry>Time of the last failed archival operation</entry>
2300 <entry><structfield>stats_reset</structfield></entry>
2301 <entry><type>timestamp with time zone</type></entry>
2302 <entry>Time at which these statistics were last reset</entry>
2309 The <structname>pg_stat_archiver</structname> view will always have a
2310 single row, containing data about the archiver process of the cluster.
2313 <table id="pg-stat-bgwriter-view" xreflabel="pg_stat_bgwriter">
2314 <title><structname>pg_stat_bgwriter</structname> View</title>
2319 <entry>Column</entry>
2321 <entry>Description</entry>
2327 <entry><structfield>checkpoints_timed</structfield></entry>
2328 <entry><type>bigint</type></entry>
2329 <entry>Number of scheduled checkpoints that have been performed</entry>
2332 <entry><structfield>checkpoints_req</structfield></entry>
2333 <entry><type>bigint</type></entry>
2334 <entry>Number of requested checkpoints that have been performed</entry>
2337 <entry><structfield>checkpoint_write_time</structfield></entry>
2338 <entry><type>double precision</type></entry>
2340 Total amount of time that has been spent in the portion of
2341 checkpoint processing where files are written to disk, in milliseconds
2345 <entry><structfield>checkpoint_sync_time</structfield></entry>
2346 <entry><type>double precision</type></entry>
2348 Total amount of time that has been spent in the portion of
2349 checkpoint processing where files are synchronized to disk, in
2354 <entry><structfield>buffers_checkpoint</structfield></entry>
2355 <entry><type>bigint</type></entry>
2356 <entry>Number of buffers written during checkpoints</entry>
2359 <entry><structfield>buffers_clean</structfield></entry>
2360 <entry><type>bigint</type></entry>
2361 <entry>Number of buffers written by the background writer</entry>
2364 <entry><structfield>maxwritten_clean</structfield></entry>
2365 <entry><type>bigint</type></entry>
2366 <entry>Number of times the background writer stopped a cleaning
2367 scan because it had written too many buffers</entry>
2370 <entry><structfield>buffers_backend</structfield></entry>
2371 <entry><type>bigint</type></entry>
2372 <entry>Number of buffers written directly by a backend</entry>
2375 <entry><structfield>buffers_backend_fsync</structfield></entry>
2376 <entry><type>bigint</type></entry>
2377 <entry>Number of times a backend had to execute its own
2378 <function>fsync</function> call (normally the background writer handles those
2379 even when the backend does its own write)</entry>
2382 <entry><structfield>buffers_alloc</structfield></entry>
2383 <entry><type>bigint</type></entry>
2384 <entry>Number of buffers allocated</entry>
2387 <entry><structfield>stats_reset</structfield></entry>
2388 <entry><type>timestamp with time zone</type></entry>
2389 <entry>Time at which these statistics were last reset</entry>
2396 The <structname>pg_stat_bgwriter</structname> view will always have a
2397 single row, containing global data for the cluster.
2400 <table id="pg-stat-database-view" xreflabel="pg_stat_database">
2401 <title><structname>pg_stat_database</structname> View</title>
2405 <entry>Column</entry>
2407 <entry>Description</entry>
2413 <entry><structfield>datid</structfield></entry>
2414 <entry><type>oid</type></entry>
2415 <entry>OID of a database</entry>
2418 <entry><structfield>datname</structfield></entry>
2419 <entry><type>name</type></entry>
2420 <entry>Name of this database</entry>
2423 <entry><structfield>numbackends</structfield></entry>
2424 <entry><type>integer</type></entry>
2425 <entry>Number of backends currently connected to this database.
2426 This is the only column in this view that returns a value reflecting
2427 current state; all other columns return the accumulated values since
2428 the last reset.</entry>
2431 <entry><structfield>xact_commit</structfield></entry>
2432 <entry><type>bigint</type></entry>
2433 <entry>Number of transactions in this database that have been
2437 <entry><structfield>xact_rollback</structfield></entry>
2438 <entry><type>bigint</type></entry>
2439 <entry>Number of transactions in this database that have been
2443 <entry><structfield>blks_read</structfield></entry>
2444 <entry><type>bigint</type></entry>
2445 <entry>Number of disk blocks read in this database</entry>
2448 <entry><structfield>blks_hit</structfield></entry>
2449 <entry><type>bigint</type></entry>
2450 <entry>Number of times disk blocks were found already in the buffer
2451 cache, so that a read was not necessary (this only includes hits in the
2452 PostgreSQL buffer cache, not the operating system's file system cache)
2456 <entry><structfield>tup_returned</structfield></entry>
2457 <entry><type>bigint</type></entry>
2458 <entry>Number of rows returned by queries in this database</entry>
2461 <entry><structfield>tup_fetched</structfield></entry>
2462 <entry><type>bigint</type></entry>
2463 <entry>Number of rows fetched by queries in this database</entry>
2466 <entry><structfield>tup_inserted</structfield></entry>
2467 <entry><type>bigint</type></entry>
2468 <entry>Number of rows inserted by queries in this database</entry>
2471 <entry><structfield>tup_updated</structfield></entry>
2472 <entry><type>bigint</type></entry>
2473 <entry>Number of rows updated by queries in this database</entry>
2476 <entry><structfield>tup_deleted</structfield></entry>
2477 <entry><type>bigint</type></entry>
2478 <entry>Number of rows deleted by queries in this database</entry>
2481 <entry><structfield>conflicts</structfield></entry>
2482 <entry><type>bigint</type></entry>
2483 <entry>Number of queries canceled due to conflicts with recovery
2484 in this database. (Conflicts occur only on standby servers; see
2485 <xref linkend="pg-stat-database-conflicts-view"/> for details.)
2489 <entry><structfield>temp_files</structfield></entry>
2490 <entry><type>bigint</type></entry>
2491 <entry>Number of temporary files created by queries in this database.
2492 All temporary files are counted, regardless of why the temporary file
2493 was created (e.g., sorting or hashing), and regardless of the
2494 <xref linkend="guc-log-temp-files"/> setting.
2498 <entry><structfield>temp_bytes</structfield></entry>
2499 <entry><type>bigint</type></entry>
2500 <entry>Total amount of data written to temporary files by queries in
2501 this database. All temporary files are counted, regardless of why
2502 the temporary file was created, and
2503 regardless of the <xref linkend="guc-log-temp-files"/> setting.
2507 <entry><structfield>deadlocks</structfield></entry>
2508 <entry><type>bigint</type></entry>
2509 <entry>Number of deadlocks detected in this database</entry>
2512 <entry><structfield>blk_read_time</structfield></entry>
2513 <entry><type>double precision</type></entry>
2514 <entry>Time spent reading data file blocks by backends in this database,
2515 in milliseconds</entry>
2518 <entry><structfield>blk_write_time</structfield></entry>
2519 <entry><type>double precision</type></entry>
2520 <entry>Time spent writing data file blocks by backends in this database,
2521 in milliseconds</entry>
2524 <entry><structfield>stats_reset</structfield></entry>
2525 <entry><type>timestamp with time zone</type></entry>
2526 <entry>Time at which these statistics were last reset</entry>
2533 The <structname>pg_stat_database</structname> view will contain one row
2534 for each database in the cluster, showing database-wide statistics.
2537 <table id="pg-stat-database-conflicts-view" xreflabel="pg_stat_database_conflicts">
2538 <title><structname>pg_stat_database_conflicts</structname> View</title>
2542 <entry>Column</entry>
2544 <entry>Description</entry>
2550 <entry><structfield>datid</structfield></entry>
2551 <entry><type>oid</type></entry>
2552 <entry>OID of a database</entry>
2555 <entry><structfield>datname</structfield></entry>
2556 <entry><type>name</type></entry>
2557 <entry>Name of this database</entry>
2560 <entry><structfield>confl_tablespace</structfield></entry>
2561 <entry><type>bigint</type></entry>
2562 <entry>Number of queries in this database that have been canceled due to
2563 dropped tablespaces</entry>
2566 <entry><structfield>confl_lock</structfield></entry>
2567 <entry><type>bigint</type></entry>
2568 <entry>Number of queries in this database that have been canceled due to
2569 lock timeouts</entry>
2572 <entry><structfield>confl_snapshot</structfield></entry>
2573 <entry><type>bigint</type></entry>
2574 <entry>Number of queries in this database that have been canceled due to
2575 old snapshots</entry>
2578 <entry><structfield>confl_bufferpin</structfield></entry>
2579 <entry><type>bigint</type></entry>
2580 <entry>Number of queries in this database that have been canceled due to
2581 pinned buffers</entry>
2584 <entry><structfield>confl_deadlock</structfield></entry>
2585 <entry><type>bigint</type></entry>
2586 <entry>Number of queries in this database that have been canceled due to
2594 The <structname>pg_stat_database_conflicts</structname> view will contain
2595 one row per database, showing database-wide statistics about
2596 query cancels occurring due to conflicts with recovery on standby servers.
2597 This view will only contain information on standby servers, since
2598 conflicts do not occur on master servers.
2601 <table id="pg-stat-all-tables-view" xreflabel="pg_stat_all_tables">
2602 <title><structname>pg_stat_all_tables</structname> View</title>
2606 <entry>Column</entry>
2608 <entry>Description</entry>
2614 <entry><structfield>relid</structfield></entry>
2615 <entry><type>oid</type></entry>
2616 <entry>OID of a table</entry>
2619 <entry><structfield>schemaname</structfield></entry>
2620 <entry><type>name</type></entry>
2621 <entry>Name of the schema that this table is in</entry>
2624 <entry><structfield>relname</structfield></entry>
2625 <entry><type>name</type></entry>
2626 <entry>Name of this table</entry>
2629 <entry><structfield>seq_scan</structfield></entry>
2630 <entry><type>bigint</type></entry>
2631 <entry>Number of sequential scans initiated on this table</entry>
2634 <entry><structfield>seq_tup_read</structfield></entry>
2635 <entry><type>bigint</type></entry>
2636 <entry>Number of live rows fetched by sequential scans</entry>
2639 <entry><structfield>idx_scan</structfield></entry>
2640 <entry><type>bigint</type></entry>
2641 <entry>Number of index scans initiated on this table</entry>
2644 <entry><structfield>idx_tup_fetch</structfield></entry>
2645 <entry><type>bigint</type></entry>
2646 <entry>Number of live rows fetched by index scans</entry>
2649 <entry><structfield>n_tup_ins</structfield></entry>
2650 <entry><type>bigint</type></entry>
2651 <entry>Number of rows inserted</entry>
2654 <entry><structfield>n_tup_upd</structfield></entry>
2655 <entry><type>bigint</type></entry>
2656 <entry>Number of rows updated (includes HOT updated rows)</entry>
2659 <entry><structfield>n_tup_del</structfield></entry>
2660 <entry><type>bigint</type></entry>
2661 <entry>Number of rows deleted</entry>
2664 <entry><structfield>n_tup_hot_upd</structfield></entry>
2665 <entry><type>bigint</type></entry>
2666 <entry>Number of rows HOT updated (i.e., with no separate index
2667 update required)</entry>
2670 <entry><structfield>n_live_tup</structfield></entry>
2671 <entry><type>bigint</type></entry>
2672 <entry>Estimated number of live rows</entry>
2675 <entry><structfield>n_dead_tup</structfield></entry>
2676 <entry><type>bigint</type></entry>
2677 <entry>Estimated number of dead rows</entry>
2680 <entry><structfield>n_mod_since_analyze</structfield></entry>
2681 <entry><type>bigint</type></entry>
2682 <entry>Estimated number of rows modified since this table was last analyzed</entry>
2685 <entry><structfield>last_vacuum</structfield></entry>
2686 <entry><type>timestamp with time zone</type></entry>
2687 <entry>Last time at which this table was manually vacuumed
2688 (not counting <command>VACUUM FULL</command>)</entry>
2691 <entry><structfield>last_autovacuum</structfield></entry>
2692 <entry><type>timestamp with time zone</type></entry>
2693 <entry>Last time at which this table was vacuumed by the autovacuum
2697 <entry><structfield>last_analyze</structfield></entry>
2698 <entry><type>timestamp with time zone</type></entry>
2699 <entry>Last time at which this table was manually analyzed</entry>
2702 <entry><structfield>last_autoanalyze</structfield></entry>
2703 <entry><type>timestamp with time zone</type></entry>
2704 <entry>Last time at which this table was analyzed by the autovacuum
2708 <entry><structfield>vacuum_count</structfield></entry>
2709 <entry><type>bigint</type></entry>
2710 <entry>Number of times this table has been manually vacuumed
2711 (not counting <command>VACUUM FULL</command>)</entry>
2714 <entry><structfield>autovacuum_count</structfield></entry>
2715 <entry><type>bigint</type></entry>
2716 <entry>Number of times this table has been vacuumed by the autovacuum
2720 <entry><structfield>analyze_count</structfield></entry>
2721 <entry><type>bigint</type></entry>
2722 <entry>Number of times this table has been manually analyzed</entry>
2725 <entry><structfield>autoanalyze_count</structfield></entry>
2726 <entry><type>bigint</type></entry>
2727 <entry>Number of times this table has been analyzed by the autovacuum
2735 The <structname>pg_stat_all_tables</structname> view will contain
2736 one row for each table in the current database (including TOAST
2737 tables), showing statistics about accesses to that specific table. The
2738 <structname>pg_stat_user_tables</structname> and
2739 <structname>pg_stat_sys_tables</structname> views
2740 contain the same information,
2741 but filtered to only show user and system tables respectively.
2744 <table id="pg-stat-all-indexes-view" xreflabel="pg_stat_all_indexes">
2745 <title><structname>pg_stat_all_indexes</structname> View</title>
2749 <entry>Column</entry>
2751 <entry>Description</entry>
2757 <entry><structfield>relid</structfield></entry>
2758 <entry><type>oid</type></entry>
2759 <entry>OID of the table for this index</entry>
2762 <entry><structfield>indexrelid</structfield></entry>
2763 <entry><type>oid</type></entry>
2764 <entry>OID of this index</entry>
2767 <entry><structfield>schemaname</structfield></entry>
2768 <entry><type>name</type></entry>
2769 <entry>Name of the schema this index is in</entry>
2772 <entry><structfield>relname</structfield></entry>
2773 <entry><type>name</type></entry>
2774 <entry>Name of the table for this index</entry>
2777 <entry><structfield>indexrelname</structfield></entry>
2778 <entry><type>name</type></entry>
2779 <entry>Name of this index</entry>
2782 <entry><structfield>idx_scan</structfield></entry>
2783 <entry><type>bigint</type></entry>
2784 <entry>Number of index scans initiated on this index</entry>
2787 <entry><structfield>idx_tup_read</structfield></entry>
2788 <entry><type>bigint</type></entry>
2789 <entry>Number of index entries returned by scans on this index</entry>
2792 <entry><structfield>idx_tup_fetch</structfield></entry>
2793 <entry><type>bigint</type></entry>
2794 <entry>Number of live table rows fetched by simple index scans using this
2802 The <structname>pg_stat_all_indexes</structname> view will contain
2803 one row for each index in the current database,
2804 showing statistics about accesses to that specific index. The
2805 <structname>pg_stat_user_indexes</structname> and
2806 <structname>pg_stat_sys_indexes</structname> views
2807 contain the same information,
2808 but filtered to only show user and system indexes respectively.
2812 Indexes can be used by simple index scans, <quote>bitmap</quote> index scans,
2813 and the optimizer. In a bitmap scan
2814 the output of several indexes can be combined via AND or OR rules,
2815 so it is difficult to associate individual heap row fetches
2816 with specific indexes when a bitmap scan is used. Therefore, a bitmap
2818 <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_read</structfield>
2819 count(s) for the index(es) it uses, and it increments the
2820 <structname>pg_stat_all_tables</structname>.<structfield>idx_tup_fetch</structfield>
2821 count for the table, but it does not affect
2822 <structname>pg_stat_all_indexes</structname>.<structfield>idx_tup_fetch</structfield>.
2823 The optimizer also accesses indexes to check for supplied constants
2824 whose values are outside the recorded range of the optimizer statistics
2825 because the optimizer statistics might be stale.
2830 The <structfield>idx_tup_read</structfield> and <structfield>idx_tup_fetch</structfield> counts
2831 can be different even without any use of bitmap scans,
2832 because <structfield>idx_tup_read</structfield> counts
2833 index entries retrieved from the index while <structfield>idx_tup_fetch</structfield>
2834 counts live rows fetched from the table. The latter will be less if any
2835 dead or not-yet-committed rows are fetched using the index, or if any
2836 heap fetches are avoided by means of an index-only scan.
2840 <table id="pg-statio-all-tables-view" xreflabel="pg_statio_all_tables">
2841 <title><structname>pg_statio_all_tables</structname> View</title>
2845 <entry>Column</entry>
2847 <entry>Description</entry>
2853 <entry><structfield>relid</structfield></entry>
2854 <entry><type>oid</type></entry>
2855 <entry>OID of a table</entry>
2858 <entry><structfield>schemaname</structfield></entry>
2859 <entry><type>name</type></entry>
2860 <entry>Name of the schema that this table is in</entry>
2863 <entry><structfield>relname</structfield></entry>
2864 <entry><type>name</type></entry>
2865 <entry>Name of this table</entry>
2868 <entry><structfield>heap_blks_read</structfield></entry>
2869 <entry><type>bigint</type></entry>
2870 <entry>Number of disk blocks read from this table</entry>
2873 <entry><structfield>heap_blks_hit</structfield></entry>
2874 <entry><type>bigint</type></entry>
2875 <entry>Number of buffer hits in this table</entry>
2878 <entry><structfield>idx_blks_read</structfield></entry>
2879 <entry><type>bigint</type></entry>
2880 <entry>Number of disk blocks read from all indexes on this table</entry>
2883 <entry><structfield>idx_blks_hit</structfield></entry>
2884 <entry><type>bigint</type></entry>
2885 <entry>Number of buffer hits in all indexes on this table</entry>
2888 <entry><structfield>toast_blks_read</structfield></entry>
2889 <entry><type>bigint</type></entry>
2890 <entry>Number of disk blocks read from this table's TOAST table (if any)</entry>
2893 <entry><structfield>toast_blks_hit</structfield></entry>
2894 <entry><type>bigint</type></entry>
2895 <entry>Number of buffer hits in this table's TOAST table (if any)</entry>
2898 <entry><structfield>tidx_blks_read</structfield></entry>
2899 <entry><type>bigint</type></entry>
2900 <entry>Number of disk blocks read from this table's TOAST table indexes (if any)</entry>
2903 <entry><structfield>tidx_blks_hit</structfield></entry>
2904 <entry><type>bigint</type></entry>
2905 <entry>Number of buffer hits in this table's TOAST table indexes (if any)</entry>
2912 The <structname>pg_statio_all_tables</structname> view will contain
2913 one row for each table in the current database (including TOAST
2914 tables), showing statistics about I/O on that specific table. The
2915 <structname>pg_statio_user_tables</structname> and
2916 <structname>pg_statio_sys_tables</structname> views
2917 contain the same information,
2918 but filtered to only show user and system tables respectively.
2921 <table id="pg-statio-all-indexes-view" xreflabel="pg_statio_all_indexes">
2922 <title><structname>pg_statio_all_indexes</structname> View</title>
2926 <entry>Column</entry>
2928 <entry>Description</entry>
2934 <entry><structfield>relid</structfield></entry>
2935 <entry><type>oid</type></entry>
2936 <entry>OID of the table for this index</entry>
2939 <entry><structfield>indexrelid</structfield></entry>
2940 <entry><type>oid</type></entry>
2941 <entry>OID of this index</entry>
2944 <entry><structfield>schemaname</structfield></entry>
2945 <entry><type>name</type></entry>
2946 <entry>Name of the schema this index is in</entry>
2949 <entry><structfield>relname</structfield></entry>
2950 <entry><type>name</type></entry>
2951 <entry>Name of the table for this index</entry>
2954 <entry><structfield>indexrelname</structfield></entry>
2955 <entry><type>name</type></entry>
2956 <entry>Name of this index</entry>
2959 <entry><structfield>idx_blks_read</structfield></entry>
2960 <entry><type>bigint</type></entry>
2961 <entry>Number of disk blocks read from this index</entry>
2964 <entry><structfield>idx_blks_hit</structfield></entry>
2965 <entry><type>bigint</type></entry>
2966 <entry>Number of buffer hits in this index</entry>
2973 The <structname>pg_statio_all_indexes</structname> view will contain
2974 one row for each index in the current database,
2975 showing statistics about I/O on that specific index. The
2976 <structname>pg_statio_user_indexes</structname> and
2977 <structname>pg_statio_sys_indexes</structname> views
2978 contain the same information,
2979 but filtered to only show user and system indexes respectively.
2982 <table id="pg-statio-all-sequences-view" xreflabel="pg_statio_all_sequences">
2983 <title><structname>pg_statio_all_sequences</structname> View</title>
2987 <entry>Column</entry>
2989 <entry>Description</entry>
2995 <entry><structfield>relid</structfield></entry>
2996 <entry><type>oid</type></entry>
2997 <entry>OID of a sequence</entry>
3000 <entry><structfield>schemaname</structfield></entry>
3001 <entry><type>name</type></entry>
3002 <entry>Name of the schema this sequence is in</entry>
3005 <entry><structfield>relname</structfield></entry>
3006 <entry><type>name</type></entry>
3007 <entry>Name of this sequence</entry>
3010 <entry><structfield>blks_read</structfield></entry>
3011 <entry><type>bigint</type></entry>
3012 <entry>Number of disk blocks read from this sequence</entry>
3015 <entry><structfield>blks_hit</structfield></entry>
3016 <entry><type>bigint</type></entry>
3017 <entry>Number of buffer hits in this sequence</entry>
3024 The <structname>pg_statio_all_sequences</structname> view will contain
3025 one row for each sequence in the current database,
3026 showing statistics about I/O on that specific sequence.
3029 <table id="pg-stat-user-functions-view" xreflabel="pg_stat_user_functions">
3030 <title><structname>pg_stat_user_functions</structname> View</title>
3034 <entry>Column</entry>
3036 <entry>Description</entry>
3042 <entry><structfield>funcid</structfield></entry>
3043 <entry><type>oid</type></entry>
3044 <entry>OID of a function</entry>
3047 <entry><structfield>schemaname</structfield></entry>
3048 <entry><type>name</type></entry>
3049 <entry>Name of the schema this function is in</entry>
3052 <entry><structfield>funcname</structfield></entry>
3053 <entry><type>name</type></entry>
3054 <entry>Name of this function</entry>
3057 <entry><structfield>calls</structfield></entry>
3058 <entry><type>bigint</type></entry>
3059 <entry>Number of times this function has been called</entry>
3062 <entry><structfield>total_time</structfield></entry>
3063 <entry><type>double precision</type></entry>
3064 <entry>Total time spent in this function and all other functions
3065 called by it, in milliseconds</entry>
3068 <entry><structfield>self_time</structfield></entry>
3069 <entry><type>double precision</type></entry>
3070 <entry>Total time spent in this function itself, not including
3071 other functions called by it, in milliseconds</entry>
3078 The <structname>pg_stat_user_functions</structname> view will contain
3079 one row for each tracked function, showing statistics about executions of
3080 that function. The <xref linkend="guc-track-functions"/> parameter
3081 controls exactly which functions are tracked.
3086 <sect2 id="monitoring-stats-functions">
3087 <title>Statistics Functions</title>
3090 Other ways of looking at the statistics can be set up by writing
3091 queries that use the same underlying statistics access functions used by
3092 the standard views shown above. For details such as the functions' names,
3093 consult the definitions of the standard views. (For example, in
3094 <application>psql</application> you could issue <literal>\d+ pg_stat_activity</literal>.)
3095 The access functions for per-database statistics take a database OID as an
3096 argument to identify which database to report on.
3097 The per-table and per-index functions take a table or index OID.
3098 The functions for per-function statistics take a function OID.
3099 Note that only tables, indexes, and functions in the current database
3100 can be seen with these functions.
3104 Additional functions related to statistics collection are listed in <xref
3105 linkend="monitoring-stats-funcs-table"/>.
3108 <table id="monitoring-stats-funcs-table">
3109 <title>Additional Statistics Functions</title>
3114 <entry>Function</entry>
3115 <entry>Return Type</entry>
3116 <entry>Description</entry>
3123 <!-- See also the entry for this in func.sgml -->
3124 <entry><literal><function>pg_backend_pid()</function></literal></entry>
3125 <entry><type>integer</type></entry>
3127 Process ID of the server process handling the current session
3132 <entry><literal><function>pg_stat_get_activity</function>(<type>integer</type>)</literal><indexterm><primary>pg_stat_get_activity</primary></indexterm></entry>
3133 <entry><type>setof record</type></entry>
3135 Returns a record of information about the backend with the specified PID, or
3136 one record for each active backend in the system if <symbol>NULL</symbol> is
3137 specified. The fields returned are a subset of those in the
3138 <structname>pg_stat_activity</structname> view.
3143 <entry><literal><function>pg_stat_get_snapshot_timestamp()</function></literal><indexterm><primary>pg_stat_get_snapshot_timestamp</primary></indexterm></entry>
3144 <entry><type>timestamp with time zone</type></entry>
3146 Returns the timestamp of the current statistics snapshot
3151 <entry><literal><function>pg_stat_clear_snapshot()</function></literal><indexterm><primary>pg_stat_clear_snapshot</primary></indexterm></entry>
3152 <entry><type>void</type></entry>
3154 Discard the current statistics snapshot
3159 <entry><literal><function>pg_stat_reset()</function></literal><indexterm><primary>pg_stat_reset</primary></indexterm></entry>
3160 <entry><type>void</type></entry>
3162 Reset all statistics counters for the current database to zero
3163 (requires superuser privileges by default, but EXECUTE for this
3164 function can be granted to others.)
3169 <entry><literal><function>pg_stat_reset_shared</function>(text)</literal><indexterm><primary>pg_stat_reset_shared</primary></indexterm></entry>
3170 <entry><type>void</type></entry>
3172 Reset some cluster-wide statistics counters to zero, depending on the
3173 argument (requires superuser privileges by default, but EXECUTE for
3174 this function can be granted to others).
3175 Calling <literal>pg_stat_reset_shared('bgwriter')</literal> will zero all the
3176 counters shown in the <structname>pg_stat_bgwriter</structname> view.
3177 Calling <literal>pg_stat_reset_shared('archiver')</literal> will zero all the
3178 counters shown in the <structname>pg_stat_archiver</structname> view.
3183 <entry><literal><function>pg_stat_reset_single_table_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_table_counters</primary></indexterm></entry>
3184 <entry><type>void</type></entry>
3186 Reset statistics for a single table or index in the current database to
3187 zero (requires superuser privileges by default, but EXECUTE for this
3188 function can be granted to others)
3193 <entry><literal><function>pg_stat_reset_single_function_counters</function>(oid)</literal><indexterm><primary>pg_stat_reset_single_function_counters</primary></indexterm></entry>
3194 <entry><type>void</type></entry>
3196 Reset statistics for a single function in the current database to
3197 zero (requires superuser privileges by default, but EXECUTE for this
3198 function can be granted to others)
3206 <function>pg_stat_get_activity</function>, the underlying function of
3207 the <structname>pg_stat_activity</structname> view, returns a set of records
3208 containing all the available information about each backend process.
3209 Sometimes it may be more convenient to obtain just a subset of this
3210 information. In such cases, an older set of per-backend statistics
3211 access functions can be used; these are shown in <xref
3212 linkend="monitoring-stats-backend-funcs-table"/>.
3213 These access functions use a backend ID number, which ranges from one
3214 to the number of currently active backends.
3215 The function <function>pg_stat_get_backend_idset</function> provides a
3216 convenient way to generate one row for each active backend for
3217 invoking these functions. For example, to show the <acronym>PID</acronym>s and
3218 current queries of all backends:
3221 SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
3222 pg_stat_get_backend_activity(s.backendid) AS query
3223 FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
3227 <table id="monitoring-stats-backend-funcs-table">
3228 <title>Per-Backend Statistics Functions</title>
3233 <entry>Function</entry>
3234 <entry>Return Type</entry>
3235 <entry>Description</entry>
3242 <entry><literal><function>pg_stat_get_backend_idset()</function></literal></entry>
3243 <entry><type>setof integer</type></entry>
3244 <entry>Set of currently active backend ID numbers (from 1 to the
3245 number of active backends)</entry>
3249 <entry><literal><function>pg_stat_get_backend_activity(integer)</function></literal></entry>
3250 <entry><type>text</type></entry>
3251 <entry>Text of this backend's most recent query</entry>
3255 <entry><literal><function>pg_stat_get_backend_activity_start(integer)</function></literal></entry>
3256 <entry><type>timestamp with time zone</type></entry>
3257 <entry>Time when the most recent query was started</entry>
3261 <entry><literal><function>pg_stat_get_backend_client_addr(integer)</function></literal></entry>
3262 <entry><type>inet</type></entry>
3263 <entry>IP address of the client connected to this backend</entry>
3267 <entry><literal><function>pg_stat_get_backend_client_port(integer)</function></literal></entry>
3268 <entry><type>integer</type></entry>
3269 <entry>TCP port number that the client is using for communication</entry>
3273 <entry><literal><function>pg_stat_get_backend_dbid(integer)</function></literal></entry>
3274 <entry><type>oid</type></entry>
3275 <entry>OID of the database this backend is connected to</entry>
3279 <entry><literal><function>pg_stat_get_backend_pid(integer)</function></literal></entry>
3280 <entry><type>integer</type></entry>
3281 <entry>Process ID of this backend</entry>
3285 <entry><literal><function>pg_stat_get_backend_start(integer)</function></literal></entry>
3286 <entry><type>timestamp with time zone</type></entry>
3287 <entry>Time when this process was started</entry>
3291 <entry><literal><function>pg_stat_get_backend_userid(integer)</function></literal></entry>
3292 <entry><type>oid</type></entry>
3293 <entry>OID of the user logged into this backend</entry>
3297 <entry><literal><function>pg_stat_get_backend_wait_event_type(integer)</function></literal></entry>
3298 <entry><type>text</type></entry>
3299 <entry>Wait event type name if backend is currently waiting, otherwise NULL.
3300 See <xref linkend="wait-event-table"/> for details.
3305 <entry><literal><function>pg_stat_get_backend_wait_event(integer)</function></literal></entry>
3306 <entry><type>text</type></entry>
3307 <entry>Wait event name if backend is currently waiting, otherwise NULL.
3308 See <xref linkend="wait-event-table"/> for details.
3313 <entry><literal><function>pg_stat_get_backend_xact_start(integer)</function></literal></entry>
3314 <entry><type>timestamp with time zone</type></entry>
3315 <entry>Time when the current transaction was started</entry>
3325 <sect1 id="monitoring-locks">
3326 <title>Viewing Locks</title>
3328 <indexterm zone="monitoring-locks">
3329 <primary>lock</primary>
3330 <secondary>monitoring</secondary>
3334 Another useful tool for monitoring database activity is the
3335 <structname>pg_locks</structname> system table. It allows the
3336 database administrator to view information about the outstanding
3337 locks in the lock manager. For example, this capability can be used
3343 View all the locks currently outstanding, all the locks on
3344 relations in a particular database, all the locks on a
3345 particular relation, or all the locks held by a particular
3346 <productname>PostgreSQL</productname> session.
3352 Determine the relation in the current database with the most
3353 ungranted locks (which might be a source of contention among
3360 Determine the effect of lock contention on overall database
3361 performance, as well as the extent to which contention varies
3362 with overall database traffic.
3367 Details of the <structname>pg_locks</structname> view appear in
3368 <xref linkend="view-pg-locks"/>.
3369 For more information on locking and managing concurrency with
3370 <productname>PostgreSQL</productname>, refer to <xref linkend="mvcc"/>.
3374 <sect1 id="progress-reporting">
3375 <title>Progress Reporting</title>
3378 <productname>PostgreSQL</productname> has the ability to report the progress of
3379 certain commands during command execution. Currently, the only command
3380 which supports progress reporting is <command>VACUUM</command>. This may be
3381 expanded in the future.
3384 <sect2 id="vacuum-progress-reporting">
3385 <title>VACUUM Progress Reporting</title>
3388 Whenever <command>VACUUM</command> is running, the
3389 <structname>pg_stat_progress_vacuum</structname> view will contain
3390 one row for each backend (including autovacuum worker processes) that is
3391 currently vacuuming. The tables below describe the information
3392 that will be reported and provide information about how to interpret it.
3393 Progress reporting is not currently supported for <command>VACUUM FULL</command>
3394 and backends running <command>VACUUM FULL</command> will not be listed in this
3398 <table id="pg-stat-progress-vacuum-view" xreflabel="pg_stat_progress_vacuum">
3399 <title><structname>pg_stat_progress_vacuum</structname> View</title>
3403 <entry>Column</entry>
3405 <entry>Description</entry>
3411 <entry><structfield>pid</structfield></entry>
3412 <entry><type>integer</type></entry>
3413 <entry>Process ID of backend.</entry>
3416 <entry><structfield>datid</structfield></entry>
3417 <entry><type>oid</type></entry>
3418 <entry>OID of the database to which this backend is connected.</entry>
3421 <entry><structfield>datname</structfield></entry>
3422 <entry><type>name</type></entry>
3423 <entry>Name of the database to which this backend is connected.</entry>
3426 <entry><structfield>relid</structfield></entry>
3427 <entry><type>oid</type></entry>
3428 <entry>OID of the table being vacuumed.</entry>
3431 <entry><structfield>phase</structfield></entry>
3432 <entry><type>text</type></entry>
3434 Current processing phase of vacuum. See <xref linkend='vacuum-phases'/>.
3438 <entry><structfield>heap_blks_total</structfield></entry>
3439 <entry><type>bigint</type></entry>
3441 Total number of heap blocks in the table. This number is reported
3442 as of the beginning of the scan; blocks added later will not be (and
3443 need not be) visited by this <command>VACUUM</command>.
3447 <entry><structfield>heap_blks_scanned</structfield></entry>
3448 <entry><type>bigint</type></entry>
3450 Number of heap blocks scanned. Because the
3451 <link linkend="storage-vm">visibility map</link> is used to optimize scans,
3452 some blocks will be skipped without inspection; skipped blocks are
3453 included in this total, so that this number will eventually become
3454 equal to <structfield>heap_blks_total</structfield> when the vacuum is complete.
3455 This counter only advances when the phase is <literal>scanning heap</literal>.
3459 <entry><structfield>heap_blks_vacuumed</structfield></entry>
3460 <entry><type>bigint</type></entry>
3462 Number of heap blocks vacuumed. Unless the table has no indexes, this
3463 counter only advances when the phase is <literal>vacuuming heap</literal>.
3464 Blocks that contain no dead tuples are skipped, so the counter may
3465 sometimes skip forward in large increments.
3469 <entry><structfield>index_vacuum_count</structfield></entry>
3470 <entry><type>bigint</type></entry>
3472 Number of completed index vacuum cycles.
3476 <entry><structfield>max_dead_tuples</structfield></entry>
3477 <entry><type>bigint</type></entry>
3479 Number of dead tuples that we can store before needing to perform
3480 an index vacuum cycle, based on
3481 <xref linkend="guc-maintenance-work-mem"/>.
3485 <entry><structfield>num_dead_tuples</structfield></entry>
3486 <entry><type>bigint</type></entry>
3488 Number of dead tuples collected since the last index vacuum cycle.
3495 <table id="vacuum-phases">
3496 <title>VACUUM phases</title>
3500 <entry>Phase</entry>
3501 <entry>Description</entry>
3507 <entry><literal>initializing</literal></entry>
3509 <command>VACUUM</command> is preparing to begin scanning the heap. This
3510 phase is expected to be very brief.
3514 <entry><literal>scanning heap</literal></entry>
3516 <command>VACUUM</command> is currently scanning the heap. It will prune and
3517 defragment each page if required, and possibly perform freezing
3518 activity. The <structfield>heap_blks_scanned</structfield> column can be used
3519 to monitor the progress of the scan.
3523 <entry><literal>vacuuming indexes</literal></entry>
3525 <command>VACUUM</command> is currently vacuuming the indexes. If a table has
3526 any indexes, this will happen at least once per vacuum, after the heap
3527 has been completely scanned. It may happen multiple times per vacuum
3528 if <xref linkend="guc-maintenance-work-mem"/> is insufficient to
3529 store the number of dead tuples found.
3533 <entry><literal>vacuuming heap</literal></entry>
3535 <command>VACUUM</command> is currently vacuuming the heap. Vacuuming the heap
3536 is distinct from scanning the heap, and occurs after each instance of
3537 vacuuming indexes. If <structfield>heap_blks_scanned</structfield> is less than
3538 <structfield>heap_blks_total</structfield>, the system will return to scanning
3539 the heap after this phase is completed; otherwise, it will begin
3540 cleaning up indexes after this phase is completed.
3544 <entry><literal>cleaning up indexes</literal></entry>
3546 <command>VACUUM</command> is currently cleaning up indexes. This occurs after
3547 the heap has been completely scanned and all vacuuming of the indexes
3548 and the heap has been completed.
3552 <entry><literal>truncating heap</literal></entry>
3554 <command>VACUUM</command> is currently truncating the heap so as to return
3555 empty pages at the end of the relation to the operating system. This
3556 occurs after cleaning up indexes.
3560 <entry><literal>performing final cleanup</literal></entry>
3562 <command>VACUUM</command> is performing final cleanup. During this phase,
3563 <command>VACUUM</command> will vacuum the free space map, update statistics
3564 in <literal>pg_class</literal>, and report statistics to the statistics
3565 collector. When this phase is completed, <command>VACUUM</command> will end.
3575 <sect1 id="dynamic-trace">
3576 <title>Dynamic Tracing</title>
3578 <indexterm zone="dynamic-trace">
3579 <primary>DTrace</primary>
3583 <productname>PostgreSQL</productname> provides facilities to support
3584 dynamic tracing of the database server. This allows an external
3585 utility to be called at specific points in the code and thereby trace
3590 A number of probes or trace points are already inserted into the source
3591 code. These probes are intended to be used by database developers and
3592 administrators. By default the probes are not compiled into
3593 <productname>PostgreSQL</productname>; the user needs to explicitly tell
3594 the configure script to make the probes available.
3599 <ulink url="https://en.wikipedia.org/wiki/DTrace">DTrace</ulink>
3600 utility is supported, which, at the time of this writing, is available
3601 on Solaris, macOS, FreeBSD, NetBSD, and Oracle Linux. The
3602 <ulink url="http://sourceware.org/systemtap/">SystemTap</ulink> project
3603 for Linux provides a DTrace equivalent and can also be used. Supporting other dynamic
3604 tracing utilities is theoretically possible by changing the definitions for
3605 the macros in <filename>src/include/utils/probes.h</filename>.
3608 <sect2 id="compiling-for-trace">
3609 <title>Compiling for Dynamic Tracing</title>
3612 By default, probes are not available, so you will need to
3613 explicitly tell the configure script to make the probes available
3614 in <productname>PostgreSQL</productname>. To include DTrace support
3615 specify <option>--enable-dtrace</option> to configure. See <xref
3616 linkend="install-procedure"/> for further information.
3620 <sect2 id="trace-points">
3621 <title>Built-in Probes</title>
3624 A number of standard probes are provided in the source code,
3625 as shown in <xref linkend="dtrace-probe-point-table"/>;
3626 <xref linkend="typedefs-table"/>
3627 shows the types used in the probes. More probes can certainly be
3628 added to enhance <productname>PostgreSQL</productname>'s observability.
3631 <table id="dtrace-probe-point-table">
3632 <title>Built-in DTrace Probes</title>
3637 <entry>Parameters</entry>
3638 <entry>Description</entry>
3645 <entry><literal>transaction-start</literal></entry>
3646 <entry><literal>(LocalTransactionId)</literal></entry>
3647 <entry>Probe that fires at the start of a new transaction.
3648 arg0 is the transaction ID.</entry>
3651 <entry><literal>transaction-commit</literal></entry>
3652 <entry><literal>(LocalTransactionId)</literal></entry>
3653 <entry>Probe that fires when a transaction completes successfully.
3654 arg0 is the transaction ID.</entry>
3657 <entry><literal>transaction-abort</literal></entry>
3658 <entry><literal>(LocalTransactionId)</literal></entry>
3659 <entry>Probe that fires when a transaction completes unsuccessfully.
3660 arg0 is the transaction ID.</entry>
3663 <entry><literal>query-start</literal></entry>
3664 <entry><literal>(const char *)</literal></entry>
3665 <entry>Probe that fires when the processing of a query is started.
3666 arg0 is the query string.</entry>
3669 <entry><literal>query-done</literal></entry>
3670 <entry><literal>(const char *)</literal></entry>
3671 <entry>Probe that fires when the processing of a query is complete.
3672 arg0 is the query string.</entry>
3675 <entry><literal>query-parse-start</literal></entry>
3676 <entry><literal>(const char *)</literal></entry>
3677 <entry>Probe that fires when the parsing of a query is started.
3678 arg0 is the query string.</entry>
3681 <entry><literal>query-parse-done</literal></entry>
3682 <entry><literal>(const char *)</literal></entry>
3683 <entry>Probe that fires when the parsing of a query is complete.
3684 arg0 is the query string.</entry>
3687 <entry><literal>query-rewrite-start</literal></entry>
3688 <entry><literal>(const char *)</literal></entry>
3689 <entry>Probe that fires when the rewriting of a query is started.
3690 arg0 is the query string.</entry>
3693 <entry><literal>query-rewrite-done</literal></entry>
3694 <entry><literal>(const char *)</literal></entry>
3695 <entry>Probe that fires when the rewriting of a query is complete.
3696 arg0 is the query string.</entry>
3699 <entry><literal>query-plan-start</literal></entry>
3700 <entry><literal>()</literal></entry>
3701 <entry>Probe that fires when the planning of a query is started.</entry>
3704 <entry><literal>query-plan-done</literal></entry>
3705 <entry><literal>()</literal></entry>
3706 <entry>Probe that fires when the planning of a query is complete.</entry>
3709 <entry><literal>query-execute-start</literal></entry>
3710 <entry><literal>()</literal></entry>
3711 <entry>Probe that fires when the execution of a query is started.</entry>
3714 <entry><literal>query-execute-done</literal></entry>
3715 <entry><literal>()</literal></entry>
3716 <entry>Probe that fires when the execution of a query is complete.</entry>
3719 <entry><literal>statement-status</literal></entry>
3720 <entry><literal>(const char *)</literal></entry>
3721 <entry>Probe that fires anytime the server process updates its
3722 <structname>pg_stat_activity</structname>.<structfield>status</structfield>.
3723 arg0 is the new status string.</entry>
3726 <entry><literal>checkpoint-start</literal></entry>
3727 <entry><literal>(int)</literal></entry>
3728 <entry>Probe that fires when a checkpoint is started.
3729 arg0 holds the bitwise flags used to distinguish different checkpoint
3730 types, such as shutdown, immediate or force.</entry>
3733 <entry><literal>checkpoint-done</literal></entry>
3734 <entry><literal>(int, int, int, int, int)</literal></entry>
3735 <entry>Probe that fires when a checkpoint is complete.
3736 (The probes listed next fire in sequence during checkpoint processing.)
3737 arg0 is the number of buffers written. arg1 is the total number of
3738 buffers. arg2, arg3 and arg4 contain the number of WAL files added,
3739 removed and recycled respectively.</entry>
3742 <entry><literal>clog-checkpoint-start</literal></entry>
3743 <entry><literal>(bool)</literal></entry>
3744 <entry>Probe that fires when the CLOG portion of a checkpoint is started.
3745 arg0 is true for normal checkpoint, false for shutdown
3749 <entry><literal>clog-checkpoint-done</literal></entry>
3750 <entry><literal>(bool)</literal></entry>
3751 <entry>Probe that fires when the CLOG portion of a checkpoint is
3752 complete. arg0 has the same meaning as for <literal>clog-checkpoint-start</literal>.</entry>
3755 <entry><literal>subtrans-checkpoint-start</literal></entry>
3756 <entry><literal>(bool)</literal></entry>
3757 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
3759 arg0 is true for normal checkpoint, false for shutdown
3763 <entry><literal>subtrans-checkpoint-done</literal></entry>
3764 <entry><literal>(bool)</literal></entry>
3765 <entry>Probe that fires when the SUBTRANS portion of a checkpoint is
3766 complete. arg0 has the same meaning as for
3767 <literal>subtrans-checkpoint-start</literal>.</entry>
3770 <entry><literal>multixact-checkpoint-start</literal></entry>
3771 <entry><literal>(bool)</literal></entry>
3772 <entry>Probe that fires when the MultiXact portion of a checkpoint is
3774 arg0 is true for normal checkpoint, false for shutdown
3778 <entry><literal>multixact-checkpoint-done</literal></entry>
3779 <entry><literal>(bool)</literal></entry>
3780 <entry>Probe that fires when the MultiXact portion of a checkpoint is
3781 complete. arg0 has the same meaning as for
3782 <literal>multixact-checkpoint-start</literal>.</entry>
3785 <entry><literal>buffer-checkpoint-start</literal></entry>
3786 <entry><literal>(int)</literal></entry>
3787 <entry>Probe that fires when the buffer-writing portion of a checkpoint
3789 arg0 holds the bitwise flags used to distinguish different checkpoint
3790 types, such as shutdown, immediate or force.</entry>
3793 <entry><literal>buffer-sync-start</literal></entry>
3794 <entry><literal>(int, int)</literal></entry>
3795 <entry>Probe that fires when we begin to write dirty buffers during
3796 checkpoint (after identifying which buffers must be written).
3797 arg0 is the total number of buffers.
3798 arg1 is the number that are currently dirty and need to be written.</entry>
3801 <entry><literal>buffer-sync-written</literal></entry>
3802 <entry><literal>(int)</literal></entry>
3803 <entry>Probe that fires after each buffer is written during checkpoint.
3804 arg0 is the ID number of the buffer.</entry>
3807 <entry><literal>buffer-sync-done</literal></entry>
3808 <entry><literal>(int, int, int)</literal></entry>
3809 <entry>Probe that fires when all dirty buffers have been written.
3810 arg0 is the total number of buffers.
3811 arg1 is the number of buffers actually written by the checkpoint process.
3812 arg2 is the number that were expected to be written (arg1 of
3813 <literal>buffer-sync-start</literal>); any difference reflects other processes flushing
3814 buffers during the checkpoint.</entry>
3817 <entry><literal>buffer-checkpoint-sync-start</literal></entry>
3818 <entry><literal>()</literal></entry>
3819 <entry>Probe that fires after dirty buffers have been written to the
3820 kernel, and before starting to issue fsync requests.</entry>
3823 <entry><literal>buffer-checkpoint-done</literal></entry>
3824 <entry><literal>()</literal></entry>
3825 <entry>Probe that fires when syncing of buffers to disk is
3829 <entry><literal>twophase-checkpoint-start</literal></entry>
3830 <entry><literal>()</literal></entry>
3831 <entry>Probe that fires when the two-phase portion of a checkpoint is
3835 <entry><literal>twophase-checkpoint-done</literal></entry>
3836 <entry><literal>()</literal></entry>
3837 <entry>Probe that fires when the two-phase portion of a checkpoint is
3841 <entry><literal>buffer-read-start</literal></entry>
3842 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool)</literal></entry>
3843 <entry>Probe that fires when a buffer read is started.
3844 arg0 and arg1 contain the fork and block numbers of the page (but
3845 arg1 will be -1 if this is a relation extension request).
3846 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3847 identifying the relation.
3848 arg5 is the ID of the backend which created the temporary relation for a
3849 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3850 arg6 is true for a relation extension request, false for normal
3854 <entry><literal>buffer-read-done</literal></entry>
3855 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, bool, bool)</literal></entry>
3856 <entry>Probe that fires when a buffer read is complete.
3857 arg0 and arg1 contain the fork and block numbers of the page (if this
3858 is a relation extension request, arg1 now contains the block number
3859 of the newly added block).
3860 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3861 identifying the relation.
3862 arg5 is the ID of the backend which created the temporary relation for a
3863 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3864 arg6 is true for a relation extension request, false for normal
3866 arg7 is true if the buffer was found in the pool, false if not.</entry>
3869 <entry><literal>buffer-flush-start</literal></entry>
3870 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3871 <entry>Probe that fires before issuing any write request for a shared
3873 arg0 and arg1 contain the fork and block numbers of the page.
3874 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3875 identifying the relation.</entry>
3878 <entry><literal>buffer-flush-done</literal></entry>
3879 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3880 <entry>Probe that fires when a write request is complete. (Note
3881 that this just reflects the time to pass the data to the kernel;
3882 it's typically not actually been written to disk yet.)
3883 The arguments are the same as for <literal>buffer-flush-start</literal>.</entry>
3886 <entry><literal>buffer-write-dirty-start</literal></entry>
3887 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3888 <entry>Probe that fires when a server process begins to write a dirty
3889 buffer. (If this happens often, it implies that
3890 <xref linkend="guc-shared-buffers"/> is too
3891 small or the background writer control parameters need adjustment.)
3892 arg0 and arg1 contain the fork and block numbers of the page.
3893 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3894 identifying the relation.</entry>
3897 <entry><literal>buffer-write-dirty-done</literal></entry>
3898 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid)</literal></entry>
3899 <entry>Probe that fires when a dirty-buffer write is complete.
3900 The arguments are the same as for <literal>buffer-write-dirty-start</literal>.</entry>
3903 <entry><literal>wal-buffer-write-dirty-start</literal></entry>
3904 <entry><literal>()</literal></entry>
3905 <entry>Probe that fires when a server process begins to write a
3906 dirty WAL buffer because no more WAL buffer space is available.
3907 (If this happens often, it implies that
3908 <xref linkend="guc-wal-buffers"/> is too small.)</entry>
3911 <entry><literal>wal-buffer-write-dirty-done</literal></entry>
3912 <entry><literal>()</literal></entry>
3913 <entry>Probe that fires when a dirty WAL buffer write is complete.</entry>
3916 <entry><literal>wal-insert</literal></entry>
3917 <entry><literal>(unsigned char, unsigned char)</literal></entry>
3918 <entry>Probe that fires when a WAL record is inserted.
3919 arg0 is the resource manager (rmid) for the record.
3920 arg1 contains the info flags.</entry>
3923 <entry><literal>wal-switch</literal></entry>
3924 <entry><literal>()</literal></entry>
3925 <entry>Probe that fires when a WAL segment switch is requested.</entry>
3928 <entry><literal>smgr-md-read-start</literal></entry>
3929 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
3930 <entry>Probe that fires when beginning to read a block from a relation.
3931 arg0 and arg1 contain the fork and block numbers of the page.
3932 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3933 identifying the relation.
3934 arg5 is the ID of the backend which created the temporary relation for a
3935 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
3938 <entry><literal>smgr-md-read-done</literal></entry>
3939 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
3940 <entry>Probe that fires when a block read is complete.
3941 arg0 and arg1 contain the fork and block numbers of the page.
3942 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3943 identifying the relation.
3944 arg5 is the ID of the backend which created the temporary relation for a
3945 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3946 arg6 is the number of bytes actually read, while arg7 is the number
3947 requested (if these are different it indicates trouble).</entry>
3950 <entry><literal>smgr-md-write-start</literal></entry>
3951 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int)</literal></entry>
3952 <entry>Probe that fires when beginning to write a block to a relation.
3953 arg0 and arg1 contain the fork and block numbers of the page.
3954 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3955 identifying the relation.
3956 arg5 is the ID of the backend which created the temporary relation for a
3957 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
3960 <entry><literal>smgr-md-write-done</literal></entry>
3961 <entry><literal>(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int)</literal></entry>
3962 <entry>Probe that fires when a block write is complete.
3963 arg0 and arg1 contain the fork and block numbers of the page.
3964 arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
3965 identifying the relation.
3966 arg5 is the ID of the backend which created the temporary relation for a
3967 local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
3968 arg6 is the number of bytes actually written, while arg7 is the number
3969 requested (if these are different it indicates trouble).</entry>
3972 <entry><literal>sort-start</literal></entry>
3973 <entry><literal>(int, bool, int, int, bool, int)</literal></entry>
3974 <entry>Probe that fires when a sort operation is started.
3975 arg0 indicates heap, index or datum sort.
3976 arg1 is true for unique-value enforcement.
3977 arg2 is the number of key columns.
3978 arg3 is the number of kilobytes of work memory allowed.
3979 arg4 is true if random access to the sort result is required.
3980 arg5 indicates serial when <literal>0</literal>, parallel worker when
3981 <literal>1</literal>, or parallel leader when <literal>2</literal>.</entry>
3984 <entry><literal>sort-done</literal></entry>
3985 <entry><literal>(bool, long)</literal></entry>
3986 <entry>Probe that fires when a sort is complete.
3987 arg0 is true for external sort, false for internal sort.
3988 arg1 is the number of disk blocks used for an external sort,
3989 or kilobytes of memory used for an internal sort.</entry>
3992 <entry><literal>lwlock-acquire</literal></entry>
3993 <entry><literal>(char *, LWLockMode)</literal></entry>
3994 <entry>Probe that fires when an LWLock has been acquired.
3995 arg0 is the LWLock's tranche.
3996 arg1 is the requested lock mode, either exclusive or shared.</entry>
3999 <entry><literal>lwlock-release</literal></entry>
4000 <entry><literal>(char *)</literal></entry>
4001 <entry>Probe that fires when an LWLock has been released (but note
4002 that any released waiters have not yet been awakened).
4003 arg0 is the LWLock's tranche.</entry>
4006 <entry><literal>lwlock-wait-start</literal></entry>
4007 <entry><literal>(char *, LWLockMode)</literal></entry>
4008 <entry>Probe that fires when an LWLock was not immediately available and
4009 a server process has begun to wait for the lock to become available.
4010 arg0 is the LWLock's tranche.
4011 arg1 is the requested lock mode, either exclusive or shared.</entry>
4014 <entry><literal>lwlock-wait-done</literal></entry>
4015 <entry><literal>(char *, LWLockMode)</literal></entry>
4016 <entry>Probe that fires when a server process has been released from its
4017 wait for an LWLock (it does not actually have the lock yet).
4018 arg0 is the LWLock's tranche.
4019 arg1 is the requested lock mode, either exclusive or shared.</entry>
4022 <entry><literal>lwlock-condacquire</literal></entry>
4023 <entry><literal>(char *, LWLockMode)</literal></entry>
4024 <entry>Probe that fires when an LWLock was successfully acquired when the
4025 caller specified no waiting.
4026 arg0 is the LWLock's tranche.
4027 arg1 is the requested lock mode, either exclusive or shared.</entry>
4030 <entry><literal>lwlock-condacquire-fail</literal></entry>
4031 <entry><literal>(char *, LWLockMode)</literal></entry>
4032 <entry>Probe that fires when an LWLock was not successfully acquired when
4033 the caller specified no waiting.
4034 arg0 is the LWLock's tranche.
4035 arg1 is the requested lock mode, either exclusive or shared.</entry>
4038 <entry><literal>lock-wait-start</literal></entry>
4039 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4040 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4041 has begun to wait because the lock is not available.
4042 arg0 through arg3 are the tag fields identifying the object being
4043 locked. arg4 indicates the type of object being locked.
4044 arg5 indicates the lock type being requested.</entry>
4047 <entry><literal>lock-wait-done</literal></entry>
4048 <entry><literal>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE)</literal></entry>
4049 <entry>Probe that fires when a request for a heavyweight lock (lmgr lock)
4050 has finished waiting (i.e., has acquired the lock).
4051 The arguments are the same as for <literal>lock-wait-start</literal>.</entry>
4054 <entry><literal>deadlock-found</literal></entry>
4055 <entry><literal>()</literal></entry>
4056 <entry>Probe that fires when a deadlock is found by the deadlock
4064 <table id="typedefs-table">
4065 <title>Defined Types Used in Probe Parameters</title>
4070 <entry>Definition</entry>
4077 <entry><type>LocalTransactionId</type></entry>
4078 <entry><type>unsigned int</type></entry>
4081 <entry><type>LWLockMode</type></entry>
4082 <entry><type>int</type></entry>
4085 <entry><type>LOCKMODE</type></entry>
4086 <entry><type>int</type></entry>
4089 <entry><type>BlockNumber</type></entry>
4090 <entry><type>unsigned int</type></entry>
4093 <entry><type>Oid</type></entry>
4094 <entry><type>unsigned int</type></entry>
4097 <entry><type>ForkNumber</type></entry>
4098 <entry><type>int</type></entry>
4101 <entry><type>bool</type></entry>
4102 <entry><type>char</type></entry>
4112 <sect2 id="using-trace-points">
4113 <title>Using Probes</title>
4116 The example below shows a DTrace script for analyzing transaction
4117 counts in the system, as an alternative to snapshotting
4118 <structname>pg_stat_database</structname> before and after a performance test:
4120 #!/usr/sbin/dtrace -qs
4122 postgresql$1:::transaction-start
4124 @start["Start"] = count();
4125 self->ts = timestamp;
4128 postgresql$1:::transaction-abort
4130 @abort["Abort"] = count();
4133 postgresql$1:::transaction-commit
4136 @commit["Commit"] = count();
4137 @time["Total time (ns)"] = sum(timestamp - self->ts);
4141 When executed, the example D script gives output such as:
4143 # ./txn_count.d `pgrep -n postgres` or ./txn_count.d <PID>
4148 Total time (ns) 2312105013
4154 SystemTap uses a different notation for trace scripts than DTrace does,
4155 even though the underlying trace points are compatible. One point worth
4156 noting is that at this writing, SystemTap scripts must reference probe
4157 names using double underscores in place of hyphens. This is expected to
4158 be fixed in future SystemTap releases.
4163 You should remember that DTrace scripts need to be carefully written and
4164 debugged, otherwise the trace information collected might
4165 be meaningless. In most cases where problems are found it is the
4166 instrumentation that is at fault, not the underlying system. When
4167 discussing information found using dynamic tracing, be sure to enclose
4168 the script used to allow that too to be checked and discussed.
4172 <sect2 id="defining-trace-points">
4173 <title>Defining New Probes</title>
4176 New probes can be defined within the code wherever the developer
4177 desires, though this will require a recompilation. Below are the steps
4178 for inserting new probes:
4184 Decide on probe names and data to be made available through the probes
4190 Add the probe definitions to <filename>src/backend/utils/probes.d</filename>
4196 Include <filename>pg_trace.h</filename> if it is not already present in the
4197 module(s) containing the probe points, and insert
4198 <literal>TRACE_POSTGRESQL</literal> probe macros at the desired locations
4205 Recompile and verify that the new probes are available
4211 <title>Example:</title>
4213 Here is an example of how you would add a probe to trace all new
4214 transactions by transaction ID.
4221 Decide that the probe will be named <literal>transaction-start</literal> and
4222 requires a parameter of type <type>LocalTransactionId</type>
4228 Add the probe definition to <filename>src/backend/utils/probes.d</filename>:
4230 probe transaction__start(LocalTransactionId);
4232 Note the use of the double underline in the probe name. In a DTrace
4233 script using the probe, the double underline needs to be replaced with a
4234 hyphen, so <literal>transaction-start</literal> is the name to document for
4241 At compile time, <literal>transaction__start</literal> is converted to a macro
4242 called <literal>TRACE_POSTGRESQL_TRANSACTION_START</literal> (notice the
4243 underscores are single here), which is available by including
4244 <filename>pg_trace.h</filename>. Add the macro call to the appropriate location
4245 in the source code. In this case, it looks like the following:
4248 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
4255 After recompiling and running the new binary, check that your newly added
4256 probe is available by executing the following DTrace command. You
4257 should see similar output:
4259 # dtrace -ln transaction-start
4260 ID PROVIDER MODULE FUNCTION NAME
4261 18705 postgresql49878 postgres StartTransactionCommand transaction-start
4262 18755 postgresql49877 postgres StartTransactionCommand transaction-start
4263 18805 postgresql49876 postgres StartTransactionCommand transaction-start
4264 18855 postgresql49875 postgres StartTransactionCommand transaction-start
4265 18986 postgresql49873 postgres StartTransactionCommand transaction-start
4272 There are a few things to be careful about when adding trace macros
4278 You should take care that the data types specified for a probe's
4279 parameters match the data types of the variables used in the macro.
4280 Otherwise, you will get compilation errors.
4287 On most platforms, if <productname>PostgreSQL</productname> is
4288 built with <option>--enable-dtrace</option>, the arguments to a trace
4289 macro will be evaluated whenever control passes through the
4290 macro, <emphasis>even if no tracing is being done</emphasis>. This is
4291 usually not worth worrying about if you are just reporting the
4292 values of a few local variables. But beware of putting expensive
4293 function calls into the arguments. If you need to do that,
4294 consider protecting the macro with a check to see if the trace
4295 is actually enabled:
4298 if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
4299 TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
4302 Each trace macro has a corresponding <literal>ENABLED</literal> macro.