postgresql 的pg_stat_statements blk_read_time指标问题

实验环境

select version();
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11), 64-bit
(1 row)

实验方法

创建一个800多M的表。

CREATE TABLE sampletable (x numeric);
 INSERT INTO sampletable
         SELECT random() * 10000
         FROM generate_series(1, 10000000);

执行并行查询

set max_parallel_workers_per_gather=2;
explain  analyze SELECT * FROM sampletable xx33xx  WHERE x < 423;
                                                                  QUERY PLAN                                                                  
----------------------------------------------------------------------------------------------------------------------------------------------
 Gather  (cost=1000.00..197473.27 rows=412972 width=11) (actual time=3.280..5196.528 rows=423548 loops=1)
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Seq Scan on sampletable xx33xx  (cost=0.00..155176.07 rows=172072 width=11) (actual time=0.858..3833.489 rows=141183 loops=3)
         Filter: (x < '423'::numeric)
         Rows Removed by Filter: 3192151
 Planning time: 0.198 ms
 Execution time: 5217.594 ms
(8 rows)


查看统计信息

--结果显示blk_read_time>total_time
select query,total_time,blk_read_time,blk_write_time,queryid from pg_stat_statements where query like '%xx33xx%';
                              query                               | total_time  | blk_read_time | blk_write_time |  queryid  
------------------------------------------------------------------+-------------+---------------+----------------+-----------
 explain  analyze SELECT * FROM sampletable xx33xx  WHERE x < 423 | 5217.881478 |   7398.202573 |              0 | 403994828
(1 row)

清理缓存

[root@node1 ~]# sync
[root@node1 ~]# echo 3 >/proc/sys/vm/drop_caches 

执行非并行查询

set max_parallel_workers_per_gather=0;
explain  analyze SELECT * FROM sampletable xx22xx WHERE x < 423;
                                                          QUERY PLAN                                                           
-------------------------------------------------------------------------------------------------------------------------------
 Seq Scan on sampletable xx22xx  (cost=0.00..228092.36 rows=412972 width=11) (actual time=1.265..5021.838 rows=423548 loops=1)
   Filter: (x < '423'::numeric)
   Rows Removed by Filter: 9576452
 Planning time: 0.213 ms
 Execution time: 5043.451 ms
(5 rows)

查看统计信息

select calls,query,total_time,blk_read_time,blk_write_time,queryid from pg_stat_statements where query like '%xx22xx%';
 calls |                              query                              | total_time  | blk_read_time | blk_write_time |  queryid  
-------+-----------------------------------------------------------------+-------------+---------------+----------------+-----------
     1 | explain  analyze SELECT * FROM sampletable xx22xx WHERE x < 423 | 5043.752919 |   2171.352884 |              0 | 512530458
(1 row)

查看物理读

--物理读的块数都是一样的
select * from pg_statio_all_tables where relname='sampletable';

实验结果

证明postgresql的pg_stat_statements的blk_read_time 在并行情况下统计的时间远高于没并行的情况,但是其实读取的块数是一样的,说明这个指标在并行情况下并不准确。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值