You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "Alena0704 (via GitHub)" <gi...@apache.org> on 2026/10/05 16:13:54 UTC

[PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Alena0704 opened a new pull request, #2079:
URL: https://github.com/apache/cloudberry/pull/2079

   ### What does this PR do?
   
   Make VACUUM work available to SQL so administrators can compare maintenance
   results across runs, relations and segments. Counter differences help find
   relations that consume most vacuum time, retain dead tuples, repeatedly
   lose visibility-map markings, or need aggressive maintenance.
   
   This [PR#2078](https://github.com/apache/cloudberry/pull/2078) includes the [instrumentation branch](https://github.com/open-gpdb/cloudberry/tree/vacuum_instrumentation_rel2)
   through a dedicated merge commit. The six following commits add reporting
   and the extension. [Review only this PR's additions](https://github.com/open-gpdb/cloudberry/compare/vacuum_instrumentation_rel2...vacuum_reporting_rel2).
   When targeting `REL_2_STABLE`, the full diff also contains the first PR
   until its commits are merged into that branch.
   
   - Accumulate tuple removal, remaining dead tuples, page work and freeze-age
     counts per relation and database. Keep index work out of database totals
     where the owning table already includes it.
   - Report AO row/column compaction, exact truncated bytes, remaining hidden
     tuples and the latest segment-file metadata count, including index work.
   - Count completed heap vacuums that entered wraparound failsafe and heap
     vacuums interrupted by ERROR, including cancellation.
   - Add the `vacuum_stats` extension with local `pg_stat_vacuum_*` views and
     coordinator/segment `gp_stat_vacuum_*` views identified by `gp_segment_id`.
     Expose work counters alongside timing and visibility-map statistics.
   - Add relation and database vacuum-statistics reset functions that preserve
     ordinary access counters, maintenance counts/timestamps and ANALYZE times.
   
   ### Type of Change
   
   - [x] New feature
   
   ### Impact
   
   Extended work counters require `track_vacuum_statistics = on` on the
   coordinator and segments, followed by a restart. The setting is off by
   default; disabled tracking omits storage for those counters. Timing,
   visibility-map clearings, failsafe and interruption counts follow
   `track_counts` independently of this setting.
   
   Install SQL access with `CREATE EXTENSION vacuum_stats`. All new functions
   and views belong to the extension; the system catalog and its version are
   unchanged. The saved statistics format changes, so older saved statistics
   are discarded on startup.
   
   Most values are cumulative observations, not current relation contents.
   `total_file_segs` is the latest AO snapshot. Summed segment time is accumulated
   work, not the wall-clock duration of a distributed VACUUM.
   
   ### Checklist
   - [x] Followed [contribution guide](https://cloudberry.apache.org/contribute/code)
   - [x] Requested review from [cloudberry committers](https://github.com/orgs/apache/teams/cloudberry-committers)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "Alena0704 (via GitHub) via commits" <co...@cloudberry.apache.org>.
Alena0704 commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4493558867


##########
contrib/vacuum_stats/vacuum_stats--1.0.sql:
##########
@@ -0,0 +1,607 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * contrib/vacuum_stats/vacuum_stats--1.0.sql
+ */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION vacuum_stats" to load this file. \quit
+
+--
+-- Per-relation accessor functions (tables and indexes).
+--
+CREATE FUNCTION pg_stat_get_vacuum_tuples_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_tuples_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_dead_tuples(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_dead_tuples'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_bytes_removed(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_bytes_removed'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_total_file_segs(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_total_file_segs'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_dead_pages(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_dead_pages'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_frozen(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_frozen'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_all_visible(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_all_visible'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_freeze_age_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_freeze_age_count'
+LANGUAGE C STABLE STRICT;
+
+--
+-- Per-database accessor functions.
+--
+CREATE FUNCTION pg_stat_get_db_vacuum_tuples_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_tuples_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_dead_tuples(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_dead_tuples'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_bytes_removed(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_bytes_removed'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_dead_pages(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_dead_pages'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_frozen(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_frozen'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_all_visible(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_all_visible'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_freeze_age_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_freeze_age_count'
+LANGUAGE C STABLE STRICT;
+
+-- Access to counters stored in ordinary relation and database statistics.
+CREATE FUNCTION pg_stat_get_frozen_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_frozen_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_visible_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_visible_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_vacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_vacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autovacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autovacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_vacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_vacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autovacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autovacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_analyze_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_analyze_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autoanalyze_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autoanalyze_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_vacuum_failsafe_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_failsafe_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_frozen_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_frozen_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_visible_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_visible_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_vacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_vacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_autovacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_autovacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_vacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_vacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_autovacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_autovacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_failsafe_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_failsafe_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_interrupt_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_interrupt_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+-- Local statistics, in milliseconds for timing columns.
+CREATE VIEW pg_stat_vacuum_tables AS
+    SELECT
+        c.oid AS relid,
+        n.nspname AS schemaname,
+        c.relname AS relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid) AS dead_pages,
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid) AS total_autovacuum_delay_time,
+        @extschema@.pg_stat_get_total_analyze_time(c.oid) AS total_analyze_time,
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid) AS total_autoanalyze_time,
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid) AS total_file_segs
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm');
+
+CREATE VIEW pg_stat_vacuum_indexes AS
+    SELECT
+        c.oid AS relid,
+        i.oid AS indexrelid,
+        n.nspname AS schemaname,
+        c.relname AS relname,
+        i.relname AS indexrelname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid) AS dead_pages,
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid) AS total_autovacuum_delay_time
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i';
+
+CREATE VIEW pg_stat_vacuum_database AS
+    SELECT
+        d.oid AS datid,
+        d.datname AS datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid) AS dead_pages,
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid) AS total_autovacuum_delay_time,
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid) AS vacuum_interrupt_count
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d;
+
+-- Cluster views execute on the coordinator and all segments. The bodies
+-- access catalogs directly because segment functions cannot scan local views.
+-- Utility sessions return their local rows once, without a segment branch.
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_tables() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        n.nspname,
+        c.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_analyze_time(c.oid),
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid),
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid)
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm')
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_tables() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        n.nspname,
+        c.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_analyze_time(c.oid),
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid),
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid)
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm')
+        AND pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_tables AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_tables() AS T
+        (gp_segment_id int,
+         relid oid,
+         schemaname name,
+         relname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         total_analyze_time double precision,
+         total_autoanalyze_time double precision,
+         total_file_segs int8)
+    UNION ALL
+    SELECT * FROM gp_stat_get_segment_vacuum_tables() AS T
+        (gp_segment_id int,
+         relid oid,
+         schemaname name,
+         relname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         total_analyze_time double precision,
+         total_autoanalyze_time double precision,
+         total_file_segs int8);
+
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_indexes() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        i.oid,
+        n.nspname,
+        c.relname,
+        i.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid)
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i'
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_indexes() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        i.oid,
+        n.nspname,
+        c.relname,
+        i.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid)
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i'
+        AND pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_indexes AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_indexes() AS T
+        (gp_segment_id int,
+         relid oid,
+         indexrelid oid,
+         schemaname name,
+         relname name,
+         indexrelname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision)
+    UNION ALL
+    SELECT * FROM gp_stat_get_segment_vacuum_indexes() AS T
+        (gp_segment_id int,
+         relid oid,
+         indexrelid oid,
+         schemaname name,
+         relname name,
+         indexrelname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision);
+
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_database() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        d.oid,
+        d.datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid),
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid)
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_database() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        d.oid,
+        d.datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid),
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid)
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d
+        WHERE pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_database AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_database() AS T
+        (gp_segment_id int,
+         datid oid,
+         datname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         vacuum_interrupt_count int8)
+    UNION ALL

Review Comment:
   Agreed, a common abstraction for this pattern would reduce duplication across extensions. It would need well-defined utility-mode behavior too. Let's consider it separately.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "tuhaihe (via GitHub) via commits" <co...@cloudberry.apache.org>.
tuhaihe commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4510937697


##########
contrib/vacuum_stats/README.md:
##########
@@ -0,0 +1,139 @@
+# vacuum_stats

Review Comment:
   If it's created by our community, we can also add a standard license header: https://github.com/apache/cloudberry/blob/e8afb9ab0c191467463d03c3f029eb71a58558d7/AGENTS.md.template#L1-L18



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "Alena0704 (via GitHub)" <gi...@apache.org>.
Alena0704 commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4366868670


##########
src/backend/commands/vacuum_ao.c:
##########
@@ -443,6 +519,10 @@ void
 ao_vacuum_rel(Relation rel, VacuumParams *params, BufferAccessStrategy bstrategy)
 {
 	static AOVacuumRelStats *vacrelstats = NULL;
+	instr_time	phasestart;
+	instr_time	phaseend;
+	int64		startdelaytime;
+
 	Assert(RelationStorageIsAO(rel));
 	Assert(params != NULL);

Review Comment:
   Thanks, confirmed. I’ve added the reset at the start of pre-cleanup and an isolation2 regression test covering cancellation for AO row storage and an injected error for AO column storage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "Alena0704 (via GitHub) via commits" <co...@cloudberry.apache.org>.
Alena0704 commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4589444315


##########
contrib/vacuum_stats/README.md:
##########
@@ -0,0 +1,139 @@
+# vacuum_stats

Review Comment:
   Fixed. Thank you)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "leborchuk (via GitHub) via commits" <co...@cloudberry.apache.org>.
