根据手册中的pageindexes don't need to be maintained.然而,我们使用的是一个PostgresQL表,它的连续速率为updatesdeletesinserts,随着时间的推移(几天),查询性能会显著下降.如果我们删除并重新创建索引,查询性能就会恢复.

我们使用的是现成的设置

我们是searching based of an index, not the primary key(我已经确认该指数正在使用,至少在正常情况下)

该表被用作单个进程的持久存储.

我愿意放弃insert and update performance以保持查询性能.

我们正在考虑重新构建应用程序,以便数据以一种允许我们定期删除和重建索引的方式分布在各种动态表中,而不会影响应用程序.然而,和往常一样,要想让它正常工作还需要时间,我怀疑我们在配置或使用中缺少了一些基本的东西.

我们考虑过forcing vacuumingrebuild 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).如果要重做或进行重大重构,将会有很多变化.

推荐答案

自动吸尘器应该可以做到这一点,前提是您根据所需的性能对其进行了配置.

笔记:

真空:这将重建表统计信息并回收一些磁盘空间.它可以与生产系统并行运行,但会产生大量IO,从而影响性能.

分析:这将重建查询计划器统计信息.这是由真空触发的,但可以自行运行.

detailed notes found here

Postgresql相关问答推荐

在postgres中查找多个表中不同列的计数和总和

包含JSONB属性的过滤器的索引策略

Org.postgresql.util.PSQLException:错误:函数LOWER(BYTEA)不存在

Postgres从spark触发post-write

无法将 json 范围读取为 pgtype.Int4range

在特定距离内创建点的唯一索引

如何在 MockDataProvider 中创建自定义 JOOQ 记录?

Postgres 低估了导致错误查询计划的行数

MERGE 语句的锁定级别

有没有办法使用postgresql将具有不同ID的同一行多次添加到表中?

使用间隔参数的 go postgres 准备好的语句不起作用

无法从在 wsl 2 上运行的服务之一连接到在 wsl 2 上的容器中运行的 postgres 数据库

并发刷新materialized视图

如何让 Rails 使用 SSL 连接到 PostgreSQL?

为什么 sqlalchemy 的默认列值不起作用

postgres - 比较两个数组

Windows 上的 GeoDjango:Could not find the GDAL library" / "OSError: [WinError 126] The specified module could not be found

在同一台机器上创建多个 Postgres 实例

为什么是||在 PostgreSQL/Redshift 中用作字符串连接

postgresql DB中唯一键的正确数据类型是什么?