From 13d7dfb34dc9286379e55157c847b01cf77b5097 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Sat, 5 Oct 2024 18:30:34 +0200 Subject: [PATCH v1 2/4] Add core versions to pg_system_versions Populate pg_system_versions with a set of core versions: host system architecture, ICU version, PostgreSQL itself and compiler which was used to build everything. All of them are compile time versions. 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 | Compile Time Core | 18devel | Compile Time Compiler | gcc-14.0.1 | Compile Time --- configure | 12 +++++++ configure.ac | 4 +++ meson.build | 4 +++ src/backend/tcop/postgres.c | 12 +++++++ src/backend/utils/misc/system_version.c | 46 +++++++++++++++++++++++++ src/include/pg_config.h.in | 4 +++ src/include/utils/system_version.h | 7 ++++ src/test/regress/expected/sysviews.out | 8 +++++ src/test/regress/sql/sysviews.sql | 4 +++ 9 files changed, 101 insertions(+) diff --git a/configure b/configure index 53c8a1f..63e6d3e 100755 --- a/configure +++ b/configure @@ -19223,6 +19223,18 @@ else fi +cat >>confdefs.h <<_ACEOF +#define PG_CC_STR "$cc_string" +_ACEOF + + + +cat >>confdefs.h <<_ACEOF +#define PG_ARCH_STR "$host" +_ACEOF + + + cat >>confdefs.h <<_ACEOF #define PG_VERSION_STR "PostgreSQL $PG_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit" _ACEOF diff --git a/configure.ac b/configure.ac index 6a35b28..d063504 100644 --- a/configure.ac +++ b/configure.ac @@ -2417,6 +2417,10 @@ else cc_string=$CC fi +AC_DEFINE_UNQUOTED(PG_CC_STR, ["$cc_string"], [C compiler version]) + +AC_DEFINE_UNQUOTED(PG_ARCH_STR, ["$host"], [Platform]) + AC_DEFINE_UNQUOTED(PG_VERSION_STR, ["PostgreSQL $PG_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"], [A string containing the version number, platform, and C compiler]) diff --git a/meson.build b/meson.build index 7150f85..c5dfba6 100644 --- a/meson.build +++ b/meson.build @@ -2756,6 +2756,10 @@ cdata.set('USE_@0@_SEMAPHORES'.format(sema_kind.to_upper()), 1) cdata.set('MEMSET_LOOP_LIMIT', memset_loop_limit) cdata.set_quoted('DLSUFFIX', dlsuffix) +cdata.set_quoted('PG_CC_STR', '@0@-@1@'.format(cc.get_id(), cc.version())) + +cdata.set_quoted('PG_ARCH_STR', '@0@-@1@'.format( + host_machine.cpu_family(), host_system)) # built later than the rest of the version metadata, we need SIZEOF_VOID_P cdata.set_quoted('PG_VERSION_STR', diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 7f5eada..3b45fdc 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -80,6 +80,7 @@ #include "utils/timeout.h" #include "utils/timestamp.h" #include "utils/varlena.h" +#include "utils/system_version.h" /* ---------------- * global variables @@ -197,6 +198,7 @@ static void drop_unnamed_stmt(void); static void log_disconnections(int code, Datum arg); static void enable_statement_timeout(void); static void disable_statement_timeout(void); +static void register_system_versions(void); /* ---------------------------------------------------------------- @@ -4369,6 +4371,9 @@ PostgresMain(const char *dbname, const char *username) */ BeginReportingGUCOptions(); + /* Prepare information for reporting versions and libraries. */ + register_system_versions(); + /* * Also set up handler to log session end; we have to wait till now to be * sure Log_disconnections has its final value. @@ -5282,3 +5287,10 @@ disable_statement_timeout(void) if (get_timeout_active(STATEMENT_TIMEOUT)) disable_timeout(STATEMENT_TIMEOUT, false); } + +static void +register_system_versions() +{ + /* Set up reporting of core versions. */ + register_core_versions(); +} diff --git a/src/backend/utils/misc/system_version.c b/src/backend/utils/misc/system_version.c index 4d633fc..8ebd0c3 100644 --- a/src/backend/utils/misc/system_version.c +++ b/src/backend/utils/misc/system_version.c @@ -67,6 +67,52 @@ add_system_version(const char* name, SystemVersionCB cb, VersionType type) hentry->type = type; } +/* + * Register versions that describe core components and do not correspond to any + * individual component. + */ +void +register_core_versions() +{ + add_system_version("Core", core_get_version, CompileTime); + add_system_version("Arch", core_get_arch, CompileTime); + add_system_version("Compiler", core_get_compiler, CompileTime); + add_system_version("ICU", icu_get_version, CompileTime); +} + +const char* +core_get_version(bool *available) +{ + *available = true; + return (const char*) psprintf("%s", PG_VERSION); +} + +const char* +core_get_arch(bool *available) +{ + *available = true; + return (const char*) psprintf("%s", PG_ARCH_STR); +} + +const char* +core_get_compiler(bool *available) +{ + *available = true; + return (const char*) psprintf("%s", PG_CC_STR); +} + +const char* +icu_get_version(bool *available) +{ +#ifdef USE_ICU + *available = true; + return (const char*) U_UNICODE_VERSION; +#else + *available = false; + return (const char*) ""; +#endif +} + /* * pg_get_system_versions * diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 3800636..b0a588b 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -621,6 +621,10 @@ /* PostgreSQL version as a number */ #undef PG_VERSION_NUM +#undef PG_CC_STR + +#undef PG_ARCH_STR + /* A string containing the version number, platform, and C compiler */ #undef PG_VERSION_STR diff --git a/src/include/utils/system_version.h b/src/include/utils/system_version.h index a73f046..9537f47 100644 --- a/src/include/utils/system_version.h +++ b/src/include/utils/system_version.h @@ -36,5 +36,12 @@ typedef struct SystemVersion } SystemVersion; void add_system_version(const char* name, SystemVersionCB cb, VersionType type); +extern void register_core_versions(void); + +const char* core_get_version(bool *available); +const char* core_get_arch(bool *available); +const char* core_get_compiler(bool *available); + +const char* icu_get_version(bool *available); #endif /* SYSTEM_VERSION_H */ diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out index fad7fc3..0afabc1 100644 --- a/src/test/regress/expected/sysviews.out +++ b/src/test/regress/expected/sysviews.out @@ -222,3 +222,11 @@ select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; t (1 row) +-- At least 4 core versions should be present, architecture, ICU, core and +-- compiler +select count(*) >= 4 as ok FROM pg_system_versions; + ok +---- + t +(1 row) + diff --git a/src/test/regress/sql/sysviews.sql b/src/test/regress/sql/sysviews.sql index b2a7923..7a5a5f6 100644 --- a/src/test/regress/sql/sysviews.sql +++ b/src/test/regress/sql/sysviews.sql @@ -98,3 +98,7 @@ set timezone_abbreviations = 'Australia'; select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; set timezone_abbreviations = 'India'; select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; + +-- At least 4 core versions should be present, architecture, ICU, core and +-- compiler +select count(*) >= 4 as ok FROM pg_system_versions; -- 2.45.1