@ -993,7 +993,113 @@ PostmasterMain(int argc, char *argv[])
*/
*/
InitializeMaxBackends ( ) ;
InitializeMaxBackends ( ) ;
/* Report server startup in log */
/*
* Set up shared memory and semaphores .
*/
reset_shared ( ) ;
/*
* 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 ( ) ;
/*
* Set reference point for stack - depth checking .
*/
set_stack_base ( ) ;
/*
* Initialize pipe ( or process handle on Windows ) that allows children to
* wake up from sleep on postmaster death .
*/
InitPostmasterDeathWatchHandle ( ) ;
# ifdef WIN32
/*
* Initialize I / O completion port used to deliver list of dead children .
*/
win32ChildQueue = CreateIoCompletionPort ( INVALID_HANDLE_VALUE , NULL , 0 , 1 ) ;
if ( win32ChildQueue = = NULL )
ereport ( FATAL ,
( errmsg ( " could not create I/O completion port for child queue " ) ) ) ;
# endif
# ifdef EXEC_BACKEND
/* Write out nondefault GUC settings for child processes to use */
write_nondefault_variables ( PGC_POSTMASTER ) ;
/*
* Clean out the temp directory used to transmit parameters to child
* processes ( see internal_forkexec , below ) . We must do this before
* launching any child processes , else we have a race condition : we could
* remove a parameter file before the child can read it . It should be
* safe to do so now , because we verified earlier that there are no
* conflicting Postgres processes in this data directory .
*/
RemovePgTempFilesInDir ( PG_TEMP_FILES_DIR , true , false ) ;
# endif
/*
* Forcibly remove the files signaling a standby promotion request .
* Otherwise , the existence of those files triggers a promotion too early ,
* whether a user wants that or not .
*
* This removal of files is usually unnecessary because they can exist
* only during a few moments during a standby promotion . However there is
* a race condition : if pg_ctl promote is executed and creates the files
* during a promotion , the files can stay around even after the server is
* brought up to new master . Then , if new standby starts by using the
* backup taken from that master , the files can exist at the server
* startup and should be removed in order to avoid an unexpected
* promotion .
*
* Note that promotion signal files need to be removed before the startup
* process is invoked . Because , after that , they can be used by
* postmaster ' s SIGUSR1 signal handler .
*/
RemovePromoteSignalFiles ( ) ;
/* Do the same for logrotate signal file */
RemoveLogrotateSignalFiles ( ) ;
/* Remove any outdated file holding the current log filenames. */
if ( unlink ( LOG_METAINFO_DATAFILE ) < 0 & & errno ! = ENOENT )
ereport ( LOG ,
( errcode_for_file_access ( ) ,
errmsg ( " could not remove file \" %s \" : %m " ,
LOG_METAINFO_DATAFILE ) ) ) ;
/*
* If enabled , start up syslogger collection subprocess
*/
SysLoggerPID = SysLogger_Start ( ) ;
/*
* Reset whereToSendOutput from DestDebug ( its starting state ) to
* DestNone . This stops ereport from sending log messages to stderr unless
* Log_destination permits . We don ' t do this until the postmaster is
* fully launched , since startup failures may as well be reported to
* stderr .
*
* If we are in fact disabling logging to stderr , first emit a log message
* saying so , to provide a breadcrumb trail for users who may not remember
* that their logging is configured to go somewhere else .
*/
if ( ! ( Log_destination & LOG_DESTINATION_STDERR ) )
ereport ( LOG ,
( errmsg ( " ending log output to stderr " ) ,
errhint ( " Future log output will go to log destination \" %s \" . " ,
Log_destination_string ) ) ) ;
whereToSendOutput = DestNone ;
/*
* Report server startup in log . While we could emit this much earlier ,
* it seems best to do so after starting the log collector , if we intend
* to use one .
*/
ereport ( LOG ,
ereport ( LOG ,
( errmsg ( " starting %s " , PG_VERSION_STR ) ) ) ;
( errmsg ( " starting %s " , PG_VERSION_STR ) ) ) ;
@ -1172,51 +1278,13 @@ PostmasterMain(int argc, char *argv[])
if ( ! listen_addr_saved )
if ( ! listen_addr_saved )
AddToDataDirLockFile ( LOCK_FILE_LINE_LISTEN_ADDR , " " ) ;
AddToDataDirLockFile ( LOCK_FILE_LINE_LISTEN_ADDR , " " ) ;
/*
* Set up shared memory and semaphores .
*/
reset_shared ( ) ;
/*
* 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 ( ) ;
/*
* Set reference point for stack - depth checking .
*/
set_stack_base ( ) ;
/*
* Initialize pipe ( or process handle on Windows ) that allows children to
* wake up from sleep on postmaster death .
*/
InitPostmasterDeathWatchHandle ( ) ;
# ifdef WIN32
/*
* Initialize I / O completion port used to deliver list of dead children .
*/
win32ChildQueue = CreateIoCompletionPort ( INVALID_HANDLE_VALUE , NULL , 0 , 1 ) ;
if ( win32ChildQueue = = NULL )
ereport ( FATAL ,
( errmsg ( " could not create I/O completion port for child queue " ) ) ) ;
# endif
/*
/*
* Record postmaster options . We delay this till now to avoid recording
* Record postmaster options . We delay this till now to avoid recording
* bogus options ( eg , NBuffers too high for available memory ) .
* bogus options ( eg , unusable port number ) .
*/
*/
if ( ! CreateOptsFile ( argc , argv , my_exec_path ) )
if ( ! CreateOptsFile ( argc , argv , my_exec_path ) )
ExitPostmaster ( 1 ) ;
ExitPostmaster ( 1 ) ;
# ifdef EXEC_BACKEND
/* Write out nondefault GUC settings for child processes to use */
write_nondefault_variables ( PGC_POSTMASTER ) ;
# endif
/*
/*
* Write the external PID file if requested
* Write the external PID file if requested
*/
*/
@ -1247,60 +1315,6 @@ PostmasterMain(int argc, char *argv[])
*/
*/
RemovePgTempFiles ( ) ;
RemovePgTempFiles ( ) ;
/*
* Forcibly remove the files signaling a standby promotion request .
* Otherwise , the existence of those files triggers a promotion too early ,
* whether a user wants that or not .
*
* This removal of files is usually unnecessary because they can exist
* only during a few moments during a standby promotion . However there is
* a race condition : if pg_ctl promote is executed and creates the files
* during a promotion , the files can stay around even after the server is
* brought up to new master . Then , if new standby starts by using the
* backup taken from that master , the files can exist at the server
* startup and should be removed in order to avoid an unexpected
* promotion .
*
* Note that promotion signal files need to be removed before the startup
* process is invoked . Because , after that , they can be used by
* postmaster ' s SIGUSR1 signal handler .
*/
RemovePromoteSignalFiles ( ) ;
/* Do the same for logrotate signal file */
RemoveLogrotateSignalFiles ( ) ;
/* Remove any outdated file holding the current log filenames. */
if ( unlink ( LOG_METAINFO_DATAFILE ) < 0 & & errno ! = ENOENT )
ereport ( LOG ,
( errcode_for_file_access ( ) ,
errmsg ( " could not remove file \" %s \" : %m " ,
LOG_METAINFO_DATAFILE ) ) ) ;
/*
* If enabled , start up syslogger collection subprocess
*/
SysLoggerPID = SysLogger_Start ( ) ;
/*
* Reset whereToSendOutput from DestDebug ( its starting state ) to
* DestNone . This stops ereport from sending log messages to stderr unless
* Log_destination permits . We don ' t do this until the postmaster is
* fully launched , since startup failures may as well be reported to
* stderr .
*
* If we are in fact disabling logging to stderr , first emit a log message
* saying so , to provide a breadcrumb trail for users who may not remember
* that their logging is configured to go somewhere else .
*/
if ( ! ( Log_destination & LOG_DESTINATION_STDERR ) )
ereport ( LOG ,
( errmsg ( " ending log output to stderr " ) ,
errhint ( " Future log output will go to log destination \" %s \" . " ,
Log_destination_string ) ) ) ;
whereToSendOutput = DestNone ;
/*
/*
* Initialize stats collection subsystem ( this does NOT start the
* Initialize stats collection subsystem ( this does NOT start the
* collector process ! )
* collector process ! )