zoukankan      html  css  js  c++  java
  • 初步学习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状态。

  • 相关阅读:
    设计模式(6)--Adapter(适配器模式)--结构型
    设计模式原则(1)--Single Responsibility Principle(SRP)--单一职责原则
    设计模式(5)--Builder(建造模式)--创建型
    设计模式(4)--AbstractFactory(抽象工厂模式)--创建型
    设计模式(3)--SimpleFactory( [1] 简单工厂模式)--创建型
    JS 的map和array集合组合返回JSON字符串
    HTML中直接写js 函数
    设计模式(3)--FactoryMethod( [2] 工厂方法模式)--创建型
    图片剪贴工具类
    远程Get,Post请求工具类
  • 原文地址:https://www.cnblogs.com/gaojian/p/3227640.html
Copyright © 2011-2022 走看看