PG-267 Add testcase to test histogram.
This commit adds following three sql based testcases: 1) Test unique application name set by user. 2) Histogram function is working properly as desired. 3) Error on insert is shown with proper message.pull/184/head
parent
0573be4090
commit
5aa6764041
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
|
|||
LDFLAGS_SL += $(filter -lm, $(LIBS))
|
||||
|
||||
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_monitor/pg_stat_monitor.conf --inputdir=regression
|
||||
REGRESS = basic version guc counters relations database top_query application_name cmd_type error state rows tags
|
||||
REGRESS = basic version guc counters relations database error_insert application_name application_name_unique top_query cmd_type error rows tags histogram
|
||||
|
||||
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
|
||||
# which typical installcheck users do not have (e.g. buildfarm clients).
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
Create EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set application_name = 'naeem' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
Set application_name = 'psql' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C";
|
||||
query | application_name
|
||||
--------------------------------+------------------------------------
|
||||
SELECT $1 AS num | naeem
|
||||
SELECT $1 AS num | psql
|
||||
SELECT pg_stat_monitor_reset() | pg_regress/application_name_unique
|
||||
Set application_name = 'naeem' | naeem
|
||||
Set application_name = 'psql' | psql
|
||||
(5 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,34 @@
|
|||
Drop Table if exists Company;
|
||||
NOTICE: table "company" does not exist, skipping
|
||||
CREATE TABLE Company(
|
||||
ID INT PRIMARY KEY NOT NULL,
|
||||
NAME TEXT NOT NULL
|
||||
);
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
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, $2) | 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 | |
|
||||
(4 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,34 @@
|
|||
Drop Table if exists Company;
|
||||
NOTICE: table "company" does not exist, skipping
|
||||
CREATE TABLE Company(
|
||||
ID INT PRIMARY KEY NOT NULL,
|
||||
NAME TEXT NOT NULL
|
||||
);
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
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, $2) | 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 | |
|
||||
(4 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,71 @@
|
|||
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.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) | 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.track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep($1) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(4 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)} | 2 | ■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,71 @@
|
|||
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.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) | 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.track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep($1) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(4 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)} | 2 | ■■■■■■■■■■■■■■■■■■■■
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,9 @@
|
|||
Create EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
Set application_name = 'naeem' ;
|
||||
SELECT 1 AS num;
|
||||
Set application_name = 'psql' ;
|
||||
SELECT 1 AS num;
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C";
|
||||
SELECT pg_stat_monitor_reset();
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,17 @@
|
|||
Drop Table if exists Company;
|
||||
|
||||
CREATE TABLE Company(
|
||||
ID INT PRIMARY KEY NOT NULL,
|
||||
NAME TEXT NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
|
||||
Drop Table if exists Company;
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -1,28 +1,39 @@
|
|||
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;
|
||||
|
||||
CREATE TABLE t1(a int);
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
Set pg_stat_monitor.track='all';
|
||||
select run_pg_sleep(5);
|
||||
|
||||
INSERT INTO t1 VALUES(generate_series(1,10));
|
||||
ANALYZE t1;
|
||||
SELECT count(*) FROM t1;
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
|
||||
INSERT INTO t1 VALUES(generate_series(1,10000));
|
||||
ANALYZE t1;
|
||||
SELECT count(*) FROM t1;;
|
||||
select * from generate_histogram();
|
||||
|
||||
INSERT INTO t1 VALUES(generate_series(1,1000000));
|
||||
ANALYZE t1;
|
||||
SELECT count(*) FROM t1;
|
||||
|
||||
INSERT INTO t1 VALUES(generate_series(1,10000000));
|
||||
ANALYZE t1;
|
||||
SELECT count(*) FROM t1;
|
||||
|
||||
SELECT query, calls, min_time, max_time, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
SELECT * FROM histogram(0, 'F44CD1B4B33A47AF') AS a(range TEXT, freq INT, bar TEXT);
|
||||
|
||||
DROP TABLE t1;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
Loading…
Reference in New Issue