Draft
Conversation
Adds a new PGSTAT_KIND_RESQUEUE statistics kind that tracks per-queue throughput and latency counters, exposed through the pg_stat_resqueues view and pg_stat_get_resqueue_stats() SQL function. New statistics tracked per resource queue: - queries_submitted / admitted / rejected / completed - elapsed_wait_secs / max_wait_secs - elapsed_exec_secs / max_exec_secs - total_cost / total_memory_kb - stat_reset_timestamp Implementation notes: - All stat updates use pgstat_get_entry_ref_locked() to write directly to shared memory, bypassing the pending/flush mechanism. This makes stats immediately visible without explicit flushes, and is safe when called from PG_CATCH blocks (pgstat_resqueue_rejected is invoked inside PG_CATCH in ResLockPortal/ResLockUtilityPortal). - Per-portal timing is tracked in a backend-local hash table keyed by portalid; entries are removed when the portal is admitted, rejected, or completed. Also fixes a pre-existing bug in resqueue.c: dclist_delete_from() already decrements waitProcs.count internally, but three call sites additionally did a manual count-- causing count to underflow to UINT32_MAX. The next dclist_push_tail() would then overflow count back to 0 and trip the overflow assertion in ResProcSleep, crashing the backend. New files: - src/backend/utils/activity/pgstat_resqueue.c - src/test/isolation2/sql/resqueue_stats.sql - src/test/isolation2/expected/resqueue_stats.out Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ributed tables In GPDB, DML (INSERT/UPDATE/DELETE) executes on QE segments, but autovacuum lives on the QD coordinator. Before this change the QD never received modification counts from QEs, so n_mod_since_analyze remained 0 and auto-ANALYZE never triggered for distributed tables. Add two functions: - pgstat_send_qd_tabstats() (QE side, pgstat.c): reads per-table counts from pgStatXactStack before finish_xact_command() NULLs it, serialises them as PgStatTabRecordFromQE[] and attaches the array to the libpq PGresult via extras/PGExtraTypeTableStats. - pgstat_combine_from_qe() (QD side, pgstat_relation.c): called from mppExecutorFinishup/mppExecutorWait after dispatch; iterates QE results, deserialises PgStatTabRecordFromQE arrays and merges each record into the QD's pending stats via pgstat_prep_relation_pending(), then calls pgstat_force_next_flush() to bypass rate-limiting. Using the pending path (rather than writing directly to shared memory) is critical when auto_stats triggers ANALYZE in the same command: pgstat_report_analyze() resets mod_since_analyze to 0, but pending counts are added back when pgstat_report_stat() flushes after ANALYZE. Also add pgstat_get_current_xact_stack() to read pgStatXactStack without side effects, and update the Makefile to include libpq_srcdir for libpq-int.h (PGExtraType, pg_result internals). The autovacuum-analyze isolation2 test verifies all four auto-ANALYZE scenarios: plain heap table, partition leaf tables, lock-conflict abort, and coexistence with auto_stats (on_no_stats / on_change / below threshold). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions