根据手册中的page,indexes don't need to be maintained
.然而,我们使用的是一个PostgresQL表,它的连续速率为updates
、deletes
和inserts
,随着时间的推移(几天),查询性能会显著下降.如果我们删除并重新创建索引,查询性能就会恢复.
我们使用的是现成的设置
我们是searching based of an index, not the primary key
(我已经确认该指数正在使用,至少在正常情况下)
该表被用作单个进程的持久存储.
我愿意放弃insert and update performance
以保持查询性能.
我们正在考虑重新构建应用程序,以便数据以一种允许我们定期删除和重建索引的方式分布在各种动态表中,而不会影响应用程序.然而,和往常一样,要想让它正常工作还需要时间,我怀疑我们在配置或使用中缺少了一些基本的东西.
我们考虑过forcing vacuuming
和rebuild to run at certain times
,但我怀疑是locking period for such an action would cause our query to block
.这可能是一种 Select ,但有一些实时(3-5秒的窗口)的影响,需要在我们的代码中进行其他更改.
Additional information:
CREATE TABLE icl_contacts
(
id bigint NOT NULL,
campaignfqname character varying(255) NOT NULL,
currentstate character(16) NOT NULL,
xmlscheduledtime character(23) NOT NULL,
...
25 or so other fields. Most of them fixed or varying character fiel
...
CONSTRAINT icl_contacts_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
ALTER TABLE icl_contacts OWNER TO postgres;
CREATE INDEX icl_contacts_idx
ON icl_contacts
USING btree
(xmlscheduledtime, currentstate, campaignfqname);
分析:
Limit (cost=0.00..3792.10 rows=750 width=32) (actual time=48.922..59.601 rows=750 loops=1)
-> Index Scan using icl_contacts_idx on icl_contacts (cost=0.00..934580.47 rows=184841 width=32) (actual time=48.909..55.961 rows=750 loops=1)
Index Cond: ((xmlscheduledtime < '2010-05-20T13:00:00.000'::bpchar) AND (currentstate = 'SCHEDULED'::bpchar) AND ((campaignfqname)::text = '.main.ee45692a-6113-43cb-9257-7b6bf65f0c3e'::text))
是的,我知道有很多事情.其中一些选项可能对我们有用.
My focus in this question is关于理解how PostgresQL is managing the index and query over time (understand why, not just fix)
.如果要重做或进行重大重构,将会有很多变化.