mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	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
This commit is contained in:
		@@ -334,6 +334,12 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	CreateSharedMemoryAndSemaphores();
 | 
						CreateSharedMemoryAndSemaphores();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Estimate number of openable files.  This is essential too in --check
 | 
				
			||||||
 | 
						 * mode, because on some platforms semaphores count as open files.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						set_max_safe_fds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * XXX: It might make sense to move this into its own function at some
 | 
						 * XXX: It might make sense to move this into its own function at some
 | 
				
			||||||
	 * point. Right now it seems like it'd cause more code duplication than
 | 
						 * point. Right now it seems like it'd cause more code duplication than
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4099,8 +4099,18 @@ PostgresSingleUserMain(int argc, char *argv[],
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	InitializeWalConsistencyChecking();
 | 
						InitializeWalConsistencyChecking();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Create shared memory etc.  (Nothing's really "shared" in single-user
 | 
				
			||||||
 | 
						 * mode, but we must have these data structures anyway.)
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
	CreateSharedMemoryAndSemaphores();
 | 
						CreateSharedMemoryAndSemaphores();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Estimate number of openable files.  This must happen after setting up
 | 
				
			||||||
 | 
						 * semaphores, because on some platforms semaphores count as open files.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						set_max_safe_fds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Remember stand-alone backend startup time,roughly at the same point
 | 
						 * Remember stand-alone backend startup time,roughly at the same point
 | 
				
			||||||
	 * during startup that postmaster does so.
 | 
						 * during startup that postmaster does so.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user