2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/pgstatstatements.sgml -->
|
2009-01-04 23:19:59 +01:00
|
|
|
|
2011-05-08 04:29:20 +02:00
|
|
|
<sect1 id="pgstatstatements" xreflabel="pg_stat_statements">
|
2023-01-20 20:01:59 +01:00
|
|
|
<title>pg_stat_statements — track statistics of SQL planning and execution</title>
|
2009-01-04 23:19:59 +01:00
|
|
|
|
|
|
|
<indexterm zone="pgstatstatements">
|
|
|
|
<primary>pg_stat_statements</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <filename>pg_stat_statements</filename> module provides a means for
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
tracking planning and execution statistics of all SQL statements executed by
|
|
|
|
a server.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The module must be loaded by adding <literal>pg_stat_statements</literal> to
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-shared-preload-libraries"/> in
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgresql.conf</filename>, because it requires additional shared memory.
|
2009-01-04 23:19:59 +01:00
|
|
|
This means that a server restart is needed to add or remove the module.
|
2021-05-15 20:13:09 +02:00
|
|
|
In addition, query identifier calculation must be enabled in order for the
|
|
|
|
module to be active, which is done automatically if <xref linkend="guc-compute-query-id"/>
|
|
|
|
is set to <literal>auto</literal> or <literal>on</literal>, or any third-party
|
|
|
|
module that calculates query identifiers is loaded.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
|
2021-04-07 19:06:47 +02:00
|
|
|
<para>
|
2021-05-15 20:13:09 +02:00
|
|
|
When <filename>pg_stat_statements</filename> is active, it tracks
|
2015-05-09 20:11:31 +02:00
|
|
|
statistics across all databases of the server. To access and manipulate
|
2020-11-26 13:18:05 +01:00
|
|
|
these statistics, the module provides views
|
|
|
|
<structname>pg_stat_statements</structname> and
|
|
|
|
<structname>pg_stat_statements_info</structname>,
|
2017-10-09 03:44:17 +02:00
|
|
|
and the utility functions <function>pg_stat_statements_reset</function> and
|
|
|
|
<function>pg_stat_statements</function>. These are not available globally but
|
2015-05-09 20:11:31 +02:00
|
|
|
can be enabled for a specific database with
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>CREATE EXTENSION pg_stat_statements</command>.
|
2015-05-09 20:11:31 +02:00
|
|
|
</para>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-pg-stat-statements">
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>The <structname>pg_stat_statements</structname> View</title>
|
2009-01-04 23:19:59 +01:00
|
|
|
|
|
|
|
<para>
|
2013-12-07 18:06:02 +01:00
|
|
|
The statistics gathered by the module are made available via a
|
2017-10-09 03:44:17 +02:00
|
|
|
view named <structname>pg_stat_statements</structname>. This view
|
2021-07-14 11:04:15 +02:00
|
|
|
contains one row for each distinct combination of database ID, user
|
2021-07-16 10:35:38 +02:00
|
|
|
ID, query ID and whether it's a top-level statement or not (up to
|
2021-07-14 11:04:15 +02:00
|
|
|
the maximum number of distinct statements that the module can track).
|
|
|
|
The columns of the view are shown in
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="pgstatstatements-columns"/>.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
|
2009-05-18 13:08:24 +02:00
|
|
|
<table id="pgstatstatements-columns">
|
2017-10-09 03:44:17 +02:00
|
|
|
<title><structname>pg_stat_statements</structname> Columns</title>
|
2020-05-14 05:03:39 +02:00
|
|
|
<tgroup cols="1">
|
2009-01-04 23:19:59 +01:00
|
|
|
<thead>
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
Column Type
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Description
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
</thead>
|
2020-05-14 05:03:39 +02:00
|
|
|
|
2009-01-04 23:19:59 +01:00
|
|
|
<tbody>
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>userid</structfield> <type>oid</type>
|
|
|
|
(references <link linkend="catalog-pg-authid"><structname>pg_authid</structname></link>.<structfield>oid</structfield>)
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
OID of user who executed the statement
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>dbid</structfield> <type>oid</type>
|
|
|
|
(references <link linkend="catalog-pg-database"><structname>pg_database</structname></link>.<structfield>oid</structfield>)
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
OID of database in which the statement was executed
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
2021-04-08 10:23:10 +02:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>toplevel</structfield> <type>bool</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
2021-07-16 10:35:38 +02:00
|
|
|
True if the query was executed as a top-level statement
|
2021-05-17 10:59:54 +02:00
|
|
|
(always true if <varname>pg_stat_statements.track</varname> is set to
|
|
|
|
<literal>top</literal>)
|
2021-04-08 10:23:10 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2013-12-07 18:06:02 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>queryid</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
2021-04-07 19:06:47 +02:00
|
|
|
Hash code to identify identical normalized queries.
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
2013-12-07 18:06:02 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>query</structfield> <type>text</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Text of a representative statement
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>plans</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Number of times the statement was planned
|
2020-07-03 04:35:22 +02:00
|
|
|
(if <varname>pg_stat_statements.track_planning</varname> is enabled,
|
|
|
|
otherwise zero)
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>total_plan_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time spent planning the statement, in milliseconds
|
2020-07-03 04:35:22 +02:00
|
|
|
(if <varname>pg_stat_statements.track_planning</varname> is enabled,
|
|
|
|
otherwise zero)
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>min_plan_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
Minimum time spent planning the statement, in milliseconds.
|
|
|
|
This field will be zero if <varname>pg_stat_statements.track_planning</varname>
|
|
|
|
is disabled, or if the counter has been reset using the
|
|
|
|
<function>pg_stat_statements_reset</function> function with the
|
|
|
|
<structfield>minmax_only</structfield> parameter set to <literal>true</literal>
|
|
|
|
and never been planned since.
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>max_plan_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
Maximum time spent planning the statement, in milliseconds.
|
|
|
|
This field will be zero if <varname>pg_stat_statements.track_planning</varname>
|
|
|
|
is disabled, or if the counter has been reset using the
|
|
|
|
<function>pg_stat_statements_reset</function> function with the
|
|
|
|
<structfield>minmax_only</structfield> parameter set to <literal>true</literal>
|
|
|
|
and never been planned since.
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>mean_plan_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Mean time spent planning the statement, in milliseconds
|
2020-07-03 04:35:22 +02:00
|
|
|
(if <varname>pg_stat_statements.track_planning</varname> is enabled,
|
|
|
|
otherwise zero)
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>stddev_plan_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-07-03 04:35:22 +02:00
|
|
|
Population standard deviation of time spent planning the statement,
|
|
|
|
in milliseconds
|
|
|
|
(if <varname>pg_stat_statements.track_planning</varname> is enabled,
|
|
|
|
otherwise zero)
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</row>
|
|
|
|
|
2009-01-04 23:19:59 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>calls</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Number of times the statement was executed
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>total_exec_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time spent executing the statement, in milliseconds
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
2015-03-27 20:43:22 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>min_exec_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
Minimum time spent executing the statement, in milliseconds,
|
|
|
|
this field will be zero until this statement
|
|
|
|
is executed first time after reset performed by the
|
|
|
|
<function>pg_stat_statements_reset</function> function with the
|
|
|
|
<structfield>minmax_only</structfield> parameter set to <literal>true</literal>
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
2015-03-27 20:43:22 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>max_exec_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
Maximum time spent executing the statement, in milliseconds,
|
|
|
|
this field will be zero until this statement
|
|
|
|
is executed first time after reset performed by the
|
|
|
|
<function>pg_stat_statements_reset</function> function with the
|
|
|
|
<structfield>minmax_only</structfield> parameter set to <literal>true</literal>
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
2015-03-27 20:43:22 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>mean_exec_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Mean time spent executing the statement, in milliseconds
|
|
|
|
</para></entry>
|
2015-03-27 20:43:22 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>stddev_exec_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Population standard deviation of time spent executing the statement, in milliseconds
|
|
|
|
</para></entry>
|
2015-03-27 20:43:22 +01:00
|
|
|
</row>
|
|
|
|
|
2009-01-04 23:19:59 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>rows</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of rows retrieved or affected by the statement
|
|
|
|
</para></entry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</row>
|
|
|
|
|
2010-01-08 01:38:20 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>shared_blks_hit</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of shared block cache hits by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>shared_blks_read</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of shared blocks read by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
2012-02-23 02:33:05 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>shared_blks_dirtied</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of shared blocks dirtied by the statement
|
|
|
|
</para></entry>
|
2012-02-23 02:33:05 +01:00
|
|
|
</row>
|
|
|
|
|
2010-01-08 01:38:20 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>shared_blks_written</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of shared blocks written by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blks_hit</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of local block cache hits by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blks_read</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of local blocks read by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
2012-02-23 02:33:05 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blks_dirtied</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of local blocks dirtied by the statement
|
|
|
|
</para></entry>
|
2012-02-23 02:33:05 +01:00
|
|
|
</row>
|
|
|
|
|
2010-01-08 01:38:20 +01:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blks_written</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of local blocks written by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>temp_blks_read</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of temp blocks read by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>temp_blks_written</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of temp blocks written by the statement
|
|
|
|
</para></entry>
|
2010-01-08 01:38:20 +01:00
|
|
|
</row>
|
|
|
|
|
2012-03-27 21:17:22 +02:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-10-19 04:26:40 +02:00
|
|
|
<structfield>shared_blk_read_time</structfield> <type>double precision</type>
|
2020-05-14 05:03:39 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-10-19 04:26:40 +02:00
|
|
|
Total time the statement spent reading shared blocks, in milliseconds
|
2020-05-14 05:03:39 +02:00
|
|
|
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
|
|
|
|
</para></entry>
|
2012-03-27 21:17:22 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-10-19 04:26:40 +02:00
|
|
|
<structfield>shared_blk_write_time</structfield> <type>double precision</type>
|
2020-05-14 05:03:39 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-10-19 04:26:40 +02:00
|
|
|
Total time the statement spent writing shared blocks, in milliseconds
|
2020-05-14 05:03:39 +02:00
|
|
|
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
|
|
|
|
</para></entry>
|
2012-03-27 21:17:22 +02:00
|
|
|
</row>
|
|
|
|
|
2023-10-19 07:03:31 +02:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blk_read_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time the statement spent reading local blocks, in milliseconds
|
|
|
|
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>local_blk_write_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time the statement spent writing local blocks, in milliseconds
|
|
|
|
(if <xref linkend="guc-track-io-timing"/> is enabled, otherwise zero)
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2022-04-08 06:12:07 +02:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>temp_blk_read_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time the statement spent reading temporary file blocks, in
|
|
|
|
milliseconds (if <xref linkend="guc-track-io-timing"/> is enabled,
|
|
|
|
otherwise zero)
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>temp_blk_write_time</structfield> <type>double precision</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time the statement spent writing temporary file blocks, in
|
|
|
|
milliseconds (if <xref linkend="guc-track-io-timing"/> is enabled,
|
|
|
|
otherwise zero)
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2020-04-05 04:04:04 +02:00
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>wal_records</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of WAL records generated by the statement
|
|
|
|
</para></entry>
|
2020-04-05 04:04:04 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>wal_fpi</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of WAL full page images generated by the statement
|
|
|
|
</para></entry>
|
2020-04-05 04:04:04 +02:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
2020-05-14 05:03:39 +02:00
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>wal_bytes</structfield> <type>numeric</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-12-24 09:05:49 +01:00
|
|
|
Total amount of WAL generated by the statement in bytes
|
2020-05-14 05:03:39 +02:00
|
|
|
</para></entry>
|
2020-04-05 04:04:04 +02:00
|
|
|
</row>
|
2022-04-08 13:51:01 +02:00
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>jit_functions</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of functions JIT-compiled by the statement
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2022-05-21 10:57:23 +02:00
|
|
|
<structfield>jit_generation_time</structfield> <type>double precision</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total time spent by the statement on generating JIT code, in milliseconds
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2023-09-08 15:05:12 +02:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_inlining_count</structfield> <type>bigint</type>
|
2023-09-08 15:05:12 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Number of times functions have been inlined
|
2023-09-08 15:05:12 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_inlining_time</structfield> <type>double precision</type>
|
2023-09-08 15:05:12 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Total time spent by the statement on inlining functions, in milliseconds
|
2023-09-08 15:05:12 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2022-04-08 13:51:01 +02:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_optimization_count</structfield> <type>bigint</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Number of times the statement has been optimized
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_optimization_time</structfield> <type>double precision</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Total time spent by the statement on optimizing, in milliseconds
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_emission_count</structfield> <type>bigint</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Number of times code has been emitted
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_emission_time</structfield> <type>double precision</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Total time spent by the statement on emitting code, in milliseconds
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_deform_count</structfield> <type>bigint</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Total number of tuple deform functions JIT-compiled by the statement
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
2023-11-15 14:07:00 +01:00
|
|
|
<structfield>jit_deform_time</structfield> <type>double precision</type>
|
2022-04-08 13:51:01 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-15 14:07:00 +01:00
|
|
|
Total time spent by the statement on JIT-compiling tuple deform
|
|
|
|
functions, in milliseconds
|
2022-04-08 13:51:01 +02:00
|
|
|
</para></entry>
|
|
|
|
</row>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>stats_since</structfield> <type>timestamp with time zone</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Time at which statistics gathering started for this statement
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>minmax_stats_since</structfield> <type>timestamp with time zone</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Time at which min/max statistics gathering started for this
|
|
|
|
statement (fields <structfield>min_plan_time</structfield>,
|
|
|
|
<structfield>max_plan_time</structfield>,
|
|
|
|
<structfield>min_exec_time</structfield> and
|
|
|
|
<structfield>max_exec_time</structfield>)
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
2009-01-04 23:19:59 +01:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<para>
|
2022-03-28 21:10:04 +02:00
|
|
|
For security reasons, only superusers and roles with privileges of the
|
2017-03-30 23:13:44 +02:00
|
|
|
<literal>pg_read_all_stats</literal> role are allowed to see the SQL text and
|
2017-03-30 20:18:53 +02:00
|
|
|
<structfield>queryid</structfield> of queries executed by other users.
|
|
|
|
Other users can see the statistics, however, if the view has been installed
|
|
|
|
in their database.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Plannable queries (that is, <command>SELECT</command>, <command>INSERT</command>,
|
2023-03-01 02:31:55 +01:00
|
|
|
<command>UPDATE</command>, <command>DELETE</command>, and <command>MERGE</command>)
|
|
|
|
and utility commands are combined into a single
|
2017-10-09 03:44:17 +02:00
|
|
|
<structname>pg_stat_statements</structname> entry whenever they have identical query
|
2012-03-29 03:00:31 +02:00
|
|
|
structures according to an internal hash calculation. Typically, two
|
|
|
|
queries will be considered the same for this purpose if they are
|
|
|
|
semantically equivalent except for the values of literal constants
|
2023-03-01 02:31:55 +01:00
|
|
|
appearing in the query.
|
2012-03-29 03:00:31 +02:00
|
|
|
</para>
|
|
|
|
|
2021-04-07 19:06:47 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The following details about constant replacement and
|
2021-04-09 06:53:07 +02:00
|
|
|
<structfield>queryid</structfield> only apply when <xref
|
2021-04-07 19:06:47 +02:00
|
|
|
linkend="guc-compute-query-id"/> is enabled. If you use an external
|
|
|
|
module instead to compute <structfield>queryid</structfield>, you
|
|
|
|
should refer to its documentation for details.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
2012-03-29 03:00:31 +02:00
|
|
|
<para>
|
2017-03-28 02:14:36 +02:00
|
|
|
When a constant's value has been ignored for purposes of matching the query
|
|
|
|
to other queries, the constant is replaced by a parameter symbol, such
|
2017-10-09 03:44:17 +02:00
|
|
|
as <literal>$1</literal>, in the <structname>pg_stat_statements</structname>
|
2017-03-28 02:14:36 +02:00
|
|
|
display.
|
|
|
|
The rest of the query text is that of the first query that had the
|
2017-10-09 03:44:17 +02:00
|
|
|
particular <structfield>queryid</structfield> hash value associated with the
|
|
|
|
<structname>pg_stat_statements</structname> entry.
|
2012-03-29 03:00:31 +02:00
|
|
|
</para>
|
|
|
|
|
2023-03-01 02:47:01 +01:00
|
|
|
<para>
|
|
|
|
Queries on which normalization can be applied may be observed with constant
|
|
|
|
values in <structname>pg_stat_statements</structname>, especially when there
|
|
|
|
is a high rate of entry deallocations. To reduce the likelihood of this
|
|
|
|
happening, consider increasing <varname>pg_stat_statements.max</varname>.
|
|
|
|
The <structname>pg_stat_statements_info</structname> view, discussed below
|
|
|
|
in <xref linkend="pgstatstatements-pg-stat-statements-info"/>,
|
|
|
|
provides statistics about entry deallocations.
|
|
|
|
</para>
|
|
|
|
|
2012-03-29 03:00:31 +02:00
|
|
|
<para>
|
|
|
|
In some cases, queries with visibly different texts might get merged into a
|
2017-10-09 03:44:17 +02:00
|
|
|
single <structname>pg_stat_statements</structname> entry. Normally this will happen
|
2012-03-29 03:00:31 +02:00
|
|
|
only for semantically equivalent queries, but there is a small chance of
|
|
|
|
hash collisions causing unrelated queries to be merged into one entry.
|
|
|
|
(This cannot happen for queries belonging to different users or databases,
|
|
|
|
however.)
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Since the <structfield>queryid</structfield> hash value is computed on the
|
2013-12-07 18:06:02 +01:00
|
|
|
post-parse-analysis representation of the queries, the opposite is
|
|
|
|
also possible: queries with identical texts might appear as
|
|
|
|
separate entries, if they have different meanings as a result of
|
2017-10-09 03:44:17 +02:00
|
|
|
factors such as different <varname>search_path</varname> settings.
|
2013-12-07 18:06:02 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Consumers of <structname>pg_stat_statements</structname> may wish to use
|
|
|
|
<structfield>queryid</structfield> (perhaps in combination with
|
|
|
|
<structfield>dbid</structfield> and <structfield>userid</structfield>) as a more stable
|
2013-12-07 18:06:02 +01:00
|
|
|
and reliable identifier for each entry than its query text.
|
|
|
|
However, it is important to understand that there are only limited
|
2017-10-09 03:44:17 +02:00
|
|
|
guarantees around the stability of the <structfield>queryid</structfield> hash
|
2013-12-07 18:06:02 +01:00
|
|
|
value. Since the identifier is derived from the
|
|
|
|
post-parse-analysis tree, its value is a function of, among other
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
things, the internal object identifiers appearing in this representation.
|
|
|
|
This has some counterintuitive implications. For example,
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>pg_stat_statements</filename> will consider two apparently-identical
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
queries to be distinct, if they reference a table that was dropped
|
|
|
|
and recreated between the executions of the two queries.
|
|
|
|
The hashing process is also sensitive to differences in
|
2013-12-07 18:06:02 +01:00
|
|
|
machine architecture and other facets of the platform.
|
2017-10-09 03:44:17 +02:00
|
|
|
Furthermore, it is not safe to assume that <structfield>queryid</structfield>
|
|
|
|
will be stable across major versions of <productname>PostgreSQL</productname>.
|
2013-12-07 18:06:02 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2024-04-20 03:53:35 +02:00
|
|
|
Two servers participating in replication based on physical WAL replay can
|
|
|
|
be expected to have identical <structfield>queryid</structfield> values for
|
|
|
|
the same query. However, logical replication schemes do not promise to
|
|
|
|
keep replicas identical in all relevant details, so
|
|
|
|
<structfield>queryid</structfield> will not be a useful identifier for
|
|
|
|
accumulating costs across a set of logical replicas.
|
|
|
|
If in doubt, direct testing is recommended.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Generally, it can be assumed that <structfield>queryid</structfield> values
|
|
|
|
are stable between minor version releases of <productname>PostgreSQL</productname>,
|
|
|
|
providing that instances are running on the same machine architecture and
|
|
|
|
the catalog metadata details match. Compatibility will only be broken
|
|
|
|
between minor versions as a last resort.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
2015-10-05 18:44:12 +02:00
|
|
|
|
2017-03-28 02:14:36 +02:00
|
|
|
<para>
|
|
|
|
The parameter symbols used to replace constants in
|
|
|
|
representative query texts start from the next number after the
|
2017-10-09 03:44:17 +02:00
|
|
|
highest <literal>$</literal><replaceable>n</replaceable> parameter in the original query
|
|
|
|
text, or <literal>$1</literal> if there was none. It's worth noting that in
|
2017-03-28 02:14:36 +02:00
|
|
|
some cases there may be hidden parameter symbols that affect this
|
2017-10-09 03:44:17 +02:00
|
|
|
numbering. For example, <application>PL/pgSQL</application> uses hidden parameter
|
2017-03-28 02:14:36 +02:00
|
|
|
symbols to insert values of function local variables into queries, so that
|
2017-10-09 03:44:17 +02:00
|
|
|
a <application>PL/pgSQL</application> statement like <literal>SELECT i + 1 INTO j</literal>
|
|
|
|
would have representative text like <literal>SELECT i + $2</literal>.
|
2017-03-28 02:14:36 +02:00
|
|
|
</para>
|
|
|
|
|
2015-10-05 18:44:12 +02:00
|
|
|
<para>
|
|
|
|
The representative query texts are kept in an external disk file, and do
|
|
|
|
not consume shared memory. Therefore, even very lengthy query texts can
|
|
|
|
be stored successfully. However, if many long query texts are
|
|
|
|
accumulated, the external file might grow unmanageably large. As a
|
2017-10-09 03:44:17 +02:00
|
|
|
recovery method if that happens, <filename>pg_stat_statements</filename> may
|
2015-10-05 18:44:12 +02:00
|
|
|
choose to discard the query texts, whereupon all existing entries in
|
2017-10-09 03:44:17 +02:00
|
|
|
the <structname>pg_stat_statements</structname> view will show
|
|
|
|
null <structfield>query</structfield> fields, though the statistics associated with
|
|
|
|
each <structfield>queryid</structfield> are preserved. If this happens, consider
|
2015-10-05 18:44:12 +02:00
|
|
|
reducing <varname>pg_stat_statements.max</varname> to prevent
|
|
|
|
recurrences.
|
|
|
|
</para>
|
2020-04-09 05:56:36 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
<structfield>plans</structfield> and <structfield>calls</structfield> aren't
|
|
|
|
always expected to match because planning and execution statistics are
|
|
|
|
updated at their respective end phase, and only for successful operations.
|
|
|
|
For example, if a statement is successfully planned but fails during
|
|
|
|
the execution phase, only its planning statistics will be updated.
|
|
|
|
If planning is skipped because a cached plan is used, only its execution
|
|
|
|
statistics will be updated.
|
|
|
|
</para>
|
2009-01-04 23:19:59 +01:00
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-pg-stat-statements-info">
|
2020-11-26 13:18:05 +01:00
|
|
|
<title>The <structname>pg_stat_statements_info</structname> View</title>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>pg_stat_statements_info</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The statistics of the <filename>pg_stat_statements</filename> module
|
|
|
|
itself are tracked and made available via a view named
|
|
|
|
<structname>pg_stat_statements_info</structname>. This view contains
|
|
|
|
only a single row. The columns of the view are shown in
|
|
|
|
<xref linkend="pgstatstatementsinfo-columns"/>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<table id="pgstatstatementsinfo-columns">
|
|
|
|
<title><structname>pg_stat_statements_info</structname> Columns</title>
|
|
|
|
<tgroup cols="1">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
Column Type
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Description
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>dealloc</structfield> <type>bigint</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Total number of times <structname>pg_stat_statements</structname>
|
|
|
|
entries about the least-executed statements were deallocated
|
|
|
|
because more distinct statements than
|
|
|
|
<varname>pg_stat_statements.max</varname> were observed
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
pg_stat_statements: Track time at which all statistics were last reset.
This commit adds "stats_reset" column into the pg_stat_statements_info
view. This column indicates the time at which all statistics in the
pg_stat_statements view were last reset.
Per discussion, this commit also changes pg_stat_statements_info code
so that "dealloc" column is reset at the same time as "stats_reset" is reset,
i.e., whenever all pg_stat_statements entries are removed, for the sake
of consistency. Previously "dealloc" was reset only when
pg_stat_statements_reset(0, 0, 0) is called and was not reset when
pg_stat_statements_reset() with non-zero value argument discards all
entries. This was confusing.
Author: Naoki Nakamichi, Yuki Seino
Reviewed-by: Yuki Seino, Kyotaro Horiguchi, Li Japin, Fujii Masao
Discussion: https://postgr.es/m/c102cf3180d0ee73c1c5a0f7f8558322@oss.nttdata.com
2020-12-18 02:49:58 +01:00
|
|
|
<row>
|
|
|
|
<entry role="catalog_table_entry"><para role="column_definition">
|
|
|
|
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Time at which all statistics in the
|
|
|
|
<structname>pg_stat_statements</structname> view were last reset.
|
|
|
|
</para></entry>
|
|
|
|
</row>
|
|
|
|
|
2020-11-26 13:18:05 +01:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-funcs">
|
2009-01-04 23:19:59 +01:00
|
|
|
<title>Functions</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
<function>pg_stat_statements_reset(userid Oid, dbid Oid, queryid
|
|
|
|
bigint, minmax_only boolean) returns timestamp with time zone</function>
|
2014-05-07 03:28:58 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>pg_stat_statements_reset</primary>
|
|
|
|
</indexterm>
|
2009-01-04 23:19:59 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-01-11 04:20:09 +01:00
|
|
|
<function>pg_stat_statements_reset</function> discards statistics
|
|
|
|
gathered so far by <filename>pg_stat_statements</filename> corresponding
|
|
|
|
to the specified <structfield>userid</structfield>, <structfield>dbid</structfield>
|
|
|
|
and <structfield>queryid</structfield>. If any of the parameters are not
|
|
|
|
specified, the default value <literal>0</literal>(invalid) is used for
|
|
|
|
each of them and the statistics that match with other parameters will be
|
|
|
|
reset. If no parameter is specified or all the specified parameters are
|
pg_stat_statements: Track time at which all statistics were last reset.
This commit adds "stats_reset" column into the pg_stat_statements_info
view. This column indicates the time at which all statistics in the
pg_stat_statements view were last reset.
Per discussion, this commit also changes pg_stat_statements_info code
so that "dealloc" column is reset at the same time as "stats_reset" is reset,
i.e., whenever all pg_stat_statements entries are removed, for the sake
of consistency. Previously "dealloc" was reset only when
pg_stat_statements_reset(0, 0, 0) is called and was not reset when
pg_stat_statements_reset() with non-zero value argument discards all
entries. This was confusing.
Author: Naoki Nakamichi, Yuki Seino
Reviewed-by: Yuki Seino, Kyotaro Horiguchi, Li Japin, Fujii Masao
Discussion: https://postgr.es/m/c102cf3180d0ee73c1c5a0f7f8558322@oss.nttdata.com
2020-12-18 02:49:58 +01:00
|
|
|
<literal>0</literal>(invalid), it will discard all statistics.
|
|
|
|
If all statistics in the <filename>pg_stat_statements</filename>
|
|
|
|
view are discarded, it will also reset the statistics in the
|
|
|
|
<structname>pg_stat_statements_info</structname> view.
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
When <structfield>minmax_only</structfield> is <literal>true</literal> only the
|
2023-12-13 11:32:13 +01:00
|
|
|
values of minimum and maximum planning and execution time will be reset (i.e.
|
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
2023-11-27 01:51:18 +01:00
|
|
|
<structfield>min_plan_time</structfield>, <structfield>max_plan_time</structfield>,
|
|
|
|
<structfield>min_exec_time</structfield> and <structfield>max_exec_time</structfield>
|
|
|
|
fields). The default value for <structfield>minmax_only</structfield> parameter is
|
|
|
|
<literal>false</literal>. Time of last min/max reset performed is shown in
|
|
|
|
<structfield>minmax_stats_since</structfield> field of the
|
|
|
|
<structname>pg_stat_statements</structname> view.
|
|
|
|
This function returns the time of a reset. This time is saved to
|
|
|
|
<structfield>stats_reset</structfield> field of
|
|
|
|
<structname>pg_stat_statements_info</structname> view or to
|
|
|
|
<structfield>minmax_stats_since</structfield> field of the
|
|
|
|
<structname>pg_stat_statements</structname> view if the corresponding reset was
|
|
|
|
actually performed.
|
pg_stat_statements: Track time at which all statistics were last reset.
This commit adds "stats_reset" column into the pg_stat_statements_info
view. This column indicates the time at which all statistics in the
pg_stat_statements view were last reset.
Per discussion, this commit also changes pg_stat_statements_info code
so that "dealloc" column is reset at the same time as "stats_reset" is reset,
i.e., whenever all pg_stat_statements entries are removed, for the sake
of consistency. Previously "dealloc" was reset only when
pg_stat_statements_reset(0, 0, 0) is called and was not reset when
pg_stat_statements_reset() with non-zero value argument discards all
entries. This was confusing.
Author: Naoki Nakamichi, Yuki Seino
Reviewed-by: Yuki Seino, Kyotaro Horiguchi, Li Japin, Fujii Masao
Discussion: https://postgr.es/m/c102cf3180d0ee73c1c5a0f7f8558322@oss.nttdata.com
2020-12-18 02:49:58 +01:00
|
|
|
By default, this function can only be executed by superusers.
|
2020-11-26 13:18:05 +01:00
|
|
|
Access may be granted to others using <command>GRANT</command>.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<function>pg_stat_statements(showtext boolean) returns setof record</function>
|
2014-05-07 03:28:58 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>pg_stat_statements</primary>
|
|
|
|
<secondary>function</secondary>
|
|
|
|
</indexterm>
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <structname>pg_stat_statements</structname> view is defined in
|
2017-10-09 03:44:17 +02:00
|
|
|
terms of a function also named <function>pg_stat_statements</function>.
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
It is possible for clients to call
|
|
|
|
the <function>pg_stat_statements</function> function directly, and by
|
|
|
|
specifying <literal>showtext := false</literal> have query text be
|
|
|
|
omitted (that is, the <literal>OUT</literal> argument that corresponds
|
2017-10-09 03:44:17 +02:00
|
|
|
to the view's <structfield>query</structfield> column will return nulls). This
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
feature is intended to support external tools that might wish to avoid
|
|
|
|
the overhead of repeatedly retrieving query texts of indeterminate
|
|
|
|
length. Such tools can instead cache the first query text observed
|
|
|
|
for each entry themselves, since that is
|
2017-10-09 03:44:17 +02:00
|
|
|
all <filename>pg_stat_statements</filename> itself does, and then retrieve
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
query texts only as needed. Since the server stores query texts in a
|
|
|
|
file, this approach may reduce physical I/O for repeated examination
|
|
|
|
of the <structname>pg_stat_statements</structname> data.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2009-01-04 23:19:59 +01:00
|
|
|
</variablelist>
|
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-config-params">
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Configuration Parameters</title>
|
2009-01-04 23:19:59 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>pg_stat_statements.max</varname> (<type>integer</type>)
|
2021-11-09 04:39:47 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary><varname>pg_stat_statements.max</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
2009-01-04 23:19:59 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<varname>pg_stat_statements.max</varname> is the maximum number of
|
|
|
|
statements tracked by the module (i.e., the maximum number of rows
|
2017-10-09 03:44:17 +02:00
|
|
|
in the <structname>pg_stat_statements</structname> view). If more distinct
|
2009-01-04 23:19:59 +01:00
|
|
|
statements than that are observed, information about the least-executed
|
2020-11-26 13:18:05 +01:00
|
|
|
statements is discarded. The number of times such information was
|
|
|
|
discarded can be seen in the
|
|
|
|
<structname>pg_stat_statements_info</structname> view.
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
The default value is 5000.
|
2009-01-04 23:19:59 +01:00
|
|
|
This parameter can only be set at server start.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>pg_stat_statements.track</varname> (<type>enum</type>)
|
2021-11-09 04:39:47 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary><varname>pg_stat_statements.track</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
2009-01-04 23:19:59 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<varname>pg_stat_statements.track</varname> controls which statements
|
|
|
|
are counted by the module.
|
2017-10-09 03:44:17 +02:00
|
|
|
Specify <literal>top</literal> to track top-level statements (those issued
|
|
|
|
directly by clients), <literal>all</literal> to also track nested statements
|
|
|
|
(such as statements invoked within functions), or <literal>none</literal> to
|
2012-04-28 22:03:57 +02:00
|
|
|
disable statement statistics collection.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default value is <literal>top</literal>.
|
2009-01-04 23:19:59 +01:00
|
|
|
Only superusers can change this setting.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2009-12-15 21:04:49 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>pg_stat_statements.track_utility</varname> (<type>boolean</type>)
|
2021-11-09 04:39:47 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary><varname>pg_stat_statements.track_utility</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
2009-12-15 21:04:49 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<varname>pg_stat_statements.track_utility</varname> controls whether
|
|
|
|
utility commands are tracked by the module. Utility commands are
|
2017-10-09 03:44:17 +02:00
|
|
|
all those other than <command>SELECT</command>, <command>INSERT</command>,
|
2022-09-27 10:44:42 +02:00
|
|
|
<command>UPDATE</command>, <command>DELETE</command>, and <command>MERGE</command>.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default value is <literal>on</literal>.
|
2009-12-15 21:04:49 +01:00
|
|
|
Only superusers can change this setting.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>pg_stat_statements.track_planning</varname> (<type>boolean</type>)
|
2021-11-09 04:39:47 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary><varname>pg_stat_statements.track_planning</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<varname>pg_stat_statements.track_planning</varname> controls whether
|
|
|
|
planning operations and duration are tracked by the module.
|
2020-07-06 07:27:09 +02:00
|
|
|
Enabling this parameter may incur a noticeable performance penalty,
|
2021-07-07 14:54:47 +02:00
|
|
|
especially when statements with identical query structure are executed
|
|
|
|
by many concurrent connections which compete to update a small number of
|
|
|
|
<structname>pg_stat_statements</structname> entries.
|
2020-07-03 04:35:22 +02:00
|
|
|
The default value is <literal>off</literal>.
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
Only superusers can change this setting.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2009-01-04 23:19:59 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>pg_stat_statements.save</varname> (<type>boolean</type>)
|
2021-11-09 04:39:47 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary><varname>pg_stat_statements.save</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
2009-01-04 23:19:59 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<varname>pg_stat_statements.save</varname> specifies whether to
|
|
|
|
save statement statistics across server shutdowns.
|
2017-10-09 03:44:17 +02:00
|
|
|
If it is <literal>off</literal> then statistics are not saved at
|
2009-01-04 23:19:59 +01:00
|
|
|
shutdown nor reloaded at server start.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default value is <literal>on</literal>.
|
|
|
|
This parameter can only be set in the <filename>postgresql.conf</filename>
|
2009-01-04 23:19:59 +01:00
|
|
|
file or on the server command line.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
<para>
|
Keep pg_stat_statements' query texts in a file, not in shared memory.
This change allows us to eliminate the previous limit on stored query
length, and it makes the shared-memory hash table very much smaller,
allowing more statements to be tracked. (The default value of
pg_stat_statements.max is therefore increased from 1000 to 5000.)
In typical scenarios, the hash table can be large enough to hold all the
statements commonly issued by an application, so that there is little
"churn" in the set of tracked statements, and thus little need to do I/O
to the file.
To further reduce the need for I/O to the query-texts file, add a way
to retrieve all the columns of the pg_stat_statements view except for
the query text column. This is probably not of much interest for human
use but it could be exploited by programs, which will prefer using the
queryid anyway.
Ordinarily, we'd need to bump the extension version number for the latter
change. But since we already advanced pg_stat_statements' version number
from 1.1 to 1.2 in the 9.4 development cycle, it seems all right to just
redefine what 1.2 means.
Peter Geoghegan, reviewed by Pavel Stehule
2014-01-27 21:37:54 +01:00
|
|
|
The module requires additional shared memory proportional to
|
|
|
|
<varname>pg_stat_statements.max</varname>. Note that this
|
2009-01-04 23:19:59 +01:00
|
|
|
memory is consumed whenever the module is loaded, even if
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>pg_stat_statements.track</varname> is set to <literal>none</literal>.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
These parameters must be set in <filename>postgresql.conf</filename>.
|
2011-10-04 18:36:18 +02:00
|
|
|
Typical usage might be:
|
2009-01-04 23:19:59 +01:00
|
|
|
|
2010-07-29 21:34:41 +02:00
|
|
|
<programlisting>
|
2009-01-04 23:19:59 +01:00
|
|
|
# postgresql.conf
|
|
|
|
shared_preload_libraries = 'pg_stat_statements'
|
|
|
|
|
2021-04-21 05:02:41 +02:00
|
|
|
compute_query_id = on
|
2009-01-04 23:19:59 +01:00
|
|
|
pg_stat_statements.max = 10000
|
|
|
|
pg_stat_statements.track = all
|
2010-07-29 21:34:41 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2009-01-04 23:19:59 +01:00
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-sample-output">
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Sample Output</title>
|
2009-01-04 23:19:59 +01:00
|
|
|
|
2010-07-29 21:34:41 +02:00
|
|
|
<screen>
|
2010-01-08 01:38:20 +01:00
|
|
|
bench=# SELECT pg_stat_statements_reset();
|
2009-01-04 23:19:59 +01:00
|
|
|
|
2010-01-08 01:38:20 +01:00
|
|
|
$ pgbench -i bench
|
2012-03-29 03:00:31 +02:00
|
|
|
$ pgbench -c10 -t300 bench
|
2009-01-04 23:19:59 +01:00
|
|
|
|
2010-01-08 01:38:20 +01:00
|
|
|
bench=# \x
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
bench=# SELECT query, calls, total_exec_time, rows, 100.0 * shared_blks_hit /
|
2010-01-08 01:38:20 +01:00
|
|
|
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 5;
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 1 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2
|
|
|
|
calls | 3000
|
|
|
|
total_exec_time | 25565.855387
|
|
|
|
rows | 3000
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 2 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2
|
|
|
|
calls | 3000
|
|
|
|
total_exec_time | 20756.669379
|
|
|
|
rows | 3000
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 3 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | copy pgbench_accounts from stdin
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 291.865911
|
|
|
|
rows | 100000
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 4 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2
|
|
|
|
calls | 3000
|
|
|
|
total_exec_time | 271.232977
|
|
|
|
rows | 3000
|
|
|
|
hit_percent | 98.8454011741682975
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 5 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | alter table pgbench_accounts add primary key (aid)
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 160.588563
|
|
|
|
rows | 0
|
|
|
|
hit_percent | 100.0000000000000000
|
2019-01-11 04:20:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
bench=# SELECT pg_stat_statements_reset(0,0,s.queryid) FROM pg_stat_statements AS s
|
|
|
|
WHERE s.query = 'UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2';
|
|
|
|
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
bench=# SELECT query, calls, total_exec_time, rows, 100.0 * shared_blks_hit /
|
2019-01-11 04:20:09 +01:00
|
|
|
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 5;
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 1 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2
|
|
|
|
calls | 3000
|
|
|
|
total_exec_time | 20756.669379
|
|
|
|
rows | 3000
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 2 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | copy pgbench_accounts from stdin
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 291.865911
|
|
|
|
rows | 100000
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 3 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2
|
|
|
|
calls | 3000
|
|
|
|
total_exec_time | 271.232977
|
|
|
|
rows | 3000
|
|
|
|
hit_percent | 98.8454011741682975
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 4 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | alter table pgbench_accounts add primary key (aid)
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 160.588563
|
|
|
|
rows | 0
|
|
|
|
hit_percent | 100.0000000000000000
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 5 ]---+--------------------------------------------------&zwsp;------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | vacuum analyze pgbench_accounts
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 136.448116
|
|
|
|
rows | 0
|
|
|
|
hit_percent | 99.9201915403032721
|
2019-01-11 04:20:09 +01:00
|
|
|
|
|
|
|
bench=# SELECT pg_stat_statements_reset(0,0,0);
|
|
|
|
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
bench=# SELECT query, calls, total_exec_time, rows, 100.0 * shared_blks_hit /
|
2019-01-11 04:20:09 +01:00
|
|
|
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 5;
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 1 ]---+--------------------------------------------------&zwsp;---------------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | SELECT pg_stat_statements_reset(0,0,0)
|
|
|
|
calls | 1
|
|
|
|
total_exec_time | 0.189497
|
|
|
|
rows | 1
|
2022-04-20 17:04:28 +02:00
|
|
|
hit_percent |
|
2020-05-15 00:13:08 +02:00
|
|
|
-[ RECORD 2 ]---+--------------------------------------------------&zwsp;---------------------------
|
Allow pg_stat_statements to track planning statistics.
This commit makes pg_stat_statements support new GUC
pg_stat_statements.track_planning. If this option is enabled,
pg_stat_statements tracks the planning statistics of the statements,
e.g., the number of times the statement was planned, the total time
spent planning the statement, etc. This feature is useful to check
the statements that it takes a long time to plan. Previously since
pg_stat_statements tracked only the execution statistics, we could
not use that for the purpose.
The planning and execution statistics are stored at the end of
each phase separately. So there are not always one-to-one relationship
between them. For example, if the statement is successfully planned
but fails in the execution phase, only its planning statistics are stored.
This may cause the users to be able to see different pg_stat_statements
results from the previous version. To avoid this,
pg_stat_statements.track_planning needs to be disabled.
This commit bumps the version of pg_stat_statements to 1.8
since it changes the definition of pg_stat_statements function.
Author: Julien Rouhaud, Pascal Legrand, Thomas Munro, Fujii Masao
Reviewed-by: Sergei Kornilov, Tomas Vondra, Yoshikazu Imai, Haribabu Kommi, Tom Lane
Discussion: https://postgr.es/m/CAHGQGwFx_=DO-Gu-MfPW3VQ4qC7TfVdH2zHmvZfrGv6fQ3D-Tw@mail.gmail.com
Discussion: https://postgr.es/m/CAEepm=0e59Y_6Q_YXYCTHZkqOc6H2pJ54C_Xe=VFu50Aqqp_sA@mail.gmail.com
Discussion: https://postgr.es/m/DB6PR0301MB21352F6210E3B11934B0DCC790B00@DB6PR0301MB2135.eurprd03.prod.outlook.com
2020-04-02 04:20:19 +02:00
|
|
|
query | SELECT query, calls, total_exec_time, rows, $1 * shared_blks_hit / +
|
|
|
|
| nullif(shared_blks_hit + shared_blks_read, $2) AS hit_percent+
|
|
|
|
| FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT $3
|
|
|
|
calls | 0
|
|
|
|
total_exec_time | 0
|
|
|
|
rows | 0
|
2022-04-20 17:04:28 +02:00
|
|
|
hit_percent |
|
2019-01-11 04:20:09 +01:00
|
|
|
|
2010-07-29 21:34:41 +02:00
|
|
|
</screen>
|
2009-01-04 23:19:59 +01:00
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="pgstatstatements-authors">
|
2012-04-13 22:42:24 +02:00
|
|
|
<title>Authors</title>
|
2009-01-04 23:19:59 +01:00
|
|
|
|
|
|
|
<para>
|
2012-04-13 22:42:24 +02:00
|
|
|
Takahiro Itagaki <email>itagaki.takahiro@oss.ntt.co.jp</email>.
|
|
|
|
Query normalization added by Peter Geoghegan <email>peter@2ndquadrant.com</email>.
|
2009-01-04 23:19:59 +01:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|