小编sta*_* jr的帖子

优化 Postgresql 中的选择计数结果

我正在尝试优化包含超过 8000 万行的表。需要 20 多分钟才能获得行计数结果。我尝试过集群、vacuum full 和重新索引,但性能没有提高。为了改进数据查询和检索,我需要配置或调整什么?我在 Windows 2019 下使用 Postgresql 12。

更新信息:

  • 目前总行数约为 9200 万以上
  • 表列数 = 44
  • Explain query result using 'select count(*) from doc_details':  
        Finalize Aggregate  (cost=5554120.84..5554120.85 rows=1 width=8) (actual time=1249204.001..1249210.027 rows=1 loops=1)  
      ->  Gather  (cost=5554120.63..5554120.83 rows=2 width=8) (actual time=1249203.642..1249210.020 rows=3 loops=1)  
            Workers Planned: 2  
            Workers Launched: 2  
            ->  Partial Aggregate  (cost=5553120.63..5553120.63 rows=1 width=8) (actual time=1249153.615..1249153.616 rows=1 loops=3)  
                  ->  Parallel Seq Scan on doc_details  (cost=0.00..5456055.30 rows=38826130 width=0) (actual time=3.793..1245165.604 rows=31018949 loops=3)  
    Planning Time: 1.290 ms  
    Execution Time: …
    Run Code Online (Sandbox Code Playgroud)

postgresql count postgresql-12 query-performance

5
推荐指数
1
解决办法
5252
查看次数