v9-0002-Reflect-the-value-of-max_safe_fds-in-max_files_pe.patch
text/x-patch
Filename: v9-0002-Reflect-the-value-of-max_safe_fds-in-max_files_pe.patch
Type: text/x-patch
Part: 1
From 94c19d3857102dbf6470d64295fc263b6e68556e Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sun, 7 Dec 2025 15:06:54 +0100
Subject: [PATCH v9 2/2] Reflect the value of max_safe_fds in
max_files_per_process
It is currently hard to figure out if max_safe_fds is significantly
lower than max_files_per_process. This starts reflecting the value of
max_safe_fds in max_files_per_process after our limit detection. We
still want to have two separate variables because for the bootstrap or
standalone-backend cases their values differ on purpose.
---
src/backend/storage/file/fd.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 40212d733e9..2d27207ab89 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1179,6 +1179,7 @@ set_max_safe_fds(void)
{
int usable_fds;
int already_open;
+ char *max_safe_fds_string;
/*----------
* We want to set max_safe_fds to
@@ -1194,6 +1195,16 @@ set_max_safe_fds(void)
max_safe_fds = Min(usable_fds, max_files_per_process);
+ /*
+ * Update GUC variable to allow users to see if the result is different
+ * than what the used value turns out to be different than what they had
+ * configured.
+ */
+ max_safe_fds_string = psprintf("%d", max_safe_fds);
+ SetConfigOption("max_files_per_process", max_safe_fds_string,
+ PGC_POSTMASTER, PGC_S_OVERRIDE);
+ pfree(max_safe_fds_string);
+
/*
* Take off the FDs reserved for system() etc.
*/
--
2.52.0