Conversation
2a67beb to
ebd5f98
Compare
Merge the current heads of apache#2102, apache#2103, apache#2104 and apache#2105. Keep resource hooks independent of native completion reports, adopt the new VM counter layout, and remove the superseded relallfrozen catalog changes. Account for AO compaction index insertions in the database resource aggregate without attributing the all-index sample to one relation. Preserve native timing, work and interruption accounting exactly once. Update catalog/statistics format versions, regression expectations and Meson TAP registration. Cover AO/AOCO resource aggregation and preservation of native page counters across work-only resets. Validation: full assert-enabled macOS build; 14 core TAP files (210 tests), 5 existing extension TAP files (81 tests), and AO/AOCO resource TAP coverage (14 tests). macOS build uses diagnostic overrides for pre-existing warnings outside these changes. Distributed cluster regressions not run. Assisted-by: ChatGPT
Integrate PRs apache#2102, apache#2103, apache#2104 and apache#2105 on current main. Preserve the existing extension integration and the vacuum_stats expected-output whitespace fix.
10064ad to
87deb7a
Compare
Integrate PRs apache#2102, apache#2103, apache#2104 and apache#2105 on current main. Preserve the existing extension integration and the vacuum_stats expected-output whitespace fix.
|
See issues found by OCR. PTAL, allocation in a critical section looks serious and should be fixed |
88606f5 to
76ed992
Compare
Thank you for your review. Fixed. |
76ed992 to
5a561d6
Compare
5a561d6 to
b55b91e
Compare
b55b91e to
c8f1507
Compare
MisterRaindrop
left a comment
There was a problem hiding this comment.
Thanks for the work on this. Two things should be fixed before merging: the analyze-time columns in gp_stat_all_tables_summary (1), and the conflict with main, where PGSTAT_FILE_FORMAT_ID needs a new value (2). The rest is smaller. I built this PR (head a47c2399dd7) and ran item 1 on a 3-segment demo cluster.
1. gp_stat_all_tables_summary reports auto-analyze time as manual analyze time
src/backend/catalog/system_views_gp_summary.sql:143-144 (computed at :182-183)
The two time columns are summed over the segments (m). The two count columns come from the coordinator (s). ANALYZE also runs do_analyze_rel() on every segment, and pgstat_report_analyze() there decides manual vs auto with IsAutoVacuumWorkerProcess(). A QE is never an autovacuum worker. So the segments record every ANALYZE as manual, even one that the coordinator's autovacuum started.
After one auto-analyze of a user table:
analyze_count |
autoanalyze_count |
total_analyze_time |
total_autoanalyze_time |
|
|---|---|---|---|---|
gp_stat_all_tables_summary |
0 | 1 | 16 | 0 |
| coordinator | 0 | 1 | 0 | 21 |
| each segment | 1 | 0 | 5-6 | 0 |
So for user tables total_autoanalyze_time stays 0, and auto-analyze work shows up as manual time. Taking both time columns from s makes them agree with the counts. The coordinator's time covers the whole ANALYZE, including the part that runs on the segments. For a manual ANALYZE the two sources happen to be close: 32 ms summed over the segments vs 33 ms on the coordinator in my run.
Repro
-- coordinator only: gpconfig -c autovacuum_naptime -v 2 --masteronly && gpstop -u
CREATE TABLE autoana_t (a int)
WITH (autovacuum_analyze_threshold = 100, autovacuum_analyze_scale_factor = 0)
DISTRIBUTED BY (a);
INSERT INTO autoana_t SELECT generate_series(1, 200000);
-- wait until pg_stat_all_tables.autoanalyze_count = 1 on the coordinator
SELECT analyze_count, autoanalyze_count, total_analyze_time, total_autoanalyze_time
FROM gp_stat_all_tables_summary WHERE relname = 'autoana_t';
SELECT gp_segment_id, analyze_count, autoanalyze_count, total_analyze_time, total_autoanalyze_time
FROM gp_stat_all_tables WHERE relname = 'autoana_t' ORDER BY 1;No test covers these two columns yet, so a test along these lines would help.
2. Conflict with main; PGSTAT_FILE_FORMAT_ID needs a fresh value
src/include/pgstat.h:249
Main has since merged the pluggable cumulative statistics backport. The PR now conflicts in src/include/pgstat.h and src/test/modules/test_misc/meson.build. Main's format ID is now 0x01A5BCC0; this PR uses 0x01A5BCB6.
When resolving, please don't keep main's value. If you do, a stats file written by a main build passes the ID check, and it gets read with this PR's new PgStat_StatTabEntry / PgStat_StatDBEntry layout. The file should be discarded instead. Any unused value works, for example 0x01A5BCC1.
#2105 bumps the same constant and catversion. Whichever of the two lands second has to bump both again.
3. The OCR item "allocation in a critical section" is unchanged in the code
src/include/pgstat.h:776-789, called from src/backend/access/heap/visibilitymap.c:206-208
The reply on Nov 16 says this is fixed, but both macros still call pgstat_should_count_relation(). When rel->pgstat_info is NULL, that function calls pgstat_assoc_relation() → pgstat_prep_pending_entry(), which allocates memory. The heapam callers run visibilitymap_clear_rel() inside START_CRIT_SECTION().
I don't think it can happen today. Every heapam caller reads the same heap page through ReadBufferExtended() first, and the pgstat_count_buffer_read() there sets pgstat_info outside the critical section. But nothing in the VM code states or checks that assumption. Suggest counting only when the entry already exists, e.g. if ((rel)->pgstat_info != NULL) in the two macros. The cost is that a clear can go uncounted in a case that doesn't occur today. At minimum, an Assert would document the assumption.
4. The other two OCR items also look unchanged
- OCR 2: pre-cleanup and compaction times are kept in a backend-local static and published by the worker that runs post-cleanup. If the QE gang is replaced between phases, those times are lost, but
vacuum_countstill increments. - OCR 3:
track_cost_delay_timingis still inunsync_guc_name.h.
If both are intentional, one sentence in the PR saying so would help. #2105 solves the OCR 2 problem for its own counters by publishing after every phase. That creates a different problem: the compaction phase runs inside the dispatched two-phase transaction, so the published numbers survive a rollback (details in my review of #2105). It would be good if the two PRs handled this the same way.
5. PR description
The description still lists pg_class.relallfrozen. That column is no longer in the code; pages_frozen / pages_all_visible replaced it.
Smaller things
src/backend/access/heap/vacuumlazy.c:1543:VM_ALL_VISIBLE()now runs insideSTART_CRIT_SECTION()on the empty-page path. It is safe today becauselazy_scan_heap()has already pinned the right VM page, sovisibilitymap_get_status()does no I/O. Moving the check aboveSTART_CRIT_SECTION()removes that dependency at no cost.src/backend/commands/vacuum.c:2904: the error counter only wrapstable_relation_vacuum(). A failed heap VACUUM FULL goes throughcluster_rel()a few lines up and is not counted. Errors invacuum_open_relation()are not counted either. Please document whatvacuum_interrupt_countcovers.gp_stat_vacuum_summary(system_views_gp_summary.sql:104-105) usesmax()forvacuum_failsafe_countandvacuum_interrupt_count. Suppose segment 0 enters failsafe in one VACUUM and segment 1 in the next: the summary shows 1.sum()counts segment-level events, which is at least well defined. Otherwise, please document what the value means.- The progress summary views (
gp_stat_progress_vacuum_summary,gp_stat_progress_analyze_summary) don't expose the newdelay_timecolumn. parallel_vacuum_worker_delay_ns(vacuum.c:122,:3260) is written but never read, and parallel vacuum is#if 0'd invacuumlazy.cin this tree. The parallel timing code can go.- The new TAP tests
t/016,t/017,t/018andt/020never run in CI. No job inbuild-cloudberry.ymlrunssrc/test/modules/test_misc. CI builds with autoconf, so themeson.buildentries don't run them either. Either addtest_miscto theic-taplist, or move the important assertions into regress/isolation2. - CI on the current head (merge commit
a47c2399dd7) was cancelled. The last complete run, onc8f15070a82, was green. Please rerun it after the rebase.
8454e97 to
b3fb548
Compare
Thanks for the detailed review! Fixed the ANALYZE summary, VM accounting, and progress summaries, and updated the format IDs. AO timing is now published after each successful phase and survives a later rollback; completion is counted only after post-cleanup. track_cost_delay_timing remains instance-local, with this behavior documented. Added tests and wired them into CI. The fixes are folded into the PR commits, and conflicts with current main are resolved. |
…alyze This commit adds four fields to the statistics of relations, aggregating the amount of time spent for each operation on a relation: - total_vacuum_time, for manual vacuum. - total_autovacuum_time, for vacuum done by the autovacuum daemon. - total_analyze_time, for manual analyze. - total_autoanalyze_time, for analyze done by the autovacuum daemon. This gives users the option to derive the average time spent for these operations with the help of the related "count" fields. Bump PGSTAT_FILE_FORMAT_ID for the additions in PgStat_StatTabEntry. Catalog functions, views and their version bump follow separately. Author: Sami Imseih Reviewed-by: Bertrand Drouvot, Michael Paquier Discussion: https://postgr.es/m/CAA5RZ0uVOGBYmPEeGF2d1B_67tgNjKx_bKDuL+oUftuoz+=Y1g@mail.gmail.com (cherry picked from commit 30a6ed0) Cloudberry adaptation: time AO vacuum from its first phase and pass the start timestamp to the collector at final cleanup, so the changed API is usable by heap and AO immediately. Co-authored-by: Alena Rybakina <alenka.rybakina@gmail.com>
This function is used in both vacuum and analyze code paths, and a follow-up commit will require distinguishing between the two. This commit forces callers to specify whether they are in a vacuum or analyze path, but it does not use that information for anything yet. Author: Nathan Bossart <nathandbossart@gmail.com> Co-authored-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/ZmaXmWDL829fzAVX%40ip-10-97-1-34.eu-west-3.compute.internal Backported from PostgreSQL 18 (commit e5b0b0c) as a prerequisite of the vacuum statistics series. Cloudberry adaptation: the append-optimized and AOCS sample-row acquisition and compaction call vacuum_delay_point() too; the former pass is_analyze = true, the latter false.
This commit adds the amount of time spent sleeping due to cost-based delay to the pg_stat_progress_vacuum and pg_stat_progress_analyze system views. A new configuration parameter named track_cost_delay_timing, which is off by default, controls whether this information is gathered. SQL view definitions and the catalog version change are included in the native SQL reporting commit. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Co-authored-by: Nathan Bossart <nathandbossart@gmail.com> Reviewed-by: Sami Imseih <samimseih@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Masahiro Ikeda <ikedamsh@oss.nttdata.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Reviewed-by: Sergei Kornilov <sk@zsrv.org> Discussion: https://postgr.es/m/ZmaXmWDL829fzAVX%40ip-10-97-1-34.eu-west-3.compute.internal Backported from PostgreSQL 18 (commit bb8dff9) as a prerequisite of the vacuum statistics series. Cloudberry adaptation: the vacuum progress parameters of this branch end at num_dead_tuples, so the delay time is PROGRESS_VACUUM_DELAY_TIME 7 (param8 of the view). Cloudberry does not run parallel vacuum (see dead_items_alloc()), so omit the unused parallel-worker delay accumulator. Local progress reporting measures the VACUUM or ANALYZE backend's own cost delays. The new GUC is listed in unsync_guc_names_array, next to track_io_timing, as every GUC has to be in one of the two lists here. SQL progress-view changes are separated into the native SQL reporting commit; measurement, the GUC and progress counters are introduced here.
Port the process-local VacuumDelayTime accumulator from the REL_2_STABLE commit. Accumulate measured cost-based VACUUM sleep time only while track_cost_delay_timing is enabled, excluding ANALYZE. Consumers take before/after differences to attribute delays to their own operations. The preceding PostgreSQL 18 progress-view backport already provides the GUC, its documentation, sample setting, unsynchronized registration and sleep timing. Reuse that measurement and preserve both VACUUM and ANALYZE progress reporting. Keep the accumulator in milliseconds as double to match this branch's cumulative timing consumers, rather than the source branch's int64 microseconds. Extract the accumulator from the index/database timing commit and fold in the ANALYZE exclusion previously included in the combined heap/index/AO measurements commit. The final branch contents are unchanged. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/ZmaXmWDL829fzAVX%40ip-10-97-1-34.eu-west-3.compute.internal Backported from PostgreSQL 18 (commit bb8dff9). (cherry picked from commit 01aaacb) Co-authored-by: Nathan Bossart <nathandbossart@gmail.com> Co-authored-by: Alena Rybakina <alenka.rybakina@gmail.com>
Accumulate elapsed time and cost-based delays over active AO vacuum phases, excluding the gaps between phases. Discard state left over from an interrupted operation. Prepare per-index timing measurements for the subsequent cumulative-reporting change. Adapted-from: 6f38fb2
Record index-pass elapsed and cost-delay time, including parallel workers with the leader's autovacuum classification. Add cumulative table delay time and database totals without adding index time to database totals a second time. Include removed tuple counts in verbose index reports. Catalog getters, views, documentation and SQL-dependent tests follow in the separate native SQL reporting commit.
Accumulate relation and database failsafe counts for completed heap vacuums. Pass false for AO, which has no heap wraparound failsafe mode. Keep this counter distinct from scans made aggressive by the freeze age. Catalog getters, views and tests follow in the native SQL reporting commit.
Count ERROR reports in the heap vacuum callback using local counters for database-local and shared relations. Transfer them to pending database statistics at transaction end. Test cancellation of a running vacuum.
Add visible_page_marks_cleared and frozen_page_marks_cleared counters to
pg_stat_all_tables tracking the number of times the all-visible and
all-frozen bits are cleared in the visibility map. These bits are cleared by
backend processes during regular DML operations. Hence, the counters are placed
in table statistic entry.
A high visible_page_marks_cleared rate relative to DML volume indicates
that modifications are scattered across previously-clean pages rather
than concentrated on already-dirty ones, causing index-only scans to
fall back to heap fetches. A high frozen_page_marks_cleared rate indicates
that vacuum's freezing work is being frequently undone by concurrent
DML.
Authors: Alena Rybakina <lena.ribackina@yandex.ru>,
Andrei Lepikhov <lepihov@gmail.com>,
Andrei Zubkov <a.zubkov@postgrespro.ru>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>,
Masahiko Sawada <sawada.mshk@gmail.com>,
Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>,
Jian He <jian.universality@gmail.com>,
Kirill Reshke <reshkekirill@gmail.com>,
Alexander Korotkov <aekorotkov@gmail.com>,
Jim Nasby <jnasby@upgrade.com>,
Sami Imseih <samimseih@gmail.com>,
Karina Litskevich <litskevichkarina@gmail.com>,
Andrey Borodin <x4mmm@yandex-team.ru>
Backported-from: https://www.postgresql.org/message-id/attachment/205562/v45-0009-Track-table-VM-stability.patch
Co-authored-by: Andrei Lepikhov <lepihov@gmail.com>
Co-authored-by: Andrei Zubkov <zubkov@moonset.ru>
Connect AO index-pass timing measurements to cumulative statistics and report interrupted vacuums. Add cumulative delay reporting for AO tables. Failsafe and visibility-map counters remain inapplicable to AO. The cluster isolation test is included later with its gp_stat_vacuum dependency. Active-phase elapsed reporting is connected in a later commit.
Describe track_cost_delay_timing alongside the instrumentation it enables. Give the accumulated instrumentation fields their own statistics-file format identifier independent of the pluggable-statistics series.
Publish elapsed and cost-delay time after each successful AO phase, preserving work if the next phase runs in a replacement QE. Exclude gaps between phases and retain consumed time after a later rollback. Only post-cleanup updates tuple estimates and the completed-vacuum count. Remove obsolete cross-phase timing state. SQL exposure, documentation and tests follow separately.
Add native SQL getters and local/cluster views for maintenance elapsed and cost-delay time, failsafe runs, interrupted vacuums and cleared VM bits. Use coordinator ANALYZE times alongside coordinator counts, sum instance-level events, and expose worker delays in progress summaries. Document per-phase AO timing and add isolation coverage for auto-analyze, phase rollback, QE replacement and progress delays. Run the native maintenance TAP tests in the ic-tap CI job.
Move cluster timing, index-summary cardinality, and track_cost_delay_timing scope checks from the extension regression into the core vacuum_stats test. Cover distributed and replicated tables, and explicitly flush database statistics before checking their timing aggregate.
Reuse PostgreSQL 16 frozen_pages measurements for completed heap vacuums. Expose pages_frozen through native statistics and summary views, with documentation and reset/no-double-count coverage.
Count newly set all-visible VM marks while holding the heap page lock, including empty-page and second-pass cleanup paths. Expose pages_all_visible in native statistics, summary views and VERBOSE output, and extend regression coverage.
Count at the table access method error boundary instead of error-context callbacks, so caught expression-index exceptions during AO compaction do not inflate vacuum_interrupt_count. Preserve heap diagnostic context and rethrow escaping errors. Wait for VacuumDelay before cancellation and cover caught and escaping index exceptions for both AO storage orientations.
b3fb548 to
23ed5dc
Compare
DetailsSummaryReviewed range: No blocking correctness bugs found. Several things look right:
The points below are mostly about the PR description, MPP semantics, and test stability. Medium1. The PR description says
|
| Area | Files | Status |
|---|---|---|
| Core vacuum/analyze | vacuum.c, vacuum_ao.c, vacuumlazy.c, visibilitymap.c, heapam.c, analyze.c, vacuumparallel.c |
reviewed |
| Stats | pgstat_relation.c, pgstat_database.c, pgstatfuncs.c, pgstat.h |
reviewed |
| Catalog / views | system_views.sql, system_views_gp_summary.sql, pg_proc.dat (OID check only) |
reviewed |
| AM call sites | gin/gist/hash/nbtree/spgist/bloom/file_fdw/AO/AOCS/typanalyze | reviewed (mechanical vacuum_delay_point(bool) changes) |
| GUC / headers | guc_tables.c, unsync_guc_name.h, progress.h, vacuum.h, gin_private.h, appendonly_compaction.h, visibilitymap.h, catversion.h |
reviewed |
| Tests | isolation2 SQL (6), TAP 016/017/018/021, regress/sql/vacuum_stats.sql, schedules, test_misc/Makefile, CI workflow |
reviewed |
Generated by Claude Code using ocr delegate (rules from OpenCodeReview, review performed by the agent). Findings are suggestions only.
Count visibility-map clears by heap_force_kill and cover repeated surgery on the same frozen page. Preserve the upstream ginInsertCleanup signature with a separate auto-analyze entry point so cleanup delays retain their ANALYZE attribution without changing existing GIN callers. Use instr_time and nearest-millisecond rounding for maintenance timing, including serial and parallel index passes. Remove the INT_MAX duration cap and avoid rounding every short index pass up to one millisecond. Clarify per-instance interrupt and failsafe counts in cluster summaries. Replace fixed AO statistics waits with a forced cluster flush, remove the obsolete wall-clock bound and relallfrozen absence assertion, and restore auto-analyze settings immediately after the test wait.
What does this PR do?
Expose maintenance duration and visibility-map stability through native
cumulative statistics and catalog views.
vacuum totals.
expose delay time in progress reporting.
by errors.
relation lifecycle operations.
Expose the statistics through SQL getters and local, per-instance and cluster
summary views. Catalog exposure and tests are kept in a separate commit.
Test Plan
Impact
Changes the pg_class layout and bumps the catalog version; development
clusters require initdb. Updates the cumulative-statistics file format.
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelChecklist