public inbox for [email protected]help / color / mirror / Atom feed
[PATCH v8 3/8] f! progress reporting.. 73+ messages / 3 participants [nested] [flat]
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v10 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 56018745c8..28493c7931 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6293,6 +6293,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 5f2541d316..0256809f06 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1142,7 +1142,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 662aff04b4..1d8a7ca774 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index c6b139d57d..d85781ae0b 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 9b59a7b4a5..a8bcc599ac 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --mvpLiMfbWzRoNl4x Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v10-0004-Propagate-changes-to-indisclustered-to-child-par.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v9 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- doc/src/sgml/monitoring.sgml | 21 +++++++++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 55 ++++++++++++++++------------ src/backend/commands/vacuum.c | 5 +++ src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 3513e127b7..dca47f6a48 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -6231,6 +6231,27 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid, is <literal>rebuilding index</literal>. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>total_partitions</structfield> <type>bigint</type> + </para> + When clustering a partitioned table, this column is set to the total + number of partitions to be clustered. + <para> + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>done_partitions</structfield> <type>bigint</type> + </para> + <para> + When clustering a partitioned table, this column is set to the number + of partitions which have been clustered. + </para></entry> + </row> + </tbody> </tgroup> </table> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fc94a73a54..21c27f0437 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1070,7 +1070,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0c08ac56dc..7d8d1d8a69 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,26 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { /* Do the job. */ + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[2] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +216,15 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report command and number of partitions */ + progress_val[0] = PROGRESS_CLUSTER_COMMAND_CLUSTER; + /* XXX: rvs includes the parent, which is not a "partition" */ + progress_val[1] = list_length(rvs); + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +263,11 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_CLUSTER); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +304,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +314,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +330,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +344,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +355,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +365,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +423,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +430,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +445,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1632,9 +1635,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1657,6 +1661,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + ++childnum); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c064352e23..05d52858b1 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -37,6 +37,7 @@ #include "catalog/pg_namespace.h" #include "commands/cluster.h" #include "commands/defrem.h" +#include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -1937,7 +1938,11 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params) cluster_params.options |= CLUOPT_VERBOSE; /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, relid); + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); cluster_rel(relid, InvalidOid, &cluster_params); + pgstat_progress_end_command(); } else table_relation_vacuum(onerel, params, vac_strategy); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b1c9b7bdfe..c888415235 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1943,7 +1943,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --fmvA4kSBHQVZhkR6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v8 3/8] f! progress reporting.. @ 2021-02-09 02:45 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-09 02:45 UTC (permalink / raw) This follows the precedent of pg_stat_progress_create_index, which simultaneously shows the progress of 1) the leaf partition, and 2) the overall progress as partitions_done / partitions_total. This also includes current_child_index_relid, but the create_index view doesn't, so maybe this shouldn't, either. --- src/backend/catalog/system_views.sql | 4 +- src/backend/commands/cluster.c | 64 +++++++++++++++++----------- src/include/commands/progress.h | 3 ++ src/test/regress/expected/rules.out | 4 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index fa58afd9d7..9a3cb5f935 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1069,7 +1069,9 @@ CREATE VIEW pg_stat_progress_cluster AS S.param5 AS heap_tuples_written, S.param6 AS heap_blks_total, S.param7 AS heap_blks_scanned, - S.param8 AS index_rebuild_count + S.param8 AS index_rebuild_count, + S.param18 AS partitions_total, + S.param19 AS partitions_done FROM pg_stat_get_progress_info('CLUSTER') AS S LEFT JOIN pg_database D ON S.datid = D.oid; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 9b6673867c..cb4fc350c6 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -77,7 +77,7 @@ static void copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid); -static void cluster_multiple_rels(List *rvs, int options); +static void cluster_multiple_rels(List *rvs, int options, bool ispartitioned); /*--------------------------------------------------------------------------- @@ -188,16 +188,28 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) /* close relation, keep lock till commit */ table_close(rel, ShareUpdateExclusiveLock); + pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) { + pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, + OidIsValid(indexOid) ? PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); + /* Do the job. */ cluster_rel(tableOid, indexOid, ¶ms); + pgstat_progress_end_command(); } else { List *rvs; MemoryContext cluster_context; + int64 progress_val[2]; + const int progress_index[] = { + PROGRESS_CLUSTER_COMMAND, + PROGRESS_CLUSTER_PARTITIONS_TOTAL, + }; + /* Refuse to hold strong locks in a user transaction */ PreventInTransactionBlock(isTopLevel, "CLUSTER"); @@ -206,7 +218,20 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) ALLOCSET_DEFAULT_SIZES); rvs = get_tables_to_cluster_partitioned(cluster_context, indexOid); - cluster_multiple_rels(rvs, params.options); + + /* Report vacuum full or cluster and number of partitions */ + progress_val[0] = OidIsValid(indexOid) ? + PROGRESS_CLUSTER_COMMAND_CLUSTER : + PROGRESS_CLUSTER_COMMAND_VACUUM_FULL; + progress_val[1] = list_length(rvs); +// This is currently showing the total number of *tables*, including the +// parent, and intermediate partitions, so the column should be renamed, or +// we should count the number of leaf partitions + + pgstat_progress_update_multi_param(2, progress_index, progress_val); + + cluster_multiple_rels(rvs, params.options, true); + pgstat_progress_end_command(); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -245,7 +270,7 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) * cluster_context. */ rvs = get_tables_to_cluster(cluster_context); - cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED); + cluster_multiple_rels(rvs, params.options | CLUOPT_RECHECK_ISCLUSTERED, false); /* Start a new transaction for the cleanup work. */ StartTransactionCommand(); @@ -282,14 +307,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - pgstat_progress_start_command(PROGRESS_COMMAND_CLUSTER, tableOid); - if (OidIsValid(indexOid)) - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_CLUSTER); - else - pgstat_progress_update_param(PROGRESS_CLUSTER_COMMAND, - PROGRESS_CLUSTER_COMMAND_VACUUM_FULL); - /* * We grab exclusive access to the target rel and index for the duration * of the transaction. (This is redundant for the single-transaction @@ -300,10 +317,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) /* If the table has gone away, we can skip processing it */ if (!OldHeap) - { - pgstat_progress_end_command(); return; - } /* * Since we may open a new transaction for each relation, we have to check @@ -319,7 +333,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!pg_class_ownercheck(tableOid, GetUserId())) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -334,7 +347,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (RELATION_IS_OTHER_TEMP(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -346,7 +358,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(indexOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -357,7 +368,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !get_index_isclustered(indexOid)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } } @@ -416,7 +426,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) !RelationIsPopulated(OldHeap)) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -424,7 +433,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (!RELKIND_HAS_STORAGE(get_rel_relkind(tableOid))) { relation_close(OldHeap, AccessExclusiveLock); - pgstat_progress_end_command(); return; } @@ -440,8 +448,6 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) rebuild_relation(OldHeap, indexOid, verbose); /* NB: rebuild_relation does table_close() on OldHeap */ - - pgstat_progress_end_command(); } /* @@ -1366,7 +1372,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, ReindexParams reindex_params = {0}; int i; - /* Report that we are now swapping relation files */ + /* Report that we are now swapping relation files XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES); @@ -1417,13 +1423,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, else if (newrelpersistence == RELPERSISTENCE_PERMANENT) reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT; - /* Report that we are now reindexing relations */ + /* Report that we are now reindexing relations XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX); reindex_relation(OIDOldHeap, reindex_flags, &reindex_params); - /* Report that we are now doing clean up */ + /* Report that we are now doing clean up XXX */ pgstat_progress_update_param(PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP); @@ -1633,9 +1639,10 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) /* Cluster each relation in a separate transaction */ static void -cluster_multiple_rels(List *rvs, int options) +cluster_multiple_rels(List *rvs, int options, bool ispartitioned) { ListCell *lc; + off_t childnum = 0; /* Commit to get out of starting transaction */ PopActiveSnapshot(); @@ -1658,6 +1665,11 @@ cluster_multiple_rels(List *rvs, int options) cluster_rel(rvtc->tableOid, rvtc->indexOid, &cluster_params); + if (ispartitioned) + pgstat_progress_update_param(PROGRESS_CLUSTER_PARTITIONS_DONE, + childnum++); + + PopActiveSnapshot(); CommitTransactionCommand(); } diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..13499a3e72 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -60,6 +60,9 @@ #define PROGRESS_CLUSTER_TOTAL_HEAP_BLKS 5 #define PROGRESS_CLUSTER_HEAP_BLKS_SCANNED 6 #define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT 7 +/* Need to avoid the CREATE INDEX params */ +#define PROGRESS_CLUSTER_PARTITIONS_TOTAL 17 +#define PROGRESS_CLUSTER_PARTITIONS_DONE 18 /* Phases of cluster (as advertised via PROGRESS_CLUSTER_PHASE) */ #define PROGRESS_CLUSTER_PHASE_SEQ_SCAN_HEAP 1 diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index b632d9f2ea..d1fea532bc 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1941,7 +1941,9 @@ pg_stat_progress_cluster| SELECT s.pid, s.param5 AS heap_tuples_written, s.param6 AS heap_blks_total, s.param7 AS heap_blks_scanned, - s.param8 AS index_rebuild_count + s.param8 AS index_rebuild_count, + s.param18 AS partitions_total, + s.param19 AS partitions_done FROM (pg_stat_get_progress_info('CLUSTER'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) LEFT JOIN pg_database d ON ((s.datid = d.oid))); pg_stat_progress_copy| SELECT s.pid, -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0004-Propagate-changes-to-indisclustered-to-child-pare.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH v13 02/18] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 4ac1dacd7d..d6567ec231 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1638,40 +1638,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1680,6 +1660,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --QTprm0S8XgL7H0Dt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* [PATCH 2/5] f! progress reporting @ 2021-02-15 00:31 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Justin Pryzby @ 2021-02-15 00:31 UTC (permalink / raw) --- src/backend/commands/indexcmds.c | 33 +++++++------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 9ab1a66971..8f4eab22eb 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1647,40 +1647,20 @@ reindex_invalid_child_indexes(Oid indexRelationId) .options = REINDEXOPT_CONCURRENTLY }; - MemoryContext ind_context = AllocSetContextCreate(PortalContext, "CREATE INDEX", - ALLOCSET_DEFAULT_SIZES); - MemoryContext oldcontext; - List *childs = find_inheritance_children(indexRelationId, ShareLock); - List *partitions = NIL; - PreventInTransactionBlock(true, "REINDEX INDEX"); - foreach (lc, childs) + foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) { Oid partoid = lfirst_oid(lc); - /* XXX: need to retrofit progress reporting into it */ - // pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - // npart++); - - if (get_index_isvalid(partoid) || - !RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - continue; + if (!get_index_isvalid(partoid) && + RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) + ReindexRelationConcurrently(partoid, ¶ms); - /* Save partition OID */ - oldcontext = MemoryContextSwitchTo(ind_context); - partitions = lappend_oid(partitions, partoid); - MemoryContextSwitchTo(oldcontext); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, + npart++); } - /* - * Process each partition listed in a separate transaction. Note that - * this commits and then starts a new transaction immediately. - * XXX: since this is done in 2*N transactions, it could just as well - * call ReindexRelationConcurrently directly - */ - ReindexMultipleInternal(partitions, ¶ms); - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though @@ -1689,6 +1669,7 @@ reindex_invalid_child_indexes(Oid indexRelationId) * partitions. * See also: validatePartitionedIndex(). */ + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); -- 2.17.0 --dTy3Mrz/UPE2dbVg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0003-WIP-Add-SKIPVALID-flag-for-more-integration.patch" ^ permalink raw reply [nested|flat] 73+ messages in thread
* Re: logical replication empty transactions @ 2022-01-11 09:43 Ajin Cherian <[email protected]> 2022-01-26 13:16 ` RE: logical replication empty transactions [email protected] <[email protected]> 0 siblings, 1 reply; 73+ messages in thread From: Ajin Cherian @ 2022-01-11 09:43 UTC (permalink / raw) To: Peter Smith <[email protected]>; +Cc: Amit Kapila <[email protected]>; [email protected] <[email protected]>; vignesh C <[email protected]>; Michael Paquier <[email protected]>; Rahila Syed <[email protected]>; Euler Taveira <[email protected]>; Dilip Kumar <[email protected]>; Jeff Janes <[email protected]>; pgsql-hackers; Craig Ringer <[email protected]> On Wed, Sep 1, 2021 at 8:57 PM Ajin Cherian <[email protected]> wrote: > > Thanks for the comments. Addressed them in the attached patch. > > regards, > Ajin Cherian > Fujitsu Australia Minor update to rebase the patch so that it applies clean on HEAD. regards, Ajin Cherian regards, Ajin Cherian Attachments: [application/octet-stream] v16-0001-Skip-empty-transactions-for-logical-replication.patch (16.7K, ../../CAFPTHDb71G96ngCOtphPwC8pcLRhHvvJaODSeiz6+1oSFsHmsA@mail.gmail.com/2-v16-0001-Skip-empty-transactions-for-logical-replication.patch) download | inline diff: From 858fc8976c5099f4833aebc54f8337e78fdb6222 Mon Sep 17 00:00:00 2001 From: Ajin Cherian <[email protected]> Date: Tue, 11 Jan 2022 04:35:09 -0500 Subject: [PATCH v16] Skip empty transactions for logical replication. The current logical replication behavior is to send every transaction to subscriber even though the transaction is empty (because it does not contain changes from the selected publications). It is a waste of CPU cycles and network bandwidth to build/transmit these empty transactions. This patch addresses the above problem by postponing the BEGIN message until the first change. While processing a COMMIT message, if there is no other change for that transaction, do not send COMMIT message. It means that pgoutput will skip BEGIN / COMMIT messages for transactions that are empty. The patch also makes sure that in synchronous replication mode, when skipping empty transactions, keepalive messages are sent to keep the LSN locations updated on the standby. This patch does not skip empty transactions that are "streaming" or "two-phase". Discussion: https://postgr.es/m/CAMkU=1yohp9-dv48FLoSPrMqYEyyS5ZWkaZGD41RJr10xiNo_Q@mail.gmail.com --- src/backend/replication/logical/logical.c | 4 +- src/backend/replication/pgoutput/pgoutput.c | 105 ++++++++++++++++++++++++++-- src/backend/replication/syncrep.c | 12 +++- src/backend/replication/walsender.c | 22 ++++-- src/include/replication/logical.h | 3 +- src/include/replication/output_plugin.h | 2 +- src/include/replication/syncrep.h | 1 + src/test/subscription/t/020_messages.pl | 5 +- src/tools/pgindent/typedefs.list | 1 + 9 files changed, 135 insertions(+), 20 deletions(-) diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 9bc3a2d..fb1c26a 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -672,12 +672,12 @@ OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write) * Update progress tracking (if supported). */ void -OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx) +OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool send_keepalive) { if (!ctx->update_progress) return; - ctx->update_progress(ctx, ctx->write_location, ctx->write_xid); + ctx->update_progress(ctx, ctx->write_location, ctx->write_xid, send_keepalive); } /* diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index af8d51a..75296a8 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -132,6 +132,17 @@ typedef struct RelationSyncEntry TupleConversionMap *map; } RelationSyncEntry; +/* + * Maintain a per-transaction level variable to track whether the + * transaction has sent BEGIN. BEGIN is only sent when the first + * change in a transaction is processed. This makes it possible + * to skip transactions that are empty. + */ +typedef struct PGOutputTxnData +{ + bool sent_begin_txn; /* flag indicating whether begin has been sent */ +} PGOutputTxnData; + /* Map used to remember which relation schemas we sent. */ static HTAB *RelationSyncCache = NULL; @@ -396,15 +407,40 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt, } /* - * BEGIN callback + * BEGIN callback. + * + * Don't send BEGIN message here. Instead, postpone it until the first + * change. In logical replication, a common scenario is to replicate a set + * of tables (instead of all tables) and transactions whose changes were on + * table(s) that are not published will produce empty transactions. These + * empty transactions will send BEGIN and COMMIT messages to subscribers, + * using bandwidth on something with little/no use for logical replication. */ static void pgoutput_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) { + PGOutputTxnData *txndata = MemoryContextAllocZero(ctx->context, + sizeof(PGOutputTxnData)); + + txndata->sent_begin_txn = false; + txn->output_plugin_private = txndata; +} + +/* + * Send BEGIN. + * This is where the BEGIN is actually sent. This is called + * while processing the first change of the transaction. + */ +static void +pgoutput_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) +{ bool send_replication_origin = txn->origin_id != InvalidRepOriginId; + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + Assert(txndata); OutputPluginPrepareWrite(ctx, !send_replication_origin); logicalrep_write_begin(ctx->out, txn); + txndata->sent_begin_txn = true; send_repl_origin(ctx, txn->origin_id, txn->origin_lsn, send_replication_origin); @@ -419,7 +455,25 @@ static void pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn) { - OutputPluginUpdateProgress(ctx); + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + bool skip; + + Assert(txndata); + + /* + * If a BEGIN message was not yet sent, then it means there were no relevant + * changes encountered, so we can skip the COMMIT message too. + */ + skip = !txndata->sent_begin_txn; + pfree(txndata); + txn->output_plugin_private = NULL; + OutputPluginUpdateProgress(ctx, skip); + + if (skip) + { + elog(DEBUG1, "skipping replication of an empty transaction"); + return; + } OutputPluginPrepareWrite(ctx, true); logicalrep_write_commit(ctx->out, txn, commit_lsn); @@ -433,6 +487,8 @@ static void pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) { bool send_replication_origin = txn->origin_id != InvalidRepOriginId; + PGOutputTxnData *txndata = MemoryContextAllocZero(ctx->context, + sizeof(PGOutputTxnData)); OutputPluginPrepareWrite(ctx, !send_replication_origin); logicalrep_write_begin_prepare(ctx->out, txn); @@ -441,6 +497,8 @@ pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) send_replication_origin); OutputPluginWrite(ctx, true); + txndata->sent_begin_txn = true; + txn->output_plugin_private = txndata; } /* @@ -450,7 +508,7 @@ static void pgoutput_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn) { - OutputPluginUpdateProgress(ctx); + OutputPluginUpdateProgress(ctx, false); OutputPluginPrepareWrite(ctx, true); logicalrep_write_prepare(ctx->out, txn, prepare_lsn); @@ -464,7 +522,7 @@ static void pgoutput_commit_prepared_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn) { - OutputPluginUpdateProgress(ctx); + OutputPluginUpdateProgress(ctx, false); OutputPluginPrepareWrite(ctx, true); logicalrep_write_commit_prepared(ctx->out, txn, commit_lsn); @@ -480,7 +538,7 @@ pgoutput_rollback_prepared_txn(LogicalDecodingContext *ctx, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time) { - OutputPluginUpdateProgress(ctx); + OutputPluginUpdateProgress(ctx, false); OutputPluginPrepareWrite(ctx, true); logicalrep_write_rollback_prepared(ctx->out, txn, prepare_end_lsn, @@ -630,11 +688,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change) { PGOutputData *data = (PGOutputData *) ctx->output_plugin_private; + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; MemoryContext old; RelationSyncEntry *relentry; TransactionId xid = InvalidTransactionId; Relation ancestor = NULL; + /* If not streaming, should have setup txndata as part of BEGIN/BEGIN PREPARE */ + Assert(in_streaming || txndata); + if (!is_publishable_relation(relation)) return; @@ -668,6 +730,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Assert(false); } + /* + * Output BEGIN if we haven't yet, unless streaming. + */ + if (!in_streaming && !txndata->sent_begin_txn) + pgoutput_begin(ctx, txn); + /* Avoid leaking memory by using and resetting our own context */ old = MemoryContextSwitchTo(data->context); @@ -770,6 +838,7 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change) { PGOutputData *data = (PGOutputData *) ctx->output_plugin_private; + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; MemoryContext old; RelationSyncEntry *relentry; int i; @@ -777,6 +846,9 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Oid *relids; TransactionId xid = InvalidTransactionId; + /* If not streaming, should have setup txndata as part of BEGIN/BEGIN PREPARE */ + Assert(in_streaming || txndata); + /* Remember the xid for the change in streaming mode. See pgoutput_change. */ if (in_streaming) xid = change->txn->xid; @@ -813,6 +885,12 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (nrelids > 0) { + /* + * output BEGIN if we haven't yet, unless streaming. + */ + if (!in_streaming && !txndata->sent_begin_txn) + pgoutput_begin(ctx, txn); + OutputPluginPrepareWrite(ctx, true); logicalrep_write_truncate(ctx->out, xid, @@ -845,6 +923,19 @@ pgoutput_message(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (in_streaming) xid = txn->xid; + /* + * Output BEGIN if we haven't yet. + * Avoid for streaming and non-transactional messages + */ + if (!in_streaming && transactional) + { + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + + Assert(txndata); + if (!txndata->sent_begin_txn) + pgoutput_begin(ctx, txn); + } + OutputPluginPrepareWrite(ctx, true); logicalrep_write_message(ctx->out, xid, @@ -1011,7 +1102,7 @@ pgoutput_stream_commit(struct LogicalDecodingContext *ctx, Assert(!in_streaming); Assert(rbtxn_is_streamed(txn)); - OutputPluginUpdateProgress(ctx); + OutputPluginUpdateProgress(ctx, false); OutputPluginPrepareWrite(ctx, true); logicalrep_write_stream_commit(ctx->out, txn, commit_lsn); @@ -1032,7 +1123,7 @@ pgoutput_stream_prepare_txn(LogicalDecodingContext *ctx, { Assert(rbtxn_is_streamed(txn)); - OutputPluginUpdateProgress(ctx); + OutputPluginUpdateProgress(ctx, false); OutputPluginPrepareWrite(ctx, true); logicalrep_write_stream_prepare(ctx->out, txn, prepare_lsn); OutputPluginWrite(ctx, true); diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c index ce163b9..b945165 100644 --- a/src/backend/replication/syncrep.c +++ b/src/backend/replication/syncrep.c @@ -171,8 +171,7 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit) * described in SyncRepUpdateSyncStandbysDefined(). On the other hand, if * it's false, the lock is not necessary because we don't touch the queue. */ - if (!SyncRepRequested() || - !((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_defined) + if (!SyncRepEnabled()) return; /* Cap the level for anything other than commit to remote flush only. */ @@ -330,6 +329,15 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit) } /* + * Check if Synchronous Replication is enabled + */ +bool +SyncRepEnabled(void) +{ + return SyncRepRequested() && ((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_defined; +} + +/* * Insert MyProc into the specified SyncRepQueue, maintaining sorted invariant. * * Usually we will go at tail of queue, though it's possible that we arrive diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 4cf95ce..43a480f 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -170,6 +170,9 @@ static TimestampTz last_reply_timestamp = 0; /* Have we sent a heartbeat message asking for reply, since last reply? */ static bool waiting_for_ping_response = false; +/* Force keep alive when skipping transactions in synchronous replication mode */ +static bool force_keepalive_syncrep = false; + /* * While streaming WAL in Copy mode, streamingDoneSending is set to true * after we have sent CopyDone. We should not send any more CopyData messages @@ -248,7 +251,8 @@ static long WalSndComputeSleeptime(TimestampTz now); static void WalSndWait(uint32 socket_events, long timeout, uint32 wait_event); static void WalSndPrepareWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, bool last_write); static void WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, bool last_write); -static void WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid); +static void WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, + bool send_keepalive); static XLogRecPtr WalSndWaitForWal(XLogRecPtr loc); static void LagTrackerWrite(XLogRecPtr lsn, TimestampTz local_flush_time); static TimeOffset LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now); @@ -1448,12 +1452,19 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, * Write the current position to the lag tracker (see XLogSendPhysical). */ static void -WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid) +WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, + bool send_keepalive) { static TimestampTz sendTime = 0; TimestampTz now = GetCurrentTimestamp(); /* + * When skipping empty transactions in synchronous replication, we need + * to send a keep alive to keep the MyWalSnd locations updated. + */ + force_keepalive_syncrep = send_keepalive && SyncRepEnabled(); + + /* * Track lag no more than once per WALSND_LOGICAL_LAG_TRACK_INTERVAL_MS to * avoid flooding the lag tracker when we commit frequently. */ @@ -1546,10 +1557,13 @@ WalSndWaitForWal(XLogRecPtr loc) * otherwise idle, this keepalive will trigger a reply. Processing the * reply will update these MyWalSnd locations. */ - if (MyWalSnd->flush < sentPtr && + if (force_keepalive_syncrep || + (MyWalSnd->flush < sentPtr && MyWalSnd->write < sentPtr && - !waiting_for_ping_response) + !waiting_for_ping_response)) + { WalSndKeepalive(false); + } /* check whether we're done */ if (loc <= RecentFlushPtr) diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h index 1097cc9..9f59855 100644 --- a/src/include/replication/logical.h +++ b/src/include/replication/logical.h @@ -26,7 +26,8 @@ typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite; typedef void (*LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, - TransactionId xid + TransactionId xid, + bool send_keepalive ); typedef struct LogicalDecodingContext diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h index 41157fd..6f84614 100644 --- a/src/include/replication/output_plugin.h +++ b/src/include/replication/output_plugin.h @@ -243,6 +243,6 @@ typedef struct OutputPluginCallbacks /* Functions in replication/logical/logical.c */ extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write); extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write); -extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx); +extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool send_keepalive); #endif /* OUTPUT_PLUGIN_H */ diff --git a/src/include/replication/syncrep.h b/src/include/replication/syncrep.h index 27be230..7086532 100644 --- a/src/include/replication/syncrep.h +++ b/src/include/replication/syncrep.h @@ -90,6 +90,7 @@ extern void SyncRepCleanupAtProcExit(void); /* called by wal sender */ extern void SyncRepInitConfig(void); extern void SyncRepReleaseWaiters(void); +extern bool SyncRepEnabled(void); /* called by wal sender and user backend */ extern int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys); diff --git a/src/test/subscription/t/020_messages.pl b/src/test/subscription/t/020_messages.pl index 9bb31ce..1d52e47 100644 --- a/src/test/subscription/t/020_messages.pl +++ b/src/test/subscription/t/020_messages.pl @@ -87,9 +87,8 @@ $result = $node_publisher->safe_psql( 'publication_names', 'tap_pub') )); -# 66 67 == B C == BEGIN COMMIT -is( $result, qq(66 -67), +# no message and no BEGIN and COMMIT because of empty transaction optimization +is($result, qq(), 'option messages defaults to false so message (M) is not available on slot' ); diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 5015fa7..c407d54 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -1607,6 +1607,7 @@ PGMessageField PGModuleMagicFunction PGNoticeHooks PGOutputData +PGOutputTxnData PGPROC PGP_CFB PGP_Context -- 1.8.3.1 ^ permalink raw reply [nested|flat] 73+ messages in thread
* RE: logical replication empty transactions 2022-01-11 09:43 Re: logical replication empty transactions Ajin Cherian <[email protected]> @ 2022-01-26 13:16 ` [email protected] <[email protected]> 2022-01-27 13:04 ` Re: logical replication empty transactions Ajin Cherian <[email protected]> 0 siblings, 1 reply; 73+ messages in thread From: [email protected] @ 2022-01-26 13:16 UTC (permalink / raw) To: 'Ajin Cherian' <[email protected]>; Peter Smith <[email protected]>; +Cc: Amit Kapila <[email protected]>; vignesh C <[email protected]>; Michael Paquier <[email protected]>; Rahila Syed <[email protected]>; Euler Taveira <[email protected]>; Dilip Kumar <[email protected]>; Jeff Janes <[email protected]>; pgsql-hackers; Craig Ringer <[email protected]> On Tuesday, January 11, 2022 6:43 PM From: Ajin Cherian <[email protected]> wrote: > Minor update to rebase the patch so that it applies clean on HEAD. Hi, let me share some additional comments on v16. (1) comment of pgoutput_change @@ -630,11 +688,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change) { PGOutputData *data = (PGOutputData *) ctx->output_plugin_private; + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; MemoryContext old; RelationSyncEntry *relentry; TransactionId xid = InvalidTransactionId; Relation ancestor = NULL; + /* If not streaming, should have setup txndata as part of BEGIN/BEGIN PREPARE */ + Assert(in_streaming || txndata); + In my humble opinion, the comment should not touch BEGIN PREPARE, because this patch's scope doesn't include two phase commit. (We could add this in another patch to extend the scope after the commit ?) This applies to pgoutput_truncate's comment. (2) "keep alive" should be "keepalive" in WalSndUpdateProgress /* + * When skipping empty transactions in synchronous replication, we need + * to send a keep alive to keep the MyWalSnd locations updated. + */ + force_keepalive_syncrep = send_keepalive && SyncRepEnabled(); + Also, this applies to the comment for force_keepalive_syncrep. (3) Should finish the second sentence with period in the comment of pgoutput_message. @@ -845,6 +923,19 @@ pgoutput_message(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (in_streaming) xid = txn->xid; + /* + * Output BEGIN if we haven't yet. + * Avoid for streaming and non-transactional messages (4) "begin" can be changed to "BEGIN" in the comment of PGOutputTxnData definition. In the entire patch, when we express BEGIN message, we use capital letters "BEGIN" except for one place. We can apply the same to this place as well. +typedef struct PGOutputTxnData +{ + bool sent_begin_txn; /* flag indicating whether begin has been sent */ +} PGOutputTxnData; + (5) inconsistent way to write Assert statements with blank lines In the below case, it'd be better to insert one blank line after the Assert(); +static void +pgoutput_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) +{ bool send_replication_origin = txn->origin_id != InvalidRepOriginId; + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + Assert(txndata); OutputPluginPrepareWrite(ctx, !send_replication_origin); (6) new codes in the pgoutput_commit_txn looks messy slightly @@ -419,7 +455,25 @@ static void pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn) { - OutputPluginUpdateProgress(ctx); + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + bool skip; + + Assert(txndata); + + /* + * If a BEGIN message was not yet sent, then it means there were no relevant + * changes encountered, so we can skip the COMMIT message too. + */ + skip = !txndata->sent_begin_txn; + pfree(txndata); + txn->output_plugin_private = NULL; + OutputPluginUpdateProgress(ctx, skip); Could we conduct a refactoring for this new part ? IMO, writing codes to free the data structure at the top of function seems weird. One idea is to export some part there and write a new function, something like below. static bool txn_sent_begin(ReorderBufferTXN *txn) { PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; bool needs_skip; Assert(txndata); needs_skip = !txndata->sent_begin_txn; pfree(txndata); txn->output_plugin_private = NULL; return needs_skip; } FYI, I had a look at the v12-0002-Skip-empty-prepared-transactions-for-logical-rep.patch for reference of pgoutput_rollback_prepared_txn and pgoutput_commit_prepared_txn. Looks this kind of function might work for future extensions as well. What did you think ? Best Regards, Takamichi Osumi ^ permalink raw reply [nested|flat] 73+ messages in thread
* Re: logical replication empty transactions 2022-01-11 09:43 Re: logical replication empty transactions Ajin Cherian <[email protected]> 2022-01-26 13:16 ` RE: logical replication empty transactions [email protected] <[email protected]> @ 2022-01-27 13:04 ` Ajin Cherian <[email protected]> 0 siblings, 0 replies; 73+ messages in thread From: Ajin Cherian @ 2022-01-27 13:04 UTC (permalink / raw) To: [email protected] <[email protected]>; +Cc: Peter Smith <[email protected]>; Amit Kapila <[email protected]>; vignesh C <[email protected]>; Michael Paquier <[email protected]>; Rahila Syed <[email protected]>; Euler Taveira <[email protected]>; Dilip Kumar <[email protected]>; Jeff Janes <[email protected]>; pgsql-hackers; Craig Ringer <[email protected]> On Thu, Jan 27, 2022 at 12:16 AM [email protected] <[email protected]> wrote: > > On Tuesday, January 11, 2022 6:43 PM From: Ajin Cherian <[email protected]> wrote: > > Minor update to rebase the patch so that it applies clean on HEAD. > Hi, let me share some additional comments on v16. > > > (1) comment of pgoutput_change > > @@ -630,11 +688,15 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, > Relation relation, ReorderBufferChange *change) > { > PGOutputData *data = (PGOutputData *) ctx->output_plugin_private; > + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; > MemoryContext old; > RelationSyncEntry *relentry; > TransactionId xid = InvalidTransactionId; > Relation ancestor = NULL; > > + /* If not streaming, should have setup txndata as part of BEGIN/BEGIN PREPARE */ > + Assert(in_streaming || txndata); > + > > In my humble opinion, the comment should not touch BEGIN PREPARE, > because this patch's scope doesn't include two phase commit. > (We could add this in another patch to extend the scope after the commit ?) > We have to include BEGIN PREPARE as well, as the txndata has to be setup. Only difference is that we will not skip empty transaction in BEGIN PREPARE > This applies to pgoutput_truncate's comment. > > (2) "keep alive" should be "keepalive" in WalSndUpdateProgress > > /* > + * When skipping empty transactions in synchronous replication, we need > + * to send a keep alive to keep the MyWalSnd locations updated. > + */ > + force_keepalive_syncrep = send_keepalive && SyncRepEnabled(); > + > > Also, this applies to the comment for force_keepalive_syncrep. Fixed. > > (3) Should finish the second sentence with period in the comment of pgoutput_message. > > @@ -845,6 +923,19 @@ pgoutput_message(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, > if (in_streaming) > xid = txn->xid; > > + /* > + * Output BEGIN if we haven't yet. > + * Avoid for streaming and non-transactional messages > Fixed. > (4) "begin" can be changed to "BEGIN" in the comment of PGOutputTxnData definition. > > In the entire patch, when we express BEGIN message, > we use capital letters "BEGIN" except for one place. > We can apply the same to this place as well. > > +typedef struct PGOutputTxnData > +{ > + bool sent_begin_txn; /* flag indicating whether begin has been sent */ > +} PGOutputTxnData; > + > Fixed. > (5) inconsistent way to write Assert statements with blank lines > > In the below case, it'd be better to insert one blank line > after the Assert(); > > +static void > +pgoutput_begin(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) > +{ > bool send_replication_origin = txn->origin_id != InvalidRepOriginId; > + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; > > + Assert(txndata); > OutputPluginPrepareWrite(ctx, !send_replication_origin); > > Fixed. > (6) new codes in the pgoutput_commit_txn looks messy slightly > > @@ -419,7 +455,25 @@ static void > pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, > XLogRecPtr commit_lsn) > { > - OutputPluginUpdateProgress(ctx); > + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; > + bool skip; > + > + Assert(txndata); > + > + /* > + * If a BEGIN message was not yet sent, then it means there were no relevant > + * changes encountered, so we can skip the COMMIT message too. > + */ > + skip = !txndata->sent_begin_txn; > + pfree(txndata); > + txn->output_plugin_private = NULL; > + OutputPluginUpdateProgress(ctx, skip); > > Could we conduct a refactoring for this new part ? > IMO, writing codes to free the data structure at the top > of function seems weird. > > One idea is to export some part there > and write a new function, something like below. > > static bool > txn_sent_begin(ReorderBufferTXN *txn) > { > PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; > bool needs_skip; > > Assert(txndata); > > needs_skip = !txndata->sent_begin_txn; > > pfree(txndata); > txn->output_plugin_private = NULL; > > return needs_skip; > } > > FYI, I had a look at the v12-0002-Skip-empty-prepared-transactions-for-logical-rep.patch > for reference of pgoutput_rollback_prepared_txn and pgoutput_commit_prepared_txn. > Looks this kind of function might work for future extensions as well. > What did you think ? I changed a bit, but I'd hold a comprehensive rewrite when a future patch supports skipping empty transactions in two-phase transactions and streaming transactions. regards, Ajin Cherian ^ permalink raw reply [nested|flat] 73+ messages in thread
end of thread, other threads:[~2022-01-27 13:04 UTC | newest] Thread overview: 73+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v10 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v9 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-09 02:45 [PATCH v8 3/8] f! progress reporting.. Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH v13 02/18] f! progress reporting Justin Pryzby <[email protected]> 2021-02-15 00:31 [PATCH 2/5] f! progress reporting Justin Pryzby <[email protected]> 2022-01-11 09:43 Re: logical replication empty transactions Ajin Cherian <[email protected]> 2022-01-26 13:16 ` RE: logical replication empty transactions [email protected] <[email protected]> 2022-01-27 13:04 ` Re: logical replication empty transactions Ajin Cherian <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox