Skip to content

Commit f53bc2e

Browse files
committed
Backpatch pg_upgrade fixes to 9.0:
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.
1 parent 41252a1 commit f53bc2e

File tree

7 files changed

+104
-113
lines changed

7 files changed

+104
-113
lines changed

contrib/pg_upgrade/TESTING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/contrib/pg_upgrade/TESTING,v 1.2.2.1 2010/07/09 16:51:29 momjian Exp $
1+
$PostgreSQL: pgsql/contrib/pg_upgrade/TESTING,v 1.2.2.2 2010/07/13 20:15:51 momjian Exp $
22

33
The most effective way to test pg_upgrade, aside from testing on user
44
data, is by upgrading the PostgreSQL regression database.

contrib/pg_upgrade/check.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* server checks and output routines
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.11 2010/07/06 19:18:55 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.11.2.1 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"
@@ -152,9 +152,9 @@ issue_warnings(migratorContext *ctx, char *sequence_script_file_name)
152152
{
153153
prep_status(ctx, "Adjusting sequences");
154154
exec_prog(ctx, true,
155-
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on --port %d "
156-
"--username \"%s\" -f \"%s\" --dbname template1 >> \"%s\""
157-
SYSTEMQUOTE,
155+
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
156+
"--no-psqlrc --port %d --username \"%s\" "
157+
"-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
158158
ctx->new.bindir, ctx->new.port, ctx->user,
159159
sequence_script_file_name, ctx->logfile);
160160
unlink(sequence_script_file_name);

contrib/pg_upgrade/exec.c

Lines changed: 80 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* execution functions
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.8 2010/07/06 19:18:55 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/exec.c,v 1.8.2.1 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"
@@ -13,10 +13,10 @@
1313
#include <grp.h>
1414

1515

16-
static void checkBinDir(migratorContext *ctx, ClusterInfo *cluster);
16+
static void check_data_dir(migratorContext *ctx, const char *pg_data);
17+
static void check_bin_dir(migratorContext *ctx, ClusterInfo *cluster);
1718
static int check_exec(migratorContext *ctx, const char *dir, const char *cmdName);
1819
static const char *validate_exec(const char *path);
19-
static int check_data_dir(migratorContext *ctx, const char *pg_data);
2020

2121

2222
/*
@@ -55,6 +55,34 @@ exec_prog(migratorContext *ctx, bool throw_error, const char *fmt,...)
5555
}
5656

5757

58+
/*
59+
* is_server_running()
60+
*
61+
* checks whether postmaster on the given data directory is running or not.
62+
* The check is performed by looking for the existence of postmaster.pid file.
63+
*/
64+
bool
65+
is_server_running(migratorContext *ctx, const char *datadir)
66+
{
67+
char path[MAXPGPATH];
68+
int fd;
69+
70+
snprintf(path, sizeof(path), "%s/postmaster.pid", datadir);
71+
72+
if ((fd = open(path, O_RDONLY, 0)) < 0)
73+
{
74+
if (errno != ENOENT)
75+
pg_log(ctx, PG_FATAL, "\ncould not open file \"%s\" for reading\n",
76+
path);
77+
78+
return false;
79+
}
80+
81+
close(fd);
82+
return true;
83+
}
84+
85+
5886
/*
5987
* verify_directories()
6088
*
@@ -67,29 +95,70 @@ void
6795
verify_directories(migratorContext *ctx)
6896
{
6997
prep_status(ctx, "Checking old data directory (%s)", ctx->old.pgdata);
70-
if (check_data_dir(ctx, ctx->old.pgdata) != 0)
71-
pg_log(ctx, PG_FATAL, "Failed\n");
72-
checkBinDir(ctx, &ctx->old);
98+
check_data_dir(ctx, ctx->old.pgdata);
99+
check_ok(ctx);
100+
101+
prep_status(ctx, "Checking old bin directory (%s)", ctx->old.bindir);
102+
check_bin_dir(ctx, &ctx->old);
73103
check_ok(ctx);
74104

75105
prep_status(ctx, "Checking new data directory (%s)", ctx->new.pgdata);
76-
if (check_data_dir(ctx, ctx->new.pgdata) != 0)
77-
pg_log(ctx, PG_FATAL, "Failed\n");
78-
checkBinDir(ctx, &ctx->new);
106+
check_data_dir(ctx, ctx->new.pgdata);
107+
check_ok(ctx);
108+
109+
prep_status(ctx, "Checking new bin directory (%s)", ctx->new.bindir);
110+
check_bin_dir(ctx, &ctx->new);
79111
check_ok(ctx);
80112
}
81113

82114

83115
/*
84-
* checkBinDir()
116+
* check_data_dir()
117+
*
118+
* This function validates the given cluster directory - we search for a
119+
* small set of subdirectories that we expect to find in a valid $PGDATA
120+
* directory. If any of the subdirectories are missing (or secured against
121+
* us) we display an error message and exit()
122+
*
123+
*/
124+
static void
125+
check_data_dir(migratorContext *ctx, const char *pg_data)
126+
{
127+
char subDirName[MAXPGPATH];
128+
int subdirnum;
129+
const char *requiredSubdirs[] = {"base", "global", "pg_clog",
130+
"pg_multixact", "pg_subtrans", "pg_tblspc", "pg_twophase",
131+
"pg_xlog"};
132+
133+
for (subdirnum = 0;
134+
subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]);
135+
++subdirnum)
136+
{
137+
struct stat statBuf;
138+
139+
snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
140+
requiredSubdirs[subdirnum]);
141+
142+
if (stat(subDirName, &statBuf) != 0)
143+
report_status(ctx, PG_FATAL, "check for %s failed: %s",
144+
requiredSubdirs[subdirnum], getErrorText(errno));
145+
else if (!S_ISDIR(statBuf.st_mode))
146+
report_status(ctx, PG_FATAL, "%s is not a directory",
147+
requiredSubdirs[subdirnum]);
148+
}
149+
}
150+
151+
152+
/*
153+
* check_bin_dir()
85154
*
86155
* This function searches for the executables that we expect to find
87156
* in the binaries directory. If we find that a required executable
88157
* is missing (or secured against us), we display an error message and
89158
* exit().
90159
*/
91160
static void
92-
checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
161+
check_bin_dir(migratorContext *ctx, ClusterInfo *cluster)
93162
{
94163
check_exec(ctx, cluster->bindir, "postgres");
95164
check_exec(ctx, cluster->bindir, "psql");
@@ -98,34 +167,6 @@ checkBinDir(migratorContext *ctx, ClusterInfo *cluster)
98167
}
99168

100169

101-
/*
102-
* is_server_running()
103-
*
104-
* checks whether postmaster on the given data directory is running or not.
105-
* The check is performed by looking for the existence of postmaster.pid file.
106-
*/
107-
bool
108-
is_server_running(migratorContext *ctx, const char *datadir)
109-
{
110-
char path[MAXPGPATH];
111-
int fd;
112-
113-
snprintf(path, sizeof(path), "%s/postmaster.pid", datadir);
114-
115-
if ((fd = open(path, O_RDONLY, 0)) < 0)
116-
{
117-
if (errno != ENOENT)
118-
pg_log(ctx, PG_FATAL, "\ncould not open file \"%s\" for reading\n",
119-
path);
120-
121-
return false;
122-
}
123-
124-
close(fd);
125-
return true;
126-
}
127-
128-
129170
/*
130171
* check_exec()
131172
*
@@ -264,50 +305,3 @@ validate_exec(const char *path)
264305
return NULL;
265306
#endif
266307
}
267-
268-
269-
/*
270-
* check_data_dir()
271-
*
272-
* This function validates the given cluster directory - we search for a
273-
* small set of subdirectories that we expect to find in a valid $PGDATA
274-
* directory. If any of the subdirectories are missing (or secured against
275-
* us) we display an error message and exit()
276-
*
277-
*/
278-
static int
279-
check_data_dir(migratorContext *ctx, const char *pg_data)
280-
{
281-
char subDirName[MAXPGPATH];
282-
const char *requiredSubdirs[] = {"base", "global", "pg_clog",
283-
"pg_multixact", "pg_subtrans",
284-
"pg_tblspc", "pg_twophase", "pg_xlog"};
285-
bool fail = false;
286-
int subdirnum;
287-
288-
for (subdirnum = 0; subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]); ++subdirnum)
289-
{
290-
struct stat statBuf;
291-
292-
snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
293-
requiredSubdirs[subdirnum]);
294-
295-
if ((stat(subDirName, &statBuf)) != 0)
296-
{
297-
report_status(ctx, PG_WARNING, "check for %s warning: %s",
298-
requiredSubdirs[subdirnum], getErrorText(errno));
299-
fail = true;
300-
}
301-
else
302-
{
303-
if (!S_ISDIR(statBuf.st_mode))
304-
{
305-
report_status(ctx, PG_WARNING, "%s is not a directory",
306-
requiredSubdirs[subdirnum]);
307-
fail = true;
308-
}
309-
}
310-
}
311-
312-
return (fail) ? -1 : 0;
313-
}

contrib/pg_upgrade/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* file system operations
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/file.c,v 1.13.2.1 2010/07/09 16:51:29 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/file.c,v 1.13.2.2 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"

contrib/pg_upgrade/option.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* options functions
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/option.c,v 1.12 2010/07/06 19:18:55 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/option.c,v 1.12.2.1 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"
@@ -259,10 +259,6 @@ or\n"), ctx->old.port, ctx->new.port, ctx->user);
259259
C:\\> set NEWBINDIR=newCluster/bin\n\
260260
C:\\> pg_upgrade\n"));
261261
#endif
262-
printf(_("\n\
263-
You may find it useful to save the preceding 5 commands in a shell script\n\
264-
\n\
265-
Report bugs to <pg-migrator-general@lists.pgfoundry.org>\n"));
266262
}
267263

268264

contrib/pg_upgrade/pg_upgrade.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* main source file
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/pg_upgrade.c,v 1.10 2010/07/06 19:18:55 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/pg_upgrade.c,v 1.10.2.1 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"
@@ -202,9 +202,10 @@ prepare_new_databases(migratorContext *ctx)
202202
*/
203203
prep_status(ctx, "Creating databases in the new cluster");
204204
exec_prog(ctx, true,
205-
SYSTEMQUOTE "\"%s/psql\" --port %d --username \"%s\" "
206-
"--set ON_ERROR_STOP=on -f \"%s/%s\" --dbname template1 >> \"%s\""
207-
SYSTEMQUOTE,
205+
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
206+
/* --no-psqlrc prevents AUTOCOMMIT=off */
207+
"--no-psqlrc --port %d --username \"%s\" "
208+
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
208209
ctx->new.bindir, ctx->new.port, ctx->user, ctx->cwd,
209210
GLOBALS_DUMP_FILE, ctx->logfile);
210211
check_ok(ctx);
@@ -225,9 +226,9 @@ create_new_objects(migratorContext *ctx)
225226

226227
prep_status(ctx, "Restoring database schema to new cluster");
227228
exec_prog(ctx, true,
228-
SYSTEMQUOTE "\"%s/psql\" --port %d --username \"%s\" "
229-
"--set ON_ERROR_STOP=on -f \"%s/%s\" --dbname template1 >> \"%s\""
230-
SYSTEMQUOTE,
229+
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
230+
"--no-psqlrc --port %d --username \"%s\" "
231+
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
231232
ctx->new.bindir, ctx->new.port, ctx->user, ctx->cwd,
232233
DB_DUMP_FILE, ctx->logfile);
233234
check_ok(ctx);

contrib/pg_upgrade/server.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* database server functions
55
*
66
* Copyright (c) 2010, PostgreSQL Global Development Group
7-
* $PostgreSQL: pgsql/contrib/pg_upgrade/server.c,v 1.8 2010/07/06 19:18:55 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_upgrade/server.c,v 1.8.2.1 2010/07/13 20:15:51 momjian Exp $
88
*/
99

1010
#include "pg_upgrade.h"
@@ -181,21 +181,21 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet)
181181
}
182182

183183
/*
184-
* On Win32, we can't send both server output and pg_ctl output to the
184+
* On Win32, we can't send both pg_upgrade output and pg_ctl output to the
185185
* same file because we get the error: "The process cannot access the file
186-
* because it is being used by another process." so we have to send pg_ctl
186+
* because it is being used by another process." so we have to send all other
187187
* output to 'nul'.
188188
*/
189189
snprintf(cmd, sizeof(cmd),
190190
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
191191
"-o \"-p %d -c autovacuum=off "
192192
"-c autovacuum_freeze_max_age=2000000000\" "
193193
"start >> \"%s\" 2>&1" SYSTEMQUOTE,
194-
bindir, ctx->logfile, datadir, port,
194+
bindir,
195195
#ifndef WIN32
196-
ctx->logfile);
196+
ctx->logfile, datadir, port, ctx->logfile);
197197
#else
198-
DEVNULL);
198+
DEVNULL, datadir, port, DEVNULL);
199199
#endif
200200
exec_prog(ctx, true, "%s", cmd);
201201

@@ -235,11 +235,11 @@ stop_postmaster(migratorContext *ctx, bool fast, bool quiet)
235235
snprintf(cmd, sizeof(cmd),
236236
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> "
237237
"\"%s\" 2>&1" SYSTEMQUOTE,
238-
bindir, ctx->logfile, datadir, fast ? "-m fast" : "",
238+
bindir,
239239
#ifndef WIN32
240-
ctx->logfile);
240+
ctx->logfile, datadir, fast ? "-m fast" : "", ctx->logfile);
241241
#else
242-
DEVNULL);
242+
DEVNULL, datadir, fast ? "-m fast" : "", DEVNULL);
243243
#endif
244244
exec_prog(ctx, fast ? false : true, "%s", cmd);
245245

0 commit comments

Comments
 (0)