为什么我的 Postgres 9.6 创建索引并发无效?

rdb*_*oob 4 postgresql index concurrency

我正在尝试在生产中同时创建索引。\d然而,这样做时,通过查看时的索引会显示INVALID

为什么会这样呢?以前从未见过这种情况发生。

尝试过重新创建,但仍然遇到同样的问题:

指数:

create index concurrently idx_wallet_customer_id_credit_stake_expires on wallet (customer_id,wallet_credit_stake,wallet_expires)
where wallet_closed is null and wallet_staked is null;
Run Code Online (Sandbox Code Playgroud)

Erw*_*ter 5

索引是在后台构建CONCURRENTLY的,不采用独占锁。最后一步是使索引“有效”,但这要等到最后一个并发事务完成后才会发生。检查长时间运行的事务。主要嫌疑人是那些具有以下特征的人state = 'idle in transaction'

SELECT * FROM pg_stat_activity;
Run Code Online (Sandbox Code Playgroud)

看:

Postgres 12 或更高版本具有系统视图pg_stat_progress_create_index。看:

Postgres 9.6 将于 2021 年 11 月停产,请考虑升级到当前版本!