leborchuk commented on PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#issuecomment-6762195844

   [cloudberry-pr2079-ocr.txt](https://github.com/user-attachments/files/34617753/cloudberry-pr2079-ocr.txt)
   
   Found some issues using OCR, PTAL, looks interesting


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "leborchuk (via GitHub) via commits" <co...@cloudberry.apache.org>.
leborchuk merged PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "tuhaihe (via GitHub) via commits" <co...@cloudberry.apache.org>.
tuhaihe commented on PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#issuecomment-6733590526

   Hey @Alena0704, once your GitHub is connected to Gitbox, you can merge this PR yourself.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "Alena0704 (via GitHub) via commits" <co...@cloudberry.apache.org>.
Alena0704 commented on PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#issuecomment-6924572501

   > [cloudberry-pr2079-ocr.txt](https://github.com/user-attachments/files/34617753/cloudberry-pr2079-ocr.txt)
   > 
   > Found some issues using OCR, PTAL, looks interesting
   
   Agree and fixed it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "Smyatkin-Maxim (via GitHub) via commits" <co...@cloudberry.apache.org>.
Smyatkin-Maxim commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4479386142


##########
contrib/vacuum_stats/vacuum_stats--1.0.sql:
##########
@@ -0,0 +1,607 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * contrib/vacuum_stats/vacuum_stats--1.0.sql
+ */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION vacuum_stats" to load this file. \quit
+
+--
+-- Per-relation accessor functions (tables and indexes).
+--
+CREATE FUNCTION pg_stat_get_vacuum_tuples_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_tuples_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_dead_tuples(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_dead_tuples'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_bytes_removed(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_bytes_removed'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_total_file_segs(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_total_file_segs'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_dead_pages(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_dead_pages'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_frozen(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_frozen'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_pages_all_visible(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_pages_all_visible'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_vacuum_freeze_age_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_freeze_age_count'
+LANGUAGE C STABLE STRICT;
+
+--
+-- Per-database accessor functions.
+--
+CREATE FUNCTION pg_stat_get_db_vacuum_tuples_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_tuples_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_dead_tuples(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_dead_tuples'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_deleted(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_deleted'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_bytes_removed(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_bytes_removed'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_dead_pages(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_dead_pages'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_frozen(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_frozen'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_pages_all_visible(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_pages_all_visible'
+LANGUAGE C STABLE STRICT;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_freeze_age_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_freeze_age_count'
+LANGUAGE C STABLE STRICT;
+
+-- Access to counters stored in ordinary relation and database statistics.
+CREATE FUNCTION pg_stat_get_frozen_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_frozen_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_visible_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_visible_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_vacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_vacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autovacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autovacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_vacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_vacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autovacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autovacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_analyze_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_analyze_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_total_autoanalyze_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_total_autoanalyze_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_vacuum_failsafe_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_vacuum_failsafe_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_frozen_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_frozen_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_visible_page_marks_cleared(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_visible_page_marks_cleared'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_vacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_vacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_autovacuum_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_autovacuum_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_vacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_vacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_total_autovacuum_delay_time(oid) RETURNS double precision
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_total_autovacuum_delay_time'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_failsafe_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_failsafe_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+CREATE FUNCTION pg_stat_get_db_vacuum_interrupt_count(oid) RETURNS int8
+AS 'MODULE_PATHNAME', 'pg_stat_get_db_vacuum_interrupt_count'
+LANGUAGE C STABLE STRICT PARALLEL RESTRICTED;
+
+-- Local statistics, in milliseconds for timing columns.
+CREATE VIEW pg_stat_vacuum_tables AS
+    SELECT
+        c.oid AS relid,
+        n.nspname AS schemaname,
+        c.relname AS relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid) AS dead_pages,
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid) AS total_autovacuum_delay_time,
+        @extschema@.pg_stat_get_total_analyze_time(c.oid) AS total_analyze_time,
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid) AS total_autoanalyze_time,
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid) AS total_file_segs
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm');
+
+CREATE VIEW pg_stat_vacuum_indexes AS
+    SELECT
+        c.oid AS relid,
+        i.oid AS indexrelid,
+        n.nspname AS schemaname,
+        c.relname AS relname,
+        i.relname AS indexrelname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid) AS dead_pages,
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid) AS total_autovacuum_delay_time
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i';
+
+CREATE VIEW pg_stat_vacuum_database AS
+    SELECT
+        d.oid AS datid,
+        d.datname AS datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid) AS tuples_deleted,
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid) AS dead_tuples,
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid) AS pages_deleted,
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid) AS bytes_removed,
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid) AS dead_pages,
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid) AS pages_frozen,
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid) AS pages_all_visible,
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid) AS frozen_page_marks_cleared,
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid) AS visible_page_marks_cleared,
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid) AS freeze_age_vacuum_count,
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid) AS vacuum_failsafe_count,
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid) AS total_vacuum_time,
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid) AS total_autovacuum_time,
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid) AS total_vacuum_delay_time,
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid) AS total_autovacuum_delay_time,
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid) AS vacuum_interrupt_count
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d;
+
+-- Cluster views execute on the coordinator and all segments. The bodies
+-- access catalogs directly because segment functions cannot scan local views.
+-- Utility sessions return their local rows once, without a segment branch.
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_tables() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        n.nspname,
+        c.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_analyze_time(c.oid),
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid),
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid)
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm')
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_tables() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        n.nspname,
+        c.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(c.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(c.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(c.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(c.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(c.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(c.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(c.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(c.oid),
+        @extschema@.pg_stat_get_total_analyze_time(c.oid),
+        @extschema@.pg_stat_get_total_autoanalyze_time(c.oid),
+        @extschema@.pg_stat_get_vacuum_total_file_segs(c.oid)
+    FROM pg_catalog.pg_class c
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm')
+        AND pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_tables AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_tables() AS T
+        (gp_segment_id int,
+         relid oid,
+         schemaname name,
+         relname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         total_analyze_time double precision,
+         total_autoanalyze_time double precision,
+         total_file_segs int8)
+    UNION ALL
+    SELECT * FROM gp_stat_get_segment_vacuum_tables() AS T
+        (gp_segment_id int,
+         relid oid,
+         schemaname name,
+         relname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         total_analyze_time double precision,
+         total_autoanalyze_time double precision,
+         total_file_segs int8);
+
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_indexes() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        i.oid,
+        n.nspname,
+        c.relname,
+        i.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid)
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i'
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_indexes() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        c.oid,
+        i.oid,
+        n.nspname,
+        c.relname,
+        i.relname,
+        @extschema@.pg_stat_get_vacuum_tuples_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_tuples(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_deleted(i.oid),
+        @extschema@.pg_stat_get_vacuum_bytes_removed(i.oid),
+        @extschema@.pg_stat_get_vacuum_dead_pages(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_frozen(i.oid),
+        @extschema@.pg_stat_get_vacuum_pages_all_visible(i.oid),
+        @extschema@.pg_stat_get_frozen_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_visible_page_marks_cleared(i.oid),
+        @extschema@.pg_stat_get_vacuum_freeze_age_count(i.oid),
+        @extschema@.pg_stat_get_vacuum_failsafe_count(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_time(i.oid),
+        @extschema@.pg_stat_get_total_vacuum_delay_time(i.oid),
+        @extschema@.pg_stat_get_total_autovacuum_delay_time(i.oid)
+    FROM pg_catalog.pg_class c
+        JOIN pg_catalog.pg_index x ON c.oid = x.indrelid
+        JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
+        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    WHERE c.relkind IN ('r', 't', 'm') AND i.relkind = 'i'
+        AND pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_indexes AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_indexes() AS T
+        (gp_segment_id int,
+         relid oid,
+         indexrelid oid,
+         schemaname name,
+         relname name,
+         indexrelname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision)
+    UNION ALL
+    SELECT * FROM gp_stat_get_segment_vacuum_indexes() AS T
+        (gp_segment_id int,
+         relid oid,
+         indexrelid oid,
+         schemaname name,
+         relname name,
+         indexrelname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision);
+
+CREATE FUNCTION gp_stat_get_coordinator_vacuum_database() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        d.oid,
+        d.datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid),
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid)
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d
+$$
+LANGUAGE SQL EXECUTE ON COORDINATOR;
+
+CREATE FUNCTION gp_stat_get_segment_vacuum_database() RETURNS SETOF RECORD AS
+$$
+    SELECT pg_catalog.gp_execution_segment() AS gp_segment_id,
+        d.oid,
+        d.datname,
+        @extschema@.pg_stat_get_db_vacuum_tuples_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_tuples(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_deleted(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_bytes_removed(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_dead_pages(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_frozen(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_pages_all_visible(d.oid),
+        @extschema@.pg_stat_get_db_frozen_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_visible_page_marks_cleared(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_freeze_age_count(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_failsafe_count(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_time(d.oid),
+        @extschema@.pg_stat_get_db_total_vacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_total_autovacuum_delay_time(d.oid),
+        @extschema@.pg_stat_get_db_vacuum_interrupt_count(d.oid)
+    FROM (
+        SELECT 0::oid AS oid, NULL::name AS datname
+        UNION ALL
+        SELECT oid, datname FROM pg_catalog.pg_database
+    ) d
+        WHERE pg_catalog.current_setting('gp_role') <> 'utility'
+$$
+LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+
+CREATE VIEW gp_stat_vacuum_database AS
+    SELECT * FROM gp_stat_get_coordinator_vacuum_database() AS T
+        (gp_segment_id int,
+         datid oid,
+         datname name,
+         tuples_deleted int8,
+         dead_tuples int8,
+         pages_deleted int8,
+         bytes_removed int8,
+         dead_pages int8,
+         pages_frozen int8,
+         pages_all_visible int8,
+         frozen_page_marks_cleared int8,
+         visible_page_marks_cleared int8,
+         freeze_age_vacuum_count int8,
+         vacuum_failsafe_count int8,
+         total_vacuum_time double precision,
+         total_autovacuum_time double precision,
+         total_vacuum_delay_time double precision,
+         total_autovacuum_delay_time double precision,
+         vacuum_interrupt_count int8)
+    UNION ALL

Review Comment:
   This union all between coordinator and segments is pretty much everywhere across our extensions. I wonder if it's time to add some syntactic sugar already. Not for this PR, just thinking out loud.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Store cumulative VACUUM statistics in the collector and expose them through vacuum_stats extension [cloudberry]

Posted by "my-ship-it (via GitHub)" <gi...@apache.org>.
my-ship-it commented on code in PR #2079:
URL: https://github.com/apache/cloudberry/pull/2079#discussion_r4356831887


##########
src/backend/commands/vacuum_ao.c:
##########
@@ -443,6 +519,10 @@ void
 ao_vacuum_rel(Relation rel, VacuumParams *params, BufferAccessStrategy bstrategy)
 {
 	static AOVacuumRelStats *vacrelstats = NULL;
+	instr_time	phasestart;
+	instr_time	phaseend;
+	int64		startdelaytime;
+
 	Assert(RelationStorageIsAO(rel));
 	Assert(params != NULL);

Review Comment:
   Thanks for working on this.
   
   ao_vacuum_rel()'s static vacrelstats is freed only at the end of post-cleanup. If a VACUUM is canceled or errors out mid-way, the next AO VACUUM in the same backend reuses it, along with the previous relation's num_dead_tuples, nbytes_truncated and starttime. Before this patch, that only affected the progress view. Now it ends up in cumulative stats, including total_vacuum_time with track_vacuum_statistics = off.
   
   A plain statement_timeout is enough to hit it:
   
   ```sql
   CREATE TABLE big (id int, v text) USING ao_row DISTRIBUTED BY (id);
   INSERT INTO big SELECT g, repeat('x', 200) FROM generate_series(1, 6000000) g;
   DELETE FROM big WHERE id % 10 <> 0;
   
   CREATE TABLE small (id int, v text) USING ao_row DISTRIBUTED BY (id);
   INSERT INTO small SELECT g, 'y' FROM generate_series(1, 300) g;
   DELETE FROM small WHERE id <= 150;
   
   SET statement_timeout = '600ms';   -- adjust so it fires during compaction
   VACUUM big;                        -- canceled
   RESET statement_timeout;
   VACUUM small;
   
   SELECT gp_segment_id, tuples_deleted, round(total_vacuum_time) AS ms
     FROM gp_stat_vacuum_tables
    WHERE relname = 'small' AND gp_segment_id >= 0 ORDER BY 1;
   ```
   
   ```
    gp_segment_id | tuples_deleted |  ms
   ---------------+----------------+-----
                0 |        1004377 | 729
                1 |        1050658 | 729
                2 |         873446 | 730
   ```
   
   The correct numbers are 58/45/47 and about 15 ms. All segments are affected. With the change below, the same sequence gives 58/45/47.
   
   ```suggestion
   	Assert(params != NULL);
   
   	/* A pre-cleanup phase starts a new VACUUM; drop state left by an aborted one. */
   	if (vacrelstats != NULL &&
   		(params->options & VACUUM_AO_PHASE_MASK) == VACOPT_AO_PRE_CLEANUP_PHASE)
   		cleanup_vacrelstats(&vacrelstats);
   ```
   
   Please add an isolation2 test for this.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org