Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb71bae4

Browse files
committed
Add stats_reset to pg_stat_user_functions
It is possible to call pg_stat_reset_single_function_counters() for asingle function, but the reset time was missing the system view showingits statistics. Like all the fields of pg_stat_user_functions, the GUCtrack_functions needs to be enabled to show the statistics aboutfunction executions.Bump catalog version.Bump PGSTAT_FILE_FORMAT_ID, as a result of the new field added toPgStat_StatFuncEntry.Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Discussion:https://postgr.es/m/aONjnsaJSx-nEdfU@paquier.xyz
1 parent035b091 commitb71bae4

File tree

13 files changed

+90
-8
lines changed

13 files changed

+90
-8
lines changed

‎doc/src/sgml/monitoring.sgml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,6 +4736,15 @@ description | Waiting for a newly initialized WAL file to reach durable storage
47364736
other functions called by it, in milliseconds
47374737
</para></entry>
47384738
</row>
4739+
4740+
<row>
4741+
<entry role="catalog_table_entry"><para role="column_definition">
4742+
<structfield>stats_reset</structfield> <type>timestamp with time zone</type>
4743+
</para>
4744+
<para>
4745+
Time at which these statistics were last reset
4746+
</para></entry>
4747+
</row>
47394748
</tbody>
47404749
</tgroup>
47414750
</table>

‎src/backend/catalog/system_views.sql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,8 @@ CREATE VIEW pg_stat_user_functions AS
11311131
P.pronameAS funcname,
11321132
pg_stat_get_function_calls(P.oid)AS calls,
11331133
pg_stat_get_function_total_time(P.oid)AS total_time,
1134-
pg_stat_get_function_self_time(P.oid)AS self_time
1134+
pg_stat_get_function_self_time(P.oid)AS self_time,
1135+
pg_stat_get_function_stat_reset_time(P.oid)AS stats_reset
11351136
FROM pg_proc PLEFT JOIN pg_namespace NON (N.oid=P.pronamespace)
11361137
WHEREP.prolang!=12-- fast check to eliminate built-in functions
11371138
AND pg_stat_get_function_calls(P.oid)IS NOT NULL;

‎src/backend/utils/activity/pgstat.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
328328
.pending_size=sizeof(PgStat_FunctionCounts),
329329

330330
.flush_pending_cb=pgstat_function_flush_cb,
331+
.reset_timestamp_cb=pgstat_function_reset_timestamp_cb,
331332
},
332333

333334
[PGSTAT_KIND_REPLSLOT]= {

‎src/backend/utils/activity/pgstat_function.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
214214
return true;
215215
}
216216

217+
void
218+
pgstat_function_reset_timestamp_cb(PgStatShared_Common*header,TimestampTzts)
219+
{
220+
((PgStatShared_Function*)header)->stats.stat_reset_timestamp=ts;
221+
}
222+
217223
/*
218224
* find any existing PgStat_FunctionCounts entry for specified function
219225
*

‎src/backend/utils/adt/pgstatfuncs.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ PG_STAT_GET_FUNCENTRY_FLOAT8_MS(total_time)
203203
/* pg_stat_get_function_self_time */
204204
PG_STAT_GET_FUNCENTRY_FLOAT8_MS(self_time)
205205

206+
Datum
207+
pg_stat_get_function_stat_reset_time(PG_FUNCTION_ARGS)
208+
{
209+
Oidfuncid=PG_GETARG_OID(0);
210+
TimestampTzresult;
211+
PgStat_StatFuncEntry*funcentry;
212+
213+
if ((funcentry=pgstat_fetch_stat_funcentry(funcid))==NULL)
214+
result=0;
215+
else
216+
result=funcentry->stat_reset_timestamp;
217+
218+
if (result==0)
219+
PG_RETURN_NULL();
220+
else
221+
PG_RETURN_TIMESTAMPTZ(result);
222+
}
223+
206224
Datum
207225
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
208226
{

‎src/include/catalog/catversion.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202510062
60+
#defineCATALOG_VERSION_NO202510081
6161

6262
#endif

‎src/include/catalog/pg_proc.dat‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,6 +6071,10 @@
60716071
proname => 'pg_stat_get_function_self_time', provolatile => 's',
60726072
proparallel => 'r', prorettype => 'float8', proargtypes => 'oid',
60736073
prosrc => 'pg_stat_get_function_self_time' },
6074+
{ oid => '8745', descr => 'statistics: last reset for a function',
6075+
proname => 'pg_stat_get_function_stat_reset_time', provolatile => 's',
6076+
proparallel => 'r', prorettype => 'timestamptz', proargtypes => 'oid',
6077+
prosrc => 'pg_stat_get_function_stat_reset_time' },
60746078

60756079
{ oid => '3037',
60766080
descr => 'statistics: number of scans done for table/index in current transaction',

‎src/include/pgstat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ typedef struct PgStat_TableXactStatus
212212
* ------------------------------------------------------------
213213
*/
214214

215-
#definePGSTAT_FILE_FORMAT_ID0x01A5BCB8
215+
#definePGSTAT_FILE_FORMAT_ID0x01A5BCB9
216216

217217
typedefstructPgStat_ArchiverStats
218218
{
@@ -384,6 +384,7 @@ typedef struct PgStat_StatFuncEntry
384384

385385
PgStat_Countertotal_time;/* times in microseconds */
386386
PgStat_Counterself_time;
387+
TimestampTzstat_reset_timestamp;
387388
}PgStat_StatFuncEntry;
388389

389390
typedefstructPgStat_StatReplSlotEntry

‎src/include/utils/pgstat_internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ extern void pgstat_database_reset_timestamp_cb(PgStatShared_Common *header, Time
691691
*/
692692

693693
externboolpgstat_function_flush_cb(PgStat_EntryRef*entry_ref,boolnowait);
694+
externvoidpgstat_function_reset_timestamp_cb(PgStatShared_Common*header,TimestampTzts);
694695

695696

696697
/*

‎src/test/isolation/expected/stats.out‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ test_stat_func| | |
10251025
(1 row)
10261026

10271027

1028-
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
1028+
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_statss1_func_stats_reset_checks1_func_stats_reset s1_func_stats s1_func_stats2 s1_func_stats s1_func_stats_reset_check
10291029
pg_stat_force_next_flush
10301030
------------------------
10311031

@@ -1137,6 +1137,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
11371137
test_stat_func| 3|t |t
11381138
(1 row)
11391139

1140+
step s1_func_stats_reset_check:
1141+
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
1142+
IS NOT NULL AS has_stats_reset;
1143+
1144+
has_stats_reset
1145+
---------------
1146+
f
1147+
(1 row)
1148+
11401149
step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc);
11411150
pg_stat_reset_single_function_counters
11421151
--------------------------------------
@@ -1185,6 +1194,15 @@ name |pg_stat_get_function_calls|total_above_zero|self_above_zero
11851194
test_stat_func| 0|f |f
11861195
(1 row)
11871196

1197+
step s1_func_stats_reset_check:
1198+
SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc)
1199+
IS NOT NULL AS has_stats_reset;
1200+
1201+
has_stats_reset
1202+
---------------
1203+
t
1204+
(1 row)
1205+
11881206

11891207
starting permutation: s1_func_stats_nonexistent s1_func_stats_reset_nonexistent s1_func_stats_nonexistent
11901208
pg_stat_force_next_flush

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp