Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 为什么对主表进行查询非常慢?_Performance_Postgresql_Partitioning - Fatal编程技术网

Performance 为什么对主表进行查询非常慢?

Performance 为什么对主表进行查询非常慢?,performance,postgresql,partitioning,Performance,Postgresql,Partitioning,我有一张很大的桌子。所以我把这张桌子隔开了。并将所有记录从主表复制到子表。然后我从主表中删除了所有记录。现在我的主桌空了。对子表进行查询速度非常快。但在主表上进行查询仍然非常缓慢。怎么了 postgres=# select count(*) from only cdr; count ------- 0 (1 row) postgres=# explain select count(*) from only cdr; QU

我有一张很大的桌子。所以我把这张桌子隔开了。并将所有记录从主表复制到子表。然后我从主表中删除了所有记录。现在我的主桌空了。对子表进行查询速度非常快。但在主表上进行查询仍然非常缓慢。怎么了

postgres=# select count(*) from only cdr;
 count 
-------
     0
(1 row)

postgres=# explain select count(*) from only cdr;
                              QUERY PLAN                               
-----------------------------------------------------------------------
 Aggregate  (cost=2045094.31..2045094.32 rows=1 width=0)
   ->  Seq Scan on cdr  (cost=0.00..2044867.85 rows=90585 width=0)
(2 rows)

postgres=# EXPLAIN ANALYZE select count(*) from only cdr;
                                                        QUERY PLAN                                                    

----------------------------------------------------------------------------------------------------------------------
-----
 Aggregate  (cost=2045094.31..2045094.32 rows=1 width=0) (actual time=168385.356..168385.356 rows=1 loops=1)
   ->  Seq Scan on cdr  (cost=0.00..2044867.85 rows=90585 width=0) (actual time=168385.351..168385.351 rows=0 loop
s=1)
 Total runtime: 168385.404 ms
(3 rows)
我还对主表进行了真空分析。但还是没有运气

博士后=#真空分析cdr; 真空


我发现其他一些人也有同样的问题。可能根本原因是,虽然主表中的旧记录已被删除,但psql仍然以某种方式扫描这些垃圾数据。一种解决方案是创建一个新的主表,并放弃旧的主表。但是这个解决方案不适合我。有没有其他不停机的解决方案?谢谢

我解决了这个问题。只需要在主表上运行“真空满”或“集群”即可。

我解决了这个问题。只需在主控台上运行“真空满”或“群集”。您是否在主控台上运行了
vacuum analyze
?我已运行了“真空分析cdr;”。但是现在仍然很慢。你在主机上运行了真空分析吗?我已经运行了“真空分析cdr;”。但现在仍然很慢。