diff options
author | Michael Paquier <michael@paquier.xyz> | 2023-02-06 08:28:42 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2023-02-06 08:28:42 +0900 |
commit | 2f6e15ac93c58c1140e4a4affe61e78f7346497a (patch) | |
tree | d2757eb6b456c8f3d882d53d711792d5ee2fdee4 /src/common/archive.c | |
parent | b2d0e13a0a4c31167d01e9871f907060c80b8fae (diff) | |
download | postgresql-2f6e15ac93c58c1140e4a4affe61e78f7346497a.tar.gz postgresql-2f6e15ac93c58c1140e4a4affe61e78f7346497a.zip |
Revert refactoring of restore command code to shell_restore.c
This reverts commits 24c35ec and 57169ad. PreRestoreCommand() and
PostRestoreCommand() need to be put closer to the system() call calling
a restore_command, as they enable in_restore_command for the startup
process which would in turn trigger an immediate proc_exit() in the
SIGTERM handler. Perhaps we could get rid of this behavior entirely,
but 24c35ec has made the window where the flag is enabled much larger
than it was, and any Postgres-like actions (palloc, etc.) taken by code
paths while the flag is enabled could lead to more severe issues in the
shutdown processing.
Note that curculio has showed that there are much more problems in this
area, unrelated to this change, actually, hence the issues related to
that had better be addressed first. Keeping the code of HEAD in line
with the stable branches should make that a bit easier.
Per discussion with Andres Freund and Nathan Bossart.
Discussion: https://postgr.es/m/Y979NR3U5VnWrTwB@paquier.xyz
Diffstat (limited to 'src/common/archive.c')
-rw-r--r-- | src/common/archive.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/common/archive.c b/src/common/archive.c new file mode 100644 index 00000000000..641a58ee888 --- /dev/null +++ b/src/common/archive.c @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------- + * + * archive.c + * Common WAL archive routines + * + * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/common/archive.c + * + *------------------------------------------------------------------------- + */ + +#ifndef FRONTEND +#include "postgres.h" +#else +#include "postgres_fe.h" +#endif + +#include "common/archive.h" +#include "common/percentrepl.h" + +/* + * BuildRestoreCommand + * + * Builds a restore command to retrieve a file from WAL archives, replacing + * the supported aliases with values supplied by the caller as defined by + * the GUC parameter restore_command: xlogpath for %p, xlogfname for %f and + * lastRestartPointFname for %r. + * + * The result is a palloc'd string for the restore command built. The + * caller is responsible for freeing it. If any of the required arguments + * is NULL and that the corresponding alias is found in the command given + * by the caller, then an error is thrown. + */ +char * +BuildRestoreCommand(const char *restoreCommand, + const char *xlogpath, + const char *xlogfname, + const char *lastRestartPointFname) +{ + char *nativePath = NULL; + char *result; + + if (xlogpath) + { + nativePath = pstrdup(xlogpath); + make_native_path(nativePath); + } + + result = replace_percent_placeholders(restoreCommand, "restore_command", "frp", + xlogfname, lastRestartPointFname, nativePath); + + if (nativePath) + pfree(nativePath); + + return result; +} |