Skip to content

Commit 21fb39c

Browse files
committed
Set max_safe_fds whenever we create shared memory and semaphores.
Formerly we skipped this in bootstrap/check mode and in single-user mode. That's bad in check mode because it may allow accepting a value of max_connections that doesn't actually work: on platforms where semaphores consume file descriptors, there may not be enough free FDs left over to satisfy fd.c, causing postmaster start to fail. It's also not great in single-user mode, because fd.c will operate with just the minimum allowable value of max_safe_fds, resulting in excess file open/close overhead if anything moderately complicated is done in single-user mode. (There may be some penalty for bootstrap mode too, though probably not much.) Discussion: https://postgr.es/m/2081982.1734393311@sss.pgh.pa.us
1 parent c91963d commit 21fb39c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/backend/bootstrap/bootstrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
334334

335335
CreateSharedMemoryAndSemaphores();
336336

337+
/*
338+
* Estimate number of openable files. This is essential too in --check
339+
* mode, because on some platforms semaphores count as open files.
340+
*/
341+
set_max_safe_fds();
342+
337343
/*
338344
* XXX: It might make sense to move this into its own function at some
339345
* point. Right now it seems like it'd cause more code duplication than

src/backend/tcop/postgres.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,8 +4099,18 @@ PostgresSingleUserMain(int argc, char *argv[],
40994099
*/
41004100
InitializeWalConsistencyChecking();
41014101

4102+
/*
4103+
* Create shared memory etc. (Nothing's really "shared" in single-user
4104+
* mode, but we must have these data structures anyway.)
4105+
*/
41024106
CreateSharedMemoryAndSemaphores();
41034107

4108+
/*
4109+
* Estimate number of openable files. This must happen after setting up
4110+
* semaphores, because on some platforms semaphores count as open files.
4111+
*/
4112+
set_max_safe_fds();
4113+
41044114
/*
41054115
* Remember stand-alone backend startup time,roughly at the same point
41064116
* during startup that postmaster does so.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy