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:
Hamid Akhtar
2023-02-22 19:14:42 +05:00
parent 837bacdf3a
commit de66ef0fce
27 changed files with 1287 additions and 1049 deletions

View File

@@ -0,0 +1,65 @@
CREATE USER su WITH SUPERUSER;
ERROR: role "su" already exists
SET ROLE su;
CREATE EXTENSION pg_stat_monitor;
CREATE USER u1;
CREATE USER u2;
GRANT ALL ON SCHEMA public TO u1;
GRANT ALL ON SCHEMA public TO u2;
SET ROLE su;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SET ROLE u1;
SELECT pg_stat_monitor_reset();
ERROR: permission denied for function pg_stat_monitor_reset
CREATE TABLE t1 (a int);
SELECT * FROM t1;
a
---
(0 rows)
SET ROLE u2;
CREATE TABLE t2 (a int);
SELECT * FROM t2;
a
---
(0 rows)
DROP TABLE t2;
SET ROLE su;
DROP OWNED BY u2;
DROP USER u2;
SELECT username, query FROM pg_stat_monitor ORDER BY username, query COLLATE "C";
username | query
----------+---------------------------------
su | DROP OWNED BY u2
su | DROP USER u2
su | SELECT pg_stat_monitor_reset()
su | SET ROLE su
u1 | CREATE TABLE t1 (a int)
u1 | SELECT * FROM t1
u1 | SELECT pg_stat_monitor_reset();
u1 | SET ROLE u1
u2 | CREATE TABLE t2 (a int)
u2 | DROP TABLE t2
u2 | SELECT * FROM t2
u2 | SET ROLE u2
(12 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP TABLE t1;
DROP OWNED BY u1;
DROP USER u1;
DROP EXTENSION pg_stat_monitor;
SET ROLE NONE;
DROP OWNED BY su;
DROP USER su;