接前文  初步学习pg_control文件之十四

再看如下这个:

int            MaxConnections;

应该说,它是一个参考值,在global.c中有如下定义

/*
* Primary determinants of sizes of shared-memory structures. MaxBackends is
* MaxConnections + autovacuum_max_workers + 1 (it is computed by the GUC
* assign hooks for those variables):
*/
int NBuffers = ;
int MaxBackends = ;
int MaxConnections = ;
/*
* This must be called ONCE during postmaster or standalone-backend startup
*/
void
StartupXLOG(void)
{

/*
* If any of the critical GUCs have changed, log them before we allow
* backends to write WAL.
*/
LocalSetXLogInsertAllowed();
XLogReportParameters(); …
}
/*
* Check if any of the GUC parameters that are critical for hot standby
* have changed, and update the value in pg_control file if necessary.
*/
static void
XLogReportParameters(void)
{
if (wal_level != ControlFile->wal_level ||
MaxConnections != ControlFile->MaxConnections ||
max_prepared_xacts != ControlFile->max_prepared_xacts ||
max_locks_per_xact != ControlFile->max_locks_per_xact)
{
ControlFile->MaxConnections = MaxConnections;
ControlFile->max_prepared_xacts = max_prepared_xacts;
ControlFile->max_locks_per_xact = max_locks_per_xact;
ControlFile->wal_level = wal_level;
UpdateControlFile();
}
}

它就是一个参考值:

/*
* This must be called ONCE during postmaster or standalone-backend startup
*/
void
StartupXLOG(void)
{
… /* REDO */
if (InRecovery)
{

/* Check that the GUCs used to generate the WAL allow recovery */
CheckRequiredParameterValues(); …
if (record != NULL)
{

/*
* main redo apply loop
*/
do
{

/*
* If we are attempting to enter Hot Standby mode, process
* XIDs we see
*/
if (standbyState >= STANDBY_INITIALIZED &&
TransactionIdIsValid(record->xl_xid))
RecordKnownAssignedTransactionIds(record->xl_xid); RmgrTable[record->xl_rmid].rm_redo(EndRecPtr, record);
… } while (record != NULL && recoveryContinue);

}

}

}
/*
* XLOG resource manager's routines
*
* Definitions of info values are in include/catalog/pg_control.h, though
* not all record types are related to control file updates.
*/
void
xlog_redo(XLogRecPtr lsn, XLogRecord *record)
{

if (info == XLOG_NEXTOID)
{

}

else if (info == XLOG_PARAMETER_CHANGE)
{

/* Check to see if any changes to max_connections give problems */
CheckRequiredParameterValues();
}
}

再看下面:

/*
* Check to see if required parameters are set high enough on this server
* for various aspects of recovery operation.
*/
static void
CheckRequiredParameterValues(void)
{
... if (InArchiveRecovery && EnableHotStandby)
{
.../* We ignore autovacuum_max_workers when we make this test. */
RecoveryRequiresIntParameter("max_connections",
MaxConnections,
ControlFile->MaxConnections);
...

}
}
04-21 00:09