初步学习pg_control文件之三

接前文,初步学习pg_control文件之二

继续学习:

研究 DBState,先研究 DB_IN_PRODUCTION ,看它如何出现:

它出现在启动Postmaster时运行的函数处:

/*                                            
 * This must be called ONCE during postmaster or standalone-backend startup
 */                                            
void                                            
StartupXLOG(void)                                            
{                                            
    …                                                                
    /*                                        
     * Read control file and check XLOG status looks valid.  
     * Note: in most control paths, *ControlFile is already valid and we need   
     * not do ReadControlFile() here, but might as well do it to be sure. 
     */                                        
    ReadControlFile();                                        
                                            
    if (ControlFile->state < DB_SHUTDOWNED ||                                        
        ControlFile->state > DB_IN_PRODUCTION ||                                    
        !XRecOffIsValid(ControlFile->checkPoint.xrecoff))                                    
        ereport(FATAL,(errmsg("control file contains invalid data")));                            
                                            
    if (ControlFile->state == DB_SHUTDOWNED)                                        
        ereport(LOG, errmsg("database system was shut down at %s", str_time(ControlFile->time))));                    
    else if (ControlFile->state == DB_SHUTDOWNED_IN_RECOVERY)                                        
        ereport(LOG,(errmsg("database system was shut down in recovery at %s", 
str_time(ControlFile
->time))));
else if (ControlFile->state == DB_SHUTDOWNING) ereport(LOG,(errmsg("database system shutdown was interrupted; last known up at %s",
str_time(ControlFile
->time)))); else if (ControlFile->state == DB_IN_CRASH_RECOVERY) ereport(LOG, (errmsg("database system was interrupted while in recovery at %s", str_time(ControlFile->time)), errhint("This probably means that some data is corrupted and" you will have to use the last backup for recovery.))); else if (ControlFile->state == DB_IN_ARCHIVE_RECOVERY) ereport(LOG, (errmsg("database system was interrupted while in recovery at log time %s", str_time(ControlFile->checkPointCopy.time)), errhint("If this has occurred more than once some data might be corrupted and you might need to choose an earlier recovery target."))); else if (ControlFile->state == DB_IN_PRODUCTION) ereport(LOG,(errmsg("database system was interrupted; last known up at %s", str_time(ControlFile->time)))); /* This is just to allow attaching to startup process with a debugger */ #ifdef XLOG_REPLAY_DELAY if (ControlFile->state != DB_SHUTDOWNED) pg_usleep(60000000L); #endif /* * Check whether we need to force recovery from WAL. If it appears to * have been a clean shutdown and we did not have a recovery.conf file, * then assume no recovery needed. */ if (XLByteLT(checkPoint.redo, RecPtr)) { … } else if (ControlFile->state != DB_SHUTDOWNED) InRecovery = true; else if (InArchiveRecovery) { /* force recovery due to presence of recovery.conf */ InRecovery = true; } /* REDO */ if (InRecovery) { … /* * Update pg_control to show that we are recovering and to show the * selected checkpoint as the place we are starting from. We also mark * pg_control with any minimum recovery stop point obtained from a * backup history file. */ if (InArchiveRecovery) ControlFile->state = DB_IN_ARCHIVE_RECOVERY; else { ereport(LOG, (errmsg("database system was not properly shut down; " automatic recovery in progress))); ControlFile->state = DB_IN_CRASH_RECOVERY; } … } … /* * Okay, we're officially UP. */ InRecovery = false; LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); ControlFile->state = DB_IN_PRODUCTION; ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); LWLockRelease(ControlFileLock); … }

可以说,只要是正常启动了,那么就是DB_IN_PRODUCTION状态。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值