Skip to content

Commit 638220d

Browse files
erthalionhackorum
authored andcommitted
Add core versions to pg_system_versions
Populate pg_system_versions with a set of core versions: host system architecture, ICU version, glibc version, PostgreSQL itself and compiler which was used to build everything. Register the core versions at the backend startup. select * from pg_system_versions; name | version | type ----------+--------------+-------------- Arch | x86_64-linux | Compile Time ICU | 15.1 | Run Time Core | 18devel | Compile Time Compiler | gcc-14.0.1 | Compile Time Glibc | 2.40 | Run Time
1 parent 9dca88b commit 638220d

9 files changed

Lines changed: 125 additions & 0 deletions

File tree

‎configure‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19760,6 +19760,18 @@ else
1976019760
fi
1976119761

1976219762

19763+
cat >>confdefs.h <<_ACEOF
19764+
#define PG_CC_STR "$cc_string"
19765+
_ACEOF
19766+
19767+
19768+
19769+
cat >>confdefs.h <<_ACEOF
19770+
#define PG_ARCH_STR "$host"
19771+
_ACEOF
19772+
19773+
19774+
1976319775
cat >>confdefs.h <<_ACEOF
1976419776
#define PG_VERSION_STR "PostgreSQL $PG_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"
1976519777
_ACEOF

‎configure.ac‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,10 @@ else
25462546
cc_string=$CC
25472547
fi
25482548

2549+
AC_DEFINE_UNQUOTED(PG_CC_STR, ["$cc_string"], [C compiler version])
2550+
2551+
AC_DEFINE_UNQUOTED(PG_ARCH_STR, ["$host"], [Platform])
2552+
25492553
AC_DEFINE_UNQUOTED(PG_VERSION_STR,
25502554
["PostgreSQL $PG_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"],
25512555
[A string containing the version number, platform, and C compiler])

‎meson.build‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,6 +3301,10 @@ cdata.set('USE_@0@_SEMAPHORES'.format(sema_kind.to_upper()), 1)
33013301
cdata.set('MEMSET_LOOP_LIMIT', memset_loop_limit)
33023302
cdata.set_quoted('DLSUFFIX', dlsuffix)
33033303

3304+
cdata.set_quoted('PG_CC_STR', '@0@-@1@'.format(cc.get_id(), cc.version()))
3305+
3306+
cdata.set_quoted('PG_ARCH_STR', '@0@-@1@'.format(
3307+
host_machine.cpu_family(), host_system))
33043308

33053309
# built later than the rest of the version metadata, we need SIZEOF_VOID_P
33063310
cdata.set_quoted('PG_VERSION_STR',

‎src/backend/tcop/postgres.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include "utils/timeout.h"
8787
#include "utils/timestamp.h"
8888
#include "utils/varlena.h"
89+
#include "utils/system_version.h"
8990

9091
/* ----------------
9192
* global variables
@@ -199,6 +200,7 @@ static void report_recovery_conflict(RecoveryConflictReason reason);
199200
static void log_disconnections(int code, Datum arg);
200201
static void enable_statement_timeout(void);
201202
static void disable_statement_timeout(void);
203+
static void register_system_versions(void);
202204

203205

204206
/* ----------------------------------------------------------------
@@ -4486,6 +4488,9 @@ PostgresMain(const char *dbname, const char *username)
44864488
*/
44874489
BeginReportingGUCOptions();
44884490

4491+
/* Prepare information for reporting versions and libraries. */
4492+
register_system_versions();
4493+
44894494
/*
44904495
* Also set up handler to log session end; we have to wait till now to be
44914496
* sure Log_disconnections has its final value.
@@ -5405,3 +5410,10 @@ disable_statement_timeout(void)
54055410
if (get_timeout_active(STATEMENT_TIMEOUT))
54065411
disable_timeout(STATEMENT_TIMEOUT, false);
54075412
}
5413+
5414+
static void
5415+
register_system_versions(void)
5416+
{
5417+
/* Set up reporting of core versions. */
5418+
register_core_versions();
5419+
}

‎src/backend/utils/misc/system_version.c‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
*/
2626
#include "postgres.h"
2727

28+
#ifdef USE_ICU
29+
#include <unicode/uchar.h>
30+
#endif
31+
32+
#ifdef __GLIBC__
33+
#include <gnu/libc-version.h>
34+
#endif
35+
2836
#include "funcapi.h"
2937
#include "utils/builtins.h"
3038
#include "utils/hsearch.h"
@@ -66,6 +74,70 @@ add_system_version(const char *name, SystemVersionCB cb, VersionType type)
6674
hentry->type = type;
6775
}
6876

77+
static const char *
78+
core_get_version(bool *available)
79+
{
80+
*available = true;
81+
return (const char *) psprintf("%s", PG_VERSION);
82+
}
83+
84+
static const char *
85+
core_get_arch(bool *available)
86+
{
87+
*available = true;
88+
return (const char *) psprintf("%s", PG_ARCH_STR);
89+
}
90+
91+
static const char *
92+
core_get_compiler(bool *available)
93+
{
94+
*available = true;
95+
return (const char *) psprintf("%s", PG_CC_STR);
96+
}
97+
98+
#ifdef USE_ICU
99+
static const char *
100+
icu_get_version(bool *available)
101+
{
102+
UVersionInfo UCDVersion;
103+
char *version = palloc0(U_MAX_VERSION_STRING_LENGTH);
104+
105+
*available = true;
106+
u_getUnicodeVersion(UCDVersion);
107+
u_versionToString(UCDVersion, version);
108+
return (const char *) version;
109+
}
110+
#endif
111+
112+
#ifdef __GLIBC__
113+
static const char *
114+
glibc_get_version(bool *available)
115+
{
116+
*available = true;
117+
return (const char *) gnu_get_libc_version();
118+
}
119+
#endif
120+
121+
/*
122+
* Register versions that describe core components and do not correspond to any
123+
* individual component.
124+
*/
125+
void
126+
register_core_versions()
127+
{
128+
add_system_version("Core", core_get_version, CompileTime);
129+
add_system_version("Arch", core_get_arch, CompileTime);
130+
add_system_version("Compiler", core_get_compiler, CompileTime);
131+
132+
#ifdef USE_ICU
133+
add_system_version("ICU", icu_get_version, RunTime);
134+
#endif
135+
136+
#ifdef __GLIBC__
137+
add_system_version("Glibc", glibc_get_version, RunTime);
138+
#endif
139+
}
140+
69141
/*
70142
* pg_get_system_versions
71143
*

‎src/include/pg_config.h.in‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@
617617
/* PostgreSQL version as a number */
618618
#undef PG_VERSION_NUM
619619

620+
#undef PG_CC_STR
621+
622+
#undef PG_ARCH_STR
623+
620624
/* A string containing the version number, platform, and C compiler */
621625
#undef PG_VERSION_STR
622626

‎src/include/utils/system_version.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ typedef struct SystemVersion
3434
} SystemVersion;
3535

3636
void add_system_version(const char *name, SystemVersionCB cb, VersionType type);
37+
extern void register_core_versions(void);
3738

3839
#endif /* SYSTEM_VERSION_H */

‎src/test/regress/expected/sysviews.out‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,13 @@ select * from pg_timezone_abbrevs where abbrev = 'LMT';
242242
LMT | @ 7 hours 52 mins 58 secs ago | f
243243
(1 row)
244244

245+
-- Check that the pg_system_versions contains something. Three core versions
246+
-- should be present: architecture, core and compiler and glibc. More records
247+
-- may be present depending on the build configuration (e.g. with ICU, GlibC or
248+
-- JIT support).
249+
select exists (table pg_system_versions);
250+
exists
251+
--------
252+
t
253+
(1 row)
254+

‎src/test/regress/sql/sysviews.sql‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs;
104104
-- One specific case we can check without much fear of breakage
105105
-- is the historical local-mean-time value used for America/Los_Angeles.
106106
select * from pg_timezone_abbrevs where abbrev = 'LMT';
107+
108+
-- Check that the pg_system_versions contains something. Three core versions
109+
-- should be present: architecture, core and compiler and glibc. More records
110+
-- may be present depending on the build configuration (e.g. with ICU, GlibC or
111+
-- JIT support).
112+
select exists (table pg_system_versions);

0 commit comments

Comments
 (0)