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

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

接前文:

继续学习,pg_control文件在何处形成的?是在initdb的时候,运用的函数如下:
/* * This func must be called ONCE on system install.  It creates pg_control * and the initial XLOG segment. */voidBootStrapXLOG(void){    CheckPoint    checkPoint;    char       *buffer;    XLogPageHeader page;    XLogLongPageHeader longpage;    XLogRecord *record;    bool        use_existent;    uint64        sysidentifier;    struct timeval tv;    pg_crc32    crc;    /*     * Select a hopefully-unique system identifier code for this installation.     * We use the result of gettimeofday(), including the fractional seconds     * field, as being about as unique as we can easily get.  (Think not to     * use random(), since it hasn't been seeded and there's no portable way     * to seed it other than the system clock value...)  The upper half of the     * uint64 value is just the tv_sec part, while the lower half is the XOR     * of tv_sec and tv_usec.  This is to ensure that we don't lose uniqueness     * unnecessarily if "uint64" is really only 32 bits wide.  A person     * knowing this encoding can determine the initialization time of the     * installation, which could perhaps be useful sometimes.     */    gettimeofday(&tv, NULL);    sysidentifier = ((uint64) tv.tv_sec) << 32;    sysidentifier |= (uint32) (tv.tv_sec | tv.tv_usec);    ...    /* Now create pg_control */    memset(ControlFile, 0, sizeof(ControlFileData));    /* Initialize pg_control status fields */    ControlFile->system_identifier = sysidentifier;    ControlFile->state = DB_SHUTDOWNED;    ControlFile->time = checkPoint.time;    ControlFile->checkPoint = checkPoint.redo;    ControlFile->checkPointCopy = checkPoint;    /* Set important parameter values for use when replaying WAL */    ControlFile->MaxConnections = MaxConnections;    ControlFile->max_prepared_xacts = max_prepared_xacts;    ControlFile->max_locks_per_xact = max_locks_per_xact;    ControlFile->wal_level = wal_level;    /* some additional ControlFile fields are set in WriteControlFile() */    WriteControlFile();    /* Bootstrap the commit log, too */    BootStrapCLOG();    BootStrapSUBTRANS();    BootStrapMultiXact();    pfree(buffer);}
说起来 system_identifier 这个东西 ,是随机算出来的一个值:
/*     * Select a hopefully-unique system identifier code for this installation.     * We use the result of gettimeofday(), including the fractional seconds     * field, as being about as unique as we can easily get.  (Think not to     * use random(), since it hasn't been seeded and there's no portable way     * to seed it other than the system clock value...)  The upper half of the     * uint64 value is just the tv_sec part, while the lower half is the XOR     * of tv_sec and tv_usec.  This is to ensure that we don't lose uniqueness     * unnecessarily if "uint64" is really only 32 bits wide.  A person     * knowing this encoding can determine the initialization time of the     * installation, which could perhaps be useful sometimes.     */    gettimeofday(&tv, NULL);    sysidentifier = ((uint64) tv.tv_sec) << 32;    sysidentifier |= (uint32) (tv.tv_sec | tv.tv_usec);...    ControlFile->system_identifier = sysidentifier;

 state 在初始化的时候,是有SHUTDOWNED。另外可能的值也都可以在pg_control.h中看到:

/* * System status indicator.  Note this is stored in pg_control; if you change * it, you must bump PG_CONTROL_VERSION */typedef enum DBState{    DB_STARTUP = 0,    DB_SHUTDOWNED,    DB_SHUTDOWNED_IN_RECOVERY,    DB_SHUTDOWNING,    DB_IN_CRASH_RECOVERY,    DB_IN_ARCHIVE_RECOVERY,    DB_IN_PRODUCTION} DBState;

这几个值何时用,状态如何变化,应该是一个很有意思的话题。  

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

你可能感兴趣的文章
vsftp简单安装
查看>>
SonarQub代码分析平台部署
查看>>
在Server 2019中安装.NET Framework 3.5功能
查看>>
Maven工程依赖,聚合,继承学习笔记
查看>>
CentOS 6.2 下编译使用Libvlc
查看>>
用报表工具创建动态查询的方法
查看>>
HQL: Hibernate查询语言
查看>>
mongodb安装配置以及其他基础操作
查看>>
虚拟化系统VMware vSphere
查看>>
SQLite中的WHERE子句
查看>>
恢复数据库时遇到无法独占错误
查看>>
Ubuntu下postgres的一些操作总结
查看>>
期末liao
查看>>
Linux学习日记--基础命令(7)--bash中的变量,配置文件
查看>>
dig命令使用大全(linux上域名查询)
查看>>
恢复在WIN64上的SSDT钩子
查看>>
nmap扫描工具
查看>>
zabbix通过JMX监控tomcat,防火墙策略配置
查看>>
Qt的Socket数据通讯的一个例子。
查看>>
删除 sybase中测试表中的重复行
查看>>