]> granicus.if.org Git - postgresql/commitdiff
Backpatch pg_upgrade fixes to 9.0:
authorBruce Momjian <bruce@momjian.us>
Tue, 13 Jul 2010 20:15:51 +0000 (20:15 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 13 Jul 2010 20:15:51 +0000 (20:15 +0000)
 In pg_upgrade, prevent psql AUTOCOMMIT=off by not loading .psqlrc.

 In pg_upgrade, report /bin directory checks independent of /data checks.

 Remove incorrect email address for pg_upgrade bug reports.

 On Win32, pg_upgrade cannot sent any server log output to the log file
 because of file access limitations on that platform.

contrib/pg_upgrade/TESTING
contrib/pg_upgrade/check.c
contrib/pg_upgrade/exec.c
contrib/pg_upgrade/file.c
contrib/pg_upgrade/option.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/server.c

index 9646697f1034012eac838662d63f02d82139aff0..dc233afacb28e26cea1f2af83a9ab7212b8fe1bb 100644 (file)
@@ -1,4 +1,4 @@
-$PostgreSQL: pgsql/contrib/pg_upgrade/TESTING,v 1.2.2.1 2010/07/09 16:51:29 momjian Exp $
+$PostgreSQL: pgsql/contrib/pg_upgrade/TESTING,v 1.2.2.2 2010/07/13 20:15:51 momjian Exp $
 
 The most effective way to test pg_upgrade, aside from testing on user
 data, is by upgrading the PostgreSQL regression database.
index 0e96705b2d181b12c7374bd8e89476b6416edc44..be746e2c46773bc4d216b166018bcd455fc6f522 100644 (file)
@@ -4,7 +4,7 @@
  *     server checks and output routines
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.11 2010/07/06 19:18:55 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.11.2.1 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
@@ -152,9 +152,9 @@ issue_warnings(migratorContext *ctx, char *sequence_script_file_name)
                {
                        prep_status(ctx, "Adjusting sequences");
                        exec_prog(ctx, true,
-                                 SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on --port %d "
-                                  "--username \"%s\" -f \"%s\" --dbname template1 >> \"%s\""
-                                         SYSTEMQUOTE,
+                                 SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
+                                 "--no-psqlrc --port %d --username \"%s\" "
+                                 "-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                                          ctx->new.bindir, ctx->new.port, ctx->user,
                                          sequence_script_file_name, ctx->logfile);
                        unlink(sequence_script_file_name);
index 88a2129e89e2cdc7fc1d9c33cf22969c5c6fc538..c347484b81d1949dce713af1f104d75ccdd3dceb 100644 (file)
@@ -4,7 +4,7 @@
  *     execution functions
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.8 2010/07/06 19:18:55 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.8.2.1 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
 #include <grp.h>
 
 
-static void checkBinDir(migratorContext *ctx, ClusterInfo *cluster);
+static void    check_data_dir(migratorContext *ctx, const char *pg_data);
+static void check_bin_dir(migratorContext *ctx, ClusterInfo *cluster);
 static int     check_exec(migratorContext *ctx, const char *dir, const char *cmdName);
 static const char *validate_exec(const char *path);
-static int     check_data_dir(migratorContext *ctx, const char *pg_data);
 
 
 /*
@@ -55,6 +55,34 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
 }
 
 
+/*
+ * is_server_running()
+ *
+ * checks whether postmaster on the given data directory is running or not.
+ * The check is performed by looking for the existence of postmaster.pid file.
+ */
+bool
+is_server_running(migratorContext *ctx, const char *datadir)
+{
+       char            path[MAXPGPATH];
+       int                     fd;
+
+       snprintf(path, sizeof(path), "%s/postmaster.pid", datadir);
+
+       if ((fd = open(path, O_RDONLY, 0)) < 0)
+       {
+               if (errno != ENOENT)
+                       pg_log(ctx, PG_FATAL, "\ncould not open file \"%s\" for reading\n",
+                                  path);
+
+               return false;
+       }
+
+       close(fd);
+       return true;
+}
+
+
 /*
  * verify_directories()
  *
@@ -67,21 +95,62 @@ void
 verify_directories(migratorContext *ctx)
 {
        prep_status(ctx, "Checking old data directory (%s)", ctx->old.pgdata);
-       if (check_data_dir(ctx, ctx->old.pgdata) != 0)
-               pg_log(ctx, PG_FATAL, "Failed\n");
-       checkBinDir(ctx, &ctx->old);
+       check_data_dir(ctx, ctx->old.pgdata);
+       check_ok(ctx);
+
+       prep_status(ctx, "Checking old bin directory (%s)", ctx->old.bindir);
+       check_bin_dir(ctx, &ctx->old);
        check_ok(ctx);
 
        prep_status(ctx, "Checking new data directory (%s)", ctx->new.pgdata);
-       if (check_data_dir(ctx, ctx->new.pgdata) != 0)
-               pg_log(ctx, PG_FATAL, "Failed\n");
-       checkBinDir(ctx, &ctx->new);
+       check_data_dir(ctx, ctx->new.pgdata);
+       check_ok(ctx);
+
+       prep_status(ctx, "Checking new bin directory (%s)", ctx->new.bindir);
+       check_bin_dir(ctx, &ctx->new);
        check_ok(ctx);
 }
 
 
 /*
- * checkBinDir()
+ * check_data_dir()
+ *
+ *     This function validates the given cluster directory - we search for a
+ *     small set of subdirectories that we expect to find in a valid $PGDATA
+ *     directory.      If any of the subdirectories are missing (or secured against
+ *     us) we display an error message and exit()
+ *
+ */
+static void
+check_data_dir(migratorContext *ctx, const char *pg_data)
+{
+       char            subDirName[MAXPGPATH];
+       int                     subdirnum;
+       const char *requiredSubdirs[] = {"base", "global", "pg_clog",
+               "pg_multixact", "pg_subtrans", "pg_tblspc", "pg_twophase",
+               "pg_xlog"};
+
+       for (subdirnum = 0;
+                subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]);
+                ++subdirnum)
+       {
+               struct stat statBuf;
+
+               snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
+                                requiredSubdirs[subdirnum]);
+
+               if (stat(subDirName, &statBuf) != 0)
+                       report_status(ctx, PG_FATAL, "check for %s failed:  %s",
+                                                 requiredSubdirs[subdirnum], getErrorText(errno));
+               else if (!S_ISDIR(statBuf.st_mode))
+                               report_status(ctx, PG_FATAL, "%s is not a directory",
+                                                         requiredSubdirs[subdirnum]);
+       }
+}
+
+
+/*
+ * check_bin_dir()
  *
  *     This function searches for the executables that we expect to find
  *     in the binaries directory.      If we find that a required executable
@@ -89,7 +158,7 @@ verify_directories(migratorContext *ctx)
  *     exit().
  */
 static void
-checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
+check_bin_dir(migratorContext *ctx, ClusterInfo *cluster)
 {
        check_exec(ctx, cluster->bindir, "postgres");
        check_exec(ctx, cluster->bindir, "psql");
@@ -98,34 +167,6 @@ checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
 }
 
 
-/*
- * is_server_running()
- *
- * checks whether postmaster on the given data directory is running or not.
- * The check is performed by looking for the existence of postmaster.pid file.
- */
-bool
-is_server_running(migratorContext *ctx, const char *datadir)
-{
-       char            path[MAXPGPATH];
-       int                     fd;
-
-       snprintf(path, sizeof(path), "%s/postmaster.pid", datadir);
-
-       if ((fd = open(path, O_RDONLY, 0)) < 0)
-       {
-               if (errno != ENOENT)
-                       pg_log(ctx, PG_FATAL, "\ncould not open file \"%s\" for reading\n",
-                                  path);
-
-               return false;
-       }
-
-       close(fd);
-       return true;
-}
-
-
 /*
  * check_exec()
  *
@@ -264,50 +305,3 @@ validate_exec(const char *path)
        return NULL;
 #endif
 }
-
-
-/*
- * check_data_dir()
- *
- *     This function validates the given cluster directory - we search for a
- *     small set of subdirectories that we expect to find in a valid $PGDATA
- *     directory.      If any of the subdirectories are missing (or secured against
- *     us) we display an error message and exit()
- *
- */
-static int
-check_data_dir(migratorContext *ctx, const char *pg_data)
-{
-       char            subDirName[MAXPGPATH];
-       const char *requiredSubdirs[] = {"base", "global", "pg_clog",
-               "pg_multixact", "pg_subtrans",
-       "pg_tblspc", "pg_twophase", "pg_xlog"};
-       bool            fail = false;
-       int                     subdirnum;
-
-       for (subdirnum = 0; subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]); ++subdirnum)
-       {
-               struct stat statBuf;
-
-               snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
-                                requiredSubdirs[subdirnum]);
-
-               if ((stat(subDirName, &statBuf)) != 0)
-               {
-                       report_status(ctx, PG_WARNING, "check for %s warning:  %s",
-                                                 requiredSubdirs[subdirnum], getErrorText(errno));
-                       fail = true;
-               }
-               else
-               {
-                       if (!S_ISDIR(statBuf.st_mode))
-                       {
-                               report_status(ctx, PG_WARNING, "%s is not a directory",
-                                                         requiredSubdirs[subdirnum]);
-                               fail = true;
-                       }
-               }
-       }
-
-       return (fail) ? -1 : 0;
-}
index e55ca2c7fa5d41fd06958e145b72dc3af6446926..358fcf51b5a36a7849ead66163fc2fbf35db6238 100644 (file)
@@ -4,7 +4,7 @@
  *     file system operations
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/file.c,v 1.13.2.1 2010/07/09 16:51:29 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/file.c,v 1.13.2.2 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
index 1704069b34bab03397981f8cfa074b00eef73e4a..d03b978619e7cde8701f948a37bdbca272d045cf 100644 (file)
@@ -4,7 +4,7 @@
  *     options functions
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/option.c,v 1.12 2010/07/06 19:18:55 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/option.c,v 1.12.2.1 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
@@ -259,10 +259,6 @@ or\n"), ctx->old.port, ctx->new.port, ctx->user);
   C:\\> set NEWBINDIR=newCluster/bin\n\
   C:\\> pg_upgrade\n"));
 #endif
-       printf(_("\n\
-You may find it useful to save the preceding 5 commands in a shell script\n\
-\n\
-Report bugs to <pg-migrator-general@lists.pgfoundry.org>\n"));
 }
 
 
index 695596ba603a14bd76794ad4fc08c8ef9a351473..1a515e75e6f69bbf9a757f0dd9a5ab42e1b49e2c 100644 (file)
@@ -4,7 +4,7 @@
  *     main source file
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/pg_upgrade.c,v 1.10 2010/07/06 19:18:55 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/pg_upgrade.c,v 1.10.2.1 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
@@ -202,9 +202,10 @@ prepare_new_databases(migratorContext *ctx)
         */
        prep_status(ctx, "Creating databases in the new cluster");
        exec_prog(ctx, true,
-                         SYSTEMQUOTE "\"%s/psql\" --port %d --username \"%s\" "
-                  "--set ON_ERROR_STOP=on -f \"%s/%s\" --dbname template1 >> \"%s\""
-                         SYSTEMQUOTE,
+                         SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
+                         /* --no-psqlrc prevents AUTOCOMMIT=off */
+                         "--no-psqlrc --port %d --username \"%s\" "
+                         "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                          ctx->new.bindir, ctx->new.port, ctx->user, ctx->cwd,
                          GLOBALS_DUMP_FILE, ctx->logfile);
        check_ok(ctx);
@@ -225,9 +226,9 @@ create_new_objects(migratorContext *ctx)
 
        prep_status(ctx, "Restoring database schema to new cluster");
        exec_prog(ctx, true,
-                         SYSTEMQUOTE "\"%s/psql\" --port %d --username \"%s\" "
-                  "--set ON_ERROR_STOP=on -f \"%s/%s\" --dbname template1 >> \"%s\""
-                         SYSTEMQUOTE,
+                         SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
+                         "--no-psqlrc --port %d --username \"%s\" "
+                         "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                          ctx->new.bindir, ctx->new.port, ctx->user, ctx->cwd,
                          DB_DUMP_FILE, ctx->logfile);
        check_ok(ctx);
index a9243ab75aead5a090df81b048b1d48093f2d5e5..eaa178cd7c2ca8c1d2575cfd72440489e247b37b 100644 (file)
@@ -4,7 +4,7 @@
  *     database server functions
  *
  *     Copyright (c) 2010, PostgreSQL Global Development Group
- *     $PostgreSQL: pgsql/contrib/pg_upgrade/server.c,v 1.8 2010/07/06 19:18:55 momjian Exp $
+ *     $PostgreSQL: pgsql/contrib/pg_upgrade/server.c,v 1.8.2.1 2010/07/13 20:15:51 momjian Exp $
  */
 
 #include "pg_upgrade.h"
@@ -181,9 +181,9 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
        }
 
        /*
-        * On Win32, we can't send both server output and pg_ctl output to the
+        * On Win32, we can't send both pg_upgrade output and pg_ctl output to the
         * same file because we get the error: "The process cannot access the file
-        * because it is being used by another process." so we have to send pg_ctl
+        * because it is being used by another process." so we have to send all other
         * output to 'nul'.
         */
        snprintf(cmd, sizeof(cmd),
@@ -191,11 +191,11 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
                         "-o \"-p %d -c autovacuum=off "
                         "-c autovacuum_freeze_max_age=2000000000\" "
                         "start >> \"%s\" 2>&1" SYSTEMQUOTE,
-                        bindir, ctx->logfile, datadir, port,
+                        bindir,
 #ifndef WIN32
-                        ctx->logfile);
+                        ctx->logfile, datadir, port, ctx->logfile);
 #else
-                        DEVNULL);
+                        DEVNULL, datadir, port, DEVNULL);
 #endif
        exec_prog(ctx, true, "%s", cmd);
 
@@ -235,11 +235,11 @@ stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> "
                         "\"%s\" 2>&1" SYSTEMQUOTE,
-                        bindir, ctx->logfile, datadir, fast ? "-m fast" : "",
+                        bindir,
 #ifndef WIN32
-                        ctx->logfile);
+                        ctx->logfile, datadir, fast ? "-m fast" : "", ctx->logfile);
 #else
-                        DEVNULL);
+                        DEVNULL, datadir, fast ? "-m fast" : "", DEVNULL);
 #endif
        exec_prog(ctx, fast ? false : true, "%s", cmd);