From a7a6c5a23d3908c1ac0416249f725bb61b79e29c Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Fri, 30 Oct 2026 10:58:59 +0800 Subject: [PATCH v1] Fix error handling in pg_flush_data() and FilePrefetch() posix_fadvise() returns an error code directly instead of setting errno. However, pg_flush_data() uses %m and errcode_for_file_access() to report errors without setting errno, potentially reporting an unrelated error. Fix this by assigning the returned error code to errno before reporting the error. FilePrefetch() is documented to return an errno error code on failure, but it returns -1 when FileAccess() fails. Fix this by returning errno instead. Author: Chao Li --- src/backend/storage/file/fd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 190c9974494..8c5edc8e17a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -683,9 +683,10 @@ retry: */ rc = posix_fadvise(fd, offset, nbytes, POSIX_FADV_DONTNEED); - if (rc != 0) { + /* for compatibility with %m printing etc */ + errno = rc; /* don't error out, this is just a performance optimization */ ereport(WARNING, (errcode_for_file_access(), @@ -2078,7 +2079,7 @@ FilePrefetch(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info) returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; retry: pgstat_report_wait_start(wait_event_info); @@ -2102,7 +2103,7 @@ retry: returnCode = FileAccess(file); if (returnCode < 0) - return returnCode; + return errno; ra.ra_offset = offset; ra.ra_count = amount; -- 2.50.1 (Apple Git-155)