Just fsync those affected files during pg_rewind.
In gpdb we've ensured that the database is in sync state before rewinding, so
we could just fsync those affected files after rewinding.
@@ -812,6 +812,12 @@ digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
* most dirty buffers to disk. Additionally fsync_pgdata uses a two-pass
* approach (only initiating writeback in the first pass), which often reduces
* the overall amount of IO noticeably.
+ *
+ * gpdb: We assume that all files are synchronized before rewinding and thus we
+ * just need to synchronize those affected files. This is a resonable
+ * assumption for gpdb since we've ensured that the db state is clean shutdown
+ * in pg_rewind by running single mode postgres if needed and also we do not
+ * copy an unsynchronized dababase without sync as the target base.
*/
static void
syncTargetDirectory(void)
@@ -819,7 +825,59 @@ syncTargetDirectory(void)
if (!do_sync || dry_run)
return;
- fsync_pgdata(datadir_target, PG_VERSION_NUM);
+ file_entry_t *entry;
+ int i;
+
+ if (chdir(datadir_target) < 0)
+ {
+ pg_log_error("could not change directory to \"%s\": %m", datadir_target);
+ exit(1);
+ }
+
+ for (i = 0; i < filemap->narray; i++)
+ {
+ entry = filemap->array[i];
+
+ if (entry->target_pages_to_overwrite.bitmapsize > 0)
+ fsync_fname(entry->path, false);
+ else
+ {
+ switch (entry->action)
+ {
+ case FILE_ACTION_COPY:
+ case FILE_ACTION_TRUNCATE:
+ case FILE_ACTION_COPY_TAIL:
+ fsync_fname(entry->path, false);
+ break;
+
+ case FILE_ACTION_CREATE:
+ fsync_fname(entry->path,
+ entry->source_type == FILE_TYPE_DIRECTORY);
+ /* FALLTHROUGH */
+ case FILE_ACTION_REMOVE:
+ /*
+ * Fsync the parent directory if we either create or delete
+ * files/directories in the parent directory. The parent
+ * directory might be missing as expected, so fsync it could
+ * fail but we ignore that error.
+ */
+ fsync_parent_path(entry->path);
+ break;
+
+ case FILE_ACTION_NONE:
+ break;
+
+ default:
+ pg_fatal("no action decided for \"%s\"", entry->path);
+ break;
+ }
+ }
+ }
+
+ /* fsync some files that are (possibly) written by pg_rewind. */
+ fsync_fname("global/pg_control", false);
+ fsync_fname("backup_label", false);
+ fsync_fname("postgresql.auto.conf", false);
}
/*
