初步学习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状态。
初步学习pg_control文件之三的更多相关文章
- 初步学习pg_control文件之四
接前文,初步学习pg_control文件之三 继续分析 何时出现 DB_SHUTDOWNING状态: 在正常的shutdown的时候,需要进行checkpoint,所以就在此处,设置pg_contr ...
- 初步学习pg_control文件之十五
接前文 初步学习pg_control文件之十四 再看如下这个: int MaxConnections; 应该说,它是一个参考值,在global.c中有如下定义 /* * Primary determ ...
- 初步学习pg_control文件之十四
接前文 初步学习pg_control文件之十三 看如下几个: /* * Parameter settings that determine if the WAL can be used for arc ...
- 初步学习pg_control文件之十三
接前文,初步学习pg_control文件之十二 看这个: * backupStartPoint is the redo pointer of the backup start checkpoint, ...
- 初步学习pg_control文件之十二
接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...
- 初步学习pg_control文件之十一
接前文 初步学习pg_control文件之十,再看这个 XLogRecPtr prevCheckPoint; /* previous check point record ptr */ 发生了che ...
- 初步学习pg_control文件之十
接前文 初步学习pg_control文件之九 看下面这个 XLogRecPtr checkPoint; /* last check point record ptr */ 看看这个pointer究竟保 ...
- 初步学习pg_control文件之九
接前文,初步学习pg_control文件之八 来看这个: pg_time_t time; /* time stamp of last pg_control update */ 当初初始化的时候,是这样 ...
- 初步学习pg_control文件之八
接前文 初步学习pg_control文件之七 继续 看:catalog_version_no 代码如下: static void WriteControlFile(void) { ... /* * ...
随机推荐
- 遍历目录树 - Unicode 模式
=info 遍历目录树 支持 Unicode Code by 523066680@163.com 2017-03 V0.5 使用Win32API判断目录硬链接 ...
- *Amazon problem: 234. Palindrome Linked List (reverse the linked list with n time)
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...
- Django:模板系统
一,常用语法 只需要记两种特殊符号: {{ }}和 {% %} 变量相关的用{{}},逻辑相关的用{%%}. 二,常量 {{ 变量名 }} 变量名由字母数字和下划线组成. 点(.)在模板语言中有特殊 ...
- 【转】Android手机分辨率基础知识(DPI,DIP计算)
1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机是3.7英寸 A ...
- HDU 5025 Saving Tang Monk 【状态压缩BFS】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Time Limit: 2000/1000 MS (Java/O ...
- mysql中set和enum使用(简单介绍)
简单介绍 SET类型 在创建表时,就指定SET类型的取值范围. 属性名 SET('值1','值2','值3'...,'值n') 其中,“属性名”参数指字段的名称:“值n”参数表示列表中的第n个值,这些 ...
- java操作文件常用的 IO流对象
1.描述:流是字节数据或字符数据序列.Java采用输入流对象和输出流对象来支持程序对数据的输入和输出.输入流对象提供了数据从源点流向程序的管道,程序可以从输入流对象读取数据:输出流对象提供了数据从程序 ...
- select 文字右对齐
select { direction: rtl; } select option { direction: ltr; }
- Redis-cluster详解
redis集群结构 特点: 1 所有redis节点(包括主和从)彼此互联(两两通信),底层使用内部的二进制传输协议,优化传输速度;(所有功能特点的基础) 2 集群中也有主从,也有高可用的 ...
- python 之函数
一 函数的定义:对功能和动作的封装和定义.二 函数的格式:def 函数名(形参列表): 函数名就是变量名:规则就是变量的规则 函数体(return) ret = 函数名(实参列表)三 函数的返回值:函 ...