Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b13c968

Browse files
committed
Take the statistics collector out of the loop for monitoring backends'
current commands; instead, store current-status information in shared memory. This substantially reduces the overhead of stats_command_string and also ensures that pg_stat_activity is fully up to date at all times. Per my recent proposal.
1 parent 6075fee commit b13c968

File tree

11 files changed

+838
-1156
lines changed

11 files changed

+838
-1156
lines changed

doc/src/sgml/config.sgml

+73-61
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.65 2006/06/18 15:38:35 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.66 2006/06/19 01:51:21 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -2845,43 +2845,6 @@ SELECT * FROM parent WHERE key = 2400;
28452845
<sect1 id="runtime-config-statistics">
28462846
<title>Run-Time Statistics</title>
28472847

2848-
<sect2 id="runtime-config-statistics-monitor">
2849-
<title>Statistics Monitoring</title>
2850-
<variablelist>
2851-
2852-
<varlistentry>
2853-
<term><varname>log_statement_stats</varname> (<type>boolean</type>)</term>
2854-
<term><varname>log_parser_stats</varname> (<type>boolean</type>)</term>
2855-
<term><varname>log_planner_stats</varname> (<type>boolean</type>)</term>
2856-
<term><varname>log_executor_stats</varname> (<type>boolean</type>)</term>
2857-
<indexterm>
2858-
<primary><varname>log_statement_stats</> configuration parameter</primary>
2859-
</indexterm>
2860-
<indexterm>
2861-
<primary><varname>log_parser_stats</> configuration parameter</primary>
2862-
</indexterm>
2863-
<indexterm>
2864-
<primary><varname>log_planner_stats</> configuration parameter</primary>
2865-
</indexterm>
2866-
<indexterm>
2867-
<primary><varname>log_executor_stats</> configuration parameter</primary>
2868-
</indexterm>
2869-
<listitem>
2870-
<para>
2871-
For each query, write performance statistics of the respective
2872-
module to the server log. This is a crude profiling
2873-
instrument. <varname>log_statement_stats</varname> reports total
2874-
statement statistics, while the others report per-module statistics.
2875-
<varname>log_statement_stats</varname> cannot be enabled together with
2876-
any of the per-module options. All of these options are disabled by
2877-
default. Only superusers can change these settings.
2878-
</para>
2879-
</listitem>
2880-
</varlistentry>
2881-
2882-
</variablelist>
2883-
2884-
</sect2>
28852848
<sect2 id="runtime-config-statistics-collector">
28862849
<title>Query and Index Statistics Collector</title>
28872850

@@ -2893,8 +2856,38 @@ SELECT * FROM parent WHERE key = 2400;
28932856
Refer to <xref linkend="monitoring"> for more information.
28942857
</para>
28952858

2859+
<note>
2860+
<para>
2861+
As of <productname>PostgreSQL</productname> 8.2,
2862+
<varname>stats_command_string</varname> controls a separate data
2863+
collection mechanism that can be turned on or off independently
2864+
of whether the statistics-collection subprocess is running.
2865+
The subprocess is only needed to support collection of
2866+
block-level or row-level statistics.
2867+
</para>
2868+
</note>
2869+
28962870
<variablelist>
28972871

2872+
<varlistentry id="guc-stats-command-string" xreflabel="stats_command_string">
2873+
<term><varname>stats_command_string</varname> (<type>boolean</type>)</term>
2874+
<indexterm>
2875+
<primary><varname>stats_command_string</> configuration parameter</primary>
2876+
</indexterm>
2877+
<listitem>
2878+
<para>
2879+
Enables the collection of information on the currently
2880+
executing command of each session, along with the time at
2881+
which that command began execution. This parameter is off by
2882+
default. Note that even when enabled, this information is not
2883+
visible to all users, only to superusers and the user owning
2884+
the session being reported on; so it should not represent a
2885+
security risk.
2886+
Only superusers can change this setting.
2887+
</para>
2888+
</listitem>
2889+
</varlistentry>
2890+
28982891
<varlistentry id="guc-stats-start-collector" xreflabel="stats_start_collector">
28992892
<term><varname>stats_start_collector</varname> (<type>boolean</type>)</term>
29002893
<indexterm>
@@ -2914,25 +2907,6 @@ SELECT * FROM parent WHERE key = 2400;
29142907
</listitem>
29152908
</varlistentry>
29162909

2917-
<varlistentry id="guc-stats-command-string" xreflabel="stats_command_string">
2918-
<term><varname>stats_command_string</varname> (<type>boolean</type>)</term>
2919-
<indexterm>
2920-
<primary><varname>stats_command_string</> configuration parameter</primary>
2921-
</indexterm>
2922-
<listitem>
2923-
<para>
2924-
Enables the collection of statistics on the currently
2925-
executing command of each session, along with the time at
2926-
which that command began execution. This parameter is off by
2927-
default. Note that even when enabled, this information is not
2928-
visible to all users, only to superusers and the user owning
2929-
the session being reported on; so it should not represent a
2930-
security risk.
2931-
Only superusers can change this setting.
2932-
</para>
2933-
</listitem>
2934-
</varlistentry>
2935-
29362910
<varlistentry id="guc-stats-block-level" xreflabel="stats_block_level">
29372911
<term><varname>stats_block_level</varname> (<type>boolean</type>)</term>
29382912
<indexterm>
@@ -2968,15 +2942,53 @@ SELECT * FROM parent WHERE key = 2400;
29682942
</indexterm>
29692943
<listitem>
29702944
<para>
2971-
If on, collected statistics are zeroed out whenever the server
2972-
is restarted. If off, statistics are accumulated across server
2973-
restarts. The default is <literal>off</>. This parameter can only
2974-
be set at server start.
2945+
If on, collected block-level and row-level statistics are zeroed out
2946+
whenever the server is restarted. If off, statistics are accumulated
2947+
across server restarts. This parameter is off by default.
2948+
This parameter can only be set at server start.
2949+
</para>
2950+
</listitem>
2951+
</varlistentry>
2952+
2953+
</variablelist>
2954+
</sect2>
2955+
2956+
<sect2 id="runtime-config-statistics-monitor">
2957+
<title>Statistics Monitoring</title>
2958+
<variablelist>
2959+
2960+
<varlistentry>
2961+
<term><varname>log_statement_stats</varname> (<type>boolean</type>)</term>
2962+
<term><varname>log_parser_stats</varname> (<type>boolean</type>)</term>
2963+
<term><varname>log_planner_stats</varname> (<type>boolean</type>)</term>
2964+
<term><varname>log_executor_stats</varname> (<type>boolean</type>)</term>
2965+
<indexterm>
2966+
<primary><varname>log_statement_stats</> configuration parameter</primary>
2967+
</indexterm>
2968+
<indexterm>
2969+
<primary><varname>log_parser_stats</> configuration parameter</primary>
2970+
</indexterm>
2971+
<indexterm>
2972+
<primary><varname>log_planner_stats</> configuration parameter</primary>
2973+
</indexterm>
2974+
<indexterm>
2975+
<primary><varname>log_executor_stats</> configuration parameter</primary>
2976+
</indexterm>
2977+
<listitem>
2978+
<para>
2979+
For each query, write performance statistics of the respective
2980+
module to the server log. This is a crude profiling
2981+
instrument. <varname>log_statement_stats</varname> reports total
2982+
statement statistics, while the others report per-module statistics.
2983+
<varname>log_statement_stats</varname> cannot be enabled together with
2984+
any of the per-module options. All of these options are disabled by
2985+
default. Only superusers can change these settings.
29752986
</para>
29762987
</listitem>
29772988
</varlistentry>
29782989

29792990
</variablelist>
2991+
29802992
</sect2>
29812993
</sect1>
29822994

doc/src/sgml/monitoring.sgml

+36-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.33 2006/06/18 15:38:35 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.34 2006/06/19 01:51:21 tgl Exp $ -->
22

33
<chapter id="monitoring">
44
<title>Monitoring Database Activity</title>
@@ -109,9 +109,14 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
109109
<productname>PostgreSQL</productname>'s <firstterm>statistics collector</>
110110
is a subsystem that supports collection and reporting of information about
111111
server activity. Presently, the collector can count accesses to tables
112-
and indexes in both disk-block and individual-row terms. It also supports
113-
determining the exact command currently being executed by other server
114-
processes.
112+
and indexes in both disk-block and individual-row terms.
113+
</para>
114+
115+
<para>
116+
<productname>PostgreSQL</productname> also supports determining the exact
117+
command currently being executed by other server processes. This is an
118+
independent facility that can be enabled or disabled whether or not
119+
block-level and row-level statistics are being collected.
115120
</para>
116121

117122
<sect2 id="monitoring-stats-setup">
@@ -136,15 +141,21 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
136141
</para>
137142

138143
<para>
139-
The parameters <xref linkend="guc-stats-command-string">,
140-
<xref linkend="guc-stats-block-level">, and <xref
144+
The parameters <xref linkend="guc-stats-block-level"> and <xref
141145
linkend="guc-stats-row-level"> control how much information is
142146
actually sent to the collector and thus determine how much run-time
143147
overhead occurs. These respectively determine whether a server
144-
process sends its current command string, disk-block-level access
145-
statistics, and row-level access statistics to the collector.
148+
process tracks disk-block-level access
149+
statistics and row-level access statistics and sends these to the collector.
146150
Additionally, per-database transaction commit and abort statistics
147-
are collected if any of these parameters are set.
151+
are collected if either of these parameters are set.
152+
</para>
153+
154+
<para>
155+
The parameter <xref linkend="guc-stats-command-string"> enables monitoring
156+
of the current command being executed by any server process.
157+
The statistics collector subprocess need not be running to enable this
158+
feature.
148159
</para>
149160

150161
<para>
@@ -165,7 +176,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
165176
very few statistics are collected in the default
166177
configuration. Enabling one or more of these configuration
167178
variables will significantly enhance the amount of useful data
168-
produced by the statistics collector, at the expense of
179+
produced by the statistics facilities, at the expense of
169180
additional run-time overhead.
170181
</para>
171182
</note>
@@ -190,10 +201,9 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
190201
progress does not affect the displayed totals. Also, the collector itself
191202
emits a new report at most once per <varname>PGSTAT_STAT_INTERVAL</varname>
192203
milliseconds (500 unless altered while building the server). So the
193-
displayed information lags behind actual activity. Current-query
194-
information is reported to the collector immediately, but is still subject
195-
to the <varname>PGSTAT_STAT_INTERVAL</varname> delay before it becomes
196-
visible.
204+
displayed information lags behind actual activity. However, current-query
205+
information collected by <varname>stats_command_string</varname> is
206+
always up-to-date.
197207
</para>
198208

199209
<para>
@@ -202,7 +212,10 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
202212
the collector process and then continues to use this snapshot for all
203213
statistical views and functions until the end of its current transaction.
204214
So the statistics will appear not to change as long as you continue the
205-
current transaction.
215+
current transaction. Similarly, information about the current queries of
216+
all processes is collected when any such information is first requested
217+
within a transaction, and the same information will be displayed throughout
218+
the transaction.
206219
This is a feature, not a bug, because it allows you to perform several
207220
queries on the statistics and correlate the results without worrying that
208221
the numbers are changing underneath you. But if you want to see new
@@ -232,9 +245,8 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
232245
parameter <varname>stats_command_string</varname> has been
233246
turned on. Furthermore, these columns read as null unless the
234247
user examining the view is a superuser or the same as the user
235-
owning the process being reported on. (Note that because of the
236-
collector's reporting delay, the current query will only be
237-
up-to-date for long-running queries.)</entry>
248+
owning the process being reported on.
249+
</entry>
238250
</row>
239251

240252
<row>
@@ -549,31 +561,32 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
549561
<entry><literal><function>pg_stat_get_last_vacuum_time</function>(<type>oid</type>)</literal></entry>
550562
<entry><type>timestamptz</type></entry>
551563
<entry>
552-
Time of the last vacuum initiated by the user
564+
Time of the last vacuum initiated by the user on this table
553565
</entry>
554566
</row>
555567

556568
<row>
557569
<entry><literal><function>pg_stat_get_last_autovacuum_time</function>(<type>oid</type>)</literal></entry>
558570
<entry><type>timestamptz</type></entry>
559571
<entry>
560-
Time of the last vacuum initiated by the autovacuum daemon
572+
Time of the last vacuum initiated by the autovacuum daemon on this table
561573
</entry>
562574
</row>
563575

564576
<row>
565577
<entry><literal><function>pg_stat_get_last_analyze_time</function>(<type>oid</type>)</literal></entry>
566578
<entry><type>timestamptz</type></entry>
567579
<entry>
568-
Time of the last analyze initiated by the user
580+
Time of the last analyze initiated by the user on this table
569581
</entry>
570582
</row>
571583

572584
<row>
573585
<entry><literal><function>pg_stat_get_last_autoanalyze_time</function>(<type>oid</type>)</literal></entry>
574586
<entry><type>timestamptz</type></entry>
575587
<entry>
576-
Time of the last analyze initiated by the autovacuum daemon
588+
Time of the last analyze initiated by the autovacuum daemon on this
589+
table
577590
</entry>
578591
</row>
579592

@@ -677,7 +690,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
677690
<entry><literal><function>pg_stat_reset</function>()</literal></entry>
678691
<entry><type>boolean</type></entry>
679692
<entry>
680-
Reset all currently collected statistics
693+
Reset all block-level and row-level statistics to zero
681694
</entry>
682695
</row>
683696
</tbody>

0 commit comments

Comments
 (0)