Skip to content

Commit a632cd3

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 in ce5c620, pgstat_drop_matching_entries(), with a callback able to filter the entries dropped. A SQL function named injection_points_stats_drop() is added with some tests. Author: Lukas Fitti Discussion: https://postgr.es/m/CAP53PkwuFbo3NkwZgxwNRMjMfqPEqidD-SggaoQ4ijotBVLJAA@mail.gmail.com
1 parent ce5c620 commit a632cd3

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+
CREATE FUNCTION injection_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+
static bool
203+
match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)
204+
{
205+
return entry->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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy