初步学习pg_control文件之四

简介:

接前文,初步学习pg_control文件之三  继续分析

何时出现 DB_SHUTDOWNING状态:

在正常的shutdown的时候,需要进行checkpoint,所以就在此处,设置pg_control文件的state状态为DB_SHUTDOWNING。

复制代码
/*
 * Perform a checkpoint --- either during shutdown, or on-the-fly
 *
 * flags is a bitwise OR of the following:
 *    CHECKPOINT_IS_SHUTDOWN: checkpoint is for database shutdown.
 *    CHECKPOINT_END_OF_RECOVERY: checkpoint is for end of WAL recovery.
 *    CHECKPOINT_IMMEDIATE: finish the checkpoint ASAP,
 *        ignoring checkpoint_completion_target parameter.
 *    CHECKPOINT_FORCE: force a checkpoint even if no XLOG activity has occured
 *        since the last one (implied by CHECKPOINT_IS_SHUTDOWN or
 *        CHECKPOINT_END_OF_RECOVERY).
 *
 * Note: flags contains other bits, of interest here only for logging purposes.
 * In particular note that this routine is synchronous and does not pay
 * attention to CHECKPOINT_WAIT.
 */
void
CreateCheckPoint(int flags)
{
    ...
    if (shutdown)
    {
        LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
        ControlFile->state = DB_SHUTDOWNING;
        ControlFile->time = (pg_time_t) time(NULL);
        UpdateControlFile();
        LWLockRelease(ControlFileLock);
    }
    ...
}
复制代码

更进一步地说,是这样的:先是Shutdowning, 后来就变化为Shutdowned

复制代码
/*                            
 * Perform a checkpoint --- either during shutdown, or on-the-fly                            
 *                            
 * flags is a bitwise OR of the following:                            
 *    CHECKPOINT_IS_SHUTDOWN: checkpoint is for database shutdown.                        
 *    CHECKPOINT_END_OF_RECOVERY: checkpoint is for end of WAL recovery.                        
 *    CHECKPOINT_IMMEDIATE: finish the checkpoint ASAP,                        
 *        ignoring checkpoint_completion_target parameter.                    
 *    CHECKPOINT_FORCE: force a checkpoint even if no XLOG activity has occured                        
 *        since the last one (implied by CHECKPOINT_IS_SHUTDOWN or                    
 *        CHECKPOINT_END_OF_RECOVERY).                    
 *                            
 * Note: flags contains other bits, of interest here only for logging purposes.                            
 * In particular note that this routine is synchronous and does not pay                            
 * attention to CHECKPOINT_WAIT.                            
 */                            
void                            
CreateCheckPoint(int flags)                            
{                            
    …                        
                            
    if (shutdown)                        
    {                        
        LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);                    
        ControlFile->state = DB_SHUTDOWNING;                    
        ControlFile->time = (pg_time_t) time(NULL);                    
        UpdateControlFile();                    
        LWLockRelease(ControlFileLock);                    
    }                        
    …                        
                            
    /*                        
     * Update the control file.                        
     */                        
    LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);                        
    if (shutdown)                        
        ControlFile->state = DB_SHUTDOWNED;                    
                            
    ControlFile->prevCheckPoint = ControlFile->checkPoint;                        
    …                        
}                            
复制代码
目录
相关文章
|
关系型数据库 PostgreSQL