初步学习pg_control文件之三
2024-10-21 09:18:28
继续学习:
研究 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状态。
最新文章
- linux下更新python
- js string to int
- 购买 CDRTools 2 正式版
- 一些 CSS 框架
- 整理 C#(同步调用、异步调用、异步回调)
- JAVA必备——Struts
- Tomcat修改端口
- Eclipse两种部署web项目方法
- kubernetes 安装metrics-server
- Netty 系列六(编解码器).
- websocket是什么
- Codeforces 15E Triangles - 组合数学
- 数据准备<;4>;:变量筛选-理论篇
- doGet和doPost区别
- 「专题训练」Air Raid(HDU-1151)
- DATE类型数据在MySql中减一天的问题
- 吴恩达《Machine Learning Yearning》总结(21-30章)
- 2、开发环境搭建-window平台
- Apache2服务配置ubuntu16.04+django1.11
- Spring入门第五课
热门文章
- 如何在ubuntu上安装virtualbox的driver module vboxdrv
- python入门6 字符串拼接、格式化输出
- Andriod ADB Interface驱动安装失败Configure USB Debug for Android
- Uva 11600 期望DP
- 【转】netstat 命令当中的内部地址和外部地址分别代表的是什么?
- [19/03/15-星期五] 常用类_String类&;StringBuilder和StringBuffer类
- [18/12/01]super 关键字和final 关键字
- stixel-net绘制指标图
- Idea Find in Path 全局搜索的功能
- PAT (Basic Level) Practise (中文)-1040. 有几个PAT(25)