Skip to content

Commit 9a4059d

Browse files
committed
Simplify logic to sync target directory at the end of pg_rewind
The previous sync logic relied on looking for and then launching externally initdb -S, which is a simple wrapper on top of fsync_pgdata. There is nothing preventing pg_rewind to directly call this routine, so remove the dependency to initdb and just call it directly. Author: Michael Paquier Reviewed-by: Heikki Linnakangas Discussion: https://postgr.es/m/20180325122607.GB3707@paquier.xyz
1 parent 0905fe8 commit 9a4059d

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

src/bin/pg_rewind/pg_rewind.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "catalog/catversion.h"
2626
#include "catalog/pg_control.h"
2727
#include "common/file_perm.h"
28+
#include "common/file_utils.h"
2829
#include "common/restricted_token.h"
2930
#include "getopt_long.h"
3031
#include "storage/bufpage.h"
@@ -701,50 +702,15 @@ updateControlFile(ControlFileData *ControlFile)
701702
*
702703
* We do this once, for the whole data directory, for performance reasons. At
703704
* the end of pg_rewind's run, the kernel is likely to already have flushed
704-
* most dirty buffers to disk. Additionally initdb -S uses a two-pass approach
705-
* (only initiating writeback in the first pass), which often reduces the
706-
* overall amount of IO noticeably.
705+
* most dirty buffers to disk. Additionally fsync_pgdata uses a two-pass
706+
* approach (only initiating writeback in the first pass), which often reduces
707+
* the overall amount of IO noticeably.
707708
*/
708709
static void
709710
syncTargetDirectory(const char *argv0)
710711
{
711-
int ret;
712-
#define MAXCMDLEN (2 * MAXPGPATH)
713-
char exec_path[MAXPGPATH];
714-
char cmd[MAXCMDLEN];
715-
716-
/* locate initdb binary */
717-
if ((ret = find_other_exec(argv0, "initdb",
718-
"initdb (PostgreSQL) " PG_VERSION "\n",
719-
exec_path)) < 0)
720-
{
721-
char full_path[MAXPGPATH];
722-
723-
if (find_my_exec(argv0, full_path) < 0)
724-
strlcpy(full_path, progname, sizeof(full_path));
725-
726-
if (ret == -1)
727-
pg_fatal("The program \"initdb\" is needed by %s but was\n"
728-
"not found in the same directory as \"%s\".\n"
729-
"Check your installation.\n", progname, full_path);
730-
else
731-
pg_fatal("The program \"initdb\" was found by \"%s\"\n"
732-
"but was not the same version as %s.\n"
733-
"Check your installation.\n", full_path, progname);
734-
}
735-
736-
/* only skip processing after ensuring presence of initdb */
737712
if (dry_run)
738713
return;
739714

740-
/* finally run initdb -S */
741-
if (debug)
742-
snprintf(cmd, MAXCMDLEN, "\"%s\" -D \"%s\" -S",
743-
exec_path, datadir_target);
744-
else
745-
snprintf(cmd, MAXCMDLEN, "\"%s\" -D \"%s\" -S > \"%s\"",
746-
exec_path, datadir_target, DEVNULL);
747-
748-
if (system(cmd) != 0)
749-
pg_fatal("sync of target directory failed\n");
715+
fsync_pgdata(datadir_target, progname, PG_VERSION_NUM);
750716
}

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