mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +03:00
pg_upgrade: Use new routine to retrieve data of PG_VERSION
Unsurprisingly, this shaves code. get_major_server_version() can be
replaced by the new routine added by cd0be131ba
, with the contents of
PG_VERSION stored in an allocated buffer instead of a fixed-sized one.
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/aOiirvWJzwdVCXph@paquier.xyz
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "common/string.h"
|
#include "common/string.h"
|
||||||
|
#include "fe_utils/version.h"
|
||||||
#include "pg_upgrade.h"
|
#include "pg_upgrade.h"
|
||||||
|
|
||||||
static void check_data_dir(ClusterInfo *cluster);
|
static void check_data_dir(ClusterInfo *cluster);
|
||||||
@@ -343,8 +344,8 @@ check_data_dir(ClusterInfo *cluster)
|
|||||||
const char *pg_data = cluster->pgdata;
|
const char *pg_data = cluster->pgdata;
|
||||||
|
|
||||||
/* get the cluster version */
|
/* get the cluster version */
|
||||||
cluster->major_version = get_major_server_version(cluster);
|
cluster->major_version = get_pg_version(cluster->pgdata,
|
||||||
|
&cluster->major_version_str);
|
||||||
check_single_dir(pg_data, "");
|
check_single_dir(pg_data, "");
|
||||||
check_single_dir(pg_data, "base");
|
check_single_dir(pg_data, "base");
|
||||||
check_single_dir(pg_data, "global");
|
check_single_dir(pg_data, "global");
|
||||||
|
@@ -298,7 +298,7 @@ typedef struct
|
|||||||
char *sockdir; /* directory for Unix Domain socket, if any */
|
char *sockdir; /* directory for Unix Domain socket, if any */
|
||||||
unsigned short port; /* port number where postmaster is waiting */
|
unsigned short port; /* port number where postmaster is waiting */
|
||||||
uint32 major_version; /* PG_VERSION of cluster */
|
uint32 major_version; /* PG_VERSION of cluster */
|
||||||
char major_version_str[64]; /* string PG_VERSION of cluster */
|
char *major_version_str; /* string PG_VERSION of cluster */
|
||||||
uint32 bin_version; /* version returned from pg_ctl */
|
uint32 bin_version; /* version returned from pg_ctl */
|
||||||
char **tablespaces; /* tablespace directories */
|
char **tablespaces; /* tablespace directories */
|
||||||
int num_tablespaces;
|
int num_tablespaces;
|
||||||
@@ -473,7 +473,6 @@ char *cluster_conn_opts(ClusterInfo *cluster);
|
|||||||
|
|
||||||
bool start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error);
|
bool start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error);
|
||||||
void stop_postmaster(bool in_atexit);
|
void stop_postmaster(bool in_atexit);
|
||||||
uint32 get_major_server_version(ClusterInfo *cluster);
|
|
||||||
void check_pghost_envvar(void);
|
void check_pghost_envvar(void);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -148,45 +148,6 @@ executeQueryOrDie(PGconn *conn, const char *fmt,...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* get_major_server_version()
|
|
||||||
*
|
|
||||||
* gets the version (in unsigned int form) for the given datadir. Assumes
|
|
||||||
* that datadir is an absolute path to a valid pgdata directory. The version
|
|
||||||
* is retrieved by reading the PG_VERSION file.
|
|
||||||
*/
|
|
||||||
uint32
|
|
||||||
get_major_server_version(ClusterInfo *cluster)
|
|
||||||
{
|
|
||||||
FILE *version_fd;
|
|
||||||
char ver_filename[MAXPGPATH];
|
|
||||||
int v1 = 0,
|
|
||||||
v2 = 0;
|
|
||||||
|
|
||||||
snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION",
|
|
||||||
cluster->pgdata);
|
|
||||||
if ((version_fd = fopen(ver_filename, "r")) == NULL)
|
|
||||||
pg_fatal("could not open version file \"%s\": %m", ver_filename);
|
|
||||||
|
|
||||||
if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
|
|
||||||
sscanf(cluster->major_version_str, "%d.%d", &v1, &v2) < 1)
|
|
||||||
pg_fatal("could not parse version file \"%s\"", ver_filename);
|
|
||||||
|
|
||||||
fclose(version_fd);
|
|
||||||
|
|
||||||
if (v1 < 10)
|
|
||||||
{
|
|
||||||
/* old style, e.g. 9.6.1 */
|
|
||||||
return v1 * 10000 + v2 * 100;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* new style, e.g. 10.1 */
|
|
||||||
return v1 * 10000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stop_postmaster_atexit(void)
|
stop_postmaster_atexit(void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user