初步学习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); … }
复制代码
目录
相关文章
|
存储 C语言
【c语言指针详解】指针的基本概念和用法
【c语言指针详解】指针的基本概念和用法
505 0
|
安全 Linux Shell
structure needs cleaning结构需要清理解决方案
structure needs cleaning结构需要清理解决方案
4720 0
|
11月前
|
机器学习/深度学习 移动开发 数据挖掘
Python是一种广泛使用的高级编程语言,具有许多优点和缺点
Python是一种广泛使用的高级编程语言,具有许多优点和缺点
451 1
|
Linux Python
Linux离线安装Python第三方库Requests
本文介绍了在无法连接外网的Linux服务器上离线安装Python第三方库Requests的过程,包括下载依赖包、解决依赖问题并成功安装的步骤。
1219 0
|
存储 C语言
【C语言基础】一篇文章搞懂指针的基本使用
本文介绍了指针的概念及其在编程中的应用。指针本质上是内存地址,通过指针变量存储并间接访问内存中的值。定义指针变量的基本格式为 `基类型 *指针变量名`。取地址操作符`&`用于获取变量地址,取值操作符`*`用于获取地址对应的数据。指针的应用场景包括传递变量地址以实现在函数间修改值,以及通过对指针进行偏移来访问数组元素等。此外,还介绍了如何使用`malloc`动态申请堆内存,并需手动释放。
329 9
|
存储 编译器 程序员
C语言程序的基本结构
C语言程序的基本结构包括:1)预处理指令,如 `#include` 和 `#define`;2)主函数 `main()`,程序从这里开始执行;3)函数声明与定义,执行特定任务的代码块;4)变量声明与初始化,用于存储数据;5)语句和表达式,构成程序基本执行单位;6)注释,解释代码功能。示例代码展示了这些组成部分的应用。
566 10
|
Linux iOS开发 MacOS
Python系统编程高手进阶:跨平台兼容性?小菜一碟💪
【9月更文挑战第6天】当我们探讨Python系统编程时,跨平台兼容性至关重要。Python凭借其解释型语言特性和多平台解释器,确保了代码能够在Windows、Linux、macOS等多种环境中顺畅运行。本文将介绍Python跨平台运行的基本原理,以及如何处理文件路径差异和系统调用等问题,助你轻松应对跨平台挑战。
326 1
|
资源调度 JavaScript 前端开发
安装 Nuxt.js 的步骤和注意事项
【8月更文挑战第6天】
391 3
|
存储 安全 算法
密钥密码学(一)(4)
密钥密码学(一)
365 2
|
JSON JavaScript 前端开发
一篇文章讲明白json文件格式详解
一篇文章讲明白json文件格式详解
718 0