1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-19 17:02:53 +03:00

Add stats_reset to pg_stat_user_functions

It is possible to call pg_stat_reset_single_function_counters() for a
single function, but the reset time was missing the system view showing
its statistics.  Like all the fields of pg_stat_user_functions, the GUC
track_functions needs to be enabled to show the statistics about
function executions.

Bump catalog version.
Bump PGSTAT_FILE_FORMAT_ID, as a result of the new field added to
PgStat_StatFuncEntry.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aONjnsaJSx-nEdfU@paquier.xyz
This commit is contained in:
Michael Paquier
2025-10-08 12:43:40 +09:00
parent 035b09131d
commit b71bae41a0
13 changed files with 90 additions and 8 deletions

View File

@@ -1025,7 +1025,7 @@ test_stat_func| | |
(1 row)
starting permutation: s1_track_funcs_all s2_track_funcs_all s1_func_call s2_func_call s2_func_call2 s1_ff s2_ff s1_func_stats s2_func_call s2_func_call2 s2_ff s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset s1_func_stats s1_func_stats2 s1_func_stats
starting permutation: s1_track_funcs_all s2_track_funcs_all s1_func_call s2_func_call s2_func_call2 s1_ff s2_ff s1_func_stats s2_func_call s2_func_call2 s2_ff s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check s1_func_stats_reset s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check
pg_stat_force_next_flush
------------------------
@@ -1137,6 +1137,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
test_stat_func| 3|t |t
(1 row)
step s1_func_stats_reset_check:
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
IS NOT NULL AS has_stats_reset;
has_stats_reset
---------------
f
(1 row)
step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc);
pg_stat_reset_single_function_counters
--------------------------------------
@@ -1185,6 +1194,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
test_stat_func| 0|f |f
(1 row)
step s1_func_stats_reset_check:
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
IS NOT NULL AS has_stats_reset;
has_stats_reset
---------------
t
(1 row)
starting permutation: s1_func_stats_nonexistent s1_func_stats_reset_nonexistent s1_func_stats_nonexistent
pg_stat_force_next_flush

View File

@@ -1025,7 +1025,7 @@ test_stat_func| | |
(1 row)
starting permutation: s1_track_funcs_all s2_track_funcs_all s1_func_call s2_func_call s2_func_call2 s1_ff s2_ff s1_func_stats s2_func_call s2_func_call2 s2_ff s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset s1_func_stats s1_func_stats2 s1_func_stats
starting permutation: s1_track_funcs_all s2_track_funcs_all s1_func_call s2_func_call s2_func_call2 s1_ff s2_ff s1_func_stats s2_func_call s2_func_call2 s2_ff s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check s1_func_stats_reset s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check
pg_stat_force_next_flush
------------------------
@@ -1137,6 +1137,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
test_stat_func| 3|t |t
(1 row)
step s1_func_stats_reset_check:
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
IS NOT NULL AS has_stats_reset;
has_stats_reset
---------------
f
(1 row)
step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc);
pg_stat_reset_single_function_counters
--------------------------------------
@@ -1185,6 +1194,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
test_stat_func| 0|f |f
(1 row)
step s1_func_stats_reset_check:
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
IS NOT NULL AS has_stats_reset;
has_stats_reset
---------------
t
(1 row)
starting permutation: s1_func_stats_nonexistent s1_func_stats_reset_nonexistent s1_func_stats_nonexistent
pg_stat_force_next_flush

View File

@@ -58,6 +58,10 @@ step s1_track_funcs_none { SET track_functions = 'none'; }
step s1_func_call { SELECT test_stat_func(); }
step s1_func_drop { DROP FUNCTION test_stat_func(); }
step s1_func_stats_reset { SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc); }
step s1_func_stats_reset_check {
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
IS NOT NULL AS has_stats_reset;
}
step s1_func_stats_reset_nonexistent { SELECT pg_stat_reset_single_function_counters(12000); }
step s1_reset { SELECT pg_stat_reset(); }
step s1_func_stats {
@@ -235,9 +239,9 @@ permutation
s1_ff s2_ff
s1_func_stats
s2_func_call s2_func_call2 s2_ff
s1_func_stats s1_func_stats2 s1_func_stats
s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check
s1_func_stats_reset
s1_func_stats s1_func_stats2 s1_func_stats
s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check
# test pg_stat_reset_single_function_counters of non-existing function
permutation

View File

@@ -2244,7 +2244,8 @@ pg_stat_user_functions| SELECT p.oid AS funcid,
p.proname AS funcname,
pg_stat_get_function_calls(p.oid) AS calls,
pg_stat_get_function_total_time(p.oid) AS total_time,
pg_stat_get_function_self_time(p.oid) AS self_time
pg_stat_get_function_self_time(p.oid) AS self_time,
pg_stat_get_function_stat_reset_time(p.oid) AS stats_reset
FROM (pg_proc p
LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace)))
WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_function_calls(p.oid) IS NOT NULL));