PostgreSQL日志和pg_stat_statements之间的时间差异

时间:2018-10-25 06:34:55

标签: postgresql database-performance

似乎log_min_duration_statement和pg_stat_statements记录的时间之间存在差异。

以下是pg log的输出:

[root@kvrh7os202 pg_log]# less postgresql-Thu-11.log
2018-10-25 10:59:59 +08 [12556]: [9195-1] user=sri,db=sri,app=PostgreSQL JDBC Driver,client=10.176.8.80 LOG:  duration: 6754.569 ms  bind <unnamed>: select resource0_.RESOURCE_FACING_SERVICE_ID as RESOURCE3_20_1_, $1 as RFS4_20_1_, $2 as QB20_1_, $3 as QR20_1_, OBJECT_ID as RESOURCE1_1_, REVISION_ID as RESOURCE2_1_, resourceen1_.OBJECT_ID as OBJECT1_20_0_, resourceen1_.REVISION_ID as REVISION7_20_0_, $4 as QB20_0_, $5 as QR20_0_, resourceen1_.OPTLOCK as OPTLOCK20_0_, resourceen1_.NAME as NAME20_0_, resourceen1_.BRANCH_ID as BRANCH8_20_0

以下来自pg_stat_statements:

postgres=# select pd.datname, substr(pss.query,0,100) AS SQLQuery, pss.rows AS rows, pss.min_time, pss.max_time, pss.stddev_time, pss.total_time, pss.calls, (pss.total_time / 1000) AS total_elapsed_in_sec, round(((pss.total_time / 1000)/calls)::numeric,6) as avg_elapsed_in_sec
postgres-# FROM pg_stat_statements AS pss
postgres-# INNER JOIN pg_database AS pd ON pss.dbid=pd.oid
postgres-# where query like 'select resource0_.RESOURCE_FACING_SERVICE_ID%';
 datname |                                              sqlquery                                               | rows | min_time | max_time  |   stddev_time    |    total_time    | calls  | total_elapsed_in_sec | avg_elapsed_in_sec
---------+-----------------------------------------------------------------------------------------------------+------+----------+-----------+------------------+------------------+--------+----------------------+--------------------
 sri     | select resource0_.RESOURCE_FACING_SERVICE_ID as RESOURCE3_20_1_, $1 as RFS4_20_1_, $2 as QB20_1_, $ |    0 | 0.047669 | 97.293171 | 2.21278920834544 | 27451.0374100001 | 106724 |     27.4510374100001 |           0.000257
 sri     | select resource0_.RESOURCE_FACING_SERVICE_ID as RESOURCE3_20_1_, $1 as RFS4_20_1_, $2 as QB20_1_, $ |    0 | 0.038346 | 133.10015 | 1.73874479902066 |     17600.230552 | 106510 |         17.600230552 |           0.000165
(2 rows)

log_min_duration_statement参数:

postgres=# show log_min_duration_statement;
log_min_duration_statement
----------------------------
 5s
(1 row)

postgres=#

Postgres日志显示查询的持续时间为6754.569 ms,而pg_stat_statements显示查询的最大持续时间为97 ms和133 ms。所以我想知道剩余的时间去了哪里。有什么方法可以追踪未计入的经过时间?

OS:CentOS Linux版本7.4.1708(核心) Postgres:PostgreSQL 10.5

0 个答案:

没有答案