|
25 | 25 | #include "catalog/catversion.h"
|
26 | 26 | #include "catalog/pg_control.h"
|
27 | 27 | #include "common/file_perm.h"
|
| 28 | +#include "common/file_utils.h" |
28 | 29 | #include "common/restricted_token.h"
|
29 | 30 | #include "getopt_long.h"
|
30 | 31 | #include "storage/bufpage.h"
|
@@ -701,50 +702,15 @@ updateControlFile(ControlFileData *ControlFile)
|
701 | 702 | *
|
702 | 703 | * We do this once, for the whole data directory, for performance reasons. At
|
703 | 704 | * 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. |
707 | 708 | */
|
708 | 709 | static void
|
709 | 710 | syncTargetDirectory(const char *argv0)
|
710 | 711 | {
|
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 */ |
737 | 712 | if (dry_run)
|
738 | 713 | return;
|
739 | 714 |
|
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); |
750 | 716 | }
|
0 commit comments