mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Add callback for backend initialization in pgstats
pgstat_initialize() is currently used by the WAL stats as a code path to take some custom actions when a backend starts. A callback is added to generalize the concept so as all stats kinds can do the same, for builtin and custom kinds, if set. Reviewed-by: Bertrand Drouvot, Kyotaro Horiguchi Discussion: https://postgr.es/m/ZtZr1K4PLdeWclXY@paquier.xyz
This commit is contained in:
@@ -441,6 +441,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
|
||||
.shared_data_off = offsetof(PgStatShared_Wal, stats),
|
||||
.shared_data_len = sizeof(((PgStatShared_Wal *) 0)->stats),
|
||||
|
||||
.init_backend_cb = pgstat_wal_init_backend_cb,
|
||||
.init_shmem_cb = pgstat_wal_init_shmem_cb,
|
||||
.reset_all_cb = pgstat_wal_reset_all_cb,
|
||||
.snapshot_cb = pgstat_wal_snapshot_cb,
|
||||
@@ -604,10 +605,19 @@ pgstat_initialize(void)
|
||||
|
||||
pgstat_attach_shmem();
|
||||
|
||||
pgstat_init_wal();
|
||||
|
||||
pgstat_init_snapshot_fixed();
|
||||
|
||||
/* Backend initialization callbacks */
|
||||
for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
|
||||
{
|
||||
const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
|
||||
|
||||
if (kind_info == NULL || kind_info->init_backend_cb == NULL)
|
||||
continue;
|
||||
|
||||
kind_info->init_backend_cb();
|
||||
}
|
||||
|
||||
/* Set up a process-exit hook to clean up */
|
||||
before_shmem_exit(pgstat_shutdown_hook, 0);
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ pgstat_flush_wal(bool nowait)
|
||||
}
|
||||
|
||||
void
|
||||
pgstat_init_wal(void)
|
||||
pgstat_wal_init_backend_cb(void)
|
||||
{
|
||||
/*
|
||||
* Initialize prevWalUsage with pgWalUsage so that pgstat_flush_wal() can
|
||||
|
||||
Reference in New Issue
Block a user