mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 05:56:21 +00:00
PG-544: Regression cleanup.
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(.5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1;
|
||||
?column?
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query
|
||||
--------------------------------------------------------------
|
||||
SELECT $1
|
||||
SELECT pg_stat_monitor_reset()
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
select pg_sleep($1)
|
||||
(4 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -64,7 +64,6 @@ SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
---------------------------------------------------------------------------------------------------+-------
|
||||
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
|
||||
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1
|
||||
do $$ +| 1
|
||||
declare +|
|
||||
n integer:= 1; +|
|
||||
|
||||
@@ -60,21 +60,11 @@ begin
|
||||
end loop;
|
||||
end $$;
|
||||
SELECT query,calls FROM pg_stat_monitor 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
|
||||
---------------------------------------------------------------------------------+-------
|
||||
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
|
||||
(2 rows)
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
|
||||
@@ -32,7 +32,6 @@ SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
--------------------+---------------------------------------
|
||||
db1 | SELECT * FROM t1,t2 WHERE t1.a = t2.b
|
||||
db2 | SELECT * FROM t3,t4 WHERE t3.c = t4.d
|
||||
contrib_regression | SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
contrib_regression | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE DATABASE db1;
|
||||
CREATE DATABASE db2;
|
||||
\c db1
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int);
|
||||
\c db2
|
||||
CREATE TABLE t3 (c int);
|
||||
CREATE TABLE t4 (d int);
|
||||
\c contrib_regression
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
SELECT * FROM t1,t2 WHERE t1.a = t2.b;
|
||||
a | b
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
\c db2
|
||||
SELECT * FROM t3,t4 WHERE t3.c = t4.d;
|
||||
c | d
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
\c contrib_regression
|
||||
SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
datname | query
|
||||
--------------------+---------------------------------------
|
||||
db1 | SELECT * FROM t1,t2 WHERE t1.a = t2.b
|
||||
db2 | SELECT * FROM t3,t4 WHERE t3.c = t4.d
|
||||
contrib_regression | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
\c db2
|
||||
DROP TABLE t3;
|
||||
DROP TABLE t4;
|
||||
\c contrib_regression
|
||||
DROP DATABASE db1;
|
||||
DROP DATABASE db2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -21,22 +21,17 @@ RAISE WARNING 'warning message';
|
||||
END $$;
|
||||
WARNING: warning message
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 20 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 20 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 20 | 22012 | division by zero
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
do $$ +| 0 | |
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
END $$ | | |
|
||||
do $$ +| 19 | 01000 | warning message
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
END $$; | | |
|
||||
(7 rows)
|
||||
query | elevel | sqlcode | message
|
||||
----------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 21 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 21 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 21 | 22012 | division by zero
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
do $$ +| 19 | 01000 | warning message
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message';+| | |
|
||||
END $$; | | |
|
||||
(5 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
||||
@@ -17,14 +17,12 @@ ERROR: duplicate key value violates unique constraint "company_pkey"
|
||||
DETAIL: Key (id)=(1) already exists.
|
||||
Drop Table if exists Company;
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
Drop Table if exists Company | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona') | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona'); | 20 | 23505 | duplicate key value violates unique constraint "company_pkey"
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
(5 rows)
|
||||
query | elevel | sqlcode | message
|
||||
-------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona') | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona'); | 21 | 23505 | duplicate key value violates unique constraint "company_pkey"
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
||||
@@ -11,7 +11,7 @@ select pg_sleep(.5);
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
|
||||
SELECT * FROM pg_stat_monitor_settings WHERE name NOT LIKE 'pg_stat_monitor.pgsm_track_planning' ORDER BY name COLLATE "C";
|
||||
name | value | default_value | description | minimum | maximum | options | restart
|
||||
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
|
||||
@@ -27,9 +27,8 @@ SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
|
||||
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
|
||||
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
|
||||
(15 rows)
|
||||
(14 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(.5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
|
||||
name | value | default_value | description | minimum | maximum | options | restart
|
||||
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
|
||||
pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
|
||||
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
|
||||
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
|
||||
(14 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -45,18 +45,17 @@ INFO: Sleep 5 seconds
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(5 rows)
|
||||
query | calls | resp_calls
|
||||
--------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(4 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------------------------------------------------------------------
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
|
||||
@@ -47,11 +47,12 @@ INFO: Sleep 5 seconds
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
--------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,2,0,0,0}
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,1,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(4 rows)
|
||||
(5 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
@@ -62,8 +63,8 @@ select * from generate_histogram();
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■
|
||||
(1000 - 3162)} | 1 | ■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
@@ -45,15 +45,12 @@ INFO: Sleep 5 seconds
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 4 | {0,0,0,0,0,0,3,1,0,0}
|
||||
SELECT pg_sleep(i) | 1 | {0,0,0,0,0,0,0,1,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
query | calls | resp_calls
|
||||
--------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(3 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
@@ -65,7 +62,7 @@ select * from generate_histogram();
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 1 | ■■■■■■■■■■
|
||||
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------------------------------------------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 0 |
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -1,73 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 0 |
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -1,72 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 4 | {0,0,0,0,0,0,2,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(5 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -1,73 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,2,0,0,0}
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,1,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 1 | ■■■■■■■■■■■■■■■
|
||||
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -1,442 +0,0 @@
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
--
|
||||
-- simple and compound statements
|
||||
--
|
||||
SET pg_stat_monitor.track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "int";
|
||||
int
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 'hello'
|
||||
-- multiline
|
||||
AS "text";
|
||||
text
|
||||
-------
|
||||
hello
|
||||
(1 row)
|
||||
|
||||
SELECT 'world' AS "text";
|
||||
text
|
||||
-------
|
||||
world
|
||||
(1 row)
|
||||
|
||||
-- transaction
|
||||
BEGIN;
|
||||
SELECT 1 AS "int";
|
||||
int
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 'hello' AS "text";
|
||||
text
|
||||
-------
|
||||
hello
|
||||
(1 row)
|
||||
|
||||
COMMIT;
|
||||
-- compound transaction
|
||||
BEGIN \;
|
||||
SELECT 2.0 AS "float" \;
|
||||
SELECT 'world' AS "text" \;
|
||||
COMMIT;
|
||||
-- compound with empty statements and spurious leading spacing
|
||||
\;\; SELECT 3 + 3 \;\;\; SELECT ' ' || ' !' \;\; SELECT 1 + 4 \;;
|
||||
?column?
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
-- non ;-terminated statements
|
||||
SELECT 1 + 1 + 1 AS "add" \gset
|
||||
SELECT :add + 1 + 1 AS "add" \;
|
||||
SELECT :add + 1 + 1 AS "add" \gset
|
||||
-- set operator
|
||||
SELECT 1 AS i UNION SELECT 2 ORDER BY i;
|
||||
i
|
||||
---
|
||||
1
|
||||
2
|
||||
(2 rows)
|
||||
|
||||
-- ? operator
|
||||
select '{"a":1, "b":2}'::jsonb ? 'b';
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- cte
|
||||
WITH t(f) AS (
|
||||
VALUES (1.0), (2.0)
|
||||
)
|
||||
SELECT f FROM t ORDER BY f;
|
||||
f
|
||||
-----
|
||||
1.0
|
||||
2.0
|
||||
(2 rows)
|
||||
|
||||
-- prepared statement with parameter
|
||||
PREPARE pgss_test (int) AS SELECT $1, 'test' LIMIT 1;
|
||||
EXECUTE pgss_test(1);
|
||||
?column? | ?column?
|
||||
----------+----------
|
||||
1 | test
|
||||
(1 row)
|
||||
|
||||
DEALLOCATE pgss_test;
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
BEGIN | 2 | 0
|
||||
COMMIT | 2 | 0
|
||||
PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3 | 1 | 1
|
||||
SELECT $1 | 2 | 2
|
||||
SELECT $1 +| 4 | 4
|
||||
+| |
|
||||
AS "text" | |
|
||||
SELECT $1 + $2 | 2 | 2
|
||||
SELECT $1 + $2 + $3 AS "add" | 3 | 3
|
||||
SELECT $1 AS "float" | 1 | 1
|
||||
SELECT $1 AS i UNION SELECT $2 ORDER BY i | 1 | 2
|
||||
SELECT $1 || $2 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
WITH t(f) AS ( +| 1 | 2
|
||||
VALUES ($1), ($2) +| |
|
||||
) +| |
|
||||
SELECT f FROM t ORDER BY f | |
|
||||
select $1::jsonb ? $2 | 1 | 1
|
||||
(14 rows)
|
||||
|
||||
--
|
||||
-- CRUD: INSERT SELECT UPDATE DELETE on test table
|
||||
--
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- utility "create table" should not be shown
|
||||
CREATE TEMP TABLE test (a int, b char(20));
|
||||
INSERT INTO test VALUES(generate_series(1, 10), 'aaa');
|
||||
UPDATE test SET b = 'bbb' WHERE a > 7;
|
||||
DELETE FROM test WHERE a > 9;
|
||||
-- explicit transaction
|
||||
BEGIN;
|
||||
UPDATE test SET b = '111' WHERE a = 1 ;
|
||||
COMMIT;
|
||||
BEGIN \;
|
||||
UPDATE test SET b = '222' WHERE a = 2 \;
|
||||
COMMIT ;
|
||||
UPDATE test SET b = '333' WHERE a = 3 \;
|
||||
UPDATE test SET b = '444' WHERE a = 4 ;
|
||||
BEGIN \;
|
||||
UPDATE test SET b = '555' WHERE a = 5 \;
|
||||
UPDATE test SET b = '666' WHERE a = 6 \;
|
||||
COMMIT ;
|
||||
-- many INSERT values
|
||||
INSERT INTO test (a, b) VALUES (1, 'a'), (2, 'b'), (3, 'c');
|
||||
-- SELECT with constants
|
||||
SELECT * FROM test WHERE a > 5 ORDER BY a ;
|
||||
a | b
|
||||
---+----------------------
|
||||
6 | 666
|
||||
7 | aaa
|
||||
8 | bbb
|
||||
9 | bbb
|
||||
(4 rows)
|
||||
|
||||
SELECT *
|
||||
FROM test
|
||||
WHERE a > 9
|
||||
ORDER BY a ;
|
||||
a | b
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
-- SELECT without constants
|
||||
SELECT * FROM test ORDER BY a;
|
||||
a | b
|
||||
---+----------------------
|
||||
1 | a
|
||||
1 | 111
|
||||
2 | b
|
||||
2 | 222
|
||||
3 | c
|
||||
3 | 333
|
||||
4 | 444
|
||||
5 | 555
|
||||
6 | 666
|
||||
7 | aaa
|
||||
8 | bbb
|
||||
9 | bbb
|
||||
(12 rows)
|
||||
|
||||
-- SELECT with IN clause
|
||||
SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5);
|
||||
a | b
|
||||
---+----------------------
|
||||
1 | 111
|
||||
2 | 222
|
||||
3 | 333
|
||||
4 | 444
|
||||
5 | 555
|
||||
1 | a
|
||||
2 | b
|
||||
3 | c
|
||||
(8 rows)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
BEGIN | 3 | 0
|
||||
COMMIT | 3 | 0
|
||||
CREATE TEMP TABLE test (a int, b char(20)) | 1 | 0
|
||||
DELETE FROM test WHERE a > $1 | 1 | 1
|
||||
INSERT INTO test (a, b) VALUES ($1, $2), ($3, $4), ($5, $6) | 1 | 3
|
||||
INSERT INTO test VALUES(generate_series($1, $2), $3) | 1 | 10
|
||||
SELECT * FROM test ORDER BY a | 1 | 12
|
||||
SELECT * FROM test WHERE a > $1 ORDER BY a | 2 | 4
|
||||
SELECT * FROM test WHERE a IN ($1, $2, $3, $4, $5) | 1 | 8
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
UPDATE test SET b = $1 WHERE a = $2 | 6 | 6
|
||||
UPDATE test SET b = $1 WHERE a > $2 | 1 | 3
|
||||
(13 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = none
|
||||
--
|
||||
SET pg_stat_monitor.track = 'none';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "one";
|
||||
one
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 1 + 1 AS "two";
|
||||
two
|
||||
-----
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
SELECT $1 | 1 | 1
|
||||
SELECT $1 + $2 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(4 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = top
|
||||
--
|
||||
SET pg_stat_monitor.track = 'top';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END;
|
||||
$$;
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(3);
|
||||
plus_two
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(7);
|
||||
plus_two
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(8);
|
||||
plus_one
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(10);
|
||||
plus_one
|
||||
----------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$ +| 1 | 0
|
||||
DECLARE +| |
|
||||
r INTEGER; +| |
|
||||
BEGIN +| |
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
|
||||
RETURN r; +| |
|
||||
END; $$ LANGUAGE plpgsql | |
|
||||
DO LANGUAGE plpgsql $$ +| 1 | 0
|
||||
BEGIN +| |
|
||||
-- this is a SELECT +| |
|
||||
PERFORM 'hello world'::TEXT; +| |
|
||||
END; +| |
|
||||
$$ | |
|
||||
SELECT $1 +| 1 | 1
|
||||
+| |
|
||||
AS "text" | |
|
||||
SELECT (i + $2 + $3)::INTEGER | 2 | 2
|
||||
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
|
||||
SELECT PLUS_ONE($1) | 2 | 2
|
||||
SELECT PLUS_TWO($1) | 2 | 2
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(10 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = all
|
||||
--
|
||||
SET pg_stat_monitor.track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- we drop and recreate the functions to avoid any caching funnies
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(-1);
|
||||
plus_two
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(2);
|
||||
plus_two
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(3);
|
||||
plus_one
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(1);
|
||||
plus_one
|
||||
----------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$ +| 1 | 0
|
||||
DECLARE +| |
|
||||
r INTEGER; +| |
|
||||
BEGIN +| |
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
|
||||
RETURN r; +| |
|
||||
END; $$ LANGUAGE plpgsql | |
|
||||
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
|
||||
SELECT (i + $2 + $3)::INTEGER | 2 | 2
|
||||
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
|
||||
SELECT PLUS_ONE($1) | 2 | 2
|
||||
SELECT PLUS_TWO($1) | 2 | 2
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(10 rows)
|
||||
|
||||
--
|
||||
-- utility commands
|
||||
--
|
||||
SET pg_stat_monitor.track_utility = TRUE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1;
|
||||
?column?
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
CREATE INDEX test_b ON test(b);
|
||||
DROP TABLE test \;
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER);
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
NOTICE: function plus_one(pg_catalog.int4) does not exist, skipping
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE INDEX test_b ON test(b) | 1 | 0
|
||||
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
|
||||
DROP TABLE IF EXISTS test | 3 | 0
|
||||
DROP TABLE test | 1 | 0
|
||||
SELECT $1 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(9 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,31 +0,0 @@
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1;
|
||||
?column?
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 1/0; -- divide by zero
|
||||
ERROR: division by zero
|
||||
SELECT query, state_code, state FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | state_code | state
|
||||
---------------------------------------------------------------------------------+------------+---------------------
|
||||
SELECT $1 | 3 | FINISHED
|
||||
SELECT 1/0; | 4 | FINISHED WITH ERROR
|
||||
SELECT pg_stat_monitor_reset() | 3 | FINISHED
|
||||
SELECT query, state_code, state FROM pg_stat_monitor ORDER BY query COLLATE "C" | 2 | ACTIVE
|
||||
(4 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
@@ -24,24 +24,12 @@ SELECT add2(1,2);
|
||||
(1 row)
|
||||
|
||||
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | top_query
|
||||
-------------------------------------------------------------------------+------------------
|
||||
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS +|
|
||||
$$ +|
|
||||
BEGIN +|
|
||||
return (select $1 + $2); +|
|
||||
END; $$ language plpgsql |
|
||||
CREATE OR REPLACE function add2(int, int) RETURNS int as +|
|
||||
$$ +|
|
||||
BEGIN +|
|
||||
return add($1,$2); +|
|
||||
END; +|
|
||||
$$ language plpgsql |
|
||||
SELECT (select $1 + $2) | SELECT add2(1,2)
|
||||
SELECT add2(1,2) |
|
||||
SELECT pg_stat_monitor_reset() |
|
||||
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C" |
|
||||
(6 rows)
|
||||
query | top_query
|
||||
--------------------------------+------------------
|
||||
(select $1 + $2) | SELECT add2(1,2)
|
||||
SELECT add2(1,2) |
|
||||
SELECT pg_stat_monitor_reset() |
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
CREATE USER su WITH SUPERUSER;
|
||||
ERROR: role "su" already exists
|
||||
SET ROLE su;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE USER u1;
|
||||
CREATE USER u2;
|
||||
SET ROLE su;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SET ROLE u1;
|
||||
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)
|
||||
|
||||
SET ROLE su;
|
||||
SELECT userid, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
userid | query
|
||||
--------+---------------------------------
|
||||
u1 | CREATE TABLE t1 (a int);
|
||||
u2 | CREATE TABLE t2 (a int);
|
||||
u1 | SELECT * FROM t1;
|
||||
u2 | SELECT * FROM t2;
|
||||
su | SELECT pg_stat_monitor_reset();
|
||||
su | SET ROLE su;
|
||||
u1 | SET ROLE u1;
|
||||
u2 | SET ROLE u2;
|
||||
(8 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP USER u1;
|
||||
DROP USER u2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
Reference in New Issue
Block a user