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

Commita632cd3

Browse files
committed
injection_points: Add routine able to drop all stats
This serves as an example of how to use the new function introduced ince5c620, pgstat_drop_matching_entries(), with a callback able tofilter the entries dropped.A SQL function named injection_points_stats_drop() is added with sometests.Author: Lukas FittiDiscussion:https://postgr.es/m/CAP53PkwuFbo3NkwZgxwNRMjMfqPEqidD-SggaoQ4ijotBVLJAA@mail.gmail.com
1 parentce5c620 commita632cd3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎src/test/modules/injection_points/injection_points--1.0.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ RETURNS bigint
8585
AS'MODULE_PATHNAME','injection_points_stats_numcalls'
8686
LANGUAGE C STRICT;
8787

88+
--
89+
-- injection_points_stats_drop()
90+
--
91+
-- Drop all statistics of injection points.
92+
--
93+
CREATEFUNCTIONinjection_points_stats_drop()
94+
RETURNS void
95+
AS'MODULE_PATHNAME','injection_points_stats_drop'
96+
LANGUAGE C STRICT;
97+
8898
--
8999
-- injection_points_stats_fixed()
90100
--

‎src/test/modules/injection_points/injection_stats.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,22 @@ injection_points_stats_numcalls(PG_FUNCTION_ARGS)
197197

198198
PG_RETURN_INT64(entry->numcalls);
199199
}
200+
201+
/* Only used by injection_points_stats_drop() */
202+
staticbool
203+
match_inj_entries(PgStatShared_HashEntry*entry,Datummatch_data)
204+
{
205+
returnentry->key.kind==PGSTAT_KIND_INJECTION;
206+
}
207+
208+
/*
209+
* SQL function that drops all injection point statistics.
210+
*/
211+
PG_FUNCTION_INFO_V1(injection_points_stats_drop);
212+
Datum
213+
injection_points_stats_drop(PG_FUNCTION_ARGS)
214+
{
215+
pgstat_drop_matching_entries(match_inj_entries,0);
216+
217+
PG_RETURN_VOID();
218+
}

‎src/test/modules/injection_points/t/001_stats.pl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@
6969
"SELECT * FROM injection_points_stats_fixed();");
7070
is($fixedstats,'0|0|0|0|0','fixed stats after crash');
7171

72+
# On drop all stats are gone
73+
$node->safe_psql('postgres',
74+
"SELECT injection_points_attach('stats-notice', 'notice');");
75+
$node->safe_psql('postgres',"SELECT injection_points_run('stats-notice');");
76+
$node->safe_psql('postgres',"SELECT injection_points_run('stats-notice');");
77+
$numcalls =$node->safe_psql('postgres',
78+
"SELECT injection_points_stats_numcalls('stats-notice');");
79+
is($numcalls,'2','number of stats calls');
80+
$node->safe_psql('postgres',"SELECT injection_points_stats_drop();");
81+
$numcalls =$node->safe_psql('postgres',
82+
"SELECT injection_points_stats_numcalls('stats-notice');");
83+
is($numcalls,'','no stats after drop via SQL function');
84+
7285
# Stop the server, disable the module, then restart. The server
7386
# should be able to come up.
7487
$node->stop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp