Fix pg_upgrade's use of pg_ctl on Win32 to not send command and sever
authorBruce Momjian <bruce@momjian.us>
Tue, 22 Jun 2010 16:45:10 +0000 (16:45 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 22 Jun 2010 16:45:10 +0000 (16:45 +0000)
output to the same file, because it is impossible.

Also set user name for pg_dumpall in pg_upgrade.

contrib/pg_upgrade/dump.c
contrib/pg_upgrade/option.c
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/server.c

index f3060d54d1b2c7f7fb190752d1fb8e0cfa859cc2..8e92d72e395b7ac6d43c061bb08bc63c88634f96 100644 (file)
@@ -19,9 +19,9 @@ generate_old_dump(migratorContext *ctx)
         * restores the frozenid's for databases and relations.
         */
        exec_prog(ctx, true,
-                         SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --schema-only "
-                         "--binary-upgrade > \"%s/" ALL_DUMP_FILE "\"" SYSTEMQUOTE,
-                         ctx->new.bindir, ctx->old.port, ctx->cwd);
+                         SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --username \"%s\" "
+                         "--schema-only --binary-upgrade > \"%s/" ALL_DUMP_FILE "\""
+                         SYSTEMQUOTE, ctx->new.bindir, ctx->old.port, ctx->user, ctx->cwd);
        check_ok(ctx);
 }
 
index a38a9a80fff0331ff131004fdb876fff40d89579..58606dd2bf344db449af38113fe27c5d00c6c34d 100644 (file)
@@ -174,12 +174,10 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
                 * start.
                 */
                /* truncate */
-               ctx->log_fd = fopen(ctx->logfile, "w");
-               if (!ctx->log_fd)
+               if ((ctx->log_fd = fopen(ctx->logfile, "w")) == NULL)
                        pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile);
                fclose(ctx->log_fd);
-               ctx->log_fd = fopen(ctx->logfile, "a");
-               if (!ctx->log_fd)
+               if ((ctx->log_fd = fopen(ctx->logfile, "a")) == NULL)
                        pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile);
        }
        else
index 34376047f7cf3d24218ab3e8bb2b286c074578ee..51b78a2624922613d4829d63af667c21514d5915 100644 (file)
@@ -48,7 +48,7 @@
 #define pg_link_file           win32_pghardlink
 #define EXE_EXT                                ".exe"
 #define sleep(x)                       Sleep(x * 1000)
-#define DEVNULL "nul"
+#define DEVNULL                                "nul"
 /* "con" does not work from the Msys 1.0.10 console (part of MinGW). */
 #define DEVTTY  "con"
 /* from pgport */
index 96a72b6876426f3f2de946fbd8f5565fad3c6626..9f6c9cb4181e79838ff7dd9a515520323961b757 100644 (file)
@@ -177,12 +177,22 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
                port = ctx->new.port;
        }
 
-       /* use -l for Win32 */
+       /*
+        * On Win32, we can't send both server 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 output to 'nul'.
+        */      
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
                         "-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
                         "start >> \"%s\" 2>&1" SYSTEMQUOTE,
-                        bindir, ctx->logfile, datadir, port, ctx->logfile);
+                        bindir, ctx->logfile, datadir, port,
+#ifndef WIN32
+                        ctx->logfile);
+#else
+                        DEVNULL);
+#endif
        exec_prog(ctx, true, "%s", cmd);
 
        /* wait for the server to start properly */
@@ -200,6 +210,7 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
 void
 stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
 {
+       char            cmd[MAXPGPATH];
        const char *bindir;
        const char *datadir;
 
@@ -216,10 +227,16 @@ stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
        else
                return;                                 /* no cluster running */
 
-       /* use -l for Win32 */
-       exec_prog(ctx, fast ? false : true,
+       /* See comment in start_postmaster() about why win32 output is ignored. */
+       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" : "", ctx->logfile);
+                         bindir, ctx->logfile, datadir, fast ? "-m fast" : "",
+#ifndef WIN32
+                         ctx->logfile);
+#else
+                         DEVNULL);
+#endif
+       exec_prog(ctx, fast ? false : true, "%s", cmd);
 
        ctx->postmasterPID = 0;
        ctx->running_cluster = NONE;