Re: pg_upgrade should truncate/remove its logs before running

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Daniel Gustafsson <daniel@yesql.se>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>, Andrew Dunstan <andrew@dunslane.net>, Bruce Momjian <bruce@momjian.us>, pgsql-hackers@lists.postgresql.org
Date: 2022-01-19T08:13:18Z
Lists: pgsql-hackers

Attachments

On Tue, Jan 11, 2022 at 10:08:13PM -0600, Justin Pryzby wrote:
> I asked about that before.  Right now, it'll exit(1) when mkdir fails.
> 
> I had written a patch to allow "." by skipping mkdir (or allowing it to fail if
> errno == EEXIST), but it seems like an awfully bad idea to try to make that
> work with rmtree().

So, I have been poking at this patch, and found myself doing a couple
of modifications:
- Renaming of the option from --logdir to --outputdir, as this does
not include only logs.  That matches also better with default value
assigned in previous patches, aka pg_upgrade_output.d.
- Convert the output directory to an absolute path when the various
directories are created, and use that for the whole run.  pg_upgrade
is unlikely going to chdir(), but I don't really see why we should
just not use an absolute path all the time, set from the start.
- Add some sanity check about the path used, aka no parent reference
allowed and the output path should not be a direct parent of the
current working directory.
- Rather than assuming that "log/" and "dump/" are hardcoded in
various places, save more paths into log_opts.

I have noticed a couple of incorrect things in the docs, and some
other things.  It is a bit late here, so I may have missed a couple of
things but I'll look at this stuff once again in a couple of days.

So, what do you think?
--
Michael

Commits

  1. pg_upgrade: Move all the files generated internally to a subdirectory