You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ch...@apache.org on 2026/02/04 02:26:56 UTC
(cloudberry) 01/05: Generate gp_ view for desired pg_ system views
This is an automated email from the ASF dual-hosted git repository.
chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 4fd461c3c62d6ce1da84c75748575a6f37f40084
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Mon Mar 20 07:51:33 2023 -0700
Generate gp_ view for desired pg_ system views
For a selected list of PG system views (started with 'pg_'prefix ), we
will create a corresponding 'gp_' view for each one in the list.
Each 'gp_' view is basically a UNION ALL of the results of running the
corresponding 'pg_' view on all segments (including the coordinator).
Note that, these views do not aggregate the results. The aggregate
version of the views will be named with a '_summary' appendix (such
as 'gp_stat_all_tables_summary').
To add a new 'pg_' view to this list, simply put the name in file
'src/backend/catalog/system_views_gp.in'. This commit adds an initial
list of views that we think make sense to have 'gp_' views.
With this change, we also remove the existing definition of
gp_stat_archiver view and let it be generated automatically.
We also had gp_stat_replication but it carries additional column than
pg_stat_replication so it cannot use the automatic way.
---
src/backend/catalog/.gitignore | 1 +
src/backend/catalog/Makefile | 8 ++++--
src/backend/catalog/system_views.sql | 6 +----
src/backend/catalog/system_views_gp.in | 48 ++++++++++++++++++++++++++++++++++
src/bin/initdb/initdb.c | 4 +++
5 files changed, 60 insertions(+), 7 deletions(-)
diff --git a/src/backend/catalog/.gitignore b/src/backend/catalog/.gitignore
index 6c4c6d228db..3912b022a03 100644
--- a/src/backend/catalog/.gitignore
+++ b/src/backend/catalog/.gitignore
@@ -8,3 +8,4 @@
/pg_*_d.h
/gp_*_d.h
/bki-stamp
+/system_views_gp.sql
diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index 666a861c6de..b45a3776e59 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -59,6 +59,9 @@ OBJS += pg_extprotocol.o \
gp_matview_aux.o \
pg_directory_table.o storage_directory_table.o
+GP_SYSVIEW_IN = system_views_gp.in
+GP_SYSVIEW_SQL = system_views_gp.sql
+
CATALOG_JSON:= $(addprefix $(top_srcdir)/gpMgmt/bin/gppylib/data/, $(addsuffix .json,$(GP_MAJORVERSION)))
include $(top_srcdir)/src/backend/common.mk
@@ -136,7 +139,7 @@ POSTGRES_BKI_DATA += $(addprefix $(top_srcdir)/src/include/catalog/,\
$(top_builddir)/src/include/catalog/gp_version_at_initdb.dat
-all: distprep generated-header-symlinks
+all: distprep generated-header-symlinks $(GP_SYSVIEW_SQL)
distprep: bki-stamp
@@ -200,6 +203,7 @@ ifeq ($(USE_INTERNAL_FTS_FOUND), false)
endif
$(INSTALL_DATA) $(srcdir)/system_functions.sql '$(DESTDIR)$(datadir)/system_functions.sql'
$(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
+ $(INSTALL_DATA) $(srcdir)/$(GP_SYSVIEW_SQL) '$(DESTDIR)$(datadir)/$(GP_SYSVIEW_SQL)'
$(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
$(INSTALL_DATA) $(call vpathsearch,cdb_schema.sql) '$(DESTDIR)$(datadir)/cdb_init.d/cdb_schema.sql'
$(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
@@ -220,4 +224,4 @@ endif
clean:
maintainer-clean: clean
- rm -f bki-stamp postgres.bki system_constraints.sql $(GENERATED_HEADERS)
+ rm -f bki-stamp postgres.bki system_constraints.sql $(GENERATED_HEADERS) $(GP_SYSVIEW_SQL)
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8858c3ebcd5..8dfb76c3682 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1135,6 +1135,7 @@ $$
$$
LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
+-- This view has an additional column than pg_stat_replication so cannot be generated using system_views_gp.in
CREATE VIEW gp_stat_replication AS
SELECT *, pg_catalog.gp_replication_error() AS sync_error
FROM pg_catalog.gp_stat_get_master_replication() AS R
@@ -1879,11 +1880,6 @@ UNION ALL
SELECT gp_segment_id, gp_get_suboverflowed_backends() FROM gp_dist_random('gp_id') order by 1;
-CREATE OR REPLACE VIEW gp_stat_archiver AS
- SELECT -1 AS gp_segment_id, * FROM pg_stat_archiver
- UNION
- SELECT gp_execution_segment() AS gp_segment_id, * FROM gp_dist_random('pg_stat_archiver');
-
CREATE FUNCTION gp_get_session_endpoints (OUT gp_segment_id int, OUT auth_token text,
OUT cursorname text, OUT sessionid int, OUT hostname varchar(64),
OUT port int, OUT username text, OUT state text,
diff --git a/src/backend/catalog/system_views_gp.in b/src/backend/catalog/system_views_gp.in
new file mode 100644
index 00000000000..5c0a8c2dc7e
--- /dev/null
+++ b/src/backend/catalog/system_views_gp.in
@@ -0,0 +1,48 @@
+# This file lists all the PG system views 'pg_%' that we would like to create an
+# MPP-aware view 'gp_%' out of. The generated 'gp_%' view definitions will be placed
+# in system_views_gp.sql, and initialized at the same time as system_views.sql.
+pg_backend_memory_contexts
+pg_config
+pg_cursors
+pg_file_settings
+pg_replication_origin_status
+pg_replication_slots
+pg_settings
+pg_stat_activity
+pg_stat_archiver
+pg_stat_bgwriter
+pg_stat_database
+pg_stat_database_conflicts
+pg_stat_gssapi
+pg_stat_operations
+pg_stat_progress_analyze
+pg_stat_progress_basebackup
+pg_stat_progress_cluster
+pg_stat_progress_copy
+pg_stat_progress_create_index
+pg_stat_progress_vacuum
+pg_stat_slru
+pg_stat_ssl
+pg_stat_subscription
+pg_stat_sys_indexes
+pg_stat_sys_tables
+pg_stat_user_functions
+pg_stat_user_indexes
+pg_stat_user_tables
+pg_stat_wal
+pg_stat_wal_receiver
+pg_stat_xact_all_tables
+pg_stat_xact_sys_tables
+pg_stat_xact_user_functions
+pg_stat_xact_user_tables
+pg_statio_all_indexes
+pg_statio_all_sequences
+pg_statio_all_tables
+pg_statio_sys_indexes
+pg_statio_sys_sequences
+pg_statio_sys_tables
+pg_statio_user_indexes
+pg_statio_user_sequences
+pg_statio_user_tables
+pg_stats
+pg_stats_ext
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b6db630f38a..ca0e5bbcd97 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -192,6 +192,7 @@ static char *external_fts_files;
#endif
static char *system_functions_file;
static char *system_views_file;
+static char *system_views_gp_file;
static bool success = false;
static bool made_new_pgdata = false;
static bool found_existing_pgdata = false;
@@ -3035,6 +3036,7 @@ setup_data_file_paths(void)
set_input(&system_constraints_file, "system_constraints.sql");
set_input(&system_functions_file, "system_functions.sql");
set_input(&system_views_file, "system_views.sql");
+ set_input(&system_views_gp_file, "system_views_gp.sql");
set_input(&cdb_init_d_dir, "cdb_init.d");
@@ -3068,6 +3070,7 @@ setup_data_file_paths(void)
#endif
check_input(system_functions_file);
check_input(system_views_file);
+ check_input(system_views_gp_file);
}
@@ -3397,6 +3400,7 @@ initialize_data_directory(void)
*/
setup_run_file(cmdfd, system_views_file);
+ setup_run_file(cmdfd, system_views_gp_file);
setup_description(cmdfd);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org