other functions called by it, in milliseconds
</para></entry>
</row>
+
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>stats_reset</structfield> <type>timestamp with time zone</type>
+ </para>
+ <para>
+ Time at which these statistics were last reset
+ </para></entry>
+ </row>
</tbody>
</tgroup>
</table>
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 -- fast check to eliminate built-in functions
AND pg_stat_get_function_calls(P.oid) IS NOT NULL;
.pending_size = sizeof(PgStat_FunctionCounts),
.flush_pending_cb = pgstat_function_flush_cb,
+ .reset_timestamp_cb = pgstat_function_reset_timestamp_cb,
},
[PGSTAT_KIND_REPLSLOT] = {
return true;
}
+void
+pgstat_function_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
+{
+ ((PgStatShared_Function *) header)->stats.stat_reset_timestamp = ts;
+}
+
/*
* find any existing PgStat_FunctionCounts entry for specified function
*
/* pg_stat_get_function_self_time */
PG_STAT_GET_FUNCENTRY_FLOAT8_MS(self_time)
+Datum
+pg_stat_get_function_stat_reset_time(PG_FUNCTION_ARGS)
+{
+ Oid funcid = PG_GETARG_OID(0);
+ TimestampTz result;
+ PgStat_StatFuncEntry *funcentry;
+
+ if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
+ result = 0;
+ else
+ result = funcentry->stat_reset_timestamp;
+
+ if (result == 0)
+ PG_RETURN_NULL();
+ else
+ PG_RETURN_TIMESTAMPTZ(result);
+}
+
Datum
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
{
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202510062
+#define CATALOG_VERSION_NO 202510081
#endif
proname => 'pg_stat_get_function_self_time', provolatile => 's',
proparallel => 'r', prorettype => 'float8', proargtypes => 'oid',
prosrc => 'pg_stat_get_function_self_time' },
+{ oid => '8745', descr => 'statistics: last reset for a function',
+ proname => 'pg_stat_get_function_stat_reset_time', provolatile => 's',
+ proparallel => 'r', prorettype => 'timestamptz', proargtypes => 'oid',
+ prosrc => 'pg_stat_get_function_stat_reset_time' },
{ oid => '3037',
descr => 'statistics: number of scans done for table/index in current transaction',
* ------------------------------------------------------------
*/
-#define PGSTAT_FILE_FORMAT_ID 0x01A5BCB8
+#define PGSTAT_FILE_FORMAT_ID 0x01A5BCB9
typedef struct PgStat_ArchiverStats
{
PgStat_Counter total_time; /* times in microseconds */
PgStat_Counter self_time;
+ TimestampTz stat_reset_timestamp;
} PgStat_StatFuncEntry;
typedef struct PgStat_StatReplSlotEntry
*/
extern bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
+extern void pgstat_function_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts);
/*
(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
------------------------
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
--------------------------------------
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
(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
------------------------
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
--------------------------------------
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
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 {
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
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));