diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2019-04-07 11:30:14 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2019-04-07 12:35:29 +0200 |
commit | 03f9e5cba0ee1633af4abe734504df50af46fbd8 (patch) | |
tree | a58530a21f478fc54658768e680de91e9c20ebee /src/backend | |
parent | 106f2eb664bbd38c83090becff9fcde1e9622c9c (diff) | |
download | postgresql-03f9e5cba0ee1633af4abe734504df50af46fbd8.tar.gz postgresql-03f9e5cba0ee1633af4abe734504df50af46fbd8.zip |
Report progress of REINDEX operations
This uses the same infrastructure that the CREATE INDEX progress
reporting uses. Add a column to pg_stat_progress_create_index to
report the OID of the index being worked on. This was not necessary
for CREATE INDEX, but it's useful for REINDEX.
Also edit the phase descriptions a bit to be more consistent with the
source code comments.
Discussion: https://www.postgresql.org/message-id/ef6a6757-c36a-9e81-123f-13b19e36b7d7%402ndquadrant.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/index.c | 10 | ||||
-rw-r--r-- | src/backend/catalog/system_views.sql | 9 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 41 |
3 files changed, 52 insertions, 8 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 2ed7fdb021f..9b1d5467917 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3286,12 +3286,20 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, heapId = IndexGetRelation(indexId, false); heapRelation = table_open(heapId, ShareLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, + heapId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, + indexId); + /* * Open the target index relation and get an exclusive lock on it, to * ensure that no one else is touching this particular index. */ iRel = index_open(indexId, AccessExclusiveLock); + pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, + iRel->rd_rel->relam); + /* * The case of reindexing partitioned tables and indexes is handled * differently by upper layers, so this case shouldn't arise. @@ -3442,6 +3450,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, errdetail_internal("%s", pg_rusage_show(&ru0)))); + pgstat_progress_end_command(); + /* Close rels, but keep locks */ index_close(iRel, NoLock); table_close(heapRelation, NoLock); diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 17e7aef2204..16e456a7d94 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -946,16 +946,19 @@ CREATE VIEW pg_stat_progress_create_index AS SELECT S.pid AS pid, S.datid AS datid, D.datname AS datname, S.relid AS relid, + CAST(S.param7 AS oid) AS index_relid, CASE S.param10 WHEN 0 THEN 'initializing' - WHEN 1 THEN 'waiting for old snapshots' + WHEN 1 THEN 'waiting for writers before build' WHEN 2 THEN 'building index' || COALESCE((': ' || pg_indexam_progress_phasename(S.param9::oid, S.param11)), '') - WHEN 3 THEN 'waiting for writer snapshots' + WHEN 3 THEN 'waiting for writers before validation' WHEN 4 THEN 'index validation: scanning index' WHEN 5 THEN 'index validation: sorting tuples' WHEN 6 THEN 'index validation: scanning table' - WHEN 7 THEN 'waiting for reader snapshots' + WHEN 7 THEN 'waiting for old snapshots' + WHEN 8 THEN 'waiting for readers before marking dead' + WHEN 9 THEN 'waiting for readers before dropping' END as phase, S.param4 AS lockers_total, S.param5 AS lockers_done, diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 348d5432977..46f32c21f97 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -479,6 +479,12 @@ DefineIndex(Oid relationId, relationId); /* + * No index OID to report yet + */ + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, + InvalidOid); + + /* * count key attributes in index */ numberOfKeyAttributes = list_length(stmt->indexParams); @@ -1245,6 +1251,12 @@ DefineIndex(Oid relationId, StartTransactionCommand(); /* + * The index is now visible, so we can report the OID. + */ + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, + indexRelationId); + + /* * Phase 2 of concurrent index build (see comments for validate_index() * for an overview of how this works) * @@ -2873,6 +2885,13 @@ ReindexRelationConcurrently(Oid relationOid, int options) heapRel = table_open(indexRel->rd_index->indrelid, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, + RelationGetRelid(heapRel)); + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, + indexId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, + indexRel->rd_rel->relam); + /* Choose a temporary relation name for the new index */ concurrentName = ChooseRelationName(get_rel_name(indexId), NULL, @@ -2967,7 +2986,9 @@ ReindexRelationConcurrently(Oid relationOid, int options) * DefineIndex() for more details. */ - WaitForLockersMultiple(lockTags, ShareLock, false); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_1); + WaitForLockersMultiple(lockTags, ShareLock, true); CommitTransactionCommand(); forboth(lc, indexIds, lc2, newIndexIds) @@ -3009,7 +3030,9 @@ ReindexRelationConcurrently(Oid relationOid, int options) * for more details. */ - WaitForLockersMultiple(lockTags, ShareLock, false); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_2); + WaitForLockersMultiple(lockTags, ShareLock, true); CommitTransactionCommand(); foreach(lc, newIndexIds) @@ -3057,7 +3080,9 @@ ReindexRelationConcurrently(Oid relationOid, int options) * before the reference snap was taken, we have to wait out any * transactions that might have older snapshots. */ - WaitForOlderSnapshots(limitXmin, false); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_3); + WaitForOlderSnapshots(limitXmin, true); CommitTransactionCommand(); } @@ -3128,7 +3153,9 @@ ReindexRelationConcurrently(Oid relationOid, int options) * index_drop() for more details. */ - WaitForLockersMultiple(lockTags, AccessExclusiveLock, false); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_4); + WaitForLockersMultiple(lockTags, AccessExclusiveLock, true); foreach(lc, indexIds) { @@ -3150,7 +3177,9 @@ ReindexRelationConcurrently(Oid relationOid, int options) * Drop the old indexes. */ - WaitForLockersMultiple(lockTags, AccessExclusiveLock, false); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_4); + WaitForLockersMultiple(lockTags, AccessExclusiveLock, true); PushActiveSnapshot(GetTransactionSnapshot()); @@ -3225,6 +3254,8 @@ ReindexRelationConcurrently(Oid relationOid, int options) MemoryContextDelete(private_context); + pgstat_progress_end_command(); + return true; } |