diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index dbd55a065d..7fbdbb09bd 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -193,9 +193,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_DATABASE] = { .name = "database", - .fixed_amount = false, - /* so pg_stat_database entries can be seen in all databases */ - .accessed_across_databases = true, + .kind_group = PGSTAT_CLUSTER, .shared_size = sizeof(PgStatShared_Database), .shared_data_off = offsetof(PgStatShared_Database, stats), @@ -209,7 +207,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_RELATION] = { .name = "relation", - .fixed_amount = false, + .kind_group = PGSTAT_OBJECT, .shared_size = sizeof(PgStatShared_Relation), .shared_data_off = offsetof(PgStatShared_Relation, stats), @@ -223,7 +221,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_FUNCTION] = { .name = "function", - .fixed_amount = false, + .kind_group = PGSTAT_OBJECT, .shared_size = sizeof(PgStatShared_Function), .shared_data_off = offsetof(PgStatShared_Function, stats), @@ -236,9 +234,8 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_REPLSLOT] = { .name = "replslot", - .fixed_amount = false, + .kind_group = PGSTAT_CLUSTER, - .accessed_across_databases = true, .named_on_disk = true, .shared_size = sizeof(PgStatShared_ReplSlot), @@ -254,9 +251,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_SUBSCRIPTION] = { .name = "subscription", - .fixed_amount = false, - /* so pg_stat_subscription_stats entries can be seen in all databases */ - .accessed_across_databases = true, + .kind_group = PGSTAT_CLUSTER, .shared_size = sizeof(PgStatShared_Subscription), .shared_data_off = offsetof(PgStatShared_Subscription, stats), @@ -273,7 +268,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_ARCHIVER] = { .name = "archiver", - .fixed_amount = true, + .kind_group = PGSTAT_GLOBAL, .reset_all_cb = pgstat_archiver_reset_all_cb, .snapshot_cb = pgstat_archiver_snapshot_cb, @@ -282,7 +277,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_BGWRITER] = { .name = "bgwriter", - .fixed_amount = true, + .kind_group = PGSTAT_GLOBAL, .reset_all_cb = pgstat_bgwriter_reset_all_cb, .snapshot_cb = pgstat_bgwriter_snapshot_cb, @@ -291,7 +286,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_CHECKPOINTER] = { .name = "checkpointer", - .fixed_amount = true, + .kind_group = PGSTAT_GLOBAL, .reset_all_cb = pgstat_checkpointer_reset_all_cb, .snapshot_cb = pgstat_checkpointer_snapshot_cb, @@ -300,7 +295,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_SLRU] = { .name = "slru", - .fixed_amount = true, + .kind_group = PGSTAT_GLOBAL, .reset_all_cb = pgstat_slru_reset_all_cb, .snapshot_cb = pgstat_slru_snapshot_cb, @@ -309,7 +304,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = { [PGSTAT_KIND_WAL] = { .name = "wal", - .fixed_amount = true, + .kind_group = PGSTAT_GLOBAL, .reset_all_cb = pgstat_wal_reset_all_cb, .snapshot_cb = pgstat_wal_snapshot_cb, @@ -652,7 +647,7 @@ pgstat_reset_single_counter(PgStat_Kind kind, Oid objoid) { TimestampTz ts = GetCurrentTimestamp(); - Assert(!pgstat_kind_info_for(kind)->fixed_amount); + Assert(pgstat_kind_info_for(kind)->kind_group == PGSTAT_OBJECT); /* Set the reset timestamp for the whole database */ pgstat_reset_database_timestamp(MyDatabaseId, ts); @@ -673,7 +668,7 @@ pgstat_reset_shared_counters(PgStat_Kind kind) const PgStat_KindInfo *kind_info = pgstat_kind_info_for(kind); TimestampTz now = GetCurrentTimestamp(); - Assert(kind_info->fixed_amount); + Assert(kind_info->kind_group == PGSTAT_GLOBAL); kind_info->reset_all_cb(now); } @@ -728,7 +723,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid) /* should be called from backends */ Assert(IsUnderPostmaster || !IsPostmasterEnvironment); - AssertArg(!kind_info->fixed_amount); + AssertArg(kind_info->kind_group == PGSTAT_DYNAMIC); pgstat_prep_snapshot(); @@ -825,7 +820,7 @@ pgstat_get_stat_snapshot_timestamp(bool *have_snapshot) bool pgstat_exists_entry(PgStat_Kind kind, Oid dboid, Oid objoid) { - if (pgstat_kind_info_for(kind)->fixed_amount) + if (pgstat_kind_info_for(kind)->kind_group == PGSTAT_GLOBAL) return true; return pgstat_get_entry_ref(kind, dboid, objoid, false, NULL) != NULL; @@ -841,7 +836,7 @@ void pgstat_snapshot_global(PgStat_Kind kind) { AssertArg(pgstat_kind_valid(kind)); - AssertArg(pgstat_kind_info_for(kind)->fixed_amount); + AssertArg(pgstat_kind_info_for(kind)->kind_group == PGSTAT_GLOBAL); if (pgstat_fetch_consistency == PGSTAT_FETCH_CONSISTENCY_SNAPSHOT) pgstat_build_snapshot(); @@ -909,7 +904,7 @@ pgstat_build_snapshot(void) */ if (p->key.dboid != MyDatabaseId && p->key.dboid != InvalidOid && - !kind_info->accessed_across_databases) + kind_info->kind_group == PGSTAT_OBJECT) continue; if (p->dropped) @@ -938,7 +933,7 @@ pgstat_build_snapshot(void) { const PgStat_KindInfo *kind_info = pgstat_kind_info_for(kind); - if (!kind_info->fixed_amount) + if (kind_info->kind_group == PGSTAT_DYNAMIC) { Assert(kind_info->snapshot_cb == NULL); continue; @@ -955,7 +950,7 @@ pgstat_build_snapshot_global(PgStat_Kind kind) { const PgStat_KindInfo *kind_info = pgstat_kind_info_for(kind); - Assert(kind_info->fixed_amount); + Assert(kind_info->kind_group == PGSTAT_GLOBAL); Assert(kind_info->snapshot_cb != NULL); if (pgstat_fetch_consistency == PGSTAT_FETCH_CONSISTENCY_NONE) @@ -1047,8 +1042,8 @@ pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref) void *pending_data = entry_ref->pending; Assert(pending_data != NULL); - /* !fixed_amount stats should be handled explicitly */ - Assert(!pgstat_kind_info_for(kind)->fixed_amount); + /* global stats should be handled explicitly : why?*/ + Assert(pgstat_kind_info_for(kind)->kind_group == PGSTAT_DYNAMIC); if (kind_info->delete_pending_cb) kind_info->delete_pending_cb(entry_ref); @@ -1091,7 +1086,7 @@ pgstat_flush_pending_entries(bool nowait) bool did_flush; dlist_node *next; - Assert(!kind_info->fixed_amount); + Assert(kind_info->kind_group == PGSTAT_DYNAMIC); Assert(kind_info->flush_pending_cb != NULL); /* flush the stats, if possible */ @@ -1585,7 +1580,7 @@ pgstat_reset_all_stats(TimestampTz ts) { const PgStat_KindInfo *kind_info = pgstat_kind_info_for(kind); - if (!kind_info->fixed_amount) + if (kind_info->kind_group == PGSTAT_DYNAMIC) continue; kind_info->reset_all_cb(ts); diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index d11b628710..82003df524 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -926,7 +926,7 @@ pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid) { PgStat_EntryRef *entry_ref; - Assert(!pgstat_kind_info_for(kind)->fixed_amount); + Assert(pgstat_kind_info_for(kind)->kind_group == PGSTAT_DYNAMIC); entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL); if (!entry_ref || entry_ref->shared_entry->dropped) diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 8234f9fdfb..d62ad01ddb 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -31,6 +31,15 @@ /* Default directory to store temporary statistics data in */ #define PG_STAT_TMP_DIR "pg_stat_tmp" +typedef enum PgStat_KindGroup +{ + PGSTAT_GLOBAL = 1, + PGSTAT_CLUSTER, + PGSTAT_OBJECT +} PgStat_KindGroup; + +#define PGSTAT_DYNAMIC (PGSTAT_CLUSTER | PGSTAT_OBJECT) + /* The types of statistics entries */ typedef enum PgStat_Kind { diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h index 7efa9d32a9..3fde2034b1 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -181,17 +181,7 @@ typedef struct PgStat_SubXactStatus */ typedef struct PgStat_KindInfo { - /* - * Does a fixed number of stats object exist for this kind of stats or not - * (e.g. tables). - */ - bool fixed_amount:1; - - /* - * Can stats of this kind be accessed from another database? Determines - * whether a stats object gets included in stats snapshots. - */ - bool accessed_across_databases:1; + PgStat_KindGroup kind_group; /* * For variable number stats: Identified on-disk using a name, rather than