base_backup_fadvise.patch

text/x-patch

Filename: base_backup_fadvise.patch
Type: text/x-patch
Part: 0
Message: posix_fadvsise in base backups

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/replication/basebackup.c 9 0
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 4841095..54c4d13 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -781,6 +781,15 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
 		pq_putmessage('d', buf, pad);
 	}
 
+	/*
+	 * If we have posix_fadvise(), send a note to the kernel that we are not
+	 * going to need this data anytime soon, so that it can be discarded
+	 * from the filesystem cache.
+	 */
+#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
+	(void) posix_fadvise(fileno(fp), 0, 0, POSIX_FADV_DONTNEED);
+#endif
+
 	FreeFile(fp);
 }