mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 14:06:20 +00:00
PG-588: Some queries are not being normalised.
This bug uncovered serious issues with how the data was being stored by PSGM. So it require a complete redesign. pg_stat_monitor now stores the data locally within the backend process's local memory. The data is only stored when the query completes. This reduces the number of lock acquisitions that were previously needed during various stages of the execution. Also, this avoids data loss in case the current bucket changes during execution. Also, the unavailability of jumble state during later stages of executions was causing pg_stat_monitor to save non-normalized query. This was a major problem as well. pg_stat_monitor specific memory context is implemented. It is used for saving data locally. The context memory callback helps us clear the locally saved data so that we do not store it multiple times in the shared hash. As part of this major rewrite, pgss reference in function and variable names is changed to pgsm. Memory footprint for the entries is reduced, data types are corrected where needed, and we've removed unused variables, functions and macros. This patch was mutually created by: Co-authored-by: Hamid Akhtar <hamid.akhtar@percona.com> Co-authored-by: Muhammad Usama <muhammad.usama@percona.com>
This commit is contained in:
@@ -84,8 +84,10 @@ CREATE FUNCTION pg_stat_monitor_internal(
|
||||
IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT username text,
|
||||
OUT dbid oid,
|
||||
OUT client_ip int8,
|
||||
OUT datname text,
|
||||
OUT client_ip int4,
|
||||
|
||||
OUT queryid int8, -- 4
|
||||
OUT planid int8,
|
||||
@@ -169,7 +171,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
userid::regrole AS user,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
@@ -211,7 +213,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
bucket_done
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
@@ -225,7 +227,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
userid::regrole AS user,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
@@ -278,7 +280,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
@@ -291,7 +293,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
userid::regrole AS user,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
@@ -344,7 +346,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
@@ -357,7 +359,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
userid::regrole AS user,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
@@ -423,7 +425,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
||||
jit_emission_count,
|
||||
jit_emission_time
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
@@ -451,15 +453,19 @@ $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT pgsm_create_view();
|
||||
REVOKE ALL ON FUNCTION range FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION get_cmd_type FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION decode_error_level FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_internal FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION get_histogram_timings FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_11_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_13_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_14_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_15_view FROM PUBLIC;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION range TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION decode_error_level TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_histogram_timings TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_cmd_type TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION pg_stat_monitor_internal TO PUBLIC;
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
|
||||
-- Reset is only available to super user
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset FROM PUBLIC;
|
||||
|
||||
Reference in New Issue
Block a user