mirror of https://github.com/postgres/postgres
pg_stat_statements: Add some tests for older versions still usable
When the newest version is loaded, the backend would load objects from the oldest complete SQL file (here 1.4) and then update to the latest version with transition scripts (up to 1.9 currently). This provides some coverage for upgrades of pg_stat_statements, but there is no test to show how things have changed across each version. This adds a couple of tests for the upgrade paths using objects from each version supported, stressing the objects whose behaviors have changed across each version supported. Author: Erica Zhang Reviewed-by: Julien Rouhaud, Michael Paquier Discussion: https://postgr.es/m/tencent_BBA974AFF61379F2345E782FD6C55891950A@qq.com
This commit is contained in:
parent
795862c280
commit
2b0da0365b
|
@ -16,7 +16,7 @@ PGFILEDESC = "pg_stat_statements - execution statistics of SQL statements"
|
|||
LDFLAGS_SL += $(filter -lm, $(LIBS))
|
||||
|
||||
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_statements/pg_stat_statements.conf
|
||||
REGRESS = pg_stat_statements
|
||||
REGRESS = pg_stat_statements oldextversions
|
||||
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
|
||||
# which typical installcheck users do not have (e.g. buildfarm clients).
|
||||
NO_INSTALLCHECK = 1
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
-- test old extension version entry points
|
||||
CREATE EXTENSION pg_stat_statements WITH VERSION '1.4';
|
||||
-- Execution of pg_stat_statements_reset() is granted only to
|
||||
-- superusers in 1.4, so this fails.
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
ERROR: permission denied for function pg_stat_statements_reset
|
||||
RESET SESSION AUTHORIZATION;
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.5';
|
||||
-- Execution of pg_stat_statements_reset() should be granted to
|
||||
-- pg_read_all_stats now, so this works.
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
pg_stat_statements_reset
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
-- In 1.6, it got restricted back to superusers.
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.6';
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
ERROR: permission denied for function pg_stat_statements_reset
|
||||
RESET SESSION AUTHORIZATION;
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
pg_get_functiondef
|
||||
-------------------------------------------------------------------------------
|
||||
CREATE OR REPLACE FUNCTION public.pg_stat_statements_reset() +
|
||||
RETURNS void +
|
||||
LANGUAGE c +
|
||||
PARALLEL SAFE +
|
||||
AS '$libdir/pg_stat_statements', $function$pg_stat_statements_reset$function$+
|
||||
|
||||
(1 row)
|
||||
|
||||
-- New function for pg_stat_statements_reset introduced, still
|
||||
-- restricted for non-superusers.
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.7';
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
ERROR: permission denied for function pg_stat_statements_reset
|
||||
RESET SESSION AUTHORIZATION;
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
pg_get_functiondef
|
||||
--------------------------------------------------------------------------------------------------------------------------------
|
||||
CREATE OR REPLACE FUNCTION public.pg_stat_statements_reset(userid oid DEFAULT 0, dbid oid DEFAULT 0, queryid bigint DEFAULT 0)+
|
||||
RETURNS void +
|
||||
LANGUAGE c +
|
||||
PARALLEL SAFE STRICT +
|
||||
AS '$libdir/pg_stat_statements', $function$pg_stat_statements_reset_1_7$function$ +
|
||||
|
||||
(1 row)
|
||||
|
||||
\d pg_stat_statements
|
||||
View "public.pg_stat_statements"
|
||||
Column | Type | Collation | Nullable | Default
|
||||
---------------------+------------------+-----------+----------+---------
|
||||
userid | oid | | |
|
||||
dbid | oid | | |
|
||||
queryid | bigint | | |
|
||||
query | text | | |
|
||||
calls | bigint | | |
|
||||
total_time | double precision | | |
|
||||
min_time | double precision | | |
|
||||
max_time | double precision | | |
|
||||
mean_time | double precision | | |
|
||||
stddev_time | double precision | | |
|
||||
rows | bigint | | |
|
||||
shared_blks_hit | bigint | | |
|
||||
shared_blks_read | bigint | | |
|
||||
shared_blks_dirtied | bigint | | |
|
||||
shared_blks_written | bigint | | |
|
||||
local_blks_hit | bigint | | |
|
||||
local_blks_read | bigint | | |
|
||||
local_blks_dirtied | bigint | | |
|
||||
local_blks_written | bigint | | |
|
||||
temp_blks_read | bigint | | |
|
||||
temp_blks_written | bigint | | |
|
||||
blk_read_time | double precision | | |
|
||||
blk_write_time | double precision | | |
|
||||
|
||||
SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
|
||||
has_data
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- New functions and views for pg_stat_statements in 1.8
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.8';
|
||||
\d pg_stat_statements
|
||||
View "public.pg_stat_statements"
|
||||
Column | Type | Collation | Nullable | Default
|
||||
---------------------+------------------+-----------+----------+---------
|
||||
userid | oid | | |
|
||||
dbid | oid | | |
|
||||
queryid | bigint | | |
|
||||
query | text | | |
|
||||
plans | bigint | | |
|
||||
total_plan_time | double precision | | |
|
||||
min_plan_time | double precision | | |
|
||||
max_plan_time | double precision | | |
|
||||
mean_plan_time | double precision | | |
|
||||
stddev_plan_time | double precision | | |
|
||||
calls | bigint | | |
|
||||
total_exec_time | double precision | | |
|
||||
min_exec_time | double precision | | |
|
||||
max_exec_time | double precision | | |
|
||||
mean_exec_time | double precision | | |
|
||||
stddev_exec_time | double precision | | |
|
||||
rows | bigint | | |
|
||||
shared_blks_hit | bigint | | |
|
||||
shared_blks_read | bigint | | |
|
||||
shared_blks_dirtied | bigint | | |
|
||||
shared_blks_written | bigint | | |
|
||||
local_blks_hit | bigint | | |
|
||||
local_blks_read | bigint | | |
|
||||
local_blks_dirtied | bigint | | |
|
||||
local_blks_written | bigint | | |
|
||||
temp_blks_read | bigint | | |
|
||||
temp_blks_written | bigint | | |
|
||||
blk_read_time | double precision | | |
|
||||
blk_write_time | double precision | | |
|
||||
wal_records | bigint | | |
|
||||
wal_fpi | bigint | | |
|
||||
wal_bytes | numeric | | |
|
||||
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
pg_get_functiondef
|
||||
--------------------------------------------------------------------------------------------------------------------------------
|
||||
CREATE OR REPLACE FUNCTION public.pg_stat_statements_reset(userid oid DEFAULT 0, dbid oid DEFAULT 0, queryid bigint DEFAULT 0)+
|
||||
RETURNS void +
|
||||
LANGUAGE c +
|
||||
PARALLEL SAFE STRICT +
|
||||
AS '$libdir/pg_stat_statements', $function$pg_stat_statements_reset_1_7$function$ +
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_statements;
|
|
@ -0,0 +1,39 @@
|
|||
-- test old extension version entry points
|
||||
|
||||
CREATE EXTENSION pg_stat_statements WITH VERSION '1.4';
|
||||
-- Execution of pg_stat_statements_reset() is granted only to
|
||||
-- superusers in 1.4, so this fails.
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
RESET SESSION AUTHORIZATION;
|
||||
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.5';
|
||||
-- Execution of pg_stat_statements_reset() should be granted to
|
||||
-- pg_read_all_stats now, so this works.
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
RESET SESSION AUTHORIZATION;
|
||||
|
||||
-- In 1.6, it got restricted back to superusers.
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.6';
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
RESET SESSION AUTHORIZATION;
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
|
||||
-- New function for pg_stat_statements_reset introduced, still
|
||||
-- restricted for non-superusers.
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.7';
|
||||
SET SESSION AUTHORIZATION pg_read_all_stats;
|
||||
SELECT pg_stat_statements_reset();
|
||||
RESET SESSION AUTHORIZATION;
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
\d pg_stat_statements
|
||||
SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
|
||||
|
||||
-- New functions and views for pg_stat_statements in 1.8
|
||||
AlTER EXTENSION pg_stat_statements UPDATE TO '1.8';
|
||||
\d pg_stat_statements
|
||||
SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
|
||||
|
||||
DROP EXTENSION pg_stat_statements;
|
Loading…
Reference in New Issue