Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
- index a96514ea8ca..3f4da817a0c 100644
- --- a/src/backend/utils/init/miscinit.c
- +++ b/src/backend/utils/init/miscinit.c
- @@ -1460,25 +1460,14 @@ RecheckDataDirLockFile(void)
- *-------------------------------------------------------------------------
- */
- -/*
- - * Determine whether the PG_VERSION file in directory `path' indicates
- - * a data version compatible with the version of this program.
- - *
- - * If compatible, return. Otherwise, ereport(FATAL).
- - */
- -void
- -ValidatePgVersion(const char *path)
- +long
- +ReadPgVersionFromFile(const char *path, char *file_version_string)
- {
- char full_path[MAXPGPATH];
- FILE *file;
- int ret;
- - long file_major;
- - long my_major;
- char *endptr;
- - char file_version_string[64];
- - const char *my_version_string = PG_VERSION;
- -
- - my_major = strtol(my_version_string, &endptr, 10);
- + long major;
- snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path);
- @@ -1499,7 +1488,7 @@ ValidatePgVersion(const char *path)
- file_version_string[0] = '\0';
- ret = fscanf(file, "%63s", file_version_string);
- - file_major = strtol(file_version_string, &endptr, 10);
- + major = strtol(file_version_string, &endptr, 10);
- if (ret != 1 || endptr == file_version_string)
- ereport(FATAL,
- @@ -1511,6 +1500,20 @@ ValidatePgVersion(const char *path)
- errhint("You might need to initdb.")));
- FreeFile(file);
- + return major;
- +}
- +
- +void
- +ValidatePgVersion(const char *path)
- +{
- + long file_major;
- + long my_major;
- + char *endptr;
- + char file_version_string[PG_VERSION_STRING_MAXLEN];
- + const char *my_version_string = PG_VERSION;
- +
- + my_major = strtol(my_version_string, &endptr, 10);
- + file_major = ReadPgVersionFromFile(path, file_version_string);
- if (my_major != file_major)
- ereport(FATAL,
- diff --git a/src/common/controldata_legacy.c b/src/common/controldata_legacy.c
- index 6e6b1b9a7a0..56c51d0c9b5 100644
- --- a/src/common/controldata_legacy.c
- +++ b/src/common/controldata_legacy.c
- @@ -22,6 +22,7 @@
- #include <fcntl.h>
- #include <unistd.h>
- +#include <miscadmin.h>
- #if defined(USE_ICU) && !defined(FRONTEND)
- #include <unicode/uversion.h>
- #endif
- @@ -425,13 +426,12 @@ PrintClusterCompatibilityInfo(const char *DataDir)
- bool crc_ok;
- bool server_uses_icu = false;
- bool data_uses_icu = false;
- - char server_icu_version_str[20] = "";
- - char data_icu_version_str[20] = "";
- CompatibilityInfo compat_info;
- ControlFileDataGeneric *ControlFile = GetGenericControlFile(DataDir,
- &crc_ok, &compat_info, NULL, NULL, NULL);
- uint32 control_ver = GET_PG_CONTROL_VERSION(ControlFile);
- uint32 catalog_ver = GET_CATALOG_VERSION_NO(ControlFile);
- + char major_version_string[PG_VERSION_STRING_MAXLEN];
- #define COMPARE_AND_PRINT_STRINGS(description, arg1, arg2) \
- (printf("%-38s%25s||%25s%s\n", description, arg1, arg2, \
- @@ -447,24 +447,19 @@ PrintClusterCompatibilityInfo(const char *DataDir)
- /* Prepare info about ICU usage by the server and by the cluster */
- #ifdef USE_ICU
- - UVersionInfo icu_version;
- - u_getVersion(icu_version);
- - icu_version_to_string(icu_version, server_icu_version_str);
- server_uses_icu = true;
- #endif
- if (compat_info.p_icu_version)
- - {
- data_uses_icu = icu_version_is_valid(*compat_info.p_icu_version);
- - if (data_uses_icu)
- - icu_version_to_string(*compat_info.p_icu_version,
- - data_icu_version_str);
- - }
- if (!crc_ok)
- printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
- "Either the file is corrupt, or it has a different layout than this program\n"
- "is expecting. The results below are untrustworthy.\n\n"));
- + /* Getting major version from PG_VERSION */
- + ReadPgVersionFromFile(DataDir, major_version_string);
- +
- /*
- * Now print all the info that xlog.c usually checks for deciding
- * whether the cluster and the postgres binary are compatible.
- @@ -472,6 +467,8 @@ PrintClusterCompatibilityInfo(const char *DataDir)
- * src/backend/access/transam/xlog.c => ReadControlFile()
- */
- printf("%38s%25s||%25s\n", "", _("Server binary"), _("Database files"));
- + COMPARE_AND_PRINT_STRINGS(_("Postgres major version:"),
- + PG_MAJORVERSION, major_version_string);
- COMPARE_AND_PRINT_STRINGS(_("pg_control edition:"),
- ControlEditionString(PG_CONTROL_VERSION / 65536),
- ControlEditionString(compat_info.edition));
- @@ -517,10 +514,6 @@ PrintClusterCompatibilityInfo(const char *DataDir)
- COMPARE_AND_PRINT_STRINGS(_("Uses ICU:"),
- server_uses_icu ? _("yes") : _("no"),
- data_uses_icu ? _("yes") : _("no"));
- - /* Only show ICU version if there is at least one version to show */
- - if (server_uses_icu || data_uses_icu)
- - COMPARE_AND_PRINT_STRINGS(_("ICU library version:"),
- - server_icu_version_str, data_icu_version_str);
- if (is_compatible)
- printf(_("\nRESULT: Compatibility tests passed.\n"));
- diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
- index dc0c8875dcc..48a37cbc85f 100644
- --- a/src/include/miscadmin.h
- +++ b/src/include/miscadmin.h
- @@ -29,6 +29,7 @@
- #define InvalidPid (-1)
- +#define PG_VERSION_STRING_MAXLEN 64
- /*****************************************************************************
- @@ -458,6 +459,7 @@ extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster,
- extern void TouchSocketLockFiles(void);
- extern void AddToDataDirLockFile(int target_line, const char *str);
- extern bool RecheckDataDirLockFile(void);
- +extern long ReadPgVersionFromFile(const char *path, char *file_version_string);
- extern void ValidatePgVersion(const char *path);
- extern void process_shared_preload_libraries(void);
- extern void process_session_preload_libraries(void);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement