Commit a80b8037 authored by Bruce Momjian's avatar Bruce Momjian

In pg_upgrade, pull the port number from postmaster.pid, like we do for

socket location.  Also, prevent putting the socket in the current
directory for pre-9.1 servers in live check and non-live check mode,
because pre-9.1 pg_ctl -w can't handle it.

Backpatch to 9.2.
parent 504aeea6
...@@ -58,12 +58,6 @@ output_check_banner(bool *live_check) ...@@ -58,12 +58,6 @@ output_check_banner(bool *live_check)
if (user_opts.check && is_server_running(old_cluster.pgdata)) if (user_opts.check && is_server_running(old_cluster.pgdata))
{ {
*live_check = true; *live_check = true;
if (old_cluster.port == DEF_PGUPORT)
pg_log(PG_FATAL, "When checking a live old server, "
"you must specify the old server's port number.\n");
if (old_cluster.port == new_cluster.port)
pg_log(PG_FATAL, "When checking a live server, "
"the old and new port numbers must be different.\n");
pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n"); pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n");
pg_log(PG_REPORT, "------------------------------------------------\n"); pg_log(PG_REPORT, "------------------------------------------------\n");
} }
...@@ -320,6 +314,16 @@ check_cluster_compatibility(bool live_check) ...@@ -320,6 +314,16 @@ check_cluster_compatibility(bool live_check)
new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER) new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER)
pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n" pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
"because of backend API changes made during development.\n"); "because of backend API changes made during development.\n");
/* We read the real port number for PG >= 9.1 */
if (live_check && GET_MAJOR_VERSION(old_cluster.major_version) < 901 &&
old_cluster.port == DEF_PGUPORT)
pg_log(PG_FATAL, "When checking a pre-PG 9.1 live old server, "
"you must specify the old server's port number.\n");
if (live_check && old_cluster.port == new_cluster.port)
pg_log(PG_FATAL, "When checking a live server, "
"the old and new port numbers must be different.\n");
} }
......
...@@ -392,6 +392,13 @@ void ...@@ -392,6 +392,13 @@ void
get_sock_dir(ClusterInfo *cluster, bool live_check) get_sock_dir(ClusterInfo *cluster, bool live_check)
{ {
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
/*
* sockdir and port were added to postmaster.pid in PG 9.1.
* Pre-9.1 cannot process pg_ctl -w for sockets in non-default
* locations.
*/
if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
{
if (!live_check) if (!live_check)
{ {
/* Use the current directory for the socket */ /* Use the current directory for the socket */
...@@ -405,36 +412,45 @@ get_sock_dir(ClusterInfo *cluster, bool live_check) ...@@ -405,36 +412,45 @@ get_sock_dir(ClusterInfo *cluster, bool live_check)
* If we are doing a live check, we will use the old cluster's Unix * If we are doing a live check, we will use the old cluster's Unix
* domain socket directory so we can connect to the live server. * domain socket directory so we can connect to the live server.
*/ */
unsigned short orig_port = cluster->port;
/* sockdir was added to postmaster.pid in PG 9.1 */ char filename[MAXPGPATH], line[MAXPGPATH];
if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
{
char filename[MAXPGPATH];
FILE *fp; FILE *fp;
int i; int lineno;
snprintf(filename, sizeof(filename), "%s/postmaster.pid", snprintf(filename, sizeof(filename), "%s/postmaster.pid",
cluster->pgdata); cluster->pgdata);
if ((fp = fopen(filename, "r")) == NULL) if ((fp = fopen(filename, "r")) == NULL)
pg_log(PG_FATAL, "Could not get socket directory of the old server\n"); pg_log(PG_FATAL, "Cannot open file %s: %m\n", filename);
cluster->sockdir = pg_malloc(MAXPGPATH); for (lineno = 1;
for (i = 0; i < LOCK_FILE_LINE_SOCKET_DIR; i++) lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
if (fgets(cluster->sockdir, MAXPGPATH, fp) == NULL) lineno++)
pg_log(PG_FATAL, "Could not get socket directory of the old server\n"); {
if (fgets(line, sizeof(line), fp) == NULL)
pg_log(PG_FATAL, "Cannot read line %d from %s: %m\n", lineno, filename);
/* potentially overwrite user-supplied value */
if (lineno == LOCK_FILE_LINE_PORT)
sscanf(line, "%hu", &old_cluster.port);
if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
{
cluster->sockdir = pg_malloc(MAXPGPATH);
/* strip off newline */
sscanf(line, "%s\n", cluster->sockdir);
}
}
fclose(fp); fclose(fp);
/* Remove trailing newline */ /* warn of port number correction */
if (strchr(cluster->sockdir, '\n') != NULL) if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
*strchr(cluster->sockdir, '\n') = '\0'; pg_log(PG_WARNING, "User-supplied old port number %hu corrected to %hu\n",
orig_port, cluster->port);
}
} }
else else
{ /* Can't get sockdir and pg_ctl -w can't use a non-default, use default */
/* Can't get live sockdir, so assume the default is OK. */
cluster->sockdir = NULL; cluster->sockdir = NULL;
}
}
#else /* !HAVE_UNIX_SOCKETS */ #else /* !HAVE_UNIX_SOCKETS */
cluster->sockdir = NULL; cluster->sockdir = NULL;
#endif #endif
......
...@@ -86,11 +86,12 @@ main(int argc, char **argv) ...@@ -86,11 +86,12 @@ main(int argc, char **argv)
setup(argv[0], live_check); setup(argv[0], live_check);
check_cluster_versions(); check_cluster_versions();
check_cluster_compatibility(live_check);
get_sock_dir(&old_cluster, live_check); get_sock_dir(&old_cluster, live_check);
get_sock_dir(&new_cluster, false); get_sock_dir(&new_cluster, false);
check_cluster_compatibility(live_check);
check_old_cluster(live_check, &sequence_script_file_name); check_old_cluster(live_check, &sequence_script_file_name);
......
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