Skip to content

Commit f75a338

Browse files
huansongweinan003
authored andcommitted
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.
1 parent b45836d commit f75a338

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

src/backend/catalog/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/pg_*_d.h
99
/gp_*_d.h
1010
/bki-stamp
11+
/system_views_gp.sql

src/backend/catalog/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ OBJS += pg_extprotocol.o \
5656
gp_matview_aux.o \
5757
pg_directory_table.o storage_directory_table.o
5858

59+
GP_SYSVIEW_IN = system_views_gp.in
60+
GP_SYSVIEW_SQL = system_views_gp.sql
61+
5962
CATALOG_JSON:= $(addprefix $(top_srcdir)/gpMgmt/bin/gppylib/data/, $(addsuffix .json,$(GP_MAJORVERSION)))
6063

6164
include $(top_srcdir)/src/backend/common.mk
@@ -133,7 +136,7 @@ POSTGRES_BKI_DATA += $(addprefix $(top_srcdir)/src/include/catalog/,\
133136
$(top_builddir)/src/include/catalog/gp_version_at_initdb.dat
134137

135138

136-
all: distprep generated-header-symlinks
139+
all: distprep generated-header-symlinks $(GP_SYSVIEW_SQL)
137140

138141
distprep: bki-stamp
139142

@@ -197,6 +200,7 @@ ifeq ($(USE_INTERNAL_FTS_FOUND), false)
197200
endif
198201
$(INSTALL_DATA) $(srcdir)/system_functions.sql '$(DESTDIR)$(datadir)/system_functions.sql'
199202
$(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
203+
$(INSTALL_DATA) $(srcdir)/$(GP_SYSVIEW_SQL) '$(DESTDIR)$(datadir)/$(GP_SYSVIEW_SQL)'
200204
$(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
201205
$(INSTALL_DATA) $(call vpathsearch,cdb_schema.sql) '$(DESTDIR)$(datadir)/cdb_init.d/cdb_schema.sql'
202206
$(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
@@ -216,4 +220,4 @@ endif
216220
clean:
217221

218222
maintainer-clean: clean
219-
rm -f bki-stamp postgres.bki system_constraints.sql $(GENERATED_HEADERS)
223+
rm -f bki-stamp postgres.bki system_constraints.sql $(GENERATED_HEADERS) $(GP_SYSVIEW_SQL)

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ $$
10981098
$$
10991099
LANGUAGE SQL EXECUTE ON ALL SEGMENTS;
11001100

1101+
-- This view has an additional column than pg_stat_replication so cannot be generated using system_views_gp.in
11011102
CREATE VIEW gp_stat_replication AS
11021103
SELECT *, pg_catalog.gp_replication_error() AS sync_error
11031104
FROM pg_catalog.gp_stat_get_master_replication() AS R
@@ -1805,11 +1806,6 @@ UNION ALL
18051806
SELECT gp_segment_id, gp_get_suboverflowed_backends() FROM gp_dist_random('gp_id') order by 1;
18061807

18071808

1808-
CREATE OR REPLACE VIEW gp_stat_archiver AS
1809-
SELECT -1 AS gp_segment_id, * FROM pg_stat_archiver
1810-
UNION
1811-
SELECT gp_execution_segment() AS gp_segment_id, * FROM gp_dist_random('pg_stat_archiver');
1812-
18131809
CREATE FUNCTION gp_get_session_endpoints (OUT gp_segment_id int, OUT auth_token text,
18141810
OUT cursorname text, OUT sessionid int, OUT hostname varchar(64),
18151811
OUT port int, OUT username text, OUT state text,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This file lists all the PG system views 'pg_%' that we would like to create an
2+
# MPP-aware view 'gp_%' out of. The generated 'gp_%' view definitions will be placed
3+
# in system_views_gp.sql, and initialized at the same time as system_views.sql.
4+
pg_backend_memory_contexts
5+
pg_config
6+
pg_cursors
7+
pg_file_settings
8+
pg_replication_origin_status
9+
pg_replication_slots
10+
pg_settings
11+
pg_stat_activity
12+
pg_stat_archiver
13+
pg_stat_bgwriter
14+
pg_stat_database
15+
pg_stat_database_conflicts
16+
pg_stat_gssapi
17+
pg_stat_operations
18+
pg_stat_progress_analyze
19+
pg_stat_progress_basebackup
20+
pg_stat_progress_cluster
21+
pg_stat_progress_copy
22+
pg_stat_progress_create_index
23+
pg_stat_progress_vacuum
24+
pg_stat_slru
25+
pg_stat_ssl
26+
pg_stat_subscription
27+
pg_stat_sys_indexes
28+
pg_stat_sys_tables
29+
pg_stat_user_functions
30+
pg_stat_user_indexes
31+
pg_stat_user_tables
32+
pg_stat_wal
33+
pg_stat_wal_receiver
34+
pg_stat_xact_all_tables
35+
pg_stat_xact_sys_tables
36+
pg_stat_xact_user_functions
37+
pg_stat_xact_user_tables
38+
pg_statio_all_indexes
39+
pg_statio_all_sequences
40+
pg_statio_all_tables
41+
pg_statio_sys_indexes
42+
pg_statio_sys_sequences
43+
pg_statio_sys_tables
44+
pg_statio_user_indexes
45+
pg_statio_user_sequences
46+
pg_statio_user_tables
47+
pg_stats
48+
pg_stats_ext

src/bin/initdb/initdb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static char *external_fts_files;
174174
#endif
175175
static char *system_functions_file;
176176
static char *system_views_file;
177+
static char *system_views_gp_file;
177178
static bool success = false;
178179
static bool made_new_pgdata = false;
179180
static bool found_existing_pgdata = false;
@@ -2831,6 +2832,7 @@ setup_data_file_paths(void)
28312832
set_input(&system_constraints_file, "system_constraints.sql");
28322833
set_input(&system_functions_file, "system_functions.sql");
28332834
set_input(&system_views_file, "system_views.sql");
2835+
set_input(&system_views_gp_file, "system_views_gp.sql");
28342836

28352837
set_input(&cdb_init_d_dir, "cdb_init.d");
28362838

@@ -2864,6 +2866,7 @@ setup_data_file_paths(void)
28642866
#endif
28652867
check_input(system_functions_file);
28662868
check_input(system_views_file);
2869+
check_input(system_views_gp_file);
28672870
}
28682871

28692872

@@ -3231,6 +3234,7 @@ initialize_data_directory(void)
32313234
*/
32323235

32333236
setup_run_file(cmdfd, system_views_file);
3237+
setup_run_file(cmdfd, system_views_gp_file);
32343238

32353239
setup_description(cmdfd);
32363240

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
*/
5757

5858
/* 3yyymmddN */
59-
#define CATALOG_VERSION_NO 302502091
59+
#define CATALOG_VERSION_NO 302506101
6060

6161
#endif

0 commit comments

Comments
 (0)