Commit 67c9e444 authored by Bruce Momjian's avatar Bruce Momjian

Furter pg_upgrade optimizations to reduce function call argument count.

parent 6e6bee98
...@@ -209,8 +209,8 @@ void ...@@ -209,8 +209,8 @@ void
check_cluster_versions(void) check_cluster_versions(void)
{ {
/* get old and new cluster versions */ /* get old and new cluster versions */
old_cluster.major_version = get_major_server_version(&old_cluster, &old_cluster.major_version_str); old_cluster.major_version = get_major_server_version(&old_cluster);
new_cluster.major_version = get_major_server_version(&new_cluster, &new_cluster.major_version_str); new_cluster.major_version = get_major_server_version(&new_cluster);
/* We allow upgrades from/to the same major version for alpha/beta upgrades */ /* We allow upgrades from/to the same major version for alpha/beta upgrades */
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
static void get_db_infos(ClusterInfo *cluster); static void get_db_infos(ClusterInfo *cluster);
static void dbarr_print(ClusterInfo *cluster); static void dbarr_print(ClusterInfo *cluster);
static void relarr_print(RelInfoArr *arr); static void relarr_print(RelInfoArr *arr);
static void get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, static void get_rel_infos(ClusterInfo *cluster, const int dbnum);
RelInfoArr *relarr);
static void relarr_free(RelInfoArr *rel_arr); static void relarr_free(RelInfoArr *rel_arr);
static void map_rel(const RelInfo *oldrel, static void map_rel(const RelInfo *oldrel,
const RelInfo *newrel, const DbInfo *old_db, const RelInfo *newrel, const DbInfo *old_db,
...@@ -272,8 +271,7 @@ get_db_and_rel_infos(ClusterInfo *cluster) ...@@ -272,8 +271,7 @@ get_db_and_rel_infos(ClusterInfo *cluster)
get_db_infos(cluster); get_db_infos(cluster);
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++) for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum], get_rel_infos(cluster, dbnum);
&cluster->dbarr.dbs[dbnum].rel_arr);
if (log_opts.debug) if (log_opts.debug)
dbarr_print(cluster); dbarr_print(cluster);
...@@ -290,9 +288,10 @@ get_db_and_rel_infos(ClusterInfo *cluster) ...@@ -290,9 +288,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
* FirstNormalObjectId belongs to the user * FirstNormalObjectId belongs to the user
*/ */
static void static void
get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr) get_rel_infos(ClusterInfo *cluster, const int dbnum)
{ {
PGconn *conn = connectToServer(cluster, dbinfo->db_name); PGconn *conn = connectToServer(cluster,
cluster->dbarr.dbs[dbnum].db_name);
PGresult *res; PGresult *res;
RelInfo *relinfos; RelInfo *relinfos;
int ntups; int ntups;
...@@ -374,16 +373,16 @@ get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr) ...@@ -374,16 +373,16 @@ get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
tblspace = PQgetvalue(res, relnum, i_spclocation); tblspace = PQgetvalue(res, relnum, i_spclocation);
/* if no table tablespace, use the database tablespace */ /* if no table tablespace, use the database tablespace */
if (strlen(tblspace) == 0) if (strlen(tblspace) == 0)
tblspace = dbinfo->db_tblspace; tblspace = cluster->dbarr.dbs[dbnum].db_tblspace;
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace)); strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
} }
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
relarr->rels = relinfos; cluster->dbarr.dbs[dbnum].rel_arr.rels = relinfos;
relarr->nrels = num_rels; cluster->dbarr.dbs[dbnum].rel_arr.nrels = num_rels;
relarr->last_relname_lookup = 0; cluster->dbarr.dbs[dbnum].rel_arr.last_relname_lookup = 0;
} }
......
...@@ -384,8 +384,6 @@ cleanup(void) ...@@ -384,8 +384,6 @@ cleanup(void)
dbarr_free(&new_cluster.dbarr); dbarr_free(&new_cluster.dbarr);
pg_free(log_opts.filename); pg_free(log_opts.filename);
pg_free(os_info.user); pg_free(os_info.user);
pg_free(old_cluster.major_version_str);
pg_free(new_cluster.major_version_str);
pg_free(old_cluster.controldata.lc_collate); pg_free(old_cluster.controldata.lc_collate);
pg_free(new_cluster.controldata.lc_collate); pg_free(new_cluster.controldata.lc_collate);
pg_free(old_cluster.controldata.lc_ctype); pg_free(old_cluster.controldata.lc_ctype);
......
...@@ -179,7 +179,7 @@ typedef struct ...@@ -179,7 +179,7 @@ typedef struct
char *bindir; /* pathname for cluster's executable directory */ char *bindir; /* pathname for cluster's executable directory */
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; /* string PG_VERSION of cluster */ char major_version_str[64]; /* string PG_VERSION of cluster */
Oid pg_database_oid; /* OID of pg_database relation */ Oid pg_database_oid; /* OID of pg_database relation */
char *libpath; /* pathname for cluster's pkglibdir */ char *libpath; /* pathname for cluster's pkglibdir */
char *tablespace_suffix; /* directory specification */ char *tablespace_suffix; /* directory specification */
...@@ -357,7 +357,7 @@ PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...); ...@@ -357,7 +357,7 @@ PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
void start_postmaster(ClusterInfo *cluster, bool quiet); void start_postmaster(ClusterInfo *cluster, bool quiet);
void stop_postmaster(bool fast, bool quiet); void stop_postmaster(bool fast, bool quiet);
uint32 get_major_server_version(ClusterInfo *cluster, char **verstr); uint32 get_major_server_version(ClusterInfo *cluster);
void check_for_libpq_envvars(void); void check_for_libpq_envvars(void);
......
...@@ -129,22 +129,21 @@ get_postmaster_pid(const char *datadir) ...@@ -129,22 +129,21 @@ get_postmaster_pid(const char *datadir)
* is retrieved by reading the PG_VERSION file. * is retrieved by reading the PG_VERSION file.
*/ */
uint32 uint32
get_major_server_version(ClusterInfo *cluster, char **verstr) get_major_server_version(ClusterInfo *cluster)
{ {
const char *datadir = cluster->pgdata; const char *datadir = cluster->pgdata;
FILE *version_fd; FILE *version_fd;
char ver_file[MAXPGPATH]; char ver_filename[MAXPGPATH];
int integer_version = 0; int integer_version = 0;
int fractional_version = 0; int fractional_version = 0;
*verstr = pg_malloc(64); snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION", datadir);
if ((version_fd = fopen(ver_filename, "r")) == NULL)
snprintf(ver_file, sizeof(ver_file), "%s/PG_VERSION", datadir);
if ((version_fd = fopen(ver_file, "r")) == NULL)
return 0; return 0;
if (fscanf(version_fd, "%63s", *verstr) == 0 || if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
sscanf(*verstr, "%d.%d", &integer_version, &fractional_version) != 2) sscanf(cluster->major_version_str, "%d.%d", &integer_version,
&fractional_version) != 2)
{ {
pg_log(PG_FATAL, "could not get version from %s\n", datadir); pg_log(PG_FATAL, "could not get version from %s\n", datadir);
fclose(version_fd); fclose(version_fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment