log based
parent
982b1304d3
commit
02f2e9e5ce
|
|
@ -247,6 +247,7 @@ static void fill_in_constant_lengths(JumbleState *jstate, const char *query, int
|
|||
static int comp_location(const void *a, const void *b);
|
||||
|
||||
static uint64 get_next_wbucket(pgsmSharedState *pgsm);
|
||||
static void pgsm_log_bucket_json(uint64 bucket_id);
|
||||
|
||||
/*
|
||||
* To prevent deadlocks against our own backend we need to disable error
|
||||
|
|
@ -3966,47 +3967,17 @@ pgsm_lock_release(pgsmSharedState *pgsm)
|
|||
LWLockRelease(pgsm->lock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Log bucket data as JSON to PostgreSQL log
|
||||
*/
|
||||
static void
|
||||
pgsm_log_bucket_json(uint64 bucket_id)
|
||||
{
|
||||
pgsmSharedState *pgsm = pgsm_get_ss();
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
pgsmEntry *entry;
|
||||
bool first_entry = true;
|
||||
|
||||
if (!pgsm_enable_json_log)
|
||||
return;
|
||||
|
||||
/* Start JSON object for the bucket */
|
||||
elog(LOG, "[pg_stat_monitor] JSON export bucket %lu: {\"bucket_id\": %lu, \"queries\": [",
|
||||
bucket_id, bucket_id);
|
||||
|
||||
pgsm_lock_aquire(pgsm, LW_SHARED);
|
||||
|
||||
hash_seq_init(&hash_seq, pgsm->hash);
|
||||
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
||||
{
|
||||
/* Only export entries from the specified bucket */
|
||||
if (entry->key.bucket_id != bucket_id)
|
||||
continue;
|
||||
|
||||
if (!first_entry)
|
||||
elog(LOG, "[pg_stat_monitor] JSON export: ,");
|
||||
else
|
||||
first_entry = false;
|
||||
|
||||
/* Log a simplified JSON object for each query */
|
||||
elog(LOG, "[pg_stat_monitor] JSON export: {\"query_id\": %lu, \"calls\": %lu, \"total_time\": %.3f, \"query\": \"%s\"}",
|
||||
entry->key.queryid, entry->counters.calls,
|
||||
entry->counters.total_exec_time,
|
||||
entry->query_len > 0 ? pgsm_get_query_text(entry, NULL, NULL) : "");
|
||||
}
|
||||
|
||||
pgsm_lock_release(pgsm);
|
||||
|
||||
/* Close JSON array and object */
|
||||
elog(LOG, "[pg_stat_monitor] JSON export: ]}");
|
||||
/* Log a simple JSON message for bucket rotation */
|
||||
elog(LOG, "[pg_stat_monitor] JSON export: {\"event\": \"bucket_rotation\", \"bucket_id\": %lu, \"timestamp\": \"%ld\"}",
|
||||
bucket_id, time(NULL));
|
||||
}
|
||||
|
|
|
|||
134
regression.diffs
134
regression.diffs
|
|
@ -1,134 +0,0 @@
|
|||
diff -U3 /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/basic.out /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/basic.out
|
||||
--- /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/basic.out 2025-09-20 13:48:01
|
||||
+++ /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/basic.out 2025-09-20 13:54:55
|
||||
@@ -12,11 +12,9 @@
|
||||
(1 row)
|
||||
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
- query
|
||||
---------------------------------
|
||||
- SELECT 1 AS num
|
||||
- SELECT pg_stat_monitor_reset()
|
||||
-(2 rows)
|
||||
+ query
|
||||
+-------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
diff -U3 /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/counters.out /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/counters.out
|
||||
--- /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/counters.out 2025-09-20 13:48:01
|
||||
+++ /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/counters.out 2025-09-20 13:54:55
|
||||
@@ -37,11 +37,9 @@
|
||||
(0 rows)
|
||||
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
- query | calls
|
||||
----------------------------------------------------------------------------------+-------
|
||||
- SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a | 4
|
||||
- SELECT pg_stat_monitor_reset() | 1
|
||||
-(2 rows)
|
||||
+ query | calls
|
||||
+-------+-------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
@@ -60,21 +58,9 @@
|
||||
end loop;
|
||||
end $$;
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
- query | calls
|
||||
----------------------------------------------------------------------------------------------------+-------
|
||||
- SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a | 1000
|
||||
- SELECT pg_stat_monitor_reset() | 1
|
||||
- do $$ +| 1
|
||||
- declare +|
|
||||
- n integer:= 1; +|
|
||||
- begin +|
|
||||
- loop +|
|
||||
- PERFORM a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;+|
|
||||
- exit when n = 1000; +|
|
||||
- n := n + 1; +|
|
||||
- end loop; +|
|
||||
- end $$ |
|
||||
-(3 rows)
|
||||
+ query | calls
|
||||
+-------+-------
|
||||
+(0 rows)
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
diff -U3 /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/relations.out /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/relations.out
|
||||
--- /Users/oliverrice/Documents/supabase/pg_stat_monitor/regression/expected/relations.out 2025-09-20 13:48:01
|
||||
+++ /Users/oliverrice/Documents/supabase/pg_stat_monitor/results/relations.out 2025-09-20 13:54:55
|
||||
@@ -37,14 +37,9 @@
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
- query | relations
|
||||
---------------------------------------+---------------------------------------------------
|
||||
- SELECT * FROM foo1 | {public.foo1}
|
||||
- SELECT * FROM foo1, foo2 | {public.foo1,public.foo2}
|
||||
- SELECT * FROM foo1, foo2, foo3 | {public.foo1,public.foo2,public.foo3}
|
||||
- SELECT * FROM foo1, foo2, foo3, foo4 | {public.foo1,public.foo2,public.foo3,public.foo4}
|
||||
- SELECT pg_stat_monitor_reset() |
|
||||
-(5 rows)
|
||||
+ query | relations
|
||||
+-------+-----------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
@@ -88,14 +83,9 @@
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
- query | relations
|
||||
-----------------------------------------------------------+-------------------------------------------
|
||||
- SELECT * FROM sch1.foo1 | {sch1.foo1}
|
||||
- SELECT * FROM sch1.foo1, sch2.foo2 | {sch1.foo1,sch2.foo2}
|
||||
- SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3 | {sch1.foo1,sch2.foo2,sch3.foo3}
|
||||
- SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3, sch4.foo4 | {sch1.foo1,sch2.foo2,sch3.foo3,sch4.foo4}
|
||||
- SELECT pg_stat_monitor_reset() |
|
||||
-(5 rows)
|
||||
+ query | relations
|
||||
+-------+-----------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
@@ -120,12 +110,9 @@
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query;
|
||||
- query | relations
|
||||
-------------------------------------------------+-----------------------------------------------
|
||||
- SELECT * FROM sch1.foo1, foo1 | {sch1.foo1,public.foo1}
|
||||
- SELECT * FROM sch1.foo1, sch2.foo2, foo1, foo2 | {sch1.foo1,sch2.foo2,public.foo1,public.foo2}
|
||||
- SELECT pg_stat_monitor_reset() |
|
||||
-(3 rows)
|
||||
+ query | relations
|
||||
+-------+-----------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
@@ -165,14 +152,9 @@
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
- query | relations
|
||||
---------------------------------+-----------------------------------------------------------------------------------------------
|
||||
- SELECT * FROM v1 | {public.v1*,public.foo1}
|
||||
- SELECT * FROM v1,v2 | {public.v1*,public.foo1,public.v2*,public.foo2}
|
||||
- SELECT * FROM v1,v2,v3 | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3}
|
||||
- SELECT * FROM v1,v2,v3,v4 | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3,public.v4*,public.foo4}
|
||||
- SELECT pg_stat_monitor_reset() |
|
||||
-(5 rows)
|
||||
+ query | relations
|
||||
+-------+-----------
|
||||
+(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# using postmaster on Unix socket, default port
|
||||
not ok 1 - basic 41 ms
|
||||
not ok 2 - counters 36 ms
|
||||
not ok 3 - relations 41 ms
|
||||
1..3
|
||||
# 3 of 3 tests failed.
|
||||
# The differences that caused some tests to fail can be viewed in the file "/Users/oliverrice/Documents/supabase/pg_stat_monitor/regression.diffs".
|
||||
# A copy of the test summary that you see above is saved in the file "/Users/oliverrice/Documents/supabase/pg_stat_monitor/regression.out".
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query
|
||||
-------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE t1 (a INTEGER);
|
||||
CREATE TABLE t2 (b INTEGER);
|
||||
CREATE TABLE t3 (c INTEGER);
|
||||
CREATE TABLE t4 (d INTEGER);
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
query | calls
|
||||
-------+-------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
do $$
|
||||
declare
|
||||
n integer:= 1;
|
||||
begin
|
||||
loop
|
||||
PERFORM a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
||||
exit when n = 1000;
|
||||
n := n + 1;
|
||||
end loop;
|
||||
end $$;
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
query | calls
|
||||
-------+-------
|
||||
(0 rows)
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
DROP TABLE t4;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,181 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE foo1(a int);
|
||||
CREATE TABLE foo2(b int);
|
||||
CREATE TABLE foo3(c int);
|
||||
CREATE TABLE foo4(d int);
|
||||
-- test the simple table names
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM foo1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM foo1, foo2;
|
||||
a | b
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM foo1, foo2, foo3;
|
||||
a | b | c
|
||||
---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM foo1, foo2, foo3, foo4;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
query | relations
|
||||
-------+-----------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- test the schema qualified table
|
||||
CREATE SCHEMA sch1;
|
||||
CREATE SCHEMA sch2;
|
||||
CREATE SCHEMA sch3;
|
||||
CREATE SCHEMA sch4;
|
||||
CREATE TABLE sch1.foo1(a int);
|
||||
CREATE TABLE sch2.foo2(b int);
|
||||
CREATE TABLE sch3.foo3(c int);
|
||||
CREATE TABLE sch4.foo4(d int);
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM sch1.foo1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM sch1.foo1, sch2.foo2;
|
||||
a | b
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3;
|
||||
a | b | c
|
||||
---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3, sch4.foo4;
|
||||
a | b | c | d
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
query | relations
|
||||
-------+-----------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM sch1.foo1, foo1;
|
||||
a | a
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM sch1.foo1, sch2.foo2, foo1, foo2;
|
||||
a | b | a | b
|
||||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query;
|
||||
query | relations
|
||||
-------+-----------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- test the view
|
||||
CREATE VIEW v1 AS SELECT * from foo1;
|
||||
CREATE VIEW v2 AS SELECT * from foo1,foo2;
|
||||
CREATE VIEW v3 AS SELECT * from foo1,foo2,foo3;
|
||||
CREATE VIEW v4 AS SELECT * from foo1,foo2,foo3,foo4;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM v1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM v1,v2;
|
||||
a | a | b
|
||||
---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM v1,v2,v3;
|
||||
a | a | b | a | b | c
|
||||
---+---+---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM v1,v2,v3,v4;
|
||||
a | a | b | a | b | c | a | b | c | d
|
||||
---+---+---+---+---+---+---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
|
||||
query | relations
|
||||
-------+-----------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP VIEW v2;
|
||||
DROP VIEW v3;
|
||||
DROP VIEW v4;
|
||||
DROP TABLE foo1;
|
||||
DROP TABLE foo2;
|
||||
DROP TABLE foo3;
|
||||
DROP TABLE foo4;
|
||||
DROP TABLE sch1.foo1;
|
||||
DROP TABLE sch2.foo2;
|
||||
DROP TABLE sch3.foo3;
|
||||
DROP TABLE sch4.foo4;
|
||||
DROP SCHEMA sch1;
|
||||
DROP SCHEMA sch2;
|
||||
DROP SCHEMA sch3;
|
||||
DROP SCHEMA sch4;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
Loading…
Reference in New Issue