PostgreSQL pg_stat_progress_create_index 查看创建索引进度
PostgreSQL About 4,049 wordsSQL
select * from pg_stat_progress_create_index;
输出
postgres=# select * from pg_stat_progress_create_index;
-[ RECORD 1 ]------+-------------------------------
pid | 50417
datid | 13759
datname | postgres
relid | 28538
index_relid | 28543
command | REINDEX
phase | building index: scanning table
lockers_total | 0
lockers_done | 0
current_locker_pid | 0
blocks_total | 66667
blocks_done | 39642
tuples_total | 0
tuples_done | 0
partitions_total | 0
partitions_done | 0
postgres=# select * from pg_stat_progress_create_index;
-[ RECORD 1 ]------+------------------------------------
pid | 50417
datid | 13759
datname | postgres
relid | 28538
index_relid | 28543
command | REINDEX
phase | building index: sorting live tuples
lockers_total | 0
lockers_done | 0
current_locker_pid | 0
blocks_total | 66667
blocks_done | 66667
tuples_total | 0
tuples_done | 0
partitions_total | 0
partitions_done | 0
postgres=# select * from pg_stat_progress_create_index;
-[ RECORD 1 ]------+---------------------------------------
pid | 50417
datid | 13759
datname | postgres
relid | 28538
index_relid | 28543
command | REINDEX
phase | building index: loading tuples in tree
lockers_total | 0
lockers_done | 0
current_locker_pid | 0
blocks_total | 0
blocks_done | 0
tuples_total | 5000000
tuples_done | 1632181
partitions_total | 0
partitions_done | 0
postgres=# select * from pg_stat_progress_create_index;
(0 rows)
表字段含义
字段名称 | 类型 | 描述 |
---|---|---|
pid | integer | 进程 ID |
datid | oid | 索引所属数据库的 ID |
datname | name | 索引所属数据库的名称 |
relid | oid | 索引所属表的 ID |
index_relid | oid | 正在创建的索引的 ID |
command | text | 执行的命令,可能是 CREATE INDEX 或 REINDEX |
phase | text | 当前阶段,包括 INITIALIZE , BUILD , WAITING FOR ANALYZE 和 FINALIZE |
lockers_total | bigint | 锁住的总页面数 |
lockers_done | bigint | 已经处理完成的页面数 |
current_locker_pid | integer | 当前锁住其他进程的进程 ID |
blocks_total | bigint | 总页面数 |
blocks_done | bigint | 已经处理完成的页面数 |
tuples_total | bigint | 总行数 |
tuples_done | bigint | 已经处理完成的行数 |
partitions_total | integer | 分区中总的部分(如有分区的话) |
partitions_done | integer | 已经处理完成的部分 |
各阶段 phase 含义
initializing
- 描述:
CREATE INDEX
或REINDEX
准备创建索引。这一阶段通常非常简短。
waiting for writers before build
- 描述:
CREATE INDEX CONCURRENTLY
或REINDEX CONCURRENTLY
在开始创建索引之前,等待所有可能看到表写锁的事务完成。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
lockers_total
,lockers_done
和current_locker_pid
列包含此阶段的进度信息。
building index
- 描述: 索引正在由特定的访问方法代码构建。在此阶段,支持进度报告的访问方法填写自己的进度数据,并在此列中指示子阶段。通常
blocks_total
和blocks_done
会包含进度数据,可能还包括tuples_total
和tuples_done
。 - 进度信息:
blocks_total
,blocks_done
,tuples_total
,tuples_done
列可能包含此阶段的进度信息。
waiting for writers before validation
- 描述:
CREATE INDEX CONCURRENTLY
或REINDEX CONCURRENTLY
在验证之前,等待所有可能写入表的事务完成。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
lockers_total
,lockers_done
和current_locker_pid
列包含此阶段的进度信息。
index validation: scanning index
- 描述:
CREATE INDEX CONCURRENTLY
正在扫描索引以查找需要验证的元组。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
blocks_total
(设置为索引的总大小)和blocks_done
列包含此阶段的进度信息。
index validation: sorting tuples
- 描述:
CREATE INDEX CONCURRENTLY
正在对索引扫描阶段的输出进行排序。
index validation: scanning table
- 描述:
CREATE INDEX CONCURRENTLY
正在扫描表以验证前两个阶段收集的索引元组。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
blocks_total
(设置为表的总大小)和blocks_done
列包含此阶段的进度信息。
waiting for old snapshots
- 描述:
CREATE INDEX CONCURRENTLY
或REINDEX CONCURRENTLY
在等待可能看到表的事务释放其快照。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
lockers_total
,lockers_done
和current_locker_pid
列包含此阶段的进度信息。
waiting for readers before marking dead
- 描述:
REINDEX CONCURRENTLY
在标记旧索引无效之前,等待所有可能看到表的读锁事务完成。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
lockers_total
,lockers_done
和current_locker_pid
列包含此阶段的进度信息。
waiting for readers before dropping
- 描述:
REINDEX CONCURRENTLY
在放弃旧索引之前,等待所有可能看到表的读锁事务完成。当不是在并行模式下时,此阶段会被跳过。 - 进度信息:
lockers_total
,lockers_done
和current_locker_pid
列包含此阶段的进度信息。
官方文档
https://www.postgresql.org/docs/17/progress-reporting.html#CREATE-INDEX-PROGRESS-REPORTING
Views: 47 · Posted: 2025-02-18
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓

Loading...