From 04726e9fa8d2fa10fd7c69f06ea48ffb204828a6 Mon Sep 17 00:00:00 2001 From: justbk <249396768@qq.com> Date: Thu, 10 Aug 2023 17:03:10 +0800 Subject: [PATCH] support new db_time time record. --- src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/catalog/builtin_funcs.ini | 8 +- .../backend/catalog/performance_views.sql | 103 +- src/common/backend/catalog/system_views.sql | 35 +- src/common/backend/libpq/be-secure.cpp | 2 +- src/common/backend/utils/adt/pgstatfuncs.cpp | 15 +- src/common/backend/utils/init/globals.cpp | 2 +- src/common/backend/utils/misc/guc.cpp | 13 + src/common/pl/plpgsql/src/pl_handler.cpp | 6 +- .../instruments/statement/instr_statement.cpp | 12 +- .../unique_sql/instr_unique_sql.cpp | 23 +- src/gausskernel/process/postmaster/Makefile | 2 +- .../process/postmaster/og_record_time.cpp | 698 ++++++++++ src/gausskernel/process/postmaster/pgstat.cpp | 111 +- src/gausskernel/process/tcop/postgres.cpp | 52 +- src/gausskernel/process/tcop/pquery.cpp | 2 + .../process/threadpool/knl_session.cpp | 2 + .../runtime/executor/lightProxy.cpp | 1 + src/gausskernel/storage/ipc/ipc.cpp | 3 +- .../rollback-post_catalog_maindb_92_906.sql | 955 ++++++++++++++ .../rollback_catalog_maindb_92_906.sql | 22 + .../rollback-post_catalog_otherdb_92_906.sql | 956 ++++++++++++++ .../rollback_catalog_otherdb_92_906.sql | 22 + .../upgrade-post_catalog_maindb_92_906.sql | 1127 +++++++++++++++++ .../upgrade_catalog_maindb_92_906.sql | 22 + .../upgrade-post_catalog_otherdb_92_906.sql | 1127 +++++++++++++++++ .../upgrade_catalog_otherdb_92_906.sql | 22 + .../knl/knl_guc/knl_session_attr_common.h | 1 + src/include/knl/knl_session.h | 3 + src/include/knl/knl_thread.h | 1 + src/include/og_record_time.h | 512 ++++++++ src/include/og_record_time_rely.h | 33 + src/include/pgstat.h | 110 +- .../regress/output/recovery_2pc_tools.source | 1 + 34 files changed, 5821 insertions(+), 184 deletions(-) create mode 100644 src/gausskernel/process/postmaster/og_record_time.cpp create mode 100644 src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback_catalog_maindb_92_906.sql create mode 100644 src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback_catalog_otherdb_92_906.sql create mode 100644 src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade_catalog_maindb_92_906.sql create mode 100644 src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade_catalog_otherdb_92_906.sql create mode 100644 src/include/og_record_time.h create mode 100644 src/include/og_record_time_rely.h diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 922395615..321353905 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -755,6 +755,7 @@ ignore_standby_lsn_window|int|0,2147483647|ms|NULL| ignore_feedback_xmin_window|int|0,2147483647|ms|NULL| ss_enable_bcast_snapshot|bool|0,0|NULL|NULL| subscription_conflict_resolution|enum|error,apply_remote,keep_local|NULL|NULL| +time_record_level|int|0,10|NULL|NULL| [cmserver] log_dir|string|0,0|NULL|NULL| log_file_size|int|0,2047|MB|NULL| diff --git a/src/common/backend/catalog/builtin_funcs.ini b/src/common/backend/catalog/builtin_funcs.ini index 2ea8be3fa..0c59329f6 100755 --- a/src/common/backend/catalog/builtin_funcs.ini +++ b/src/common/backend/catalog/builtin_funcs.ini @@ -3179,7 +3179,7 @@ ), AddFuncGroup( "get_instr_unique_sql", 1, - AddBuiltinFunc(_0(5702), _1("get_instr_unique_sql"), _2(0), _3(false), _4(true), _5(get_instr_unique_sql), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(0), _21(44, 19, 23, 19, 26, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 1184, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(44, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o','o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(44, "node_name", "node_id", "user_name", "user_id", "unique_sql_id", "query", "n_calls", "min_elapse_time", "max_elapse_time", "total_elapse_time", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "n_soft_parse", "n_hard_parse", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "last_updated", "sort_count", "sort_time", "sort_mem_used", "sort_spill_count", "sort_spill_size", "hash_count", "hash_time", "hash_mem_used", "hash_spill_count", "hash_spill_size"), _24(NULL), _25("get_instr_unique_sql"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) + AddBuiltinFunc(_0(5702), _1("get_instr_unique_sql"), _2(0), _3(false), _4(true), _5(get_instr_unique_sql), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(0), _21(60, 19, 23, 19, 26, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 1184, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(60, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o','o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(60, "node_name", "node_id", "user_name", "user_id", "unique_sql_id", "query", "n_calls", "min_elapse_time", "max_elapse_time", "total_elapse_time", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "n_soft_parse", "n_hard_parse", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "last_updated", "sort_count", "sort_time", "sort_mem_used", "sort_spill_count", "sort_spill_size", "hash_count", "hash_time", "hash_mem_used", "hash_spill_count", "hash_spill_size", "net_send_time", "srt1_q", "srt2_simple_query", "srt3_analyze_rewrite", "srt4_plan_query", "srt5_light_query", "srt6_p", "srt7_b", "srt8_e", "srt9_d", "srt10_s", "srt11_c", "srt12_u", "srt13_before_query", "srt14_after_query","rtt_unknown"), _24(NULL), _25("get_instr_unique_sql"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) ), AddFuncGroup( "get_instr_user_login", 1, @@ -9105,7 +9105,7 @@ ), AddFuncGroup( "pg_stat_get_wlm_session_info", 1, - AddBuiltinFunc(_0(5002), _1("pg_stat_get_wlm_session_info"), _2(1), _3(false), _4(true), _5(pg_stat_get_wlm_session_info), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(100), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 26), _21(87, 26, 25, 25, 25, 25, 25, 869, 25, 23, 25, 20, 1184, 1184, 20, 20, 25, 25, 25, 25, 23, 23, 23, 23, 23, 25, 23, 23, 23, 23, 20, 20, 20, 23, 20, 20, 20, 23, 23, 23, 23, 23, 25, 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(87, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(87, "datid", "dbname", "schemaname", "nodename", "username", "application_name", "client_addr", "client_hostname", "client_port", "query_band", "block_time", "start_time", "finish_time", "duration", "estimate_total_time", "status", "abort_info", "resource_pool", "control_group", "estimate_memory", "min_peak_memory", "max_peak_memory", "average_peak_memory", "memory_skew_percent", "spill_info", "min_spill_size", "max_spill_size", "average_spill_size", "spill_skew_percent", "min_dn_time", "max_dn_time", "average_dn_time", "dntime_skew_percent", "min_cpu_time", "max_cpu_time", "total_cpu_time", "cpu_skew_percent", "min_peak_iops", "max_peak_iops", "average_peak_iops", "iops_skew_percent", "warning", "queryid", "query", "query_plan", "node_group", "cpu_top1_node_name", "cpu_top2_node_name", "cpu_top3_node_name", "cpu_top4_node_name", "cpu_top5_node_name", "mem_top1_node_name", "mem_top2_node_name", "mem_top3_node_name", "mem_top4_node_name", "mem_top5_node_name", "cpu_top1_value", "cpu_top2_value", "cpu_top3_value", "cpu_top4_value", "cpu_top5_value", "mem_top1_value", "mem_top2_value", "mem_top3_value", "mem_top4_value", "mem_top5_value", "top_mem_dn", "top_cpu_dn", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "net_send_time", "data_io_time", "is_slow_query"), _24(NULL), _25("pg_stat_get_wlm_session_info"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) + AddBuiltinFunc(_0(5002), _1("pg_stat_get_wlm_session_info"), _2(1), _3(false), _4(true), _5(pg_stat_get_wlm_session_info), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(100), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 26), _21(102, 26, 25, 25, 25, 25, 25, 869, 25, 23, 25, 20, 1184, 1184, 20, 20, 25, 25, 25, 25, 23, 23, 23, 23, 23, 25, 23, 23, 23, 23, 20, 20, 20, 23, 20, 20, 20, 23, 23, 23, 23, 23, 25, 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(102, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(102, "datid", "dbname", "schemaname", "nodename", "username", "application_name", "client_addr", "client_hostname", "client_port", "query_band", "block_time", "start_time", "finish_time", "duration", "estimate_total_time", "status", "abort_info", "resource_pool", "control_group", "estimate_memory", "min_peak_memory", "max_peak_memory", "average_peak_memory", "memory_skew_percent", "spill_info", "min_spill_size", "max_spill_size", "average_spill_size", "spill_skew_percent", "min_dn_time", "max_dn_time", "average_dn_time", "dntime_skew_percent", "min_cpu_time", "max_cpu_time", "total_cpu_time", "cpu_skew_percent", "min_peak_iops", "max_peak_iops", "average_peak_iops", "iops_skew_percent", "warning", "queryid", "query", "query_plan", "node_group", "cpu_top1_node_name", "cpu_top2_node_name", "cpu_top3_node_name", "cpu_top4_node_name", "cpu_top5_node_name", "mem_top1_node_name", "mem_top2_node_name", "mem_top3_node_name", "mem_top4_node_name", "mem_top5_node_name", "cpu_top1_value", "cpu_top2_value", "cpu_top3_value", "cpu_top4_value", "cpu_top5_value", "mem_top1_value", "mem_top2_value", "mem_top3_value", "mem_top4_value", "mem_top5_value", "top_mem_dn", "top_cpu_dn", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "net_send_time", "data_io_time", "is_slow_query", "srt1_q", "srt2_simple_query", "srt3_analyze_rewrite", "srt4_plan_query", "srt5_light_query", "srt6_p", "srt7_b", "srt8_e", "srt9_d", "srt10_s", "srt11_c", "srt12_u", "srt13_before_query", "srt14_after_query","rtt_unknown"), _24(NULL), _25("pg_stat_get_wlm_session_info"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) ), AddFuncGroup( "pg_stat_get_wlm_session_info_internal", 1, @@ -10997,8 +10997,8 @@ AddFuncGroup( ), AddFuncGroup( "standby_statement_history", 2, - AddBuiltinFunc(_0(3118), _1("standby_statement_history"), _2(1), _3(false), _4(true), _5(standby_statement_history_1v), _6(2249), _7(PG_DBEPERF_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(10000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(1, 16), _21(54, 16, 19, 19, 23, 19, 25, 25, 23, 20, 20, 25, 1184, 1184, 20, 20, 20, 20, 20, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 17, 16, 25, 25), _22(54, 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(54, "only_slow", "db_name", "schema_name", "origin_node", "user_name", "application_name", "client_addr", "client_port", "unique_query_id", "debug_query_id", "query", "start_time", "finish_time", "slow_sql_threshold", "transaction_id", "thread_id", "session_id", "n_soft_parse", "n_hard_parse", "query_plan", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "lock_count", "lock_time", "lock_wait_count", "lock_wait_time", "lock_max_count", "lwlock_count", "lwlock_wait_count", "lwlock_time", "lwlock_wait_time", "details", "is_slow_sql", "trace_id", "advise"),_24(NULL), _25("standby_statement_history_1v"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)), - AddBuiltinFunc(_0(3119), _1("standby_statement_history"), _2(1), _3(false), _4(true), _5(standby_statement_history), _6(2249), _7(PG_DBEPERF_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(10000), _12(1185), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(2, 16, 1185), _21(55, 16, 1185, 19, 19, 23, 19, 25, 25, 23, 20, 20, 25, 1184, 1184, 20, 20, 20, 20, 20, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 17, 16, 25, 25), _22(55, 'i', 'v', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(55, "only_slow", "finish_time", "db_name", "schema_name", "origin_node", "user_name", "application_name", "client_addr", "client_port", "unique_query_id", "debug_query_id", "query", "start_time", "finish_time", "slow_sql_threshold", "transaction_id", "thread_id", "session_id", "n_soft_parse", "n_hard_parse", "query_plan", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "lock_count", "lock_time", "lock_wait_count", "lock_wait_time", "lock_max_count", "lwlock_count", "lwlock_wait_count", "lwlock_time", "lwlock_wait_time", "details", "is_slow_sql", "trace_id", "advise"),_24(NULL), _25("standby_statement_history"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) + AddBuiltinFunc(_0(3118), _1("standby_statement_history"), _2(1), _3(false), _4(true), _5(standby_statement_history_1v), _6(2249), _7(PG_DBEPERF_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(10000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(1, 16), _21(70, 16, 19, 19, 23, 19, 25, 25, 23, 20, 20, 25, 1184, 1184, 20, 20, 20, 20, 20, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 17, 16, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(70, 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(70, "only_slow", "db_name", "schema_name", "origin_node", "user_name", "application_name", "client_addr", "client_port", "unique_query_id", "debug_query_id", "query", "start_time", "finish_time", "slow_sql_threshold", "transaction_id", "thread_id", "session_id", "n_soft_parse", "n_hard_parse", "query_plan", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "lock_count", "lock_time", "lock_wait_count", "lock_wait_time", "lock_max_count", "lwlock_count", "lwlock_wait_count", "lwlock_time", "lwlock_wait_time", "details", "is_slow_sql", "trace_id", "advise", "net_send_time","srt1_q", "srt2_simple_query", "srt3_analyze_rewrite", "srt4_plan_query", "srt5_light_query", "srt6_p", "srt7_b", "srt8_e", "srt9_d", "srt10_s", "srt11_c", "srt12_u", "srt13_before_query", "srt14_after_query","rtt_unknown"),_24(NULL), _25("standby_statement_history_1v"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)), + AddBuiltinFunc(_0(3119), _1("standby_statement_history"), _2(1), _3(false), _4(true), _5(standby_statement_history), _6(2249), _7(PG_DBEPERF_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(10000), _12(1185), _13(0), _14(false), _15(false), _16(false), _17(false), _18('v'), _19(0), _20(2, 16, 1185), _21(71, 16, 1185, 19, 19, 23, 19, 25, 25, 23, 20, 20, 25, 1184, 1184, 20, 20, 20, 20, 20, 20, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 25, 25, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 17, 16, 25, 25, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20), _22(71, 'i', 'v', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(71, "only_slow", "finish_time", "db_name", "schema_name", "origin_node", "user_name", "application_name", "client_addr", "client_port", "unique_query_id", "debug_query_id", "query", "start_time", "finish_time", "slow_sql_threshold", "transaction_id", "thread_id", "session_id", "n_soft_parse", "n_hard_parse", "query_plan", "n_returned_rows", "n_tuples_fetched", "n_tuples_returned", "n_tuples_inserted", "n_tuples_updated", "n_tuples_deleted", "n_blocks_fetched", "n_blocks_hit", "db_time", "cpu_time", "execution_time", "parse_time", "plan_time", "rewrite_time", "pl_execution_time", "pl_compilation_time", "data_io_time", "net_send_info", "net_recv_info", "net_stream_send_info", "net_stream_recv_info", "lock_count", "lock_time", "lock_wait_count", "lock_wait_time", "lock_max_count", "lwlock_count", "lwlock_wait_count", "lwlock_time", "lwlock_wait_time", "details", "is_slow_sql", "trace_id", "advise", "net_send_time","srt1_q", "srt2_simple_query", "srt3_analyze_rewrite", "srt4_plan_query", "srt5_light_query", "srt6_p", "srt7_b", "srt8_e", "srt9_d", "srt10_s", "srt11_c", "srt12_u", "srt13_before_query", "srt14_after_query","rtt_unknown"),_24(NULL), _25("standby_statement_history"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) ), AddFuncGroup( "statement_detail_decode", 1, diff --git a/src/common/backend/catalog/performance_views.sql b/src/common/backend/catalog/performance_views.sql index 0af3a1e02..4635a88af 100644 --- a/src/common/backend/catalog/performance_views.sql +++ b/src/common/backend/catalog/performance_views.sql @@ -3994,7 +3994,24 @@ CREATE OR REPLACE FUNCTION DBE_PERF.get_global_full_sql_by_timestamp OUT details bytea, OUT is_slow_sql bool, OUT trace_id text, - OUT advise text) + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint + ) RETURNS setof record AS $$ DECLARE @@ -4063,6 +4080,22 @@ CREATE OR REPLACE FUNCTION DBE_PERF.get_global_full_sql_by_timestamp is_slow_sql := row_data.is_slow_sql; trace_id := row_data.trace_id; advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; return next; END LOOP; END LOOP; @@ -4126,7 +4159,23 @@ CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp OUT details bytea, OUT is_slow_sql bool, OUT trace_id text, - OUT advise text) + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) RETURNS setof record AS $$ DECLARE @@ -4195,6 +4244,22 @@ CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp is_slow_sql := row_data.is_slow_sql; trace_id := row_data.trace_id; advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; return next; END LOOP; END LOOP; @@ -4553,7 +4618,22 @@ SELECT S.pl_execution_time, S.pl_compilation_time, S.net_send_time, - S.data_io_time + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown FROM gs_wlm_session_query_info_all S where S.is_slow_query = 1; CREATE VIEW dbe_perf.gs_slow_query_history AS @@ -4585,7 +4665,22 @@ SELECT S.pl_execution_time, S.pl_compilation_time, S.net_send_time, - S.data_io_time + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown FROM pg_catalog.pg_stat_get_wlm_session_info(0) S where S.is_slow_query = 1; CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_history diff --git a/src/common/backend/catalog/system_views.sql b/src/common/backend/catalog/system_views.sql index 41d9f8cc1..965933cdb 100644 --- a/src/common/backend/catalog/system_views.sql +++ b/src/common/backend/catalog/system_views.sql @@ -1386,7 +1386,22 @@ create table gs_wlm_session_query_info_all pl_compilation_time bigint, net_send_time bigint, data_io_time bigint, - is_slow_query bigint + is_slow_query bigint, + srt1_q bigint, + srt2_simple_query bigint, + srt3_analyze_rewrite bigint, + srt4_plan_query bigint, + srt5_light_query bigint, + srt6_p bigint, + srt7_b bigint, + srt8_e bigint, + srt9_d bigint, + srt10_s bigint, + srt11_c bigint, + srt12_u bigint, + srt13_before_query bigint, + srt14_after_query bigint, + rtt_unknown bigint ); CREATE VIEW gs_wlm_session_info_all AS @@ -3487,7 +3502,23 @@ CREATE unlogged table statement_history( details bytea, is_slow_sql bool, trace_id text, - advise text + advise text, + net_send_time bigint, + srt1_q bigint, + srt2_simple_query bigint, + srt3_analyze_rewrite bigint, + srt4_plan_query bigint, + srt5_light_query bigint, + srt6_p bigint, + srt7_b bigint, + srt8_e bigint, + srt9_d bigint, + srt10_s bigint, + srt11_c bigint, + srt12_u bigint, + srt13_before_query bigint, + srt14_after_query bigint, + rtt_unknown bigint ); REVOKE ALL on table pg_catalog.statement_history FROM public; create index statement_history_time_idx on pg_catalog.statement_history USING btree (start_time, is_slow_sql); diff --git a/src/common/backend/libpq/be-secure.cpp b/src/common/backend/libpq/be-secure.cpp index 80bbfb7a7..9504fa20c 100644 --- a/src/common/backend/libpq/be-secure.cpp +++ b/src/common/backend/libpq/be-secure.cpp @@ -572,7 +572,7 @@ ssize_t old_secure_write(Port* port, void* ptr, size_t len) /* CommProxy Interface Support */ n = comm_send(port->sock, ptr, len, 0); PGSTAT_END_TIME_RECORD(NET_SEND_TIME); - END_NET_SEND_INFO(n); + END_NET_SEND_INFO_DUPLICATE(n); /* for log printing, send message */ IPC_PERFORMANCE_LOG_COLLECT(port->msgLog, ptr, n, port->remote_hostname, NULL, SECURE_WRITE); diff --git a/src/common/backend/utils/adt/pgstatfuncs.cpp b/src/common/backend/utils/adt/pgstatfuncs.cpp index 01e1d7966..df34a6015 100644 --- a/src/common/backend/utils/adt/pgstatfuncs.cpp +++ b/src/common/backend/utils/adt/pgstatfuncs.cpp @@ -6103,7 +6103,7 @@ Datum pg_stat_get_wlm_session_info(PG_FUNCTION_ARGS) int WLM_SESSION_INFO_ATTRNUM = 0; if (t_thrd.proc->workingVersionNum >= SLOW_QUERY_VERSION) - WLM_SESSION_INFO_ATTRNUM = 87; + WLM_SESSION_INFO_ATTRNUM = 77 + TOTAL_TIME_INFO_TYPES; else WLM_SESSION_INFO_ATTRNUM = 68; @@ -6201,10 +6201,13 @@ Datum pg_stat_get_wlm_session_info(PG_FUNCTION_ARGS) TupleDescInitEntry(tupdesc, (AttrNumber)++i, "n_tuples_deleted", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber)++i, "t_blocks_fetched", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber)++i, "t_blocks_hit", INT8OID, -1, 0); - for (num = 0; num < TOTAL_TIME_INFO_TYPES; num++) { + for (num = 0; num < TOTAL_TIME_INFO_TYPES_P1; num++) { TupleDescInitEntry(tupdesc, (AttrNumber)++i, TimeInfoTypeName[num], INT8OID, -1, 0); } TupleDescInitEntry(tupdesc, (AttrNumber)++i, "is_slow_query", INT8OID, -1, 0); + for (num = TOTAL_TIME_INFO_TYPES_P1; num < TOTAL_TIME_INFO_TYPES; num++) { + TupleDescInitEntry(tupdesc, (AttrNumber)++i, TimeInfoTypeName[num], INT8OID, -1, 0); + } } funcctx->tuple_desc = BlessTupleDesc(tupdesc); funcctx->user_fctx = WLMGetSessionInfo(&qid, removed, &num); @@ -6439,11 +6442,15 @@ Datum pg_stat_get_wlm_session_info(PG_FUNCTION_ARGS) values[++i] = Int64GetDatum(detail->gendata.slowQueryInfo.current_table_counter->t_tuples_deleted); values[++i] = Int64GetDatum(detail->gendata.slowQueryInfo.current_table_counter->t_blocks_fetched); values[++i] = Int64GetDatum(detail->gendata.slowQueryInfo.current_table_counter->t_blocks_hit); - /* time Info */ - for (num = 0; num < TOTAL_TIME_INFO_TYPES; num++) { + /* time Info p1*/ + for (num = 0; num < TOTAL_TIME_INFO_TYPES_P1; num++) { values[++i] = Int64GetDatum(detail->gendata.slowQueryInfo.localTimeInfoArray[num]); } values[++i] = Int64GetDatum(0); + /* time Info */ + for (num = TOTAL_TIME_INFO_TYPES_P1; num < TOTAL_TIME_INFO_TYPES; num++) { + values[++i] = Int64GetDatum(detail->gendata.slowQueryInfo.localTimeInfoArray[num]); + } } tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); diff --git a/src/common/backend/utils/init/globals.cpp b/src/common/backend/utils/init/globals.cpp index f805918a8..139cb5b62 100644 --- a/src/common/backend/utils/init/globals.cpp +++ b/src/common/backend/utils/init/globals.cpp @@ -75,7 +75,7 @@ bool will_shutdown = false; * NEXT | 92899 | ? | ? * ********************************************/ -const uint32 GRAND_VERSION_NUM = 92905; +const uint32 GRAND_VERSION_NUM = 92906; /******************************************** * 2.VERSION NUM FOR EACH FEATURE diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 35469e94f..87f65f653 100755 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -3033,6 +3033,19 @@ static void InitConfigureNamesInt() NULL, NULL, NULL}, + {{"time_record_level", + PGC_USERSET, + NODE_SINGLENODE, + STATS_COLLECTOR, + gettext_noop("Set time record level."), + NULL}, + &u_sess->attr.attr_common.time_record_level, + 0, + 0, + 10, + NULL, + NULL, + NULL}, /* End-of-list marker */ {{NULL, (GucContext)0, diff --git a/src/common/pl/plpgsql/src/pl_handler.cpp b/src/common/pl/plpgsql/src/pl_handler.cpp index edc8d9b14..3d1967f08 100755 --- a/src/common/pl/plpgsql/src/pl_handler.cpp +++ b/src/common/pl/plpgsql/src/pl_handler.cpp @@ -699,8 +699,7 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS) int save_sec_context = 0; Oid cast_owner = InvalidOid; bool has_switch = false; - // PGSTAT_INIT_PLSQL_TIME_RECORD - int64 startTime = 0; + PGSTAT_INIT_TIME_RECORD(); bool needRecord = false; PLpgSQL_package* pkg = NULL; MemoryContext oldContext = CurrentMemoryContext; @@ -1044,8 +1043,7 @@ Datum plpgsql_inline_handler(PG_FUNCTION_ARGS) FmgrInfo flinfo; Datum retval; int rc; - // PGSTAT_INIT_PLSQL_TIME_RECORD - int64 startTime = 0; + PGSTAT_INIT_TIME_RECORD(); bool needRecord = false; _PG_init(); diff --git a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp index 9573f4b84..636e3e634 100755 --- a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp +++ b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp @@ -75,7 +75,7 @@ #define STATEMENT_DETAILS_HEAD_SIZE (1) /* [VERSION] */ #define INSTR_STMT_UNIX_DOMAIN_PORT (-1) -#define INSTR_STATEMENT_ATTRNUM 53 +#define INSTR_STATEMENT_ATTRNUM (44 + TOTAL_TIME_INFO_TYPES) /* support different areas in stmt detail column */ #define STATEMENT_DETAIL_TYPE_LEN (1) @@ -503,9 +503,10 @@ static HeapTuple GetStatementTuple(Relation rel, StatementStatContext* statement set_stmt_row_activity_cache_io(statementInfo, values, &i); /* time info */ - for (int num = 0; num < TOTAL_TIME_INFO_TYPES; num++) { - if (num == NET_SEND_TIME) + for (int num = 0; num < TOTAL_TIME_INFO_TYPES_P1; num++) { + if (num == NET_SEND_TIME) { continue; + } values[i++] = Int64GetDatum(statementInfo->timeModel[num]); } @@ -550,6 +551,11 @@ static HeapTuple GetStatementTuple(Relation rel, StatementStatContext* statement SET_TEXT_VALUES(statementInfo->trace_id, i++); set_stmt_advise(statementInfo, values, nulls, &i); + /* time info addition */ + values[i++] = Int64GetDatum(statementInfo->timeModel[NET_SEND_TIME]); + for (int num = TOTAL_TIME_INFO_TYPES_P1; num < TOTAL_TIME_INFO_TYPES; num++) { + values[i++] = Int64GetDatum(statementInfo->timeModel[num]); + } Assert(INSTR_STATEMENT_ATTRNUM == i); return heap_form_tuple(RelationGetDescr(rel), values, nulls); } diff --git a/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp b/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp index 7cae9d41f..4050899c7 100755 --- a/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp +++ b/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp @@ -1436,9 +1436,10 @@ static void create_tuple_entry(TupleDesc tupdesc) TupleDescInitEntry(tupdesc, (AttrNumber)++i, "n_soft_parse", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber)++i, "n_hard_parse", INT8OID, -1, 0); - for (num = 0; num < TOTAL_TIME_INFO_TYPES; num++) { - if (num == NET_SEND_TIME) + for (num = 0; num < TOTAL_TIME_INFO_TYPES_P1; num++) { + if (num == NET_SEND_TIME) { continue; + } TupleDescInitEntry(tupdesc, (AttrNumber)++i, TimeInfoTypeName[num], INT8OID, -1, 0); } TupleDescInitEntry(tupdesc, (AttrNumber)++i, "NET_SEND_INFO", TEXTOID, -1, 0); @@ -1458,6 +1459,10 @@ static void create_tuple_entry(TupleDesc tupdesc) TupleDescInitEntry(tupdesc, (AttrNumber)++i, "hash_mem_used", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber)++i, "hash_spill_count", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber)++i, "hash_spill_size", INT8OID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber)++i, TimeInfoTypeName[NET_SEND_TIME], INT8OID, -1, 0); + for (num = TOTAL_TIME_INFO_TYPES_P1; num < TOTAL_TIME_INFO_TYPES; num++) { + TupleDescInitEntry(tupdesc, (AttrNumber)++i, TimeInfoTypeName[num], INT8OID, -1, 0); + } } static void set_tuple_cn_node_name(UniqueSQL* unique_sql, Datum* values, int* i) @@ -1544,10 +1549,11 @@ static void set_tuple_value(UniqueSQL* unique_sql, Datum* values, bool* nulls, i values[i++] = Int64GetDatum(unique_sql->parse.soft_parse); values[i++] = Int64GetDatum(unique_sql->parse.hard_parse); - // time Info - for (num = 0; num < TOTAL_TIME_INFO_TYPES; num++) { - if (num == NET_SEND_TIME) + // time Info p1 + for (num = 0; num < TOTAL_TIME_INFO_TYPES_P1; num++) { + if (num == NET_SEND_TIME) { continue; + } values[i++] = Int64GetDatum(unique_sql->timeInfo.TimeInfoArray[num]); } int idx = 0; @@ -1576,6 +1582,11 @@ static void set_tuple_value(UniqueSQL* unique_sql, Datum* values, bool* nulls, i values[i++] = Int64GetDatum(unique_sql->hash_state.used_work_mem); values[i++] = Int64GetDatum(unique_sql->hash_state.spill_counts); values[i++] = Int64GetDatum(unique_sql->hash_state.spill_size); + // time Info + values[i++] = Int64GetDatum(unique_sql->timeInfo.TimeInfoArray[NET_SEND_TIME]); + for (num = TOTAL_TIME_INFO_TYPES_P1; num < TOTAL_TIME_INFO_TYPES; num++) { + values[i++] = Int64GetDatum(unique_sql->timeInfo.TimeInfoArray[num]); + } Assert(arr_size == i); } @@ -1614,7 +1625,7 @@ Datum get_instr_unique_sql(PG_FUNCTION_ARGS) { FuncCallContext* funcctx = NULL; long num = 0; -#define INSTRUMENTS_UNIQUE_SQL_ATTRNUM (35 + TOTAL_TIME_INFO_TYPES - 1) +#define INSTRUMENTS_UNIQUE_SQL_ATTRNUM (35 + TOTAL_TIME_INFO_TYPES) CheckVersion(); check_unique_sql_permission(); diff --git a/src/gausskernel/process/postmaster/Makefile b/src/gausskernel/process/postmaster/Makefile index 1fdb0c261..fc85d6d2d 100644 --- a/src/gausskernel/process/postmaster/Makefile +++ b/src/gausskernel/process/postmaster/Makefile @@ -31,7 +31,7 @@ ifneq "$(MAKECMDGOALS)" "clean" endif endif endif -OBJS = autovacuum.o bgwriter.o fork_process.o pgarch.o pgstat.o postmaster.o gaussdb_version.o\ +OBJS = autovacuum.o bgwriter.o fork_process.o pgarch.o pgstat.o og_record_time.o postmaster.o gaussdb_version.o\ startup.o syslogger.o walwriter.o walwriterauxiliary.o checkpointer.o pgaudit.o alarmchecker.o \ twophasecleaner.o fencedudf.o lwlockmonitor.o cbmwriter.o pagewriter.o pagerepair.o snapcapturer.o rbcleaner.o globalstats.o \ cfs_shrinker.o \ diff --git a/src/gausskernel/process/postmaster/og_record_time.cpp b/src/gausskernel/process/postmaster/og_record_time.cpp new file mode 100644 index 000000000..b27b0d42b --- /dev/null +++ b/src/gausskernel/process/postmaster/og_record_time.cpp @@ -0,0 +1,698 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * --------------------------------------------------------------------------------------- + * + * IDENTIFICATION + * src/gausskernel/process/postmaster/og_record_time.cpp + * + * NOTES + * Implements some of this code used to record sql execute time. + * + * ------------------------------------------------------------------------- + */ + +#include "og_record_time.h" +#include "tcop/tcopprot.h" +const char* TimeInfoTypeName[] = { + "DB_TIME", + "CPU_TIME", + "EXECUTION_TIME", + "PARSE_TIME", + "PLAN_TIME", + "REWRITE_TIME", /*total elapsed time of rewrite stage.*/ + "PL_EXECUTION_TIME", /*total elapsed time of plpgsql exection.*/ + "PL_COMPILATION_TIME", /*total elapsed time of plpgsql compilation.*/ + "NET_SEND_TIME", + "DATA_IO_TIME", + "SRT1_Q", + "SRT2_SIMPLE_QUERY", + "SRT3_ANALYZE_REWRITE", + "SRT4_PLAN_QUERY", + "SRT5_LIGHT_QUERY", + "SRT6_P", + "SRT7_B", + "SRT8_E", + "SRT9_D", + "SRT10_S", + "SRT11_C", + "SRT12_U", + "SRT13_BEFORE_QUERY", + "SRT14_AFTER_QUERY", + "RTT_UNKNOWN", + "NET_SEND_TIMES", + "NET_SEND_N_CALLS", + "NET_SEND_SIZE", + "NET_RECV_TIMES", + "NET_RECV_N_CALLS", + "NET_RECV_SIZE", + "NET_STREAM_SEND_times", + "NET_STREAM_SEND_n_calls", + "NET_STREAM_SEND_size", + "NET_STREAM_RECV_times", + "NET_STREAM_RECV_n_calls", + "NET_STREAM_RECV_size" +}; + +static inline knl_u_stat_context* get_record_cxt() +{ + return &(u_sess->stat_cxt); +} + +static int og_get_time_record_level() +{ + Assert(u_sess != NULL); + return u_sess->attr.attr_common.time_record_level; +} + +OgRecordStat* og_get_record_stat() +{ + OgRecordStat* record_stat = (OgRecordStat*) get_record_cxt()->og_record_stat; + Assert(record_stat != NULL); + return record_stat; +} + + +void og_record_time_cleanup(int code, Datum arg) +{ + if (u_sess == NULL) { + return; + } + ereport(DEBUG1, + (errmsg("record(%ld): cleanup called!", + get_record_cxt()->og_record_stat == NULL ? -1 : ((int64)(get_record_cxt()->og_record_stat))))); + if (get_record_cxt()->og_record_stat != NULL) { + DELETE_EX_TYPE(get_record_cxt()->og_record_stat, OgRecordStat); + } +} + +void og_record_time_reinit() +{ + if (u_sess == NULL || get_record_cxt()->og_record_stat == NULL) { + return; + } + og_get_record_stat()->reinit(); + ResetMemory(u_sess->stat_cxt.localTimeInfoArray, + sizeof(int64) * TOTAL_TIME_INFO_TYPES); + ResetMemory(u_sess->stat_cxt.localNetInfo, + sizeof(uint64) * TOTAL_NET_INFO_TYPES); +} + +const char* og_record_time_type_str(const RecordType& time_type) +{ + return og_record_time_type_str(time_type.position()); +} + +const char* og_record_time_type_str(int pos) +{ + int max_size = sizeof(TimeInfoTypeName) / sizeof(TimeInfoTypeName[0]); + if (pos < 0 || pos >= max_size) { + pos = max_size - 1; + } + return TimeInfoTypeName[pos]; +} + +bool og_time_record_start() +{ + return og_get_record_stat()->start_first_record_opt(); +} + +bool og_time_record_end() +{ + return og_get_record_stat()->free_first_record_opt(); +} + +bool og_time_record_is_started() +{ + return og_get_record_stat()->already_start(); +} + +int64 og_get_time_unique_id() +{ + if (u_sess == NULL + || ((OgRecordStat*) get_record_cxt()->og_record_stat == NULL)) { + return 0; + } + return og_get_record_stat()->get_time_unique_id(); +} + +static inline void og_record_report_start(const OgTimeDataVo& record) +{ + og_get_record_stat()->report_start(record); +} + +static inline void og_record_report_end(const OgTimeDataVo& record) +{ + og_get_record_stat()->report_end(record); +} + +static inline void og_record_report_duplicate(OgTimeDataVo& record) +{ + og_get_record_stat()->report_duplicate(record); +} + +RecordType::RecordType() +{ + type_code = (int) RTT_UNKNOWN; + rtt_type = TIME_INFO; +} + +RecordType::RecordType(TimeInfoType time_info_type) +{ + type_code = (int) time_info_type; + rtt_type = TIME_INFO; +} +RecordType::RecordType(SelfRecordType self_typ) +{ + type_code = (int) self_typ; + rtt_type = SELF_INFO; +} + +RecordType::RecordType(NetInfoType net_info_type, ssize_t str_len) +{ + type_code = (int) net_info_type; + rtt_type = NET_INFO; + this->str_len = str_len; +} + +RecordTimeType RecordType::get_record_time_type() const +{ + return rtt_type; +} + +int RecordType::get_type_code() const +{ + return type_code; +} + +ssize_t RecordType::get_str_len() const +{ + return str_len; +} + +int RecordType::get_init_pos() const +{ + if (rtt_type == NET_INFO) { + return (int) TOTAL_TIME_INFO_TYPES + (int) SRT_ALL; + } else if (rtt_type == SELF_INFO) { + return (int) TOTAL_TIME_INFO_TYPES; + } + return 0; +} + +int RecordType::position() const +{ + return get_type_code() + get_init_pos(); +} + +bool RecordType::is_root_type() const +{ + return *this == DB_TIME; +} + +bool RecordType::operator==(TimeInfoType time_type) const +{ + if (rtt_type != TIME_INFO) { + return false; + } + return type_code == (int)time_type; +} +bool RecordType::operator!=(TimeInfoType time_type) const +{ + return !(*this == time_type); +} + +bool RecordType::operator==(NetInfoType net_type) const +{ + if (rtt_type != NET_INFO) { + return false; + } + return type_code == (int) net_type; +} + +bool RecordType::operator!=(NetInfoType net_type) const +{ + return !(*this == net_type); +} + +bool RecordType::operator==(SelfRecordType self_type) const +{ + if (rtt_type != SELF_INFO) { + return false; + } + return type_code == (int) self_type; +} + +bool RecordType::operator!=(SelfRecordType self_type) const +{ + return !(*this == self_type); +} + +const char* OgTimeDataFormatHelper::format(const OgTimeDataVo& vo) +{ + int ret = snprintf_s(format_str, DEFAULT_FORMAT_LENGTH, DEFAULT_FORMAT_LENGTH - 1, + "rd:{id=%lld,s=%lld,e=%lld,t=%lld,d=%d,na=%s}", vo.id, vo.begin, + vo.end == 0 ? GetCurrentTimestamp(): vo.end, vo.end == 0 ? 0 : vo.total(), + vo.depth, og_record_time_type_str(vo.record_type)); + securec_check_ss(ret, "\0", "\0"); + return format_str; +} + +OgRecordOperator::OgRecordOperator(bool auto_record) +{ + init(auto_record, RecordType(RTT_UNKNOWN)); +} + +OgRecordOperator::OgRecordOperator(TimeInfoType time_info_type) +{ + init(true, RecordType(time_info_type)); +} + +OgRecordOperator::OgRecordOperator(NetInfoType net_info_type) +{ + init(true, RecordType(net_info_type, 0)); +} + +OgRecordOperator::OgRecordOperator(SelfRecordType self_type) +{ + init(true, RecordType(self_type)); +} + +OgRecordOperator::OgRecordOperator(bool auto_record, NetInfoType net_type) { + init(auto_record, RecordType(net_type, 0)); +} + +OgRecordOperator::OgRecordOperator(bool auto_record, TimeInfoType time_type) { + init(auto_record, RecordType(time_type)); +} + +OgRecordOperator::OgRecordOperator(bool auto_record, SelfRecordType self_type) { + init(auto_record, RecordType(self_type)); +} + +OgRecordOperator::~OgRecordOperator() +{ + if (this->auto_record) { + exit(); + } +} + +void OgRecordOperator::enter(TimeInfoType time_type) +{ + enter(RecordType(time_type)); +} + +void OgRecordOperator::enter(NetInfoType net_type) +{ + enter(RecordType(net_type, 0)); +} + +void OgRecordOperator::enter(const RecordType& record_type) +{ + if (!report_enable()) { + return; + } + if (record_type != RTT_UNKNOWN) { + base_record.record_type = record_type; + } + if (!base_record.record_type.is_root_type()) { + base_record.begin = (int64)GetCurrentTimestamp(); + } + og_record_report_start(base_record); +} + +void OgRecordOperator::exit(TimeInfoType time_info_type) +{ + exit(RecordType(time_info_type)); +} + +void OgRecordOperator::exit(NetInfoType net_type, ssize_t str_len) +{ + exit(RecordType(net_type, str_len)); +} + +void OgRecordOperator::exit(const RecordType& record_type) +{ + if (!report_enable()) { + return; + } + if (record_type != RTT_UNKNOWN) { + base_record.record_type = record_type; + } + og_record_report_end(base_record); +} + +// this only called after exit() to report new record again. +void OgRecordOperator::report_duplicate(NetInfoType net_type, ssize_t str_len) +{ + RecordType old = base_record.record_type; + base_record.record_type = RecordType(net_type, str_len); + og_record_report_duplicate(base_record); + base_record.record_type = old; +} + +int64 OgRecordOperator::get_record_id() const +{ + return base_record.id; +} + +void OgRecordOperator::update_record_id() +{ + base_record.id = og_get_time_unique_id(); +} + +bool OgRecordOperator::report_enable() const +{ + OgRecordStat* record_stat = (OgRecordStat*)get_record_cxt()->og_record_stat; + if (record_stat == NULL) { + return false; + } + // for future, we can control diff level record time. + int level = record_stat->get_time_record_level(); + return level == 0; +} + +void OgRecordOperator::init(bool auto_record, const RecordType& record_type) +{ + this->auto_record = auto_record; + if (this->auto_record) { + enter(record_type); + } else { + base_record.record_type = record_type; + } +} + +OgTimeDataVo& OgTimeDataStack::top() +{ + Assert(cur_pos >= 0 && cur_pos < DEFAULT_TIME_DATA_STACK_DEPTH); + return data_list[cur_pos]; +} + +const OgTimeDataVo& OgTimeDataStack::top() const +{ + Assert(cur_pos >= 0 && cur_pos < DEFAULT_TIME_DATA_STACK_DEPTH); + return data_list[cur_pos]; +} + +bool OgTimeDataStack::empty() const +{ + return cur_pos < 0; +} + +size_t OgTimeDataStack::size() const { + Assert(cur_pos >= -1 && cur_pos < DEFAULT_TIME_DATA_STACK_DEPTH); + return cur_pos + 1; +} + +bool OgTimeDataStack::push(const OgTimeDataVo &vo) +{ + if (cur_pos == DEFAULT_TIME_DATA_STACK_DEPTH - 1) { + return false; + } + data_list[++ cur_pos] = vo; + return true; +} + +void OgTimeDataStack::pop() +{ + if (cur_pos < 0) { + return; + } + cur_pos --; +} + +void OgTimeDataStack::reset() +{ + cur_pos = -1; +} + +OgRecordStat::OgRecordStat(int64* local_time_info, uint64* loca_net_info) +:first_record_opt(false, DB_TIME) +{ + log_trace_msg = makeStringInfo(); + record_start = false; + this->local_time_info = local_time_info; + this->local_net_info = loca_net_info; + time_unique_id = 0; + db_time_baseline = DEFAULT_DB_TIME_BASELINE; + time_record_level = 0; + reset(); +} + +OgRecordStat::~OgRecordStat() +{ + Destroy(); +} + +void OgRecordStat::Destroy() +{ + reset(); + if (log_trace_msg != NULL) { + DestroyStringInfo(log_trace_msg); + log_trace_msg = NULL; + } +} + +void OgRecordStat::reset() +{ + this->logtrace(DEBUG1, "reset"); + depth = INVALID_DEPTH; + record_start = false; + free_first_record_opt(); + records_stack.reset(); + records_stack.push(OgTimeDataVo()); +} + +void OgRecordStat::reinit() +{ + this->logtrace(DEBUG1, "reinit"); + reset(); + pre_records_stack.reset(); +} + +void OgRecordStat::report_start(const OgTimeDataVo& data_record) +{ + if (!records_stack.push(data_record)) { + return; + } + records_stack.top().depth = increment_depth(); + record_debug("begin: %s", FORMAT_VO(records_stack.top())); + if (data_record.record_type.is_root_type()) { + records_stack.top().begin = GetCurrentTimestamp(); + } +} + +void OgRecordStat::report_end(const OgTimeDataVo& record) +{ + // assert not records_stack.is_empty() + OgTimeDataVo& time_vo = records_stack.top(); + if (record != time_vo) { + record_debug("find time record not match!top =%s, curr=%s", + FORMAT_VO(time_vo), FORMAT_VO(record)); + return; + } + records_stack.pop(); + decrement_depth(); + if (!already_start()) { + return; + } + time_vo.record_type = record.record_type; + if (time_vo.record_type.is_root_type()) { + // We don't want debug time calc in root type. + time_vo.end = GetCurrentTimestamp(); + record_debug("end : %s", FORMAT_VO(time_vo)); + } else { + record_debug("end : %s", FORMAT_VO(time_vo)); + time_vo.end = GetCurrentTimestamp(); + } + OgTimeDataVo& parent_time_vo = records_stack.top(); + int64 cost = time_vo.cost(); + int64 total = time_vo.total(); + if (time_vo.record_type.get_record_time_type() != NET_INFO) { + parent_time_vo.update_other_cost(total); + } + update_record_time(time_vo.record_type, cost); +} + +// some auto report can only report net record. +void OgRecordStat::report_duplicate(OgTimeDataVo& record) +{ + Assert(record.record_type.get_record_time_type() == NET_INFO); + record_debug("duplicate : %s, str_len=%d", FORMAT_VO(record), record.record_type.get_str_len()); + if (record.end == 0) { + record.end = GetCurrentTimestamp(); + } + update_record_time(record.record_type, record.cost()); +} + +int OgRecordStat::increment_depth() +{ + return ++ depth; +} + +void OgRecordStat::decrement_depth() +{ + depth --; +} + +int64 OgRecordStat::get_time_unique_id() +{ + time_unique_id ++; + return time_unique_id; +} + +void OgRecordStat::print_self() const +{ + int64 bind_total = 0; + int64 bind_data = 0; + if (!log_enable_debug()) { + return; + } + for (int i = 0; i < TOTAL_RECORD_TYPES; i ++) + { + if (i < TOTAL_TIME_INFO_TYPES) { + bind_total += local_time_info[i]; + bind_data = local_time_info[i]; + } else if(i < TOTAL_TIME_INFO_TYPES + SRT_ALL) { + bind_data = 0; + } else if(i < TOTAL_RECORD_TYPES) { + int tmp_pos = i - TOTAL_TIME_INFO_TYPES - SRT_ALL; + bind_data = local_net_info[tmp_pos]; + } else { + // nothing to do + } + record_debug("name:%d %30s %ld", i, og_record_time_type_str(i), bind_data); + } + int64 child_cost = bind_total - get_record_times(DB_TIME) - get_record_times(CPU_TIME); + record_debug("%s,%s,diff(%lld) = total=(%lld) - child_cost(%lld)", + get_record_times(RTT_UNKNOWN) < db_time_baseline ? "rd_yes" : "rd_no ", + (child_cost == get_db_time()) ? "rd_eq " : "rd_ne", + get_record_times(RTT_UNKNOWN), + get_db_time(), child_cost); +} + +int OgRecordStat::get_time_record_level() const +{ + return time_record_level; +} + +void OgRecordStat::update_time_record_level() +{ + time_record_level = og_get_time_record_level(); +} + +bool OgRecordStat::start_first_record_opt() +{ + if (!already_start()) { + reset(); + update_time_record_level(); + first_record_opt.update_record_id(); + first_record_opt.enter(DB_TIME); + record_start = true; + while (!pre_records_stack.empty()) { + OgTimeDataVo& vo = pre_records_stack.top(); + pre_records_stack.pop(); + vo.begin = GetCurrentTimestamp(); + vo.other_cost = 0; + report_start(vo); + } + return true; + } + return false; +} + +bool OgRecordStat::free_first_record_opt() +{ + if(already_start()) { + int64 record_id = first_record_opt.get_record_id(); + while (records_stack.size() > 2 && (records_stack.top().id != record_id)) { + records_stack.top().end = GetCurrentTimestamp(); + pre_records_stack.push(records_stack.top()); + logtrace(DEBUG1, "free_head, %s", OgTimeDataFormatHelper().format(records_stack.top())); + report_end(records_stack.top()); + } + first_record_opt.exit(); + record_start = false; + logtrace(DEBUG1, "free_first_record_opt called, %d", record_id); + local_time_info[RTT_UNKNOWN] += local_time_info[DB_TIME]; + local_time_info[DB_TIME] = get_db_time(); + return true; + } + return false; +} + +const int64 OgRecordStat::get_record_times(TimeInfoType type_info) const +{ + return local_time_info[type_info]; +} + +const int64 OgRecordStat::get_db_time() const +{ + return records_stack.top().other_cost; +} + +const OgTimeDataVo& OgRecordStat::get_root_time_data_vo() const +{ + return records_stack.top(); +} + +inline bool OgRecordStat::already_start() const +{ + return record_start; +} + +void OgRecordStat::update_record_time(const RecordType& record_type, int64 cost) +{ + if (record_type.get_record_time_type() == TIME_INFO) { + local_time_info[record_type.position()] += cost; + } else if (record_type.get_record_time_type() == SELF_INFO) { + // not use, only for add new time record to quick debug + } else { + ssize_t str_len = record_type.get_str_len(); + if (str_len != 0) { + int type_code = record_type.get_type_code(); + local_net_info[type_code] += (uint64)cost; + local_net_info[type_code + 1] ++; + local_net_info[type_code + 2] += str_len; + } + } +} + +// flow database system log config +bool OgRecordStat::log_enable() const +{ + return u_sess != NULL && u_sess->attr.attr_common.log_statement == LOGSTMT_ALL; +} + +// flow database system log config +bool OgRecordStat::log_enable_debug() const +{ + return log_enable() && u_sess->attr.attr_common.log_min_messages < LOG; +} + +void OgRecordStat::logtrace(int level, const char* fmt, ...) const +{ + if (!log_enable() || log_trace_msg == NULL) { + return; + } + if (fmt != log_trace_msg->data) { + va_list args; + (void)va_start(args, fmt); + // This place just is the message print. So there is't need check the value of vsnprintf_s function return. if + // checked, when the message lengtn is over than log_trace_msg->maxlen, will be abnormal exit. + (void)vsnprintf_s(log_trace_msg->data, log_trace_msg->maxlen, log_trace_msg->maxlen - 1, fmt, args); + va_end(args); + } + ereport(level, (errmsg("record(%ld-%ld) %s", (uint64)this, + u_sess == NULL ? 0 : u_sess->session_id, log_trace_msg->data))); +} diff --git a/src/gausskernel/process/postmaster/pgstat.cpp b/src/gausskernel/process/postmaster/pgstat.cpp index 6b0b2f54a..173449517 100644 --- a/src/gausskernel/process/postmaster/pgstat.cpp +++ b/src/gausskernel/process/postmaster/pgstat.cpp @@ -8162,17 +8162,6 @@ Size sessionTimeShmemSize(void) return mul_size(SessionTimeArraySize, sizeof(SessionTimeEntry)); } -const char* TimeInfoTypeName[TOTAL_TIME_INFO_TYPES] = {"DB_TIME", - "CPU_TIME", - "EXECUTION_TIME", - "PARSE_TIME", - "PLAN_TIME", - "REWRITE_TIME", - "PL_EXECUTION_TIME", - "PL_COMPILATION_TIME", - "NET_SEND_TIME", - "DATA_IO_TIME"}; - void sessionTimeShmemInit(void) { bool found = false; @@ -8307,68 +8296,60 @@ void AttachMySessionTimeEntry(void) Assert((t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount & 1) == 0); } +static void addThreadTimeEntry() +{ + for (int i = 0; i < TOTAL_TIME_INFO_TYPES; i++) { + t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[i] += + u_sess->stat_cxt.localTimeInfoArray[i]; + } +} +void ResetMemory(void* dest, size_t size) +{ + errno_t rc; + rc = memset_s(dest, size, 0, size); + securec_check(rc, "\0", "\0"); +} + void timeInfoRecordStart(void) { - if (u_sess->stat_cxt.localTimeInfoArray[DB_TIME] == 0) { - u_sess->stat_cxt.localTimeInfoArray[DB_TIME] = GetCurrentTimestamp(); - if (u_sess->attr.attr_common.enable_instr_cpu_timer) - u_sess->stat_cxt.localTimeInfoArray[CPU_TIME] = getCpuTime(); + if (!og_time_record_start()) { + return; } + if (u_sess->attr.attr_common.enable_instr_cpu_timer) + u_sess->stat_cxt.localTimeInfoArray[CPU_TIME] = getCpuTime(); } void timeInfoRecordEnd(void) { - errno_t rc; - if (u_sess->stat_cxt.localTimeInfoArray[DB_TIME] != 0) { - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount++; - - if (u_sess->attr.attr_common.enable_instr_cpu_timer) { - int64 cur = getCpuTime(); - - u_sess->stat_cxt.localTimeInfoArray[CPU_TIME] = cur - u_sess->stat_cxt.localTimeInfoArray[CPU_TIME]; - } - u_sess->stat_cxt.localTimeInfoArray[DB_TIME] = - GetCurrentTimestamp() - u_sess->stat_cxt.localTimeInfoArray[DB_TIME]; - - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[CPU_TIME] += u_sess->stat_cxt.localTimeInfoArray[CPU_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[DB_TIME] += u_sess->stat_cxt.localTimeInfoArray[DB_TIME]; - - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[EXECUTION_TIME] += - u_sess->stat_cxt.localTimeInfoArray[EXECUTION_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[PARSE_TIME] += u_sess->stat_cxt.localTimeInfoArray[PARSE_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[PLAN_TIME] += u_sess->stat_cxt.localTimeInfoArray[PLAN_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[REWRITE_TIME] += - u_sess->stat_cxt.localTimeInfoArray[REWRITE_TIME]; - - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[PL_EXECUTION_TIME] += - u_sess->stat_cxt.localTimeInfoArray[PL_EXECUTION_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[PL_COMPILATION_TIME] += - u_sess->stat_cxt.localTimeInfoArray[PL_COMPILATION_TIME]; - - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[NET_SEND_TIME] += - u_sess->stat_cxt.localTimeInfoArray[NET_SEND_TIME]; - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->array[DATA_IO_TIME] += - u_sess->stat_cxt.localTimeInfoArray[DATA_IO_TIME]; - - t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount++; - Assert((t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount & 1) == 0); - - UniqueSQLStat sqlStat; - sqlStat.timeInfo = u_sess->stat_cxt.localTimeInfoArray; - sqlStat.netInfo = u_sess->stat_cxt.localNetInfo; - if (u_sess->unique_sql_cxt.unique_sql_id != 0 && is_unique_sql_enabled()) - UpdateUniqueSQLStat(NULL, NULL, 0, NULL, &sqlStat); - rc = memset_s(u_sess->stat_cxt.localTimeInfoArray, - sizeof(int64) * TOTAL_TIME_INFO_TYPES, - 0, - sizeof(int64) * TOTAL_TIME_INFO_TYPES); - securec_check(rc, "\0", "\0"); - rc = memset_s(u_sess->stat_cxt.localNetInfo, - sizeof(uint64) * TOTAL_NET_INFO_TYPES, - 0, - sizeof(uint64) * TOTAL_NET_INFO_TYPES); - securec_check(rc, "\0", "\0"); + if (!og_time_record_is_started()) { + return; } + t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount++; + + if (u_sess->attr.attr_common.enable_instr_cpu_timer) { + int64 cur = getCpuTime(); + u_sess->stat_cxt.localTimeInfoArray[CPU_TIME] = cur - + u_sess->stat_cxt.localTimeInfoArray[CPU_TIME]; + } + og_time_record_end(); + og_get_record_stat()->print_self(); + + addThreadTimeEntry(); + t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount++; + Assert((t_thrd.shemem_ptr_cxt.mySessionTimeEntry->changeCount & 1) == 0); + + UniqueSQLStat sqlStat; + sqlStat.timeInfo = u_sess->stat_cxt.localTimeInfoArray; + sqlStat.netInfo = u_sess->stat_cxt.localNetInfo; + if (u_sess->unique_sql_cxt.unique_sql_id != 0 && is_unique_sql_enabled()) { + UpdateUniqueSQLStat(NULL, NULL, 0, NULL, &sqlStat); + + } + + ResetMemory(u_sess->stat_cxt.localTimeInfoArray, + sizeof(int64) * TOTAL_TIME_INFO_TYPES); + ResetMemory(u_sess->stat_cxt.localNetInfo, + sizeof(uint64) * TOTAL_NET_INFO_TYPES); } /* generate result of pv_session_time view */ diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index 3954e68ab..6fae4e501 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -1023,15 +1023,13 @@ List* pg_parse_query(const char* query_string, List** query_string_locationlist, List* (*parser_hook)(const char*, List**)) { List* raw_parsetree_list = NULL; - PGSTAT_INIT_TIME_RECORD(); + OgRecordOperator _local_opt(PARSE_TIME); TRACE_POSTGRESQL_QUERY_PARSE_START(query_string); if (u_sess->attr.attr_common.log_parser_stats) ResetUsage(); - PGSTAT_START_TIME_RECORD(); - if (parser_hook == NULL) { parser_hook = raw_parser; #if (!defined(ENABLE_MULTIPLE_NODES)) && (!defined(ENABLE_PRIVATEGAUSS)) @@ -1047,7 +1045,6 @@ List* pg_parse_query(const char* query_string, List** query_string_locationlist, if (u_sess->parser_cxt.hasPartitionComment) { ereport(WARNING, (errmsg("comment is not allowed in partition/subpartition."))); } - PGSTAT_END_TIME_RECORD(PARSE_TIME); if (u_sess->attr.attr_common.log_parser_stats) ShowUsage("PARSER STATISTICS"); @@ -1082,6 +1079,7 @@ List* pg_parse_query(const char* query_string, List** query_string_locationlist, */ List* pg_analyze_and_rewrite(Node* parsetree, const char* query_string, Oid* paramTypes, int numParams) { + OgRecordOperator _local_opt(SRT3_ANALYZE_REWRITE); Query* query = NULL; List* querytree_list = NULL; @@ -1362,7 +1360,7 @@ static void check_query_acl(Query* query) PlannedStmt* pg_plan_query(Query* querytree, int cursorOptions, ParamListInfo boundParams, bool underExplain) { PlannedStmt* plan = NULL; - PGSTAT_INIT_TIME_RECORD(); + OgRecordOperator _local_opt(PLAN_TIME); bool multi_node_hint = false; /* Utility commands have no plans. */ @@ -1385,8 +1383,6 @@ PlannedStmt* pg_plan_query(Query* querytree, int cursorOptions, ParamListInfo bo /* Update hard parse counter for Unique SQL */ UniqueSQLStatCountHardParse(1); - PGSTAT_START_TIME_RECORD(); - /* check perssion for expect_computing_nodegroup */ if (!OidIsValid(lc_replan_nodegroup)) check_query_acl(querytree); @@ -1398,8 +1394,6 @@ PlannedStmt* pg_plan_query(Query* querytree, int cursorOptions, ParamListInfo bo plan = planner(querytree, cursorOptions, boundParams); } - PGSTAT_END_TIME_RECORD(PLAN_TIME); - if (u_sess->attr.attr_common.log_planner_stats) ShowUsage("PLANNER STATISTICS"); @@ -1492,6 +1486,7 @@ __attribute__((unused)) static bool is_insert_multiple_values_query_in_gtmfree(Q */ List* pg_plan_queries(List* querytrees, int cursorOptions, ParamListInfo boundParams) { + OgRecordOperator _local_opt(SRT4_PLAN_QUERY); List* stmt_list = NIL; ListCell* query_list = NULL; @@ -2377,6 +2372,7 @@ bool IsRightRefState(List* plantreeList) */ static void exec_simple_query(const char* query_string, MessageType messageType, StringInfo msg = NULL) { + OgRecordOperator _local_opt(SRT2_SIMPLE_QUERY); CommandDest dest = (CommandDest)t_thrd.postgres_cxt.whereToSendOutput; MemoryContext oldcontext; MemoryContext OptimizerContext; @@ -8404,6 +8400,10 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam if (AlignMemoryContext != NULL) MemoryContextReset(AlignMemoryContext); + + // reinit record time class and related memory. + og_record_time_reinit(); + /* * Now return to normal top-level context and clear ErrorContext for * next time. @@ -8482,10 +8482,15 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam } bool template0_locked = false; + OgRecordOperator _local_tmp_opt(false, SRT13_BEFORE_QUERY); + OgRecordOperator _local_tmp_opt1(false, SRT14_AFTER_QUERY); /* * Non-error queries loop here. */ for (;;) { + if (og_time_record_is_started()) { + _local_tmp_opt.enter(); + } /* * Since max_query_rerty_times is a USERSET GUC, so must check Statement retry * in each query loop here. @@ -8626,6 +8631,9 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam } #endif /* update our elapsed time statistics. */ + if (og_time_record_is_started()) { + _local_tmp_opt.exit(); + } timeInfoRecordEnd(); /* reset unique_sql_id & stat @@ -8642,6 +8650,9 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam send_ready_for_query = false; } else { /* update our elapsed time statistics. */ + if (og_time_record_is_started()) { + _local_tmp_opt.exit(); + } timeInfoRecordEnd(); } /* @@ -8742,6 +8753,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam firstchar = ReadCommand(&input_message); /* update our elapsed time statistics. */ timeInfoRecordStart(); + _local_tmp_opt1.enter(); /* stmt retry routine phase : pack input_message */ if (IsStmtRetryEnabled()) { @@ -8786,6 +8798,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam u_sess->proc_cxt.MyProcPort->protocol_config->fn_process_command) { firstchar = u_sess->proc_cxt.MyProcPort->protocol_config->fn_process_command(&input_message); send_ready_for_query = true; + _local_tmp_opt1.exit(); continue; } @@ -8793,8 +8806,10 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam * (7) process the command. But ignore it if we're skipping till * Sync. */ - if (u_sess->postgres_cxt.ignore_till_sync && firstchar != EOF) + if (u_sess->postgres_cxt.ignore_till_sync && firstchar != EOF) { + _local_tmp_opt1.exit(); continue; + } #ifdef ENABLE_MULTIPLE_NODES // reset some flag related to stream ResetSessionEnv(); @@ -8837,8 +8852,10 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam firstchar); if (libpqsw_process_message(firstchar, &input_message)) { + _local_tmp_opt1.exit(); continue; } + _local_tmp_opt1.exit(); switch (firstchar) { #ifdef ENABLE_MULTIPLE_NODES @@ -8992,6 +9009,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam case 'Q': /* simple query */ { const char* query_string = NULL; + OgRecordOperator _local_opt(SRT1_Q); pgstat_report_trace_id(&u_sess->trace_cxt, true); query_string = pq_getmsgstring(&input_message); @@ -9361,6 +9379,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam #endif case 'P': /* parse */ { + OgRecordOperator _local_opt(SRT6_P); const char* stmt_name = NULL; const char* query_string = NULL; int numParams; @@ -9467,6 +9486,8 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam } break; case 'B': /* bind */ + { + OgRecordOperator _local_opt(SRT7_B); #ifdef USE_RETRY_STUB if (IsStmtRetryEnabled()) u_sess->exec_cxt.RetryController->stub_.StartOneStubTest(firstchar); @@ -9479,10 +9500,11 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam */ instr_stmt_report_trace_id(u_sess->trace_cxt.trace_id); exec_bind_message(&input_message); - break; + } break; case 'E': /* execute */ { + OgRecordOperator _local_opt(SRT8_E); const char* portal_name = NULL; int max_rows; @@ -9627,6 +9649,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam case 'C': /* close */ { + OgRecordOperator _local_opt(SRT11_C); int close_type; const char* closeTarget = NULL; @@ -9689,6 +9712,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam case 'D': /* describe */ { + OgRecordOperator _local_opt(SRT9_D); int describe_type; const char* describe_target = NULL; if ((unsigned int)input_message.len > SECUREC_MEM_MAX_LEN) { @@ -9741,6 +9765,8 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam break; case 'S': /* sync */ + { + OgRecordOperator _local_opt(SRT10_S); pq_getmsgend(&input_message); #ifdef USE_RETRY_STUB if (IsStmtRetryEnabled()) { @@ -9759,8 +9785,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam if (IsStmtRetryEnabled()) { t_thrd.log_cxt.flush_message_immediately = false; } - - break; + } break; /* * 'X' means that the frontend is closing down the socket. EOF @@ -10222,6 +10247,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam case 'U': /* msg type for batch Bind-Execute for PBE */ { + OgRecordOperator _local_opt(SRT12_U); if (!u_sess->attr.attr_common.support_batch_bind) ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR), diff --git a/src/gausskernel/process/tcop/pquery.cpp b/src/gausskernel/process/tcop/pquery.cpp index 69c272945..d0bb9fcc0 100644 --- a/src/gausskernel/process/tcop/pquery.cpp +++ b/src/gausskernel/process/tcop/pquery.cpp @@ -1011,6 +1011,7 @@ bool PortalRun( { gstrace_entry(GS_TRC_ID_PortalRun); increase_instr_portal_nesting_level(); + OgRecordOperator _local_opt(EXECUTION_TIME); bool result = false; uint64 nprocessed; @@ -1759,6 +1760,7 @@ static void PortalRunMulti( { bool active_snapshot_set = false; ListCell* stmtlist_item = NULL; + OgRecordOperator _local_opt(EXECUTION_TIME); PGSTAT_INIT_TIME_RECORD(); #ifdef PGXC CombineTag combine; diff --git a/src/gausskernel/process/threadpool/knl_session.cpp b/src/gausskernel/process/threadpool/knl_session.cpp index 1752b26ab..55b942021 100755 --- a/src/gausskernel/process/threadpool/knl_session.cpp +++ b/src/gausskernel/process/threadpool/knl_session.cpp @@ -916,6 +916,8 @@ static void knl_u_stat_init(knl_u_stat_context* stat_cxt) size = sizeof(int64) * TOTAL_TIME_INFO_TYPES; stat_cxt->localTimeInfoArray = (int64*)palloc0(size); stat_cxt->localNetInfo = (uint64*)palloc0(sizeof(uint64) * TOTAL_NET_INFO_TYPES); + stat_cxt->og_record_stat = New(CurrentMemoryContext) OgRecordStat(stat_cxt->localTimeInfoArray, + stat_cxt->localNetInfo); stat_cxt->trackedMemChunks = 0; stat_cxt->trackedBytes = 0; diff --git a/src/gausskernel/runtime/executor/lightProxy.cpp b/src/gausskernel/runtime/executor/lightProxy.cpp index 1b279b7b4..1d34da09d 100644 --- a/src/gausskernel/runtime/executor/lightProxy.cpp +++ b/src/gausskernel/runtime/executor/lightProxy.cpp @@ -1336,6 +1336,7 @@ bool IsLightProxyOn(void) bool exec_query_through_light_proxy(List* querytree_list, Node* parsetree, bool snapshot_set, StringInfo msg, MemoryContext OptimizerContext) { + OgRecordOperator _local_opt(SRT5_LIGHT_QUERY); if ((list_length(querytree_list) == 1) && !IsA(parsetree, CreateTableAsStmt) && !IsA(parsetree, RefreshMatViewStmt)) { ExecNodes* single_exec_node = NULL; diff --git a/src/gausskernel/storage/ipc/ipc.cpp b/src/gausskernel/storage/ipc/ipc.cpp index 789899ce2..b35315af5 100644 --- a/src/gausskernel/storage/ipc/ipc.cpp +++ b/src/gausskernel/storage/ipc/ipc.cpp @@ -97,7 +97,8 @@ static const pg_on_exit_callback on_sess_exit_list[] = { AtProcExit_Files, audit_processlogout, log_disconnections, - libpqsw_cleanup + libpqsw_cleanup, + og_record_time_cleanup }; static const int on_sess_exit_size = lengthof(on_sess_exit_list); diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_906.sql b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_906.sql index d1f556cdc..c03aaa2e2 100644 --- a/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_906.sql +++ b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_906.sql @@ -1 +1,956 @@ DROP FUNCTION IF EXISTS pg_catalog.ss_txnstatus_cache_stat() CASCADE; + +-- those type of view and producer will recreate. +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time -- table +-- pg_catalog | gs_wlm_session_info_all | db_time -- view +-- dbe_perf | statement | db_time -- view +-- pg_catalog | statement_history | db_time -- unlogged table +-- dbe_perf | statement_history | db_time -- view +-- dbe_perf | summary_statement | db_time -- view +-- dbe_perf | gs_slow_query_info | db_time -- view +-- dbe_perf | gs_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_info | db_time -- view +-- those proc will recreated. +-- openGauss=# select proname, pronamespace from pg_proc where proargnames @> array['db_time']; +-- proname | pronamespace +-- ----------------------------------+-------------- +-- get_instr_unique_sql | 11 +-- pg_stat_get_wlm_session_info | 11 +-- standby_statement_history | 4988 +-- standby_statement_history | 4988 +-- get_global_full_sql_by_timestamp | 4988 +-- get_global_slow_sql_by_timestamp | 4988 + +/* We process history related tables、views and function now. */ +DROP VIEW IF EXISTS DBE_PERF.statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.summary_statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.statement_history CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.get_instr_unique_sql() CASCADE; +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5702; +CREATE FUNCTION pg_catalog.get_instr_unique_sql +( + OUT node_name name, + OUT node_id integer, + OUT user_name name, + OUT user_id oid, + OUT unique_sql_id bigint, + OUT query text, + OUT n_calls bigint, + OUT min_elapse_time bigint, + OUT max_elapse_time bigint, + OUT total_elapse_time bigint, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + Out net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT last_updated timestamp with time zone, + OUT sort_count bigint, + OUT sort_time bigint, + OUT sort_mem_used bigint, + OUT sort_spill_count bigint, + OUT sort_spill_size bigint, + OUT hash_count bigint, + OUT hash_time bigint, + OUT hash_mem_used bigint, + OUT hash_spill_count bigint, + OUT hash_spill_size bigint +) +RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'get_instr_unique_sql'; + +DROP INDEX IF EXISTS pg_catalog.statement_history_time_idx; +DROP TABLE IF EXISTS pg_catalog.statement_history cascade; + +CREATE unlogged table IF NOT EXISTS pg_catalog.statement_history( + db_name name, + schema_name name, + origin_node integer, + user_name name, + application_name text, + client_addr text, + client_port integer, + unique_query_id bigint, + debug_query_id bigint, + query text, + start_time timestamp with time zone, + finish_time timestamp with time zone, + slow_sql_threshold bigint, + transaction_id bigint, + thread_id bigint, + session_id bigint, + n_soft_parse bigint, + n_hard_parse bigint, + query_plan text, + n_returned_rows bigint, + n_tuples_fetched bigint, + n_tuples_returned bigint, + n_tuples_inserted bigint, + n_tuples_updated bigint, + n_tuples_deleted bigint, + n_blocks_fetched bigint, + n_blocks_hit bigint, + db_time bigint, + cpu_time bigint, + execution_time bigint, + parse_time bigint, + plan_time bigint, + rewrite_time bigint, + pl_execution_time bigint, + pl_compilation_time bigint, + data_io_time bigint, + net_send_info text, + net_recv_info text, + net_stream_send_info text, + net_stream_recv_info text, + lock_count bigint, + lock_time bigint, + lock_wait_count bigint, + lock_wait_time bigint, + lock_max_count bigint, + lwlock_count bigint, + lwlock_wait_count bigint, + lwlock_time bigint, + lwlock_wait_time bigint, + details bytea, + is_slow_sql boolean, + trace_id text, + advise text +); +REVOKE ALL on table pg_catalog.statement_history FROM public; +create index pg_catalog.statement_history_time_idx on pg_catalog.statement_history USING btree (start_time, is_slow_sql); + +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean); +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean, timestamp with time zone[]); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3118; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history_1v$function$; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3119; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + VARIADIC finish_time timestamp with time zone[], + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history$function$; + +CREATE VIEW DBE_PERF.statement AS + SELECT * FROM get_instr_unique_sql(); + +DROP FUNCTION IF EXISTS dbe_perf.get_summary_statement() cascade; +CREATE OR REPLACE FUNCTION dbe_perf.get_summary_statement() +RETURNS setof dbe_perf.statement +AS $$ +DECLARE + row_data dbe_perf.statement%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM dbe_perf.statement'; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE VIEW DBE_PERF.summary_statement AS + SELECT * FROM DBE_PERF.get_summary_statement(); + +CREATE VIEW DBE_PERF.statement_history AS + select * from pg_catalog.statement_history; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_full_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION dbe_perf.get_global_full_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text + ) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''''; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_slow_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''' and is_slow_sql = true '; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +/* we process wlm releates.*/ +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info_all CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.create_wlm_session_info(IN flag int) CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.pg_stat_get_wlm_session_info(OID) cascade; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5002; +CREATE OR REPLACE FUNCTION pg_catalog.pg_stat_get_wlm_session_info +(OID, + OUT datid oid, + OUT dbname text, + OUT schemaname text, + OUT nodename text, + OUT username text, + OUT application_name text, + OUT client_addr inet, + OUT client_hostname text, + OUT client_port integer, + OUT query_band text, + OUT block_time bigint, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT duration bigint, + OUT estimate_total_time bigint, + OUT status text, + OUT abort_info text, + OUT resource_pool text, + OUT control_group text, + OUT estimate_memory integer, + OUT min_peak_memory integer, + OUT max_peak_memory integer, + OUT average_peak_memory integer, + OUT memory_skew_percent integer, + OUT spill_info text, + OUT min_spill_size integer, + OUT max_spill_size integer, + OUT average_spill_size integer, + OUT spill_skew_percent integer, + OUT min_dn_time bigint, + OUT max_dn_time bigint, + OUT average_dn_time bigint, + OUT dntime_skew_percent integer, + OUT min_cpu_time bigint, + OUT max_cpu_time bigint, + OUT total_cpu_time bigint, + OUT cpu_skew_percent integer, + OUT min_peak_iops integer, + OUT max_peak_iops integer, + OUT average_peak_iops integer, + OUT iops_skew_percent integer, + OUT warning text, + OUT queryid bigint, + OUT query text, + OUT query_plan text, + OUT node_group text, + OUT cpu_top1_node_name text, + OUT cpu_top2_node_name text, + OUT cpu_top3_node_name text, + OUT cpu_top4_node_name text, + OUT cpu_top5_node_name text, + OUT mem_top1_node_name text, + OUT mem_top2_node_name text, + OUT mem_top3_node_name text, + OUT mem_top4_node_name text, + OUT mem_top5_node_name text, + OUT cpu_top1_value bigint, + OUT cpu_top2_value bigint, + OUT cpu_top3_value bigint, + OUT cpu_top4_value bigint, + OUT cpu_top5_value bigint, + OUT mem_top1_value bigint, + OUT mem_top2_value bigint, + OUT mem_top3_value bigint, + OUT mem_top4_value bigint, + OUT mem_top5_value bigint, + OUT top_mem_dn text, + OUT top_cpu_dn text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT net_send_time bigint, + OUT data_io_time bigint, + OUT is_slow_query bigint + ) RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'pg_stat_get_wlm_session_info'; + +CREATE VIEW pg_catalog.gs_wlm_session_info_all AS +SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(0); + +--process wlm_session info +CREATE VIEW pg_catalog.gs_wlm_session_info AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM gs_wlm_session_query_info_all S; + +CREATE VIEW pg_catalog.gs_wlm_session_history AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM pg_catalog.gs_wlm_session_info_all S; + +CREATE OR REPLACE FUNCTION pg_catalog.create_wlm_session_info(IN flag int) +RETURNS int +AS $$ +DECLARE + query_str text; + record_cnt int; + BEGIN + record_cnt := 0; + + query_str := 'SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(1)'; + + IF flag > 0 THEN + EXECUTE 'INSERT INTO pg_catalog.gs_wlm_session_query_info_all ' || query_str; + ELSE + EXECUTE query_str; + END IF; + + RETURN record_cnt; + END; $$ +LANGUAGE plpgsql NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_info() cascade; +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_history() cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_info cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_history cascade; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_info AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time +FROM gs_wlm_session_query_info_all S where S.is_slow_query = 1; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_history AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time +FROM pg_catalog.pg_stat_get_wlm_session_info(0) S where S.is_slow_query = 1; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_history +RETURNS setof dbe_perf.gs_slow_query_history +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_history%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_history'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_info() +RETURNS setof dbe_perf.gs_slow_query_info +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_info%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_info'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_history AS +SELECT * FROM DBE_PERF.global_slow_query_history(); + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_info AS +SELECT * FROM DBE_PERF.global_slow_query_info(); + +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_query_info_all TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_history TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info_all TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.STATEMENT TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.summary_statement TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.statement_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_info TO PUBLIC; diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback_catalog_maindb_92_906.sql b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback_catalog_maindb_92_906.sql new file mode 100644 index 000000000..c671518ec --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback_catalog_maindb_92_906.sql @@ -0,0 +1,22 @@ +-- this table will be remove column +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time --table +-- pg_catalog | statement_history | db_time --unlogged table, update in post-upgrade + +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt1_q cascade; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt2_simple_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt3_analyze_rewrite cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt4_plan_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt5_light_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt6_p cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt7_b cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt8_e cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt9_d cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt10_s cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt11_c cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt12_u cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt13_before_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt14_after_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists rtt_unknown cascade ; diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_906.sql b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_906.sql index d1f556cdc..f2a9f31ac 100644 --- a/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_906.sql +++ b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_906.sql @@ -1 +1,957 @@ DROP FUNCTION IF EXISTS pg_catalog.ss_txnstatus_cache_stat() CASCADE; + +-- those type of view and producer will recreate. +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time -- table +-- pg_catalog | gs_wlm_session_info_all | db_time -- view +-- dbe_perf | statement | db_time -- view +-- pg_catalog | statement_history | db_time -- unlogged table +-- dbe_perf | statement_history | db_time -- view +-- dbe_perf | summary_statement | db_time -- view +-- dbe_perf | gs_slow_query_info | db_time -- view +-- dbe_perf | gs_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_info | db_time -- view +-- those proc will recreated. +-- openGauss=# select proname, pronamespace from pg_proc where proargnames @> array['db_time']; +-- proname | pronamespace +-- ----------------------------------+-------------- +-- get_instr_unique_sql | 11 +-- pg_stat_get_wlm_session_info | 11 +-- standby_statement_history | 4988 +-- standby_statement_history | 4988 +-- get_global_full_sql_by_timestamp | 4988 +-- get_global_slow_sql_by_timestamp | 4988 + +/* We process history related tables、views and function now. */ +DROP VIEW IF EXISTS DBE_PERF.statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.summary_statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.statement_history CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.get_instr_unique_sql() CASCADE; +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5702; +CREATE FUNCTION pg_catalog.get_instr_unique_sql +( + OUT node_name name, + OUT node_id integer, + OUT user_name name, + OUT user_id oid, + OUT unique_sql_id bigint, + OUT query text, + OUT n_calls bigint, + OUT min_elapse_time bigint, + OUT max_elapse_time bigint, + OUT total_elapse_time bigint, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + Out net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT last_updated timestamp with time zone, + OUT sort_count bigint, + OUT sort_time bigint, + OUT sort_mem_used bigint, + OUT sort_spill_count bigint, + OUT sort_spill_size bigint, + OUT hash_count bigint, + OUT hash_time bigint, + OUT hash_mem_used bigint, + OUT hash_spill_count bigint, + OUT hash_spill_size bigint +) +RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'get_instr_unique_sql'; + +DROP INDEX IF EXISTS pg_catalog.statement_history_time_idx; +DROP TABLE IF EXISTS pg_catalog.statement_history cascade; + +CREATE unlogged table IF NOT EXISTS pg_catalog.statement_history( + db_name name, + schema_name name, + origin_node integer, + user_name name, + application_name text, + client_addr text, + client_port integer, + unique_query_id bigint, + debug_query_id bigint, + query text, + start_time timestamp with time zone, + finish_time timestamp with time zone, + slow_sql_threshold bigint, + transaction_id bigint, + thread_id bigint, + session_id bigint, + n_soft_parse bigint, + n_hard_parse bigint, + query_plan text, + n_returned_rows bigint, + n_tuples_fetched bigint, + n_tuples_returned bigint, + n_tuples_inserted bigint, + n_tuples_updated bigint, + n_tuples_deleted bigint, + n_blocks_fetched bigint, + n_blocks_hit bigint, + db_time bigint, + cpu_time bigint, + execution_time bigint, + parse_time bigint, + plan_time bigint, + rewrite_time bigint, + pl_execution_time bigint, + pl_compilation_time bigint, + data_io_time bigint, + net_send_info text, + net_recv_info text, + net_stream_send_info text, + net_stream_recv_info text, + lock_count bigint, + lock_time bigint, + lock_wait_count bigint, + lock_wait_time bigint, + lock_max_count bigint, + lwlock_count bigint, + lwlock_wait_count bigint, + lwlock_time bigint, + lwlock_wait_time bigint, + details bytea, + is_slow_sql boolean, + trace_id text, + advise text +); +REVOKE ALL on table pg_catalog.statement_history FROM public; +create index pg_catalog.statement_history_time_idx on pg_catalog.statement_history USING btree (start_time, is_slow_sql); + +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean); +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean, timestamp with time zone[]); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3118; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history_1v$function$; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3119; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + VARIADIC finish_time timestamp with time zone[], + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history$function$; + +CREATE VIEW DBE_PERF.statement AS + SELECT * FROM get_instr_unique_sql(); + +DROP FUNCTION IF EXISTS dbe_perf.get_summary_statement() cascade; +CREATE OR REPLACE FUNCTION dbe_perf.get_summary_statement() +RETURNS setof dbe_perf.statement +AS $$ +DECLARE + row_data dbe_perf.statement%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM dbe_perf.statement'; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE VIEW DBE_PERF.summary_statement AS + SELECT * FROM DBE_PERF.get_summary_statement(); + +CREATE VIEW DBE_PERF.statement_history AS + select * from pg_catalog.statement_history; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_full_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION dbe_perf.get_global_full_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text + ) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''''; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_slow_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''' and is_slow_sql = true '; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +/* we process wlm releates.*/ +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info_all CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.create_wlm_session_info(IN flag int) CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.pg_stat_get_wlm_session_info(OID) cascade; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5002; +CREATE OR REPLACE FUNCTION pg_catalog.pg_stat_get_wlm_session_info +(OID, + OUT datid oid, + OUT dbname text, + OUT schemaname text, + OUT nodename text, + OUT username text, + OUT application_name text, + OUT client_addr inet, + OUT client_hostname text, + OUT client_port integer, + OUT query_band text, + OUT block_time bigint, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT duration bigint, + OUT estimate_total_time bigint, + OUT status text, + OUT abort_info text, + OUT resource_pool text, + OUT control_group text, + OUT estimate_memory integer, + OUT min_peak_memory integer, + OUT max_peak_memory integer, + OUT average_peak_memory integer, + OUT memory_skew_percent integer, + OUT spill_info text, + OUT min_spill_size integer, + OUT max_spill_size integer, + OUT average_spill_size integer, + OUT spill_skew_percent integer, + OUT min_dn_time bigint, + OUT max_dn_time bigint, + OUT average_dn_time bigint, + OUT dntime_skew_percent integer, + OUT min_cpu_time bigint, + OUT max_cpu_time bigint, + OUT total_cpu_time bigint, + OUT cpu_skew_percent integer, + OUT min_peak_iops integer, + OUT max_peak_iops integer, + OUT average_peak_iops integer, + OUT iops_skew_percent integer, + OUT warning text, + OUT queryid bigint, + OUT query text, + OUT query_plan text, + OUT node_group text, + OUT cpu_top1_node_name text, + OUT cpu_top2_node_name text, + OUT cpu_top3_node_name text, + OUT cpu_top4_node_name text, + OUT cpu_top5_node_name text, + OUT mem_top1_node_name text, + OUT mem_top2_node_name text, + OUT mem_top3_node_name text, + OUT mem_top4_node_name text, + OUT mem_top5_node_name text, + OUT cpu_top1_value bigint, + OUT cpu_top2_value bigint, + OUT cpu_top3_value bigint, + OUT cpu_top4_value bigint, + OUT cpu_top5_value bigint, + OUT mem_top1_value bigint, + OUT mem_top2_value bigint, + OUT mem_top3_value bigint, + OUT mem_top4_value bigint, + OUT mem_top5_value bigint, + OUT top_mem_dn text, + OUT top_cpu_dn text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT net_send_time bigint, + OUT data_io_time bigint, + OUT is_slow_query bigint + ) RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'pg_stat_get_wlm_session_info'; + +CREATE VIEW pg_catalog.gs_wlm_session_info_all AS +SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(0); + +--process wlm_session info +CREATE VIEW pg_catalog.gs_wlm_session_info AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM gs_wlm_session_query_info_all S; + +CREATE VIEW pg_catalog.gs_wlm_session_history AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM pg_catalog.gs_wlm_session_info_all S; + +CREATE OR REPLACE FUNCTION pg_catalog.create_wlm_session_info(IN flag int) +RETURNS int +AS $$ +DECLARE + query_str text; + record_cnt int; + BEGIN + record_cnt := 0; + + query_str := 'SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(1)'; + + IF flag > 0 THEN + EXECUTE 'INSERT INTO pg_catalog.gs_wlm_session_query_info_all ' || query_str; + ELSE + EXECUTE query_str; + END IF; + + RETURN record_cnt; + END; $$ +LANGUAGE plpgsql NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_info() cascade; +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_history() cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_info cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_history cascade; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_info AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time +FROM gs_wlm_session_query_info_all S where S.is_slow_query = 1; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_history AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time +FROM pg_catalog.pg_stat_get_wlm_session_info(0) S where S.is_slow_query = 1; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_history +RETURNS setof dbe_perf.gs_slow_query_history +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_history%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_history'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_info() +RETURNS setof dbe_perf.gs_slow_query_info +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_info%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_info'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_history AS +SELECT * FROM DBE_PERF.global_slow_query_history(); + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_info AS +SELECT * FROM DBE_PERF.global_slow_query_info(); + +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_query_info_all TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_history TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info_all TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.STATEMENT TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.summary_statement TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.statement_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_info TO PUBLIC; + diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback_catalog_otherdb_92_906.sql b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback_catalog_otherdb_92_906.sql new file mode 100644 index 000000000..5b86b48b9 --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback_catalog_otherdb_92_906.sql @@ -0,0 +1,22 @@ +-- this table will be remove column +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time --table +-- pg_catalog | statement_history | db_time --unlogged table, update in post-upgrade + +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt1_q cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt2_simple_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt3_analyze_rewrite cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt4_plan_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt5_light_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt6_p cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt7_b cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt8_e cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt9_d cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt10_s cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt11_c cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt12_u cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt13_before_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists srt14_after_query cascade ; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all drop column if exists rtt_unknown cascade ; diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_906.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_906.sql index a720071e5..518497b40 100644 --- a/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_906.sql +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_906.sql @@ -13,3 +13,1130 @@ CREATE FUNCTION pg_catalog.ss_txnstatus_cache_stat( RETURNS SETOF record LANGUAGE internal STABLE NOT FENCED NOT SHIPPABLE ROWS 100 AS 'ss_txnstatus_cache_stat'; + +-- those type of view will recreate. +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time -- table +-- pg_catalog | gs_wlm_session_info_all | db_time -- view +-- dbe_perf | statement | db_time -- view +-- pg_catalog | statement_history | db_time -- unlogged table +-- dbe_perf | statement_history | db_time -- view +-- dbe_perf | summary_statement | db_time -- view +-- dbe_perf | gs_slow_query_info | db_time -- view +-- dbe_perf | gs_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_info | db_time -- view +-- those proc will recreated. +-- openGauss=# select proname, pronamespace from pg_proc where proargnames @> array['db_time']; +-- proname | pronamespace +-- ----------------------------------+-------------- +-- get_instr_unique_sql | 11 +-- pg_stat_get_wlm_session_info | 11 +-- standby_statement_history | 4988 +-- standby_statement_history | 4988 +-- get_global_full_sql_by_timestamp | 4988 +-- get_global_slow_sql_by_timestamp | 4988 + +/* We process history related tables、views and function now. */ +DROP VIEW IF EXISTS DBE_PERF.statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.summary_statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.statement_history CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.get_instr_unique_sql() CASCADE; +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5702; +CREATE FUNCTION pg_catalog.get_instr_unique_sql +( + OUT node_name name, + OUT node_id integer, + OUT user_name name, + OUT user_id oid, + OUT unique_sql_id bigint, + OUT query text, + OUT n_calls bigint, + OUT min_elapse_time bigint, + OUT max_elapse_time bigint, + OUT total_elapse_time bigint, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + Out net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT last_updated timestamp with time zone, + OUT sort_count bigint, + OUT sort_time bigint, + OUT sort_mem_used bigint, + OUT sort_spill_count bigint, + OUT sort_spill_size bigint, + OUT hash_count bigint, + OUT hash_time bigint, + OUT hash_mem_used bigint, + OUT hash_spill_count bigint, + OUT hash_spill_size bigint, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint +) +RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'get_instr_unique_sql'; + +DROP INDEX IF EXISTS pg_catalog.statement_history_time_idx; +DROP TABLE IF EXISTS pg_catalog.statement_history cascade; + +CREATE unlogged table IF NOT EXISTS pg_catalog.statement_history( + db_name name, + schema_name name, + origin_node integer, + user_name name, + application_name text, + client_addr text, + client_port integer, + unique_query_id bigint, + debug_query_id bigint, + query text, + start_time timestamp with time zone, + finish_time timestamp with time zone, + slow_sql_threshold bigint, + transaction_id bigint, + thread_id bigint, + session_id bigint, + n_soft_parse bigint, + n_hard_parse bigint, + query_plan text, + n_returned_rows bigint, + n_tuples_fetched bigint, + n_tuples_returned bigint, + n_tuples_inserted bigint, + n_tuples_updated bigint, + n_tuples_deleted bigint, + n_blocks_fetched bigint, + n_blocks_hit bigint, + db_time bigint, + cpu_time bigint, + execution_time bigint, + parse_time bigint, + plan_time bigint, + rewrite_time bigint, + pl_execution_time bigint, + pl_compilation_time bigint, + data_io_time bigint, + net_send_info text, + net_recv_info text, + net_stream_send_info text, + net_stream_recv_info text, + lock_count bigint, + lock_time bigint, + lock_wait_count bigint, + lock_wait_time bigint, + lock_max_count bigint, + lwlock_count bigint, + lwlock_wait_count bigint, + lwlock_time bigint, + lwlock_wait_time bigint, + details bytea, + is_slow_sql boolean, + trace_id text, + advise text, + net_send_time bigint, + srt1_q bigint, + srt2_simple_query bigint, + srt3_analyze_rewrite bigint, + srt4_plan_query bigint, + srt5_light_query bigint, + srt6_p bigint, + srt7_b bigint, + srt8_e bigint, + srt9_d bigint, + srt10_s bigint, + srt11_c bigint, + srt12_u bigint, + srt13_before_query bigint, + srt14_after_query bigint, + rtt_unknown bigint +); +REVOKE ALL on table pg_catalog.statement_history FROM public; +create index pg_catalog.statement_history_time_idx on pg_catalog.statement_history USING btree (start_time, is_slow_sql); + +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean); +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean, timestamp with time zone[]); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3118; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history_1v$function$; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3119; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + VARIADIC finish_time timestamp with time zone[], + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history$function$; + +CREATE VIEW DBE_PERF.statement AS + SELECT * FROM get_instr_unique_sql(); + +DROP FUNCTION IF EXISTS dbe_perf.get_summary_statement() cascade; +CREATE OR REPLACE FUNCTION dbe_perf.get_summary_statement() +RETURNS setof dbe_perf.statement +AS $$ +DECLARE + row_data dbe_perf.statement%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM dbe_perf.statement'; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE VIEW DBE_PERF.summary_statement AS + SELECT * FROM DBE_PERF.get_summary_statement(); + +CREATE VIEW DBE_PERF.statement_history AS + select * from pg_catalog.statement_history; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_full_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION dbe_perf.get_global_full_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint + ) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''''; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_slow_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''' and is_slow_sql = true '; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +/* we process wlm releates.*/ +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info_all CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.create_wlm_session_info(IN flag int) CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.pg_stat_get_wlm_session_info(OID) cascade; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5002; +CREATE OR REPLACE FUNCTION pg_catalog.pg_stat_get_wlm_session_info +(OID, + OUT datid oid, + OUT dbname text, + OUT schemaname text, + OUT nodename text, + OUT username text, + OUT application_name text, + OUT client_addr inet, + OUT client_hostname text, + OUT client_port integer, + OUT query_band text, + OUT block_time bigint, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT duration bigint, + OUT estimate_total_time bigint, + OUT status text, + OUT abort_info text, + OUT resource_pool text, + OUT control_group text, + OUT estimate_memory integer, + OUT min_peak_memory integer, + OUT max_peak_memory integer, + OUT average_peak_memory integer, + OUT memory_skew_percent integer, + OUT spill_info text, + OUT min_spill_size integer, + OUT max_spill_size integer, + OUT average_spill_size integer, + OUT spill_skew_percent integer, + OUT min_dn_time bigint, + OUT max_dn_time bigint, + OUT average_dn_time bigint, + OUT dntime_skew_percent integer, + OUT min_cpu_time bigint, + OUT max_cpu_time bigint, + OUT total_cpu_time bigint, + OUT cpu_skew_percent integer, + OUT min_peak_iops integer, + OUT max_peak_iops integer, + OUT average_peak_iops integer, + OUT iops_skew_percent integer, + OUT warning text, + OUT queryid bigint, + OUT query text, + OUT query_plan text, + OUT node_group text, + OUT cpu_top1_node_name text, + OUT cpu_top2_node_name text, + OUT cpu_top3_node_name text, + OUT cpu_top4_node_name text, + OUT cpu_top5_node_name text, + OUT mem_top1_node_name text, + OUT mem_top2_node_name text, + OUT mem_top3_node_name text, + OUT mem_top4_node_name text, + OUT mem_top5_node_name text, + OUT cpu_top1_value bigint, + OUT cpu_top2_value bigint, + OUT cpu_top3_value bigint, + OUT cpu_top4_value bigint, + OUT cpu_top5_value bigint, + OUT mem_top1_value bigint, + OUT mem_top2_value bigint, + OUT mem_top3_value bigint, + OUT mem_top4_value bigint, + OUT mem_top5_value bigint, + OUT top_mem_dn text, + OUT top_cpu_dn text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT net_send_time bigint, + OUT data_io_time bigint, + OUT is_slow_query bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint + ) RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'pg_stat_get_wlm_session_info'; + + +CREATE VIEW pg_catalog.gs_wlm_session_info_all AS +SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(0); + +--process wlm_session info +CREATE VIEW pg_catalog.gs_wlm_session_info AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM gs_wlm_session_query_info_all S; + +CREATE VIEW pg_catalog.gs_wlm_session_history AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM pg_catalog.gs_wlm_session_info_all S; + +CREATE OR REPLACE FUNCTION pg_catalog.create_wlm_session_info(IN flag int) +RETURNS int +AS $$ +DECLARE + query_str text; + record_cnt int; + BEGIN + record_cnt := 0; + + query_str := 'SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(1)'; + + IF flag > 0 THEN + EXECUTE 'INSERT INTO pg_catalog.gs_wlm_session_query_info_all ' || query_str; + ELSE + EXECUTE query_str; + END IF; + + RETURN record_cnt; + END; $$ +LANGUAGE plpgsql NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_info() cascade; +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_history() cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_info cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_history cascade; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_info AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown +FROM gs_wlm_session_query_info_all S where S.is_slow_query = 1; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_history AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown +FROM pg_catalog.pg_stat_get_wlm_session_info(0) S where S.is_slow_query = 1; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_history +RETURNS setof dbe_perf.gs_slow_query_history +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_history%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_history'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_info() +RETURNS setof dbe_perf.gs_slow_query_info +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_info%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_info'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_history AS +SELECT * FROM DBE_PERF.global_slow_query_history(); + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_info AS +SELECT * FROM DBE_PERF.global_slow_query_info(); + +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_query_info_all TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_history TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info_all TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.STATEMENT TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.summary_statement TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.statement_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_info TO PUBLIC; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade_catalog_maindb_92_906.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade_catalog_maindb_92_906.sql new file mode 100644 index 000000000..51a105b0b --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade_catalog_maindb_92_906.sql @@ -0,0 +1,22 @@ +-- this table will be add column +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time --table +-- pg_catalog | statement_history | db_time --unlogged table, update in post-upgrade + +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt1_q bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt2_simple_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt3_analyze_rewrite bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt4_plan_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt5_light_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt6_p bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt7_b bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt8_e bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt9_d bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt10_s bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt11_c bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt12_u bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt13_before_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt14_after_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column rtt_unknown bigint; diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_906.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_906.sql index a720071e5..518497b40 100644 --- a/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_906.sql +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_906.sql @@ -13,3 +13,1130 @@ CREATE FUNCTION pg_catalog.ss_txnstatus_cache_stat( RETURNS SETOF record LANGUAGE internal STABLE NOT FENCED NOT SHIPPABLE ROWS 100 AS 'ss_txnstatus_cache_stat'; + +-- those type of view will recreate. +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time -- table +-- pg_catalog | gs_wlm_session_info_all | db_time -- view +-- dbe_perf | statement | db_time -- view +-- pg_catalog | statement_history | db_time -- unlogged table +-- dbe_perf | statement_history | db_time -- view +-- dbe_perf | summary_statement | db_time -- view +-- dbe_perf | gs_slow_query_info | db_time -- view +-- dbe_perf | gs_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_history | db_time -- view +-- dbe_perf | global_slow_query_info | db_time -- view +-- those proc will recreated. +-- openGauss=# select proname, pronamespace from pg_proc where proargnames @> array['db_time']; +-- proname | pronamespace +-- ----------------------------------+-------------- +-- get_instr_unique_sql | 11 +-- pg_stat_get_wlm_session_info | 11 +-- standby_statement_history | 4988 +-- standby_statement_history | 4988 +-- get_global_full_sql_by_timestamp | 4988 +-- get_global_slow_sql_by_timestamp | 4988 + +/* We process history related tables、views and function now. */ +DROP VIEW IF EXISTS DBE_PERF.statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.summary_statement CASCADE; +DROP VIEW IF EXISTS DBE_PERF.statement_history CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.get_instr_unique_sql() CASCADE; +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5702; +CREATE FUNCTION pg_catalog.get_instr_unique_sql +( + OUT node_name name, + OUT node_id integer, + OUT user_name name, + OUT user_id oid, + OUT unique_sql_id bigint, + OUT query text, + OUT n_calls bigint, + OUT min_elapse_time bigint, + OUT max_elapse_time bigint, + OUT total_elapse_time bigint, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + Out net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT last_updated timestamp with time zone, + OUT sort_count bigint, + OUT sort_time bigint, + OUT sort_mem_used bigint, + OUT sort_spill_count bigint, + OUT sort_spill_size bigint, + OUT hash_count bigint, + OUT hash_time bigint, + OUT hash_mem_used bigint, + OUT hash_spill_count bigint, + OUT hash_spill_size bigint, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint +) +RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'get_instr_unique_sql'; + +DROP INDEX IF EXISTS pg_catalog.statement_history_time_idx; +DROP TABLE IF EXISTS pg_catalog.statement_history cascade; + +CREATE unlogged table IF NOT EXISTS pg_catalog.statement_history( + db_name name, + schema_name name, + origin_node integer, + user_name name, + application_name text, + client_addr text, + client_port integer, + unique_query_id bigint, + debug_query_id bigint, + query text, + start_time timestamp with time zone, + finish_time timestamp with time zone, + slow_sql_threshold bigint, + transaction_id bigint, + thread_id bigint, + session_id bigint, + n_soft_parse bigint, + n_hard_parse bigint, + query_plan text, + n_returned_rows bigint, + n_tuples_fetched bigint, + n_tuples_returned bigint, + n_tuples_inserted bigint, + n_tuples_updated bigint, + n_tuples_deleted bigint, + n_blocks_fetched bigint, + n_blocks_hit bigint, + db_time bigint, + cpu_time bigint, + execution_time bigint, + parse_time bigint, + plan_time bigint, + rewrite_time bigint, + pl_execution_time bigint, + pl_compilation_time bigint, + data_io_time bigint, + net_send_info text, + net_recv_info text, + net_stream_send_info text, + net_stream_recv_info text, + lock_count bigint, + lock_time bigint, + lock_wait_count bigint, + lock_wait_time bigint, + lock_max_count bigint, + lwlock_count bigint, + lwlock_wait_count bigint, + lwlock_time bigint, + lwlock_wait_time bigint, + details bytea, + is_slow_sql boolean, + trace_id text, + advise text, + net_send_time bigint, + srt1_q bigint, + srt2_simple_query bigint, + srt3_analyze_rewrite bigint, + srt4_plan_query bigint, + srt5_light_query bigint, + srt6_p bigint, + srt7_b bigint, + srt8_e bigint, + srt9_d bigint, + srt10_s bigint, + srt11_c bigint, + srt12_u bigint, + srt13_before_query bigint, + srt14_after_query bigint, + rtt_unknown bigint +); +REVOKE ALL on table pg_catalog.statement_history FROM public; +create index pg_catalog.statement_history_time_idx on pg_catalog.statement_history USING btree (start_time, is_slow_sql); + +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean); +DROP FUNCTION IF EXISTS dbe_perf.standby_statement_history(boolean, timestamp with time zone[]); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3118; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history_1v$function$; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 3119; +CREATE FUNCTION dbe_perf.standby_statement_history( + IN only_slow boolean, + VARIADIC finish_time timestamp with time zone[], + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql boolean, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) +RETURNS SETOF record NOT FENCED NOT SHIPPABLE ROWS 10000 +LANGUAGE internal AS $function$standby_statement_history$function$; + +CREATE VIEW DBE_PERF.statement AS + SELECT * FROM get_instr_unique_sql(); + +DROP FUNCTION IF EXISTS dbe_perf.get_summary_statement() cascade; +CREATE OR REPLACE FUNCTION dbe_perf.get_summary_statement() +RETURNS setof dbe_perf.statement +AS $$ +DECLARE + row_data dbe_perf.statement%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM dbe_perf.statement'; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE VIEW DBE_PERF.summary_statement AS + SELECT * FROM DBE_PERF.get_summary_statement(); + +CREATE VIEW DBE_PERF.statement_history AS + select * from pg_catalog.statement_history; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_full_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION dbe_perf.get_global_full_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint + ) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''''; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.get_global_slow_sql_by_timestamp(timestamp with time zone, timestamp with time zone); +CREATE OR REPLACE FUNCTION DBE_PERF.get_global_slow_sql_by_timestamp + (in start_timestamp timestamp with time zone, + in end_timestamp timestamp with time zone, + OUT node_name name, + OUT db_name name, + OUT schema_name name, + OUT origin_node integer, + OUT user_name name, + OUT application_name text, + OUT client_addr text, + OUT client_port integer, + OUT unique_query_id bigint, + OUT debug_query_id bigint, + OUT query text, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT slow_sql_threshold bigint, + OUT transaction_id bigint, + OUT thread_id bigint, + OUT session_id bigint, + OUT n_soft_parse bigint, + OUT n_hard_parse bigint, + OUT query_plan text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT data_io_time bigint, + OUT net_send_info text, + OUT net_recv_info text, + OUT net_stream_send_info text, + OUT net_stream_recv_info text, + OUT lock_count bigint, + OUT lock_time bigint, + OUT lock_wait_count bigint, + OUT lock_wait_time bigint, + OUT lock_max_count bigint, + OUT lwlock_count bigint, + OUT lwlock_wait_count bigint, + OUT lwlock_time bigint, + OUT lwlock_wait_time bigint, + OUT details bytea, + OUT is_slow_sql bool, + OUT trace_id text, + OUT advise text, + OUT net_send_time bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint) + RETURNS setof record + AS $$ + DECLARE + row_data pg_catalog.statement_history%rowtype; + row_name record; + query_str text; + -- node name + query_str_nodes text; + BEGIN + -- Get all node names(CN + master DN) + query_str_nodes := 'select * from dbe_perf.node_name'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'SELECT * FROM DBE_PERF.statement_history where start_time >= ''' ||$1|| ''' and start_time <= ''' || $2 || ''' and is_slow_sql = true '; + FOR row_data IN EXECUTE(query_str) LOOP + node_name := row_name.node_name; + db_name := row_data.db_name; + schema_name := row_data.schema_name; + origin_node := row_data.origin_node; + user_name := row_data.user_name; + application_name := row_data.application_name; + client_addr := row_data.client_addr; + client_port := row_data.client_port; + unique_query_id := row_data.unique_query_id; + debug_query_id := row_data.debug_query_id; + query := row_data.query; + start_time := row_data.start_time; + finish_time := row_data.finish_time; + slow_sql_threshold := row_data.slow_sql_threshold; + transaction_id := row_data.transaction_id; + thread_id := row_data.thread_id; + session_id := row_data.session_id; + n_soft_parse := row_data.n_soft_parse; + n_hard_parse := row_data.n_hard_parse; + query_plan := row_data.query_plan; + n_returned_rows := row_data.n_returned_rows; + n_tuples_fetched := row_data.n_tuples_fetched; + n_tuples_returned := row_data.n_tuples_returned; + n_tuples_inserted := row_data.n_tuples_inserted; + n_tuples_updated := row_data.n_tuples_updated; + n_tuples_deleted := row_data.n_tuples_deleted; + n_blocks_fetched := row_data.n_blocks_fetched; + n_blocks_hit := row_data.n_blocks_hit; + db_time := row_data.db_time; + cpu_time := row_data.cpu_time; + execution_time := row_data.execution_time; + parse_time := row_data.parse_time; + plan_time := row_data.plan_time; + rewrite_time := row_data.rewrite_time; + pl_execution_time := row_data.pl_execution_time; + pl_compilation_time := row_data.pl_compilation_time; + data_io_time := row_data.data_io_time; + net_send_info := row_data.net_send_info; + net_recv_info := row_data.net_recv_info; + net_stream_send_info := row_data.net_stream_send_info; + net_stream_recv_info := row_data.net_stream_recv_info; + lock_count := row_data.lock_count; + lock_time := row_data.lock_time; + lock_wait_count := row_data.lock_wait_count; + lock_wait_time := row_data.lock_wait_time; + lock_max_count := row_data.lock_max_count; + lwlock_count := row_data.lwlock_count; + lwlock_wait_count := row_data.lwlock_wait_count; + lwlock_time := row_data.lwlock_time; + lwlock_wait_time := row_data.lwlock_wait_time; + details := row_data.details; + is_slow_sql := row_data.is_slow_sql; + trace_id := row_data.trace_id; + advise := row_data.advise; + net_send_time =row_data.net_send_time; + srt1_q := row_data.srt1_q; + srt2_simple_query := row_data.srt2_simple_query; + srt3_analyze_rewrite := row_data.srt3_analyze_rewrite; + srt4_plan_query := row_data.srt4_plan_query; + srt5_light_query := row_data.srt5_light_query; + srt6_p := row_data.srt6_p; + srt7_b := row_data.srt7_b; + srt8_e := row_data.srt8_e; + srt9_d := row_data.srt9_d; + srt10_s := row_data.srt10_s; + srt11_c := row_data.srt11_c; + srt12_u := row_data.srt12_u; + srt13_before_query := row_data.srt13_before_query; + srt14_after_query := row_data.srt14_after_query; + rtt_unknown := row_data.rtt_unknown; + return next; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +/* we process wlm releates.*/ +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info_all CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP VIEW IF EXISTS pg_catalog.gs_wlm_session_info CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.create_wlm_session_info(IN flag int) CASCADE; +DROP FUNCTION IF EXISTS pg_catalog.pg_stat_get_wlm_session_info(OID) cascade; + +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 5002; +CREATE OR REPLACE FUNCTION pg_catalog.pg_stat_get_wlm_session_info +(OID, + OUT datid oid, + OUT dbname text, + OUT schemaname text, + OUT nodename text, + OUT username text, + OUT application_name text, + OUT client_addr inet, + OUT client_hostname text, + OUT client_port integer, + OUT query_band text, + OUT block_time bigint, + OUT start_time timestamp with time zone, + OUT finish_time timestamp with time zone, + OUT duration bigint, + OUT estimate_total_time bigint, + OUT status text, + OUT abort_info text, + OUT resource_pool text, + OUT control_group text, + OUT estimate_memory integer, + OUT min_peak_memory integer, + OUT max_peak_memory integer, + OUT average_peak_memory integer, + OUT memory_skew_percent integer, + OUT spill_info text, + OUT min_spill_size integer, + OUT max_spill_size integer, + OUT average_spill_size integer, + OUT spill_skew_percent integer, + OUT min_dn_time bigint, + OUT max_dn_time bigint, + OUT average_dn_time bigint, + OUT dntime_skew_percent integer, + OUT min_cpu_time bigint, + OUT max_cpu_time bigint, + OUT total_cpu_time bigint, + OUT cpu_skew_percent integer, + OUT min_peak_iops integer, + OUT max_peak_iops integer, + OUT average_peak_iops integer, + OUT iops_skew_percent integer, + OUT warning text, + OUT queryid bigint, + OUT query text, + OUT query_plan text, + OUT node_group text, + OUT cpu_top1_node_name text, + OUT cpu_top2_node_name text, + OUT cpu_top3_node_name text, + OUT cpu_top4_node_name text, + OUT cpu_top5_node_name text, + OUT mem_top1_node_name text, + OUT mem_top2_node_name text, + OUT mem_top3_node_name text, + OUT mem_top4_node_name text, + OUT mem_top5_node_name text, + OUT cpu_top1_value bigint, + OUT cpu_top2_value bigint, + OUT cpu_top3_value bigint, + OUT cpu_top4_value bigint, + OUT cpu_top5_value bigint, + OUT mem_top1_value bigint, + OUT mem_top2_value bigint, + OUT mem_top3_value bigint, + OUT mem_top4_value bigint, + OUT mem_top5_value bigint, + OUT top_mem_dn text, + OUT top_cpu_dn text, + OUT n_returned_rows bigint, + OUT n_tuples_fetched bigint, + OUT n_tuples_returned bigint, + OUT n_tuples_inserted bigint, + OUT n_tuples_updated bigint, + OUT n_tuples_deleted bigint, + OUT n_blocks_fetched bigint, + OUT n_blocks_hit bigint, + OUT db_time bigint, + OUT cpu_time bigint, + OUT execution_time bigint, + OUT parse_time bigint, + OUT plan_time bigint, + OUT rewrite_time bigint, + OUT pl_execution_time bigint, + OUT pl_compilation_time bigint, + OUT net_send_time bigint, + OUT data_io_time bigint, + OUT is_slow_query bigint, + OUT srt1_q bigint, + OUT srt2_simple_query bigint, + OUT srt3_analyze_rewrite bigint, + OUT srt4_plan_query bigint, + OUT srt5_light_query bigint, + OUT srt6_p bigint, + OUT srt7_b bigint, + OUT srt8_e bigint, + OUT srt9_d bigint, + OUT srt10_s bigint, + OUT srt11_c bigint, + OUT srt12_u bigint, + OUT srt13_before_query bigint, + OUT srt14_after_query bigint, + OUT rtt_unknown bigint + ) RETURNS setof record LANGUAGE INTERNAL VOLATILE NOT FENCED as 'pg_stat_get_wlm_session_info'; + + +CREATE VIEW pg_catalog.gs_wlm_session_info_all AS +SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(0); + +--process wlm_session info +CREATE VIEW pg_catalog.gs_wlm_session_info AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM gs_wlm_session_query_info_all S; + +CREATE VIEW pg_catalog.gs_wlm_session_history AS +SELECT + S.datid, + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.application_name, + S.client_addr, + S.client_hostname, + S.client_port, + S.query_band, + S.block_time, + S.start_time, + S.finish_time, + S.duration, + S.estimate_total_time, + S.status, + S.abort_info, + S.resource_pool, + S.control_group, + S.estimate_memory, + S.min_peak_memory, + S.max_peak_memory, + S.average_peak_memory, + S.memory_skew_percent, + S.spill_info, + S.min_spill_size, + S.max_spill_size, + S.average_spill_size, + S.spill_skew_percent, + S.min_dn_time, + S.max_dn_time, + S.average_dn_time, + S.dntime_skew_percent, + S.min_cpu_time, + S.max_cpu_time, + S.total_cpu_time, + S.cpu_skew_percent, + S.min_peak_iops, + S.max_peak_iops, + S.average_peak_iops, + S.iops_skew_percent, + S.warning, + S.queryid, + S.query, + S.query_plan, + S.node_group, + S.cpu_top1_node_name, + S.cpu_top2_node_name, + S.cpu_top3_node_name, + S.cpu_top4_node_name, + S.cpu_top5_node_name, + S.mem_top1_node_name, + S.mem_top2_node_name, + S.mem_top3_node_name, + S.mem_top4_node_name, + S.mem_top5_node_name, + S.cpu_top1_value, + S.cpu_top2_value, + S.cpu_top3_value, + S.cpu_top4_value, + S.cpu_top5_value, + S.mem_top1_value, + S.mem_top2_value, + S.mem_top3_value, + S.mem_top4_value, + S.mem_top5_value, + S.top_mem_dn, + S.top_cpu_dn +FROM pg_catalog.gs_wlm_session_info_all S; + +CREATE OR REPLACE FUNCTION pg_catalog.create_wlm_session_info(IN flag int) +RETURNS int +AS $$ +DECLARE + query_str text; + record_cnt int; + BEGIN + record_cnt := 0; + + query_str := 'SELECT * FROM pg_catalog.pg_stat_get_wlm_session_info(1)'; + + IF flag > 0 THEN + EXECUTE 'INSERT INTO pg_catalog.gs_wlm_session_query_info_all ' || query_str; + ELSE + EXECUTE query_str; + END IF; + + RETURN record_cnt; + END; $$ +LANGUAGE plpgsql NOT FENCED; + +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_info() cascade; +DROP FUNCTION IF EXISTS dbe_perf.global_slow_query_history() cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_info cascade; +DROP VIEW IF EXISTS dbe_perf.gs_slow_query_history cascade; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_info AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown +FROM gs_wlm_session_query_info_all S where S.is_slow_query = 1; + +CREATE OR REPLACE VIEW dbe_perf.gs_slow_query_history AS +SELECT + S.dbname, + S.schemaname, + S.nodename, + S.username, + S.queryid, + S.query, + S.start_time, + S.finish_time, + S.duration, + S.query_plan, + S.n_returned_rows, + S.n_tuples_fetched, + S.n_tuples_returned, + S.n_tuples_inserted, + S.n_tuples_updated, + S.n_tuples_deleted, + S.n_blocks_fetched, + S.n_blocks_hit, + S.db_time, + S.cpu_time, + S.execution_time, + S.parse_time, + S.plan_time, + S.rewrite_time, + S.pl_execution_time, + S.pl_compilation_time, + S.net_send_time, + S.data_io_time, + S.srt1_q, + S.srt2_simple_query, + S.srt3_analyze_rewrite, + S.srt4_plan_query, + S.srt5_light_query, + S.srt6_p, + S.srt7_b, + S.srt8_e, + S.srt9_d, + S.srt10_s, + S.srt11_c, + S.srt12_u, + S.srt13_before_query, + S.srt14_after_query, + S.rtt_unknown +FROM pg_catalog.pg_stat_get_wlm_session_info(0) S where S.is_slow_query = 1; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_history +RETURNS setof dbe_perf.gs_slow_query_history +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_history%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_history'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE FUNCTION dbe_perf.global_slow_query_info() +RETURNS setof dbe_perf.gs_slow_query_info +AS $$ +DECLARE + row_data dbe_perf.gs_slow_query_info%rowtype; + row_name record; + query_str text; + query_str_nodes text; + BEGIN + --Get all the node names + query_str_nodes := 'SELECT node_name FROM pgxc_node WHERE node_type=''C'' AND nodeis_active = true'; + FOR row_name IN EXECUTE(query_str_nodes) LOOP + query_str := 'EXECUTE DIRECT ON (' || row_name.node_name || ') ''SELECT * FROM dbe_perf.gs_slow_query_info'''; + FOR row_data IN EXECUTE(query_str) LOOP + return next row_data; + END LOOP; + END LOOP; + return; + END; $$ +LANGUAGE 'plpgsql' NOT FENCED; + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_history AS +SELECT * FROM DBE_PERF.global_slow_query_history(); + +CREATE OR REPLACE VIEW DBE_PERF.global_slow_query_info AS +SELECT * FROM DBE_PERF.global_slow_query_info(); + +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_query_info_all TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_history TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info TO PUBLIC; +GRANT SELECT ON TABLE pg_catalog.gs_wlm_session_info_all TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.STATEMENT TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.summary_statement TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.statement_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_history TO PUBLIC; +GRANT SELECT ON TABLE DBE_PERF.global_slow_query_info TO PUBLIC; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade_catalog_otherdb_92_906.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade_catalog_otherdb_92_906.sql new file mode 100644 index 000000000..51a105b0b --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade_catalog_otherdb_92_906.sql @@ -0,0 +1,22 @@ +-- this table will be add column +-- openGauss=# select table_schema, table_name,column_name from information_schema.columns where column_name = 'db_time'; +-- table_schema | table_name | column_name +-- --------------+-------------------------------+------------- +-- pg_catalog | gs_wlm_session_query_info_all | db_time --table +-- pg_catalog | statement_history | db_time --unlogged table, update in post-upgrade + +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt1_q bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt2_simple_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt3_analyze_rewrite bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt4_plan_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt5_light_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt6_p bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt7_b bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt8_e bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt9_d bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt10_s bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt11_c bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt12_u bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt13_before_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column srt14_after_query bigint; +ALTER TABLE pg_catalog.gs_wlm_session_query_info_all add column rtt_unknown bigint; diff --git a/src/include/knl/knl_guc/knl_session_attr_common.h b/src/include/knl/knl_guc/knl_session_attr_common.h index a7e03fe6e..fa0cb7ee6 100644 --- a/src/include/knl/knl_guc/knl_session_attr_common.h +++ b/src/include/knl/knl_guc/knl_session_attr_common.h @@ -244,6 +244,7 @@ typedef struct knl_session_attr_common { bool enable_indexscan_optimization; char* delimiter_name; bool b_compatibility_user_host_auth; + int time_record_level; } knl_session_attr_common; #endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ */ diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index 9217f7a3a..0112d3a7b 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -68,6 +68,7 @@ #include "storage/lock/lock.h" #include "utils/elog.h" #include "tcop/dest.h" +#include "og_record_time.h" typedef void (*pg_on_exit_callback)(int code, Datum arg); @@ -1755,6 +1756,8 @@ typedef struct knl_u_stat_context { bool isTopLevelPlSql; int64* localTimeInfoArray; uint64* localNetInfo; + // use to record all use time in multi thread. + void* og_record_stat; MemoryContext pgStatLocalContext; MemoryContext pgStatCollectThdStatusContext; diff --git a/src/include/knl/knl_thread.h b/src/include/knl/knl_thread.h index fee147d2b..12d8a18f9 100755 --- a/src/include/knl/knl_thread.h +++ b/src/include/knl/knl_thread.h @@ -72,6 +72,7 @@ #include "replication/worker_internal.h" #include "replication/origin.h" #include "replication/libpqsw.h" +#include "og_record_time.h" #include "catalog/pg_subscription.h" #include "port/pg_crc32c.h" #include "ddes/dms/ss_common_attr.h" diff --git a/src/include/og_record_time.h b/src/include/og_record_time.h new file mode 100644 index 000000000..05c65ff70 --- /dev/null +++ b/src/include/og_record_time.h @@ -0,0 +1,512 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * --------------------------------------------------------------------------------------- + * + * IDENTIFICATION + * src/include/og_record_time.h + * + * NOTES + * Some of this code used to record sql execute time. + * + * ------------------------------------------------------------------------- + */ + +#ifndef OG_RECORD_TIME_H +#define OG_RECORD_TIME_H +#include +#include +#include +#include "og_record_time_rely.h" +#include "knl/knl_session.h" + +typedef enum TimeInfoType { + DB_TIME = 0, /*total elapsed time while dealing user command.*/ + CPU_TIME, /*total cpu time used while dealing user command.*/ + + /*statistics of specific execution stage.*/ + EXECUTION_TIME, /*total elapsed time of execution stage.*/ + PARSE_TIME, /*total elapsed time of parse stage.*/ + PLAN_TIME, /*total elapsed time of plan stage.*/ + REWRITE_TIME, /*total elapsed time of rewrite stage.*/ + + /*statistics for plpgsql especially*/ + PL_EXECUTION_TIME, /*total elapsed time of plpgsql exection.*/ + PL_COMPILATION_TIME, /*total elapsed time of plpgsql compilation.*/ + + NET_SEND_TIME, + DATA_IO_TIME, + SRT1_Q, + SRT2_SIMPLE_QUERY, + SRT3_ANALYZE_REWRITE, + SRT4_PLAN_QUERY, + SRT5_LIGHT_QUERY, + SRT6_P, + SRT7_B, + SRT8_E, + SRT9_D, + SRT10_S, + SRT11_C, + SRT12_U, + SRT13_BEFORE_QUERY, + SRT14_AFTER_QUERY, + RTT_UNKNOWN, + TOTAL_TIME_INFO_TYPES +} TimeInfoType; + +// some procedure use old postion, so we define this. +const TimeInfoType TOTAL_TIME_INFO_TYPES_P1 = SRT1_Q; + +typedef enum NetInfoType { + NET_SEND_TIMES, + NET_SEND_N_CALLS, + NET_SEND_SIZE, + + NET_RECV_TIMES, + NET_RECV_N_CALLS, + NET_RECV_SIZE, + + NET_STREAM_SEND_TIMES, + NET_STREAM_SEND_N_CALLS, + NET_STREAM_SEND_SIZE, + + NET_STREAM_RECV_TIMES, + NET_STREAM_RECV_N_CALLS, + NET_STREAM_RECV_SIZE, + + TOTAL_NET_INFO_TYPES +} NetInfoType; + +// this for easy add new record type for debug. +typedef enum SelfRecordType { + SRT_ALL +} SelfRecordType; +// the type of record time +typedef enum RecordTimeType { + TIME_INFO = 0, + NET_INFO, + SELF_INFO +} RecordTimeType; + +const int TOTAL_RECORD_TYPES = TOTAL_TIME_INFO_TYPES + TOTAL_NET_INFO_TYPES + SRT_ALL; +// if left record time more than this, will print flag info. +const int64 DEFAULT_DB_TIME_BASELINE = 10; //ms +// the OgTimeDataStack depth +const int DEFAULT_TIME_DATA_STACK_DEPTH = 100; +// the default format length +const int DEFAULT_FORMAT_LENGTH = 1024; +const int INVALID_DEPTH = -1; +// the type of record. +class RecordType; +// the time base slice of type +class OgTimeDataVo; +// the time base vo format helper +class OgTimeDataFormatHelper; +// the time data vo stack +class OgTimeDataStack; +// the stat statics class +class OgRecordStat; + +#define FORMAT_VO(vo) (OgTimeDataFormatHelper().format(vo)) + +#ifdef _cplusplus +extern "C" { +#endif +extern const char* TimeInfoTypeName[]; +/** + * Get record stat instance, must be already init session before use it! + * */ +OgRecordStat* og_get_record_stat(); + +/** + * Clean RecordState instance memory. + * @param code error code + * @param arg the input arg + */ +void og_record_time_cleanup(int code, Datum arg); + +/** + * Reinit time record stat after set_long_jump + */ +void og_record_time_reinit(); + +/** + * Start time record, this will trigger DB_TIME begin event report. + * @return true if first started else already startted. + */ +bool og_time_record_start(); + +/** + * Stop time record, this will trigger DB_TIME end event report + * @return true if success stopped else already stopped. + */ +bool og_time_record_end(); + +/** + * Get if time record startted. + * @return true if stattted. + */ +bool og_time_record_is_started(); + +/** + * Get unique event id, id will continuously growing in a single statistic. + * @return the new event it. + */ +int64 og_get_time_unique_id(); + +/** + * Convert record_time to str. + * @param record_type the record type. + * @return const char* desc + */ +const char* og_record_time_type_str(const RecordType& record_type); + +/** + * Convert int pos to str + * @param pos the postion of record type + * @return const char* desc + */ +const char* og_record_time_type_str(int pos); + +#ifdef _cplusplus +} +#endif + +#define record_debug(fmt, ...) (og_get_record_stat()->logtrace(DEBUG1, fmt, ##__VA_ARGS__)) +#define record_info(fmt, ...) (og_get_record_stat()->logtrace(LOG, fmt, ##__VA_ARGS__)) +#define record_warn(fmt, ...) (og_get_record_stat()->logtrace(WARNING, fmt, ##__VA_ARGS__)) + +class RecordType { +public: + explicit RecordType(); + explicit RecordType(TimeInfoType time_info_type); + explicit RecordType(SelfRecordType self_typ); + explicit RecordType(NetInfoType net_info_type, ssize_t str_len); + /** + * Get which type of record it is. match the construct. + * @return + */ + RecordTimeType get_record_time_type() const; + + /** + * The enum type to int. + * @return the enum type order. + */ + int get_type_code() const; + + /** + * Only use in NET_INFO_TYPE. + * @return get the send net size len. + */ + ssize_t get_str_len() const; + + /** + * Match the RecordTimeType split postion. + * @return matched RecordTimeType base pos. + */ + int get_init_pos() const; + + /** + * Match the `og_record_time_type_str(int pos);` pos + * @return the pos of time_type_str + */ + int position() const; + + /** + * Is the DB_TIME type. DB_TIME can't be trigger by user. + * @return true if current if DB_TIME event + */ + bool is_root_type() const; + + bool operator==(TimeInfoType time_type) const; + bool operator!=(TimeInfoType time_type) const; + bool operator==(NetInfoType net_type) const; + bool operator!=(NetInfoType net_type) const; + bool operator==(SelfRecordType self_type) const; + bool operator!=(SelfRecordType self_type) const; +private: + RecordTimeType rtt_type; + int type_code; + ssize_t str_len; +}; + +class OgTimeDataVo { +public: + explicit OgTimeDataVo(): begin(0), end(0), depth(INVALID_DEPTH) + , record_type(RTT_UNKNOWN), other_cost(0), id(og_get_time_unique_id()) {} + explicit OgTimeDataVo(const RecordType& cur_record_type): begin(0), end(0), depth(INVALID_DEPTH) + , record_type(cur_record_type), other_cost(0), id(og_get_time_unique_id()) {} + + /** + * Get this stage total time. + * @return total record time. + */ + int64 total() const + { + return end - begin; + } + + /** + * Get this stage real time. sub child stage. + * @return + */ + int64 cost() const + { + return total() - other_cost; + } + + /** + * Update child stage cost. + * @param cost + */ + void update_other_cost(int64 cost) { + this->other_cost += cost; + } + + bool operator==(const OgTimeDataVo& compare) const { + return this->id == compare.id; + } + + bool operator!=(const OgTimeDataVo& compare) const { + return !(*this == compare); + } + // NOTICE: we will push this class to stack(some std::stack use this to create new instance), + // so must implementation this operator. + OgTimeDataVo& operator=(const OgTimeDataVo& vo) + { + if (this != &vo) { + this->begin = vo.begin; + this->end = vo.end; + this->depth = vo.depth; + this->record_type = vo.record_type; + this->other_cost = vo.other_cost; + this->id = vo.id; + } + return *this; + } + +public: + int64 begin; + int64 end; + int depth; + RecordType record_type; + int64 other_cost; + int64 id; +}; + +class OgTimeDataFormatHelper { +public: + const char* format(const OgTimeDataVo& vo); +private: + char format_str[DEFAULT_FORMAT_LENGTH]; +}; + +class OgTimeDataStack { +public: + OgTimeDataStack(): cur_pos(-1) {} + OgTimeDataVo& top(); + const OgTimeDataVo& top() const; + bool push(const OgTimeDataVo& vo); + void pop(); + bool empty() const; + size_t size() const; + void reset(); +private: + int cur_pos; + OgTimeDataVo data_list[DEFAULT_TIME_DATA_STACK_DEPTH]; +}; + +class OgRecordOperator { +public: + /* You must be careful when auto_record = false, it means you need ensure enter/exit pair called! + * The only situation is in loop, like in timeRecordStart/End. + * if call stack not match, some time record will discard until `OgRecordStat.reset` is called! + * We encourage this approach: OgRecordOperator _local_opt(TimeInfoType); + */ + explicit OgRecordOperator(bool auto_record); + // `NOTICE`: only TimeInfoType will record time, NetInfoType time will calculate for parent TimeInfoType stage. + // SelfRecordType only for add new stage for debug. + explicit OgRecordOperator(TimeInfoType time_info_type); + explicit OgRecordOperator(NetInfoType net_info_type); + explicit OgRecordOperator(SelfRecordType self_type); + explicit OgRecordOperator(bool auto_record, NetInfoType net_type); + explicit OgRecordOperator(bool auto_record, TimeInfoType time_type); + explicit OgRecordOperator(bool auto_record, SelfRecordType self_type); + virtual ~OgRecordOperator(); + void enter(TimeInfoType time_type=RTT_UNKNOWN); + void enter(NetInfoType net_type); + void enter(const RecordType& record_type); + void exit(TimeInfoType time_info_type=RTT_UNKNOWN); + void exit(NetInfoType net_type, ssize_t str_len); + void exit(const RecordType& record_type); + + /** + * Only TIME_INFO_TYPE will record time. this only called after exit() to report new record again. + * @param net_type NET_INTO_TYPE type + * @param str_len the send size + */ + void report_duplicate(NetInfoType net_type, ssize_t str_len); + + /** + * Get current record id. + * @return + */ + int64 get_record_id() const; + + /** + * update new record id for reuse. + */ + void update_record_id(); + + /** + * If enable report stage event. if record not start or `time_record_level` != 0 , this will false. + * @return true if need report. + */ + bool report_enable() const; +private: + void init(bool auto_record, const RecordType& record_type); +private: + OgTimeDataVo base_record; + bool auto_record; +}; + +class OgRecordStat : public BaseObject { +public: + /** + * Bind old stat memory of local_time_info and loca_net_info + * @param local_time_info the TimeInfoType memory + * @param loca_net_info the NetInfoType memory + */ + OgRecordStat(int64* local_time_info, uint64* loca_net_info); + virtual ~OgRecordStat(); + /** + * This used by DELETE_EX macro + */ + void Destroy(); + + /** + * Reset this instance. + */ + void reset(); + + /** + * Reinit after long jump + */ + void reinit(); + + /** + * Process stage event from `OgRecordOperator.enter`. + * @param data_record the record + */ + void report_start(const OgTimeDataVo& data_record); + + /** + * Process stage event from `OgRecordOperator.exit`. + * @param record the record + */ + void report_end(const OgTimeDataVo& record); + + /** + * Process start record time. this will trigger DB_TIME stage event. + * @return true if first startted. + */ + bool start_first_record_opt(); + + /** + * Process stop record time. this will trigger DB_TIME stage event. + * @return true if first stopped. + */ + bool free_first_record_opt(); + + /** + * Get the stage record time. + * @param type_info the stage + * @return record time. + */ + const int64 get_record_times(TimeInfoType type_info) const; + + /** + * Get the DB_TIME stage record time. + * @return the DB_TIME stage time. + */ + const int64 get_db_time() const; + + /** + * The root PgDataTimeVo instance, it's child_cost is equal DB_TIME stage. + * @return the root PgDataTimeVo instance. + */ + const OgTimeDataVo& get_root_time_data_vo() const; + + /** + * Get if already start record. + * @return true if already startted. + */ + bool already_start() const; + + // only for NetInfoType report. + void report_duplicate(OgTimeDataVo& record); + + /** + * Incr record depth. eveny new report stage will increment it. + * @return current depth + */ + int increment_depth(); + + /** + * Decr record depth. after record end stage will decrement it. + */ + void decrement_depth(); + + /** + * Get new unique PgDataTimeVo id. + * @return the new id. + */ + int64 get_time_unique_id(); + + /** + * Print str, only for debug use. + */ + void print_self() const; + + /** + * Get time record level for report_enable. 0-> default, all stage will report + * 1~10-> not record time. + * @return the level. + */ + int get_time_record_level() const; + + /** + * Update time record level from session. + */ + void update_time_record_level(); + + bool log_enable() const; + bool log_enable_debug() const; + void logtrace(int level, const char* fmt, ...) const; +private: + void update_record_time(const RecordType& record_type, int64 cost); + +private: + OgTimeDataStack records_stack; + OgTimeDataStack pre_records_stack; + int64* local_time_info; + uint64* local_net_info; + int depth; + int64 time_unique_id; + int64 db_time_baseline; + int time_record_level; + StringInfo log_trace_msg; + OgRecordOperator first_record_opt; + bool record_start; +}; +#endif diff --git a/src/include/og_record_time_rely.h b/src/include/og_record_time_rely.h new file mode 100644 index 000000000..43f33e3d6 --- /dev/null +++ b/src/include/og_record_time_rely.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * --------------------------------------------------------------------------------------- + * + * IDENTIFICATION + * src/include/og_record_time_rely.h + * + * NOTES + * Declare some openGauss system func or types. + * + * ------------------------------------------------------------------------- + */ + +#ifndef PG_RECORD_TIME_TMP_H +#define PG_RECORD_TIME_TMP_H +#include "postgres.h" +#include "c.h" +#include "datatype/timestamp.h" +extern TimestampTz GetCurrentTimestamp(); +void DestroyStringInfo(StringInfo str); +void ResetMemory(void* dest, size_t size); +#endif \ No newline at end of file diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 8f6049091..87f1c0ca9 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -32,6 +32,7 @@ #include "instruments/instr_event.h" #include "instruments/unique_sql_basic.h" #include "knl/knl_instance.h" +#include "og_record_time.h" /* Values for track_functions GUC variable --- order is significant! */ @@ -2474,26 +2475,6 @@ extern void DumpMemoryContext(DUMP_TYPE type); extern void getThreadMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc, uint32* procIdx); extern void getSharedMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc); -typedef enum TimeInfoType { - DB_TIME = 0, /*total elapsed time while dealing user command.*/ - CPU_TIME, /*total cpu time used while dealing user command.*/ - - /*statistics of specific execution stage.*/ - EXECUTION_TIME, /*total elapsed time of execution stage.*/ - PARSE_TIME, /*total elapsed time of parse stage.*/ - PLAN_TIME, /*total elapsed time of plan stage.*/ - REWRITE_TIME, /*total elapsed time of rewrite stage.*/ - - /*statistics for plpgsql especially*/ - PL_EXECUTION_TIME, /*total elapsed time of plpgsql exection.*/ - PL_COMPILATION_TIME, /*total elapsed time of plpgsql compilation.*/ - - NET_SEND_TIME, - DATA_IO_TIME, - - TOTAL_TIME_INFO_TYPES -} TimeInfoType; - typedef struct SessionTimeEntry { /* *protect the rest part of the entry. @@ -2527,39 +2508,37 @@ typedef struct SessionTimeEntry { #define SessionTimeArraySize (BackendStatusArray_size) -#define PGSTAT_INIT_TIME_RECORD() int64 startTime = 0; +#define PGSTAT_INIT_TIME_RECORD() OgRecordOperator og_record_opt(false); #define PGSTAT_START_TIME_RECORD() \ do { \ if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ - startTime = GetCurrentTimestamp(); \ + og_record_opt.enter(); \ } while (0) #define PGSTAT_END_TIME_RECORD(stage) \ do { \ if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ - u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ + og_record_opt.exit(stage); \ } while (0) #define PGSTAT_START_PLSQL_TIME_RECORD() \ do { \ if (u_sess->stat_cxt.isTopLevelPlSql && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - startTime = GetCurrentTimestamp(); \ u_sess->stat_cxt.isTopLevelPlSql = false; \ needRecord = true; \ + og_record_opt.enter(); \ } \ } while (0) #define PGSTAT_END_PLSQL_TIME_RECORD(stage) \ do { \ if (needRecord == true && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ u_sess->stat_cxt.isTopLevelPlSql = true; \ + og_record_opt.exit(stage); \ } \ } while (0) -extern const char* TimeInfoTypeName[TOTAL_TIME_INFO_TYPES]; - extern Size sessionTimeShmemSize(void); extern void sessionTimeShmemInit(void); @@ -2970,6 +2949,8 @@ extern void pgstat_clean_memcxt(void); extern PgBackendStatus* gs_stat_fetch_stat_beentry(int32 beid); extern void pgstat_send(void* msg, int len); extern char* GetGlobalSessionStr(GlobalSessionId globalSessionId); +void ResetMemory(void* dest, size_t size); + typedef struct PgStat_NgMemSize { int* ngmemsize; @@ -2979,60 +2960,39 @@ typedef struct PgStat_NgMemSize { uint32 allcnt; } PgStat_NgMemSize; -typedef enum NetInfoType { - NET_SEND_TIMES, - NET_SEND_N_CALLS, - NET_SEND_SIZE, +#define END_NET_SEND_INFO(str_len) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + og_record_opt.exit(NET_SEND_TIMES, str_len); \ + } \ + } while (0) +#define END_NET_SEND_INFO_DUPLICATE(str_len) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + og_record_opt.report_duplicate(NET_SEND_TIMES, str_len); \ + } \ + } while (0) - NET_RECV_TIMES, - NET_RECV_N_CALLS, - NET_RECV_SIZE, - NET_STREAM_SEND_TIMES, - NET_STREAM_SEND_N_CALLS, - NET_STREAM_SEND_SIZE, - - NET_STREAM_RECV_TIMES, - NET_STREAM_RECV_N_CALLS, - NET_STREAM_RECV_SIZE, - - TOTAL_NET_INFO_TYPES -} NetInfoType; - -#define END_NET_SEND_INFO(str_len) \ - do { \ - if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - u_sess->stat_cxt.localNetInfo[NET_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ - u_sess->stat_cxt.localNetInfo[NET_SEND_N_CALLS]++; \ - u_sess->stat_cxt.localNetInfo[NET_SEND_SIZE] += str_len; \ - } \ +#define END_NET_STREAM_SEND_INFO(str_len) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + og_record_opt.exit(NET_STREAM_SEND_TIMES, str_len); \ + } \ } while (0) -#define END_NET_STREAM_SEND_INFO(str_len) \ - do { \ - if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_N_CALLS]++; \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_SIZE] += str_len; \ - } \ +#define END_NET_RECV_INFO(str_len) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + og_record_opt.exit(NET_RECV_TIMES, str_len); \ + } \ } while (0) -#define END_NET_RECV_INFO(str_len) \ - do { \ - if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - u_sess->stat_cxt.localNetInfo[NET_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ - u_sess->stat_cxt.localNetInfo[NET_RECV_N_CALLS]++; \ - u_sess->stat_cxt.localNetInfo[NET_RECV_SIZE] += str_len; \ - } \ - } while (0) - -#define END_NET_STREAM_RECV_INFO(str_len) \ - do { \ - if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_N_CALLS]++; \ - u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_SIZE] += str_len; \ - } \ +#define END_NET_STREAM_RECV_INFO(str_len) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + og_record_opt.exit(NET_STREAM_RECV_TIMES, str_len); \ + } \ } while(0) bool GetTableGstats(Oid dbid, Oid relid, Oid parentid, PgStat_StatTabEntry *tabentry); diff --git a/src/test/regress/output/recovery_2pc_tools.source b/src/test/regress/output/recovery_2pc_tools.source index 40b317af2..6b0ac7591 100644 --- a/src/test/regress/output/recovery_2pc_tools.source +++ b/src/test/regress/output/recovery_2pc_tools.source @@ -688,6 +688,7 @@ select name,vartype,unit,min_val,max_val from pg_settings where name <> 'qunit_c temp_tablespaces | string | | | thread_pool_attr | string | | | thread_pool_stream_attr | string | | | + time_record_level | integer | | 0 | 10 time_to_target_rpo | integer | | 0 | 3600 TimeZone | string | | | timezone_abbreviations | string | | |