Re: [GENERAL] pg_upgrade from 9.5 to 9.6 fails with "invalid argument"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Thomas Kellerer <spam_eater(at)gmx(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GENERAL] pg_upgrade from 9.5 to 9.6 fails with "invalid argument"
Date: 2016-09-30 16:38:51
Message-ID: 29413.1475253531@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> writes:

> +#ifndef WIN32
> if ((src_fd = open(fromfile, O_RDONLY, 0)) < 0)
> +#else
> + if ((src_fd = open(fromfile, O_RDONLY | O_BINARY)) < 0)
> +#endif

This is easier with PG_BINARY. Also, both open() calls need this.

I'm rather inclined to also stick PG_BINARY into the open() calls in
copy_file() as well. That function isn't actively broken since it's
not used under Windows, but I think it's highly likely that the
current bug arose from copying-and-pasting that code, so leaving it
in a state that's unsafe for Windows is just asking for trouble.

Attached is the patch I'm currently working with to fix all three
of the portability issues here (PG_BINARY, endianness, alignment,
and there's some cosmetic changes too).

> + pg_log(PG_WARNING,
> + "could not read expected bytes: read = %u, expected = %u\n",
> + BLCKSZ, bytesRead);

I think this is probably better done as part of a wholesale revision
of the error reporting in this file. What I have in mind is to
redefine copyFile, linkFile, and rewriteVisibilityMap as all being
responsible for reporting their own errors and then exiting (so
they can just return void). We'd need to pass in the schema name
and table name so that they can include that context, so that the
reports don't get any less complete than they were before, but that
does not seem like a big downside.

A variant would be to have them print the error messages but then
return a bool success flag, leaving the caller to decide whether
it's fatal or not. But that would be more complicated and I see
no real reason to think pg_upgrade would ever need it.

regards, tom lane

Attachment Content-Type Size
fix-rewriteVisibilityMap-portability-issues.patch text/x-diff 9.2 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2016-09-30 16:47:17 Re: [GENERAL] pg_upgrade from 9.5 to 9.6 fails with "invalid argument"
Previous Message Jay Knight 2016-09-30 16:26:37 Re: Parallel query only when EXPLAIN ANALYZEd

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2016-09-30 16:39:04 Re: Hash Indexes
Previous Message Peter Geoghegan 2016-09-30 16:37:35 Re: On conflict update & hint bits