mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
injection_points: Add routine able to drop all stats
This serves as an example of how to use the new function introduced in ce5c620fb625, 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
This commit is contained in:
parent
ce5c620fb6
commit
a632cd354d
@ -85,6 +85,16 @@ RETURNS bigint
|
||||
AS 'MODULE_PATHNAME', 'injection_points_stats_numcalls'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
--
|
||||
-- injection_points_stats_drop()
|
||||
--
|
||||
-- Drop all statistics of injection points.
|
||||
--
|
||||
CREATE FUNCTION injection_points_stats_drop()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME', 'injection_points_stats_drop'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
--
|
||||
-- injection_points_stats_fixed()
|
||||
--
|
||||
|
@ -197,3 +197,22 @@ injection_points_stats_numcalls(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_INT64(entry->numcalls);
|
||||
}
|
||||
|
||||
/* Only used by injection_points_stats_drop() */
|
||||
static bool
|
||||
match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)
|
||||
{
|
||||
return entry->key.kind == PGSTAT_KIND_INJECTION;
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function that drops all injection point statistics.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_stats_drop);
|
||||
Datum
|
||||
injection_points_stats_drop(PG_FUNCTION_ARGS)
|
||||
{
|
||||
pgstat_drop_matching_entries(match_inj_entries, 0);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
@ -69,6 +69,19 @@ $fixedstats = $node->safe_psql('postgres',
|
||||
"SELECT * FROM injection_points_stats_fixed();");
|
||||
is($fixedstats, '0|0|0|0|0', 'fixed stats after crash');
|
||||
|
||||
# On drop all stats are gone
|
||||
$node->safe_psql('postgres',
|
||||
"SELECT injection_points_attach('stats-notice', 'notice');");
|
||||
$node->safe_psql('postgres', "SELECT injection_points_run('stats-notice');");
|
||||
$node->safe_psql('postgres', "SELECT injection_points_run('stats-notice');");
|
||||
$numcalls = $node->safe_psql('postgres',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
is($numcalls, '2', 'number of stats calls');
|
||||
$node->safe_psql('postgres', "SELECT injection_points_stats_drop();");
|
||||
$numcalls = $node->safe_psql('postgres',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
is($numcalls, '', 'no stats after drop via SQL function');
|
||||
|
||||
# Stop the server, disable the module, then restart. The server
|
||||
# should be able to come up.
|
||||
$node->stop;
|
||||
|
Loading…
x
Reference in New Issue
Block a user