Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5762a4d

Browse files
committed
Inherit max_safe_fds to child processes in EXEC_BACKEND mode.
Postmaster sets max_safe_fds by testing how many open file descriptors it can open, and that is normally inherited by all child processes at fork(). Not so on EXEC_BACKEND, ie. Windows, however. Because of that, we effectively ignored max_files_per_process on Windows, and always assumed a conservative default of 32 simultaneous open files. That could have an impact on performance, if you need to access a lot of different files in a query. After this patch, the value is passed to child processes by save/restore_backend_variables() among many other global variables. It has been like this forever, but given the lack of complaints about it, I'm not backpatching this.
1 parent d2c1740 commit 5762a4d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ typedef struct
438438
TimestampTz PgReloadTime;
439439
bool redirection_done;
440440
bool IsBinaryUpgrade;
441+
int max_safe_fds;
441442
#ifdef WIN32
442443
HANDLE PostmasterHandle;
443444
HANDLE initial_signal_pipe;
@@ -4741,6 +4742,7 @@ save_backend_variables(BackendParameters *param, Port *port,
47414742

47424743
param->redirection_done = redirection_done;
47434744
param->IsBinaryUpgrade = IsBinaryUpgrade;
4745+
param->max_safe_fds = max_safe_fds;
47444746

47454747
#ifdef WIN32
47464748
param->PostmasterHandle = PostmasterHandle;
@@ -4964,6 +4966,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
49644966

49654967
redirection_done = param->redirection_done;
49664968
IsBinaryUpgrade = param->IsBinaryUpgrade;
4969+
max_safe_fds = param->max_safe_fds;
49674970

49684971
#ifdef WIN32
49694972
PostmasterHandle = param->PostmasterHandle;

src/backend/storage/file/fd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int max_files_per_process = 1000;
103103
* Note: the value of max_files_per_process is taken into account while
104104
* setting this variable, and so need not be tested separately.
105105
*/
106-
static int max_safe_fds = 32; /* default if not changed */
106+
int max_safe_fds = 32; /* default if not changed */
107107

108108

109109
/* Debugging.... */

src/include/storage/fd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ typedef int File;
5353
/* GUC parameter */
5454
extern int max_files_per_process;
5555

56+
/*
57+
* This is private to fd.c, but exported for save/restore_backend_variables()
58+
*/
59+
extern int max_safe_fds;
60+
5661

5762
/*
5863
* prototypes for functions in fd.c

0 commit comments

Comments
 (0)