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