Skip to content

Commit 601d1ee

Browse files
committed
Fix pg_upgrade's use of pg_ctl on Win32 to not send command and sever
output to the same file, because it is impossible. Also set user name for pg_dumpall in pg_upgrade.
1 parent 7b6f290 commit 601d1ee

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

contrib/pg_upgrade/dump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ generate_old_dump(migratorContext *ctx)
1919
* restores the frozenid's for databases and relations.
2020
*/
2121
exec_prog(ctx, true,
22-
SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --schema-only "
23-
"--binary-upgrade > \"%s/" ALL_DUMP_FILE "\"" SYSTEMQUOTE,
24-
ctx->new.bindir, ctx->old.port, ctx->cwd);
22+
SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --username \"%s\" "
23+
"--schema-only --binary-upgrade > \"%s/" ALL_DUMP_FILE "\""
24+
SYSTEMQUOTE, ctx->new.bindir, ctx->old.port, ctx->user, ctx->cwd);
2525
check_ok(ctx);
2626
}
2727

contrib/pg_upgrade/option.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
174174
* start.
175175
*/
176176
/* truncate */
177-
ctx->log_fd = fopen(ctx->logfile, "w");
178-
if (!ctx->log_fd)
177+
if ((ctx->log_fd = fopen(ctx->logfile, "w")) == NULL)
179178
pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile);
180179
fclose(ctx->log_fd);
181-
ctx->log_fd = fopen(ctx->logfile, "a");
182-
if (!ctx->log_fd)
180+
if ((ctx->log_fd = fopen(ctx->logfile, "a")) == NULL)
183181
pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile);
184182
}
185183
else

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#define pg_link_file win32_pghardlink
4949
#define EXE_EXT ".exe"
5050
#define sleep(x) Sleep(x * 1000)
51-
#define DEVNULL "nul"
51+
#define DEVNULL "nul"
5252
/* "con" does not work from the Msys 1.0.10 console (part of MinGW). */
5353
#define DEVTTY "con"
5454
/* from pgport */

contrib/pg_upgrade/server.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,22 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
177177
port = ctx->new.port;
178178
}
179179

180-
/* use -l for Win32 */
180+
/*
181+
* On Win32, we can't send both server output and pg_ctl output
182+
* to the same file because we get the error:
183+
* "The process cannot access the file because it is being used by another process."
184+
* so we have to send pg_ctl output to 'nul'.
185+
*/
181186
snprintf(cmd, sizeof(cmd),
182187
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
183188
"-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" "
184189
"start >> \"%s\" 2>&1" SYSTEMQUOTE,
185-
bindir, ctx->logfile, datadir, port, ctx->logfile);
190+
bindir, ctx->logfile, datadir, port,
191+
#ifndef WIN32
192+
ctx->logfile);
193+
#else
194+
DEVNULL);
195+
#endif
186196
exec_prog(ctx, true, "%s", cmd);
187197

188198
/* wait for the server to start properly */
@@ -200,6 +210,7 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
200210
void
201211
stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
202212
{
213+
char cmd[MAXPGPATH];
203214
const char *bindir;
204215
const char *datadir;
205216

@@ -216,10 +227,16 @@ stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
216227
else
217228
return; /* no cluster running */
218229

219-
/* use -l for Win32 */
220-
exec_prog(ctx, fast ? false : true,
230+
/* See comment in start_postmaster() about why win32 output is ignored. */
231+
snprintf(cmd, sizeof(cmd),
221232
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> \"%s\" 2>&1" SYSTEMQUOTE,
222-
bindir, ctx->logfile, datadir, fast ? "-m fast" : "", ctx->logfile);
233+
bindir, ctx->logfile, datadir, fast ? "-m fast" : "",
234+
#ifndef WIN32
235+
ctx->logfile);
236+
#else
237+
DEVNULL);
238+
#endif
239+
exec_prog(ctx, fast ? false : true, "%s", cmd);
223240

224241
ctx->postmasterPID = 0;
225242
ctx->running_cluster = NONE;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy