mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	This patch adds 'stats_since' and 'minmax_stats_since' columns to the pg_stat_statements view and pg_stat_statements() function. The new min/max reset mode for the pg_stat_stetments_reset() function is controlled by the parameter minmax_only. 'stat_since' column is populated with the current timestamp when a new statement is added to the pg_stat_statements hashtable. It provides clean information about statistics collection time intervals for each statement. Besides it can be used by sampling solutions to detect situations when a statement was evicted and stored again between samples. Such a sampling solution could derive any pg_stat_statements statistic values for an interval between two samples with the exception of all min/max statistics. To address this issue this patch adds the ability to reset min/max statistics independently of the statement reset using the new minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid, queryid bigint, minmax_only boolean) function. The timestamp of such reset is stored in the minmax_stats_since field for each statement. pg_stat_statements_reset() function now returns the timestamp of a reset as the result. Discussion: https://postgr.es/m/flat/72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru Author: Andrei Zubkov Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov Reviewed-by: Alena Rybakina, Andrei Lepikhov
		
			
				
	
	
		
			59 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
| -- 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);
 | |
| 
 | |
| -- New function pg_stat_statement_info, and new function
 | |
| -- and view for pg_stat_statements introduced in 1.9
 | |
| AlTER EXTENSION pg_stat_statements UPDATE TO '1.9';
 | |
| SELECT pg_get_functiondef('pg_stat_statements_info'::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.10
 | |
| AlTER EXTENSION pg_stat_statements UPDATE TO '1.10';
 | |
| \d pg_stat_statements
 | |
| SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
 | |
| 
 | |
| -- New functions and views for pg_stat_statements in 1.11
 | |
| AlTER EXTENSION pg_stat_statements UPDATE TO '1.11';
 | |
| \d pg_stat_statements
 | |
| SELECT count(*) > 0 AS has_data FROM pg_stat_statements;
 | |
| -- New parameter minmax_only of pg_stat_statements_reset function
 | |
| SELECT pg_get_functiondef('pg_stat_statements_reset'::regproc);
 | |
| 
 | |
| DROP EXTENSION pg_stat_statements;
 |