diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/utils/activity/pgstat_shmem.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 342586397d6..770d62425c5 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -993,19 +993,39 @@ pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid) return freed; } +/* + * Scan through the shared hashtable of stats, dropping statistics if + * approved by the optional do_drop() function. + */ void -pgstat_drop_all_entries(void) +pgstat_drop_matching_entries(bool (*do_drop) (PgStatShared_HashEntry *, Datum), + Datum match_data) { dshash_seq_status hstat; PgStatShared_HashEntry *ps; uint64 not_freed_count = 0; + /* entries are removed, take an exclusive lock */ dshash_seq_init(&hstat, pgStatLocal.shared_hash, true); while ((ps = dshash_seq_next(&hstat)) != NULL) { if (ps->dropped) continue; + if (do_drop != NULL && !do_drop(ps, match_data)) + continue; + + /* delete local reference */ + if (pgStatEntryRefHash) + { + PgStat_EntryRefHashEntry *lohashent = + pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, ps->key); + + if (lohashent) + pgstat_release_entry_ref(lohashent->key, lohashent->entry_ref, + true); + } + if (!pgstat_drop_entry_internal(ps, &hstat)) not_freed_count++; } @@ -1015,6 +1035,15 @@ pgstat_drop_all_entries(void) pgstat_request_entry_refs_gc(); } +/* + * Scan through the shared hashtable of stats and drop all entries. + */ +void +pgstat_drop_all_entries(void) +{ + pgstat_drop_matching_entries(NULL, 0); +} + static void shared_stat_reset_contents(PgStat_Kind kind, PgStatShared_Common *header, TimestampTz ts) |