Skip to content

Commit d35ea27

Browse files
committed
Move information about pgstats kinds into its own header pgstat_kind.h
This includes all the definitions for the various PGSTAT_KIND_* values, the range allowed for custom stats kinds and some macros related all that. One use-case behind this split is the possibility to use this information for frontend tools, without having to rely on pgstat.h and a backend footprint. Author: Michael Paquier Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/Z24fyb3ipXKR38oS@paquier.xyz
1 parent d2181b3 commit d35ea27

File tree

2 files changed

+73
-56
lines changed

2 files changed

+73
-56
lines changed

src/include/pgstat.h

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "replication/conflict.h"
1919
#include "utils/backend_progress.h" /* for backward compatibility */
2020
#include "utils/backend_status.h" /* for backward compatibility */
21+
#include "utils/pgstat_kind.h"
2122
#include "utils/relcache.h"
2223
#include "utils/wait_event.h" /* for backward compatibility */
2324

@@ -33,62 +34,6 @@
3334
/* Default directory to store temporary statistics data in */
3435
#define PG_STAT_TMP_DIR "pg_stat_tmp"
3536

36-
/* The types of statistics entries */
37-
#define PgStat_Kind uint32
38-
39-
/* Range of IDs allowed, for built-in and custom kinds */
40-
#define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */
41-
#define PGSTAT_KIND_MAX 256 /* Maximum ID allowed */
42-
43-
/* use 0 for INVALID, to catch zero-initialized data */
44-
#define PGSTAT_KIND_INVALID 0
45-
46-
/* stats for variable-numbered objects */
47-
#define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */
48-
#define PGSTAT_KIND_RELATION 2 /* per-table statistics */
49-
#define PGSTAT_KIND_FUNCTION 3 /* per-function statistics */
50-
#define PGSTAT_KIND_REPLSLOT 4 /* per-slot statistics */
51-
#define PGSTAT_KIND_SUBSCRIPTION 5 /* per-subscription statistics */
52-
#define PGSTAT_KIND_BACKEND 6 /* per-backend statistics */
53-
54-
/* stats for fixed-numbered objects */
55-
#define PGSTAT_KIND_ARCHIVER 7
56-
#define PGSTAT_KIND_BGWRITER 8
57-
#define PGSTAT_KIND_CHECKPOINTER 9
58-
#define PGSTAT_KIND_IO 10
59-
#define PGSTAT_KIND_SLRU 11
60-
#define PGSTAT_KIND_WAL 12
61-
62-
#define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
63-
#define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
64-
#define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
65-
66-
/* Custom stats kinds */
67-
68-
/* Range of IDs allowed for custom stats kinds */
69-
#define PGSTAT_KIND_CUSTOM_MIN 128
70-
#define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
71-
#define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
72-
73-
/*
74-
* PgStat_Kind to use for extensions that require an ID, but are still in
75-
* development and have not reserved their own unique kind ID yet. See:
76-
* https://wiki.postgresql.org/wiki/CustomCumulativeStats
77-
*/
78-
#define PGSTAT_KIND_EXPERIMENTAL 128
79-
80-
static inline bool
81-
pgstat_is_kind_builtin(PgStat_Kind kind)
82-
{
83-
return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX;
84-
}
85-
86-
static inline bool
87-
pgstat_is_kind_custom(PgStat_Kind kind)
88-
{
89-
return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX;
90-
}
91-
9237
/* Values for track_functions GUC variable --- order is significant! */
9338
typedef enum TrackFunctionsLevel
9439
{

src/include/utils/pgstat_kind.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* ----------
2+
* pgstat_kind.h
3+
*
4+
* Definitions related to the statistics kinds for the PostgreSQL
5+
* cumulative statistics system. Can be included in backend or
6+
* frontend code.
7+
*
8+
* Copyright (c) 2001-2025, PostgreSQL Global Development Group
9+
*
10+
* src/include/utils/pgstat_kind.h
11+
* ----------
12+
*/
13+
#ifndef PGSTAT_KIND_H
14+
#define PGSTAT_KIND_H
15+
16+
/* The types of statistics entries */
17+
#define PgStat_Kind uint32
18+
19+
/* Range of IDs allowed, for built-in and custom kinds */
20+
#define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */
21+
#define PGSTAT_KIND_MAX 256 /* Maximum ID allowed */
22+
23+
/* use 0 for INVALID, to catch zero-initialized data */
24+
#define PGSTAT_KIND_INVALID 0
25+
26+
/* stats for variable-numbered objects */
27+
#define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */
28+
#define PGSTAT_KIND_RELATION 2 /* per-table statistics */
29+
#define PGSTAT_KIND_FUNCTION 3 /* per-function statistics */
30+
#define PGSTAT_KIND_REPLSLOT 4 /* per-slot statistics */
31+
#define PGSTAT_KIND_SUBSCRIPTION 5 /* per-subscription statistics */
32+
#define PGSTAT_KIND_BACKEND 6 /* per-backend statistics */
33+
34+
/* stats for fixed-numbered objects */
35+
#define PGSTAT_KIND_ARCHIVER 7
36+
#define PGSTAT_KIND_BGWRITER 8
37+
#define PGSTAT_KIND_CHECKPOINTER 9
38+
#define PGSTAT_KIND_IO 10
39+
#define PGSTAT_KIND_SLRU 11
40+
#define PGSTAT_KIND_WAL 12
41+
42+
#define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
43+
#define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
44+
#define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
45+
46+
/* Custom stats kinds */
47+
48+
/* Range of IDs allowed for custom stats kinds */
49+
#define PGSTAT_KIND_CUSTOM_MIN 128
50+
#define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
51+
#define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
52+
53+
/*
54+
* PgStat_Kind to use for extensions that require an ID, but are still in
55+
* development and have not reserved their own unique kind ID yet. See:
56+
* https://wiki.postgresql.org/wiki/CustomCumulativeStats
57+
*/
58+
#define PGSTAT_KIND_EXPERIMENTAL 128
59+
60+
static inline bool
61+
pgstat_is_kind_builtin(PgStat_Kind kind)
62+
{
63+
return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX;
64+
}
65+
66+
static inline bool
67+
pgstat_is_kind_custom(PgStat_Kind kind)
68+
{
69+
return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX;
70+
}
71+
72+
#endif /* PGSTAT_KIND_H */

0 commit comments

Comments
 (0)