Feature: add pg_query_state to gp_stats_collector - #1934
Open
roaldm153 wants to merge 5 commits into
Open
Conversation
tuhaihe
self-requested a review
August 28, 2026 02:15
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.
What does this PR do?
Adds a signal-based runtime query-state facility to the
gp_stats_collectorextension. It lets a session inspect the live execution state of another running backend on demand - walking its active plan tree across the QD and all QEs - without waiting for the query to finish, pushing batches to the UDS(unix domain socket).New SQL API (extension v1.2, schema
gpsc):gpsc.pg_query_state(pid, trace_id)- fan out a poll to the query running onpid; each participating backend walks its plan tree and logs a per-node snapshot.gpsc.pg_query_state_backends(pid)- list the(segid, pid)QE backends taking part in that query.cbdb_mpp_query_state(gpsc.gp_segment_pid[], trace_id)- QE-side dispatch target.The extension embeds the
pg_query_statesignal layer, which depends on three PostgreSQL core changes folded directly into the tree (configure enables the extension by default, so the tree must build without a manual patch step):ProcSignalhandlers (procsignal.c/.h,postgres.c);instrument.c/.h);EXPLAINentry points (explain.c/.h).Type of Change
Breaking Changes
None. Core changes are additive (new signal reasons, a new Instrumentation field, new runtime-EXPLAIN paths); existing behavior is unchanged.
Test Plan
Unit tests added/updated
Integration tests added/updated
Passed
make installcheckpg_regress (
gpcontrib/gp_stats_collector/test): catalog contract (function/type registration, exec location) and input-validation errors.isolation2 (
gpcontrib/gp_stats_collector/test/isolation2), multi-session:gpsc_pqs_backends- idle backend yields an empty list;gpsc_pqs_running- happy path: poll a query suspended on the QEs via a fault injector;gpsc_pqs_perms- permission gate (non-owner non-superuser denied);gpsc_pqs_disabled-STAT_DISABLEDreports no backends;gpsc_pqs_seg_count- one backend per primary segment.gpsc-crash-test- parallel tracing onmake installcheck-parallel, core dumps checkingA dedicated CI workflow builds Cloudberry with the extension across ubuntu22.04/rocky8/rocky9 and runs the pg_regress, isolation2, and core regression suites.
Impact
Performance:
No steady-state cost. Work happens only when a poll is issued: one signal fan-out plus a bounded shared-memory round-trip; the shmem lock is held only around the request, not during dispatch.
User-facing changes:
New
gpsc.pg_query_state*functions and thepg_query_state.enableGUC. Functions are granted to PUBLIC; access is gated in C so a caller may poll a backend only if it is a superuser or owns the target query.Dependencies:
None.
Checklist
Additional Context
The signal layer under
src/pg_query_state/is derived from pg_query_state (PostgreSQL License). Derived files carry dual license headers (ASF +Portions Copyright Postgres Professional) and the rootLICENSErecords a PostgreSQL-License notice for it. Happy to provide provenance details for IP clearance.