fsync-trick.patch
text/x-diff
Filename: fsync-trick.patch
Type: text/x-diff
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/storage/file/fd.c | 7 | 0 |
| src/test/perl/PostgresNode.pm | 1 | 1 |
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 94be62fa6e..091f8dc902 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -330,6 +330,9 @@ static int fsync_parent_path(const char *fname, int elevel);
int
pg_fsync(int fd)
{
+ /* on some operating systems fsyncing a file requires O_RDWR */
+ Assert((fcntl(fd, F_GETFL) & (O_WRONLY | O_RDWR)) != 0);
+
/* #if is to skip the sync_method test if there's no need for it */
#if defined(HAVE_FSYNC_WRITETHROUGH) && !defined(FSYNC_WRITETHROUGH_IS_FSYNC)
if (sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH)
@@ -3358,6 +3361,10 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
else
flags |= O_RDONLY;
+ /* trick to bypass O_RDONLY check */
+ if (isdir)
+ return 0;
+
fd = OpenTransientFile(fname, flags);
/*
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index 270bd6c856..c727e8fa27 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -441,7 +441,7 @@ sub init
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "\n# Added by PostgresNode.pm\n";
- print $conf "fsync = off\n";
+ print $conf "fsync = on\n";
print $conf "restart_after_crash = off\n";
print $conf "log_line_prefix = '%m [%p] %q%a '\n";
print $conf "log_statement = all\n";