From c880096dc1e14b62610aa34bc98db226fa134260 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 4 Jun 2019 09:16:02 +0200 Subject: [PATCH] Add command column to pg_stat_progress_create_index This allows determining which command is running, similar to pg_stat_progress_cluster. Discussion: https://www.postgresql.org/message-id/flat/f0e56b3b-74b7-6cbc-e207-a5ed6bee18dc%402ndquadrant.com --- doc/src/sgml/monitoring.sgml | 11 ++++++++++- src/backend/catalog/index.c | 2 ++ src/backend/catalog/system_views.sql | 5 +++++ src/backend/commands/indexcmds.c | 8 ++++++++ src/include/catalog/catversion.h | 2 +- src/include/commands/progress.h | 7 +++++++ src/test/regress/expected/rules.out | 7 +++++++ 7 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 570ac5e06f..bf72d0c303 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -3534,6 +3534,15 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, OID of the index being created or reindexed. During a non-concurrent CREATE INDEX, this is 0. + + command + text + + The command that is running: CREATE INDEX, + CREATE INDEX CONCURRENTLY, + REINDEX, or REINDEX CONCURRENTLY. + + phase text @@ -3965,7 +3974,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, command text - The command that is running. Either CLUSTER or VACUUM FULL. + The command that is running. Either CLUSTER or VACUUM FULL. diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 50c8bb9ce6..d2e4f53a80 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3278,6 +3278,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, heapId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, + PROGRESS_CREATEIDX_COMMAND_REINDEX); pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, indexId); diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 52a6c31584..78a103cdb9 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -956,6 +956,11 @@ CREATE VIEW pg_stat_progress_create_index AS 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.param1 WHEN 1 THEN 'CREATE INDEX' + WHEN 2 THEN 'CREATE INDEX CONCURRENTLY' + WHEN 3 THEN 'REINDEX' + WHEN 4 THEN 'REINDEX CONCURRENTLY' + END AS command, CASE S.param10 WHEN 0 THEN 'initializing' WHEN 1 THEN 'waiting for writers before build' WHEN 2 THEN 'building index' || diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 40ea629ffe..4d76da8293 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -498,8 +498,14 @@ DefineIndex(Oid relationId, * done. */ if (!OidIsValid(parentIndexId)) + { pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, relationId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, + stmt->concurrent ? + PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY : + PROGRESS_CREATEIDX_COMMAND_CREATE); + } /* * No index OID to report yet @@ -2923,6 +2929,8 @@ ReindexRelationConcurrently(Oid relationOid, int options) pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, RelationGetRelid(heapRel)); + pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, + PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY); pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, indexId); pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 468aec3890..4b8ee1cbdb 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201906031 +#define CATALOG_VERSION_NO 201906041 #endif diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 37043e926d..acd1313cb3 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -59,6 +59,7 @@ /* Progress parameters for CREATE INDEX */ /* 3, 4 and 5 reserved for "waitfor" metrics */ +#define PROGRESS_CREATEIDX_COMMAND 0 #define PROGRESS_CREATEIDX_INDEX_OID 6 #define PROGRESS_CREATEIDX_ACCESS_METHOD_OID 8 #define PROGRESS_CREATEIDX_PHASE 9 /* AM-agnostic phase # */ @@ -86,6 +87,12 @@ #define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE 1 /* Additional phases are defined by each AM */ +/* Commands of PROGRESS_CREATEIDX */ +#define PROGRESS_CREATEIDX_COMMAND_CREATE 1 +#define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY 2 +#define PROGRESS_CREATEIDX_COMMAND_REINDEX 3 +#define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY 4 + /* Lock holder wait counts */ #define PROGRESS_WAITFOR_TOTAL 3 #define PROGRESS_WAITFOR_DONE 4 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 4363ca1663..7d365c48d1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1879,6 +1879,13 @@ pg_stat_progress_create_index| SELECT s.pid, d.datname, s.relid, (s.param7)::oid AS index_relid, + CASE s.param1 + WHEN 1 THEN 'CREATE INDEX'::text + WHEN 2 THEN 'CREATE INDEX CONCURRENTLY'::text + WHEN 3 THEN 'REINDEX'::text + WHEN 4 THEN 'REINDEX CONCURRENTLY'::text + ELSE NULL::text + END AS command, CASE s.param10 WHEN 0 THEN 'initializing'::text WHEN 1 THEN 'waiting for writers before build'::text -- 2.40.0