Skip to content

Commit 040af77

Browse files
committed
pg_upgrade: Fix oversight in version checking
Mistake in f06b1c5: We should only check the version of the binaries in the target installation. The source installation can of course be of a different version. Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/flat/E1lHNKN-0005IC-V6%40gemulon.postgresql.org
1 parent 4a4241e commit 040af77

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/bin/pg_upgrade/exec.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "pg_upgrade.h"
1616

1717
static void check_data_dir(ClusterInfo *cluster);
18-
static void check_bin_dir(ClusterInfo *cluster);
18+
static void check_bin_dir(ClusterInfo *cluster, bool check_versions);
1919
static void get_bin_version(ClusterInfo *cluster);
20-
static void check_exec(const char *dir, const char *program);
20+
static void check_exec(const char *dir, const char *program, bool check_version);
2121

2222
#ifdef WIN32
2323
static int win32_check_directory_write_permissions(void);
@@ -257,9 +257,9 @@ verify_directories(void)
257257
#endif
258258
pg_fatal("You must have read and write access in the current directory.\n");
259259

260-
check_bin_dir(&old_cluster);
260+
check_bin_dir(&old_cluster, false);
261261
check_data_dir(&old_cluster);
262-
check_bin_dir(&new_cluster);
262+
check_bin_dir(&new_cluster, true);
263263
check_data_dir(&new_cluster);
264264
}
265265

@@ -362,9 +362,13 @@ check_data_dir(ClusterInfo *cluster)
362362
* in the binaries directory. If we find that a required executable
363363
* is missing (or secured against us), we display an error message and
364364
* exit().
365+
*
366+
* If check_versions is true, then the versions of the binaries are checked
367+
* against the version of this pg_upgrade. This is for checking the target
368+
* bindir.
365369
*/
366370
static void
367-
check_bin_dir(ClusterInfo *cluster)
371+
check_bin_dir(ClusterInfo *cluster, bool check_versions)
368372
{
369373
struct stat statBuf;
370374

@@ -376,9 +380,9 @@ check_bin_dir(ClusterInfo *cluster)
376380
report_status(PG_FATAL, "\"%s\" is not a directory\n",
377381
cluster->bindir);
378382

379-
check_exec(cluster->bindir, "postgres");
380-
check_exec(cluster->bindir, "pg_controldata");
381-
check_exec(cluster->bindir, "pg_ctl");
383+
check_exec(cluster->bindir, "postgres", check_versions);
384+
check_exec(cluster->bindir, "pg_controldata", check_versions);
385+
check_exec(cluster->bindir, "pg_ctl", check_versions);
382386

383387
/*
384388
* Fetch the binary version after checking for the existence of pg_ctl.
@@ -389,9 +393,9 @@ check_bin_dir(ClusterInfo *cluster)
389393

390394
/* pg_resetxlog has been renamed to pg_resetwal in version 10 */
391395
if (GET_MAJOR_VERSION(cluster->bin_version) <= 906)
392-
check_exec(cluster->bindir, "pg_resetxlog");
396+
check_exec(cluster->bindir, "pg_resetxlog", check_versions);
393397
else
394-
check_exec(cluster->bindir, "pg_resetwal");
398+
check_exec(cluster->bindir, "pg_resetwal", check_versions);
395399

396400
if (cluster == &new_cluster)
397401
{
@@ -400,17 +404,17 @@ check_bin_dir(ClusterInfo *cluster)
400404
* pg_dumpall are used to dump the old cluster, but must be of the
401405
* target version.
402406
*/
403-
check_exec(cluster->bindir, "initdb");
404-
check_exec(cluster->bindir, "pg_dump");
405-
check_exec(cluster->bindir, "pg_dumpall");
406-
check_exec(cluster->bindir, "pg_restore");
407-
check_exec(cluster->bindir, "psql");
408-
check_exec(cluster->bindir, "vacuumdb");
407+
check_exec(cluster->bindir, "initdb", check_versions);
408+
check_exec(cluster->bindir, "pg_dump", check_versions);
409+
check_exec(cluster->bindir, "pg_dumpall", check_versions);
410+
check_exec(cluster->bindir, "pg_restore", check_versions);
411+
check_exec(cluster->bindir, "psql", check_versions);
412+
check_exec(cluster->bindir, "vacuumdb", check_versions);
409413
}
410414
}
411415

412416
static void
413-
check_exec(const char *dir, const char *program)
417+
check_exec(const char *dir, const char *program, bool check_version)
414418
{
415419
char path[MAXPGPATH];
416420
char line[MAXPGPATH];
@@ -435,11 +439,14 @@ check_exec(const char *dir, const char *program)
435439
pg_fatal("check for \"%s\" failed: cannot execute\n",
436440
path);
437441

438-
pg_strip_crlf(line);
442+
if (check_version)
443+
{
444+
pg_strip_crlf(line);
439445

440-
snprintf(versionstr, sizeof(versionstr), "%s (PostgreSQL) " PG_VERSION, program);
446+
snprintf(versionstr, sizeof(versionstr), "%s (PostgreSQL) " PG_VERSION, program);
441447

442-
if (strcmp(line, versionstr) != 0)
443-
pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n",
444-
path, line, versionstr);
448+
if (strcmp(line, versionstr) != 0)
449+
pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n",
450+
path, line, versionstr);
451+
}
445452
}

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