pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: pg_upgrade: Check version of target cluster binaries
7+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2021-03-04 040af77938  pg_upgrade: Fix oversight in version checking
* pgsql: pg_upgrade: Check version of target cluster binaries
@ 2021-03-03 08:57 Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Peter Eisentraut @ 2021-03-03 08:57 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

pg_upgrade: Check version of target cluster binaries

This expands the binary validation in pg_upgrade with a version
check per binary to ensure that the target cluster installation
only contains binaries from the target version.

In order to reduce duplication, validate_exec is exported from
port.h and the local copy in pg_upgrade is removed.

Author: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://www.postgresql.org/message-id/flat/9328.1552952117@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f06b1c598254f8adb2b7f51d6a7685618a7fb121

Modified Files
--------------
src/bin/pg_upgrade/exec.c | 88 +++++++++++++++++++----------------------------
src/common/exec.c         |  3 +-
src/include/port.h        |  1 +
3 files changed, 38 insertions(+), 54 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
@ 2021-03-03 20:28 ` Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-03 21:58   ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Andrew Dunstan <andrew@dunslane.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-03-03 20:28 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-committers@lists.postgresql.org, Andrew Dunstan <andrew@dunslane.net>

Peter Eisentraut <peter@eisentraut.org> writes:
> pg_upgrade: Check version of target cluster binaries

Crake says this patch broke its cross-version upgrade tests:

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=crake&dt=2021-03-03%2009%3A02%3A31

where the important bit is

check for "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres" failed: incorrect version: found "postgres (PostgreSQL) 9.2.24", expected "postgres (PostgreSQL) 14devel"

It's not at all clear from here whether that's a bug in the patch
or in the buildfarm's test harness.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-03-03 21:58   ` Andrew Dunstan <andrew@dunslane.net>
  2021-03-03 22:04     ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Andrew Dunstan @ 2021-03-03 21:58 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-committers@lists.postgresql.org


On 3/3/21 3:28 PM, Tom Lane wrote:
> Peter Eisentraut <peter@eisentraut.org> writes:
>> pg_upgrade: Check version of target cluster binaries
> Crake says this patch broke its cross-version upgrade tests:
>
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=crake&dt=2021-03-03%2009%3A02%3A31
>
> where the important bit is
>
> check for "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres" failed: incorrect version: found "postgres (PostgreSQL) 9.2.24", expected "postgres (PostgreSQL) 14devel"
>
> It's not at all clear from here whether that's a bug in the patch
> or in the buildfarm's test harness.
>
> 			



This has worked for years ... here's the latest code:
<https://github.com/PGBuildFarm/client-code/blob/master/PGBuild/Modules/TestUpgradeXversion.pm;
The invocation of pg_upgrade is at line 560.


The log says:

    check for
    "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres"
    failed: incorrect version: found "postgres (PostgreSQL) 9.2.24",
    expected "postgres (PostgreSQL) 14devel"

But that makes no sense at all. Looks like we're confusing the source and the target.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-03 21:58   ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Andrew Dunstan <andrew@dunslane.net>
@ 2021-03-03 22:04     ` Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-04 00:06       ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-03-03 22:04 UTC (permalink / raw)
  To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Peter Eisentraut <peter@eisentraut.org>; pgsql-committers@lists.postgresql.org

Andrew Dunstan <andrew@dunslane.net> writes:
> On 3/3/21 3:28 PM, Tom Lane wrote:
>> Crake says this patch broke its cross-version upgrade tests:

> The log says:
>     check for
>     "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres"
>     failed: incorrect version: found "postgres (PostgreSQL) 9.2.24",
>     expected "postgres (PostgreSQL) 14devel"
> But that makes no sense at all. Looks like we're confusing the source and the target.

On looking closer, I think the patch is just several bricks shy of a
load.  It's applying validate_exec (which insists on a match to its
own version number) to *both* the source and target binaries.  It
must not check the source that way.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-03 21:58   ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Andrew Dunstan <andrew@dunslane.net>
  2021-03-03 22:04     ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-03-04 00:06       ` Daniel Gustafsson <daniel@yesql.se>
  2021-03-04 07:24         ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Daniel Gustafsson @ 2021-03-04 00:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andrew Dunstan <andrew@dunslane.net>; Peter Eisentraut <peter@eisentraut.org>; pgsql-committers@lists.postgresql.org

> On 3 Mar 2021, at 23:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> Andrew Dunstan <andrew@dunslane.net> writes:
>> On 3/3/21 3:28 PM, Tom Lane wrote:
>>> Crake says this patch broke its cross-version upgrade tests:
> 
>> The log says:
>>    check for
>>    "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres"
>>    failed: incorrect version: found "postgres (PostgreSQL) 9.2.24",
>>    expected "postgres (PostgreSQL) 14devel"
>> But that makes no sense at all. Looks like we're confusing the source and the target.
> 
> On looking closer, I think the patch is just several bricks shy of a
> load.  It's applying validate_exec (which insists on a match to its
> own version number) to *both* the source and target binaries.  It
> must not check the source that way.

It's much to late to focus here at the moment, I will take a look in the
morning unless beaten to it.

--
Daniel Gustafsson		https://vmware.com/






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-03 21:58   ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Andrew Dunstan <andrew@dunslane.net>
  2021-03-03 22:04     ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-04 00:06       ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Daniel Gustafsson <daniel@yesql.se>
@ 2021-03-04 07:24         ` Peter Eisentraut <peter@eisentraut.org>
  2021-03-04 08:32           ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 7+ messages in thread

From: Peter Eisentraut @ 2021-03-04 07:24 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andrew Dunstan <andrew@dunslane.net>; pgsql-committers@lists.postgresql.org

On 04.03.21 01:06, Daniel Gustafsson wrote:
>> On 3 Mar 2021, at 23:04, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>
>> Andrew Dunstan <andrew@dunslane.net> writes:
>>> On 3/3/21 3:28 PM, Tom Lane wrote:
>>>> Crake says this patch broke its cross-version upgrade tests:
>>
>>> The log says:
>>>     check for
>>>     "/home/andrew/bf/root/upgrade.crake/REL9_2_STABLE/inst/bin/postgres"
>>>     failed: incorrect version: found "postgres (PostgreSQL) 9.2.24",
>>>     expected "postgres (PostgreSQL) 14devel"
>>> But that makes no sense at all. Looks like we're confusing the source and the target.
>>
>> On looking closer, I think the patch is just several bricks shy of a
>> load.  It's applying validate_exec (which insists on a match to its
>> own version number) to *both* the source and target binaries.  It
>> must not check the source that way.
> 
> It's much to late to focus here at the moment, I will take a look in the
> morning unless beaten to it.

I think the attached would be a sensible fix.

Attachments:

0001-pg_upgrade-Fix-oversight-in-version-checking.patch (text/plain, 4.6K) download From 2c62cdb11a88d652c9a7ddade63878c8de7c30de Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Thu, 4 Mar 2021 08:21:59 +0100 Subject: [PATCH] pg_upgrade: Fix oversight in version checking Mistake in f06b1c598254f8adb2b7f51d6a7685618a7fb121: We should only check the version of the binaries in the target installation. The source installation can of course be of a different version. --- src/bin/pg_upgrade/exec.c | 51 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 4d77543d6f..9e52846ef8 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -15,9 +15,9 @@ #include "pg_upgrade.h" static void check_data_dir(ClusterInfo *cluster); -static void check_bin_dir(ClusterInfo *cluster); +static void check_bin_dir(ClusterInfo *cluster, bool check_versions); static void get_bin_version(ClusterInfo *cluster); -static void check_exec(const char *dir, const char *program); +static void check_exec(const char *dir, const char *program, bool check_version); #ifdef WIN32 static int win32_check_directory_write_permissions(void); @@ -257,9 +257,9 @@ verify_directories(void) #endif pg_fatal("You must have read and write access in the current directory.\n"); - check_bin_dir(&old_cluster); + check_bin_dir(&old_cluster, false); check_data_dir(&old_cluster); - check_bin_dir(&new_cluster); + check_bin_dir(&new_cluster, true); check_data_dir(&new_cluster); } @@ -362,9 +362,13 @@ check_data_dir(ClusterInfo *cluster) * in the binaries directory. If we find that a required executable * is missing (or secured against us), we display an error message and * exit(). + * + * If check_versions is true, then the versions of the binaries are checked + * against the version of this pg_upgrade. This is for checking the target + * bindir. */ static void -check_bin_dir(ClusterInfo *cluster) +check_bin_dir(ClusterInfo *cluster, bool check_versions) { struct stat statBuf; @@ -376,9 +380,9 @@ check_bin_dir(ClusterInfo *cluster) report_status(PG_FATAL, "\"%s\" is not a directory\n", cluster->bindir); - check_exec(cluster->bindir, "postgres"); - check_exec(cluster->bindir, "pg_controldata"); - check_exec(cluster->bindir, "pg_ctl"); + check_exec(cluster->bindir, "postgres", check_versions); + check_exec(cluster->bindir, "pg_controldata", check_versions); + check_exec(cluster->bindir, "pg_ctl", check_versions); /* * Fetch the binary version after checking for the existence of pg_ctl. @@ -389,9 +393,9 @@ check_bin_dir(ClusterInfo *cluster) /* pg_resetxlog has been renamed to pg_resetwal in version 10 */ if (GET_MAJOR_VERSION(cluster->bin_version) <= 906) - check_exec(cluster->bindir, "pg_resetxlog"); + check_exec(cluster->bindir, "pg_resetxlog", check_versions); else - check_exec(cluster->bindir, "pg_resetwal"); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { @@ -400,17 +404,17 @@ check_bin_dir(ClusterInfo *cluster) * pg_dumpall are used to dump the old cluster, but must be of the * target version. */ - check_exec(cluster->bindir, "initdb"); - check_exec(cluster->bindir, "pg_dump"); - check_exec(cluster->bindir, "pg_dumpall"); - check_exec(cluster->bindir, "pg_restore"); - check_exec(cluster->bindir, "psql"); - check_exec(cluster->bindir, "vacuumdb"); + check_exec(cluster->bindir, "initdb", check_versions); + check_exec(cluster->bindir, "pg_dump", check_versions); + check_exec(cluster->bindir, "pg_dumpall", check_versions); + check_exec(cluster->bindir, "pg_restore", check_versions); + check_exec(cluster->bindir, "psql", check_versions); + check_exec(cluster->bindir, "vacuumdb", check_versions); } } static void -check_exec(const char *dir, const char *program) +check_exec(const char *dir, const char *program, bool check_version) { char path[MAXPGPATH]; char line[MAXPGPATH]; @@ -435,11 +439,14 @@ check_exec(const char *dir, const char *program) pg_fatal("check for \"%s\" failed: cannot execute\n", path); - pg_strip_crlf(line); + if (check_version) + { + pg_strip_crlf(line); - snprintf(versionstr, sizeof(versionstr), "%s (PostgreSQL) " PG_VERSION, program); + snprintf(versionstr, sizeof(versionstr), "%s (PostgreSQL) " PG_VERSION, program); - if (strcmp(line, versionstr) != 0) - pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n", - path, line, versionstr); + if (strcmp(line, versionstr) != 0) + pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n", + path, line, versionstr); + } } -- 2.30.1
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: pgsql: pg_upgrade: Check version of target cluster binaries
  2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
  2021-03-03 20:28 ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-03 21:58   ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Andrew Dunstan <andrew@dunslane.net>
  2021-03-03 22:04     ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Tom Lane <tgl@sss.pgh.pa.us>
  2021-03-04 00:06       ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Daniel Gustafsson <daniel@yesql.se>
  2021-03-04 07:24         ` Re: pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
@ 2021-03-04 08:32           ` Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 0 replies; 7+ messages in thread

From: Daniel Gustafsson @ 2021-03-04 08:32 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Andrew Dunstan <andrew@dunslane.net>; pgsql-committers@lists.postgresql.org

> On 4 Mar 2021, at 08:24, Peter Eisentraut <peter@eisentraut.org> wrote:

> I think the attached would be a sensible fix.

That's pretty much what I ended up with as well.

I was first looking at checking the version of the binary against the
major_version_str in ClusterInfo by passing down cluster instead, but that
turns into chicken-and-egg since we don't set the extracted version until we've
checked that pg_ctl exists and works.

Thanks!

--
Daniel Gustafsson		https://vmware.com/






^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2021-03-04 08:32 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 08:57 pgsql: pg_upgrade: Check version of target cluster binaries Peter Eisentraut <peter@eisentraut.org>
2021-03-03 20:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-03 21:58   ` Andrew Dunstan <andrew@dunslane.net>
2021-03-03 22:04     ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-04 00:06       ` Daniel Gustafsson <daniel@yesql.se>
2021-03-04 07:24         ` Peter Eisentraut <peter@eisentraut.org>
2021-03-04 08:32           ` Daniel Gustafsson <daniel@yesql.se>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox