From a88f4496b75a756df371a405ce608ceb06c8fbd7 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 1 Jul 2011 18:17:12 -0400 Subject: [PATCH] Change pg_upgrade to use port 50432 by default to avoid unintended client connections during the upgrade. Also rename data/bin/port environment variables to being with 'PG'. Also no longer honor PGPORT. --- contrib/pg_upgrade/check.c | 3 +++ contrib/pg_upgrade/option.c | 28 ++++++++++++++-------------- contrib/pg_upgrade/pg_upgrade.h | 3 +++ doc/src/sgml/pgupgrade.sgml | 26 +++++++++++++++----------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c index 1ee2acac83..5c5ce72294 100644 --- a/contrib/pg_upgrade/check.c +++ b/contrib/pg_upgrade/check.c @@ -29,6 +29,9 @@ output_check_banner(bool *live_check) if (user_opts.check && is_server_running(old_cluster.pgdata)) { *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"); diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c index 4401a81562..d29aad0e1d 100644 --- a/contrib/pg_upgrade/option.c +++ b/contrib/pg_upgrade/option.c @@ -58,8 +58,8 @@ parseCommandLine(int argc, char *argv[]) os_info.progname = get_progname(argv[0]); /* Process libpq env. variables; load values here for usage() output */ - old_cluster.port = getenv("PGPORT") ? atoi(getenv("PGPORT")) : DEF_PGPORT; - new_cluster.port = getenv("PGPORT") ? atoi(getenv("PGPORT")) : DEF_PGPORT; + old_cluster.port = getenv("PGPORTOLD") ? atoi(getenv("PGPORTOLD")) : DEF_PGUPORT; + new_cluster.port = getenv("PGPORTNEW") ? atoi(getenv("PGPORTNEW")) : DEF_PGUPORT; os_user_effective_id = get_user_info(&os_info.user); /* we override just the database user name; we got the OS id above */ @@ -203,13 +203,13 @@ parseCommandLine(int argc, char *argv[]) } /* Get values from env if not already set */ - check_required_directory(&old_cluster.bindir, "OLDBINDIR", "-b", + check_required_directory(&old_cluster.bindir, "PGBINOLD", "-b", "old cluster binaries reside"); - check_required_directory(&new_cluster.bindir, "NEWBINDIR", "-B", + check_required_directory(&new_cluster.bindir, "PGBINNEW", "-B", "new cluster binaries reside"); - check_required_directory(&old_cluster.pgdata, "OLDDATADIR", "-d", + check_required_directory(&old_cluster.pgdata, "PGDATAOLD", "-d", "old cluster data resides"); - check_required_directory(&new_cluster.pgdata, "NEWDATADIR", "-D", + check_required_directory(&new_cluster.pgdata, "PGDATANEW", "-D", "new cluster data resides"); } @@ -254,17 +254,17 @@ For example:\n\ or\n"), old_cluster.port, new_cluster.port, os_info.user); #ifndef WIN32 printf(_("\ - $ export OLDDATADIR=oldCluster/data\n\ - $ export NEWDATADIR=newCluster/data\n\ - $ export OLDBINDIR=oldCluster/bin\n\ - $ export NEWBINDIR=newCluster/bin\n\ + $ export PGDATAOLD=oldCluster/data\n\ + $ export PGDATANEW=newCluster/data\n\ + $ export PGBINOLD=oldCluster/bin\n\ + $ export PGBINNEW=newCluster/bin\n\ $ pg_upgrade\n")); #else printf(_("\ - C:\\> set OLDDATADIR=oldCluster/data\n\ - C:\\> set NEWDATADIR=newCluster/data\n\ - C:\\> set OLDBINDIR=oldCluster/bin\n\ - C:\\> set NEWBINDIR=newCluster/bin\n\ + C:\\> set PGDATAOLD=oldCluster/data\n\ + C:\\> set PGDATANEW=newCluster/data\n\ + C:\\> set PGBINOLD=oldCluster/bin\n\ + C:\\> set PGBINNEW=newCluster/bin\n\ C:\\> pg_upgrade\n")); #endif printf(_("\nReport bugs to .\n")); diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h index 613ddbd03f..4729ac39d9 100644 --- a/contrib/pg_upgrade/pg_upgrade.h +++ b/contrib/pg_upgrade/pg_upgrade.h @@ -15,6 +15,9 @@ #include "libpq-fe.h" +/* Use port in the private/dynamic port number range */ +#define DEF_PGUPORT 50432 + /* Allocate for null byte */ #define USER_NAME_SIZE 128 diff --git a/doc/src/sgml/pgupgrade.sgml b/doc/src/sgml/pgupgrade.sgml index b24c1e7b98..aa633e2d41 100644 --- a/doc/src/sgml/pgupgrade.sgml +++ b/doc/src/sgml/pgupgrade.sgml @@ -60,14 +60,14 @@ old_bindir old_bindir the old cluster executable directory; - environment variable OLDBINDIR + environment variable PGBINOLD new_bindir new_bindir the new cluster executable directory; - environment variable NEWBINDIR + environment variable PGBINNEW @@ -80,14 +80,14 @@ old_datadir old_datadir the old cluster data directory; environment - variable OLDDATADIR + variable PGDATAOLD new_datadir new_datadir the new cluster data directory; environment - variable NEWDATADIR + variable PGDATANEW @@ -118,14 +118,14 @@ old_port_number old_portnum the old cluster port number; environment - variable PGPORT + variable PGPORTOLD new_port_number new_portnum the new cluster port number; environment - variable PGPORT + variable PGPORTNEW @@ -256,8 +256,7 @@ gmake prefix=/usr/local/pgsql.new install so you might want to set authentication to trust in pg_hba.conf, or if using md5 authentication, use a ~/.pgpass file (see ) - to avoid being prompted repeatedly for a password. Also make sure - pg_upgrade is the only program that can connect to the clusters. + to avoid being prompted repeatedly for a password. @@ -303,9 +302,14 @@ NET STOP pgsql-8.3 (PostgreSQL 8.3 and older used a different s copying), but you will not be able to access your old cluster once you start the new cluster after the upgrade. Link mode also requires that the old and new cluster data directories be in the - same file system. See pg_upgrade --help for a full - list of options. - + same file system. + + + + pg_upgrade defaults to running servers on port + 50432 to avoid unintended client connections. See pg_upgrade + --help for a full list of options. + For Windows users, you must be logged into an administrative account, and -- 2.11.0