博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
初步学习pg_control文件之三
阅读量:6148 次
发布时间:2019-06-21

本文共 7095 字,大约阅读时间需要 23 分钟。

接前文,

继续学习:

研究 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);                                                                                        …                                                                                    }

转载地址:http://xvqya.baihongyu.com/

你可能感兴趣的文章
用js使得输入框input只能输入数字
查看>>
Python函数
查看>>
每日记录 2016-4-29 HTML5本地存储
查看>>
BZOJ3236:[AHOI2013]作业(莫队,分块)
查看>>
使用jquery.PrintArea.js打印网页的样式问题
查看>>
hihoCoder1603
查看>>
63. Unique Paths II
查看>>
【转载】MiniUtilityFramework(三):配置文件概述
查看>>
eclipse 的代码着色插件 --Eclipse Color Theme
查看>>
Java日志系统(上)
查看>>
java中的String类常量池详解
查看>>
合并文件内容
查看>>
GPU大百科全书索引(有助于理解openGL工作流程)
查看>>
swing之JButton简单封装
查看>>
ZJOI2006 书架
查看>>
教您如何检查oracle死锁,决解死锁
查看>>
JQ-weui中的日期选择控件关于时间段的设置!
查看>>
文献随笔(一)
查看>>
C++ 小复习
查看>>
YII2中查询生成器Query()的使用
查看>>