这个据说是PostgreSQL的control file。

到底如何呢,先看看改名后如何,把pg_control文件改名,然后启动 Postgres,运行时得到信息:

[postgres@pg101 bin]$ postgres: could not find the database system
Expected to find it in the directory "/usr/local/pgsql/bin/../data",
but could not open file "/usr/local/pgsql/bin/../data/global/pg_control": No Such file or Directory

对应的源代码,在postmater.c的 checkDataDir方法中:

        snprintf(path, sizeof(path), "%s/global/pg_control", DataDir);fp = AllocateFile(path, PG_BINARY_R);if (fp == NULL){write_stderr("%s: could not find the database system\n""Expected to find it in the directory \"%s\",\n""but could not open file \"%s\": %s\n",progname, DataDir, path, strerror(errno));ExitPostmaster(2);}FreeFile(fp);

将 pg_control文件改回原来的名字后,重新启动PostgreSQL数据库,没有问题。

而在main.c中,有如下代码:

从注释中可以看到,数据库中初始化后,会有LC_CTYPE/LC_COLLATE等信息已经写入到pg_control文件中。

        /** Set up locale information from environment.  Note that LC_CTYPE and* LC_COLLATE will be overridden later from pg_control if we are in an* already-initialized database.  We set them here so that they will be* available to fill pg_control during initdb.  LC_MESSAGES will get set* later during GUC option processing, but we set it here to allow startup* error messages to be localized.*/set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres"));

在 src/backend/access/transam/xlog.c 中,有如下代码:

/** We maintain an image of pg_control in shared memory.*/
static ControlFileData *ControlFile = NULL;

可见,与pg_control文件相对应,在内存中保留着一个内存结构。

它长得是这个样子:

/** Contents of pg_control.** NOTE: try to keep this under 512 bytes so that it will fit on one physical* sector of typical disk drives.  This reduces the odds of corruption due to* power failure midway through a write.*/typedef struct ControlFileData
{/** Unique system identifier --- to ensure we match up xlog files with the* installation that produced them.*/uint64        system_identifier;/** Version identifier information.    Keep these fields at the same offset,* especially pg_control_version; they won't be real useful if they move* around.    (For historical reasons they must be 8 bytes into the file* rather than immediately at the front.)** pg_control_version identifies the format of pg_control itself.* catalog_version_no identifies the format of the system catalogs.** There are additional version identifiers in individual files; for* example, WAL logs contain per-page magic numbers that can serve as* version cues for the WAL log.*/uint32        pg_control_version;        /* PG_CONTROL_VERSION */uint32        catalog_version_no;        /* see catversion.h *//** System status data*/DBState        state;            /* see enum above */pg_time_t    time;            /* time stamp of last pg_control update */XLogRecPtr    checkPoint;        /* last check point record ptr */XLogRecPtr    prevCheckPoint; /* previous check point record ptr */CheckPoint    checkPointCopy; /* copy of last check point record *//** These two values determine the minimum point we must recover up to* before starting up:** minRecoveryPoint is updated to the latest replayed LSN whenever we* flush a data change during archive recovery. That guards against* starting archive recovery, aborting it, and restarting with an earlier* stop location. If we've already flushed data changes from WAL record X* to disk, we mustn't start up until we reach X again. Zero when not* doing archive recovery.** backupStartPoint is the redo pointer of the backup start checkpoint, if* we are recovering from an online backup and haven't reached the end of* backup yet. It is reset to zero when the end of backup is reached, and* we mustn't start up before that. A boolean would suffice otherwise, but* we use the redo pointer as a cross-check when we see an end-of-backup* record, to make sure the end-of-backup record corresponds the base* backup we're recovering from.*/XLogRecPtr    minRecoveryPoint;XLogRecPtr    backupStartPoint;/** Parameter settings that determine if the WAL can be used for archival* or hot standby.*/int            wal_level;int            MaxConnections;int            max_prepared_xacts;int            max_locks_per_xact;/** This data is used to check for hardware-architecture compatibility of* the database and the backend executable.  We need not check endianness* explicitly, since the pg_control version will surely look wrong to a* machine of different endianness, but we do need to worry about MAXALIGN* and floating-point format.  (Note: storage layout nominally also* depends on SHORTALIGN and INTALIGN, but in practice these are the same* on all architectures of interest.)** Testing just one double value is not a very bulletproof test for* floating-point compatibility, but it will catch most cases.*/uint32        maxAlign;        /* alignment requirement for tuples */double        floatFormat;    /* constant 1234567.0 */
    #define FLOATFORMAT_VALUE    1234567.0/** This data is used to make sure that configuration of this database is* compatible with the backend executable.*/uint32        blcksz;            /* data block size for this DB */uint32        relseg_size;    /* blocks per segment of large relation */uint32        xlog_blcksz;    /* block size within WAL files */uint32        xlog_seg_size;    /* size of each WAL segment */uint32        nameDataLen;    /* catalog name field width */uint32        indexMaxKeys;    /* max number of columns in an index */uint32        toast_max_chunk_size;    /* chunk size in TOAST tables *//* flag indicating internal format of timestamp, interval, time */bool        enableIntTimes; /* int64 storage enabled? *//* flags indicating pass-by-value status of various types */bool        float4ByVal;    /* float4 pass-by-value? */bool        float8ByVal;    /* float8, int8, etc pass-by-value? *//* CRC of all above ... MUST BE LAST! */pg_crc32    crc;
} ControlFileData;

然后,一个一个地看吧。

初步认识pg_control文件之一相关推荐

  1. 初步学习pg_control文件之三

    接前文,初步学习pg_control文件之二 继续学习: 研究 DBState,先研究 DB_IN_PRODUCTION ,看它如何出现: 它出现在启动Postmaster时运行的函数处: /* * ...

  2. 初步学习pg_control文件之八

    接前文  初步学习pg_control文件之七  继续 看:catalog_version_no 代码如下: static void WriteControlFile(void) {.../** In ...

  3. 初步学习pg_control文件之六

    接前文:初步学习pg_control文件之五 ,DB_IN_ARCHIVE_RECOVERY何时出现? 看代码:如果recovery.conf文件存在,则返回 InArchiveRecovery = ...

  4. 初步学习pg_control文件之十四

    接前文 初步学习pg_control文件之十三 看如下几个: /** Parameter settings that determine if the WAL can be used for arch ...

  5. 初步探讨BitTorrent文件的结构

    初步探讨BitTorrent文件的结构 百度百科介绍: torrent文件本质上是文本文件,包含Tracker信息和文件信息两部分.Tracker信息主要是BT下载中需要用到的Tracker服务器的地 ...

  6. 初步理解MultipartFile[文件上传]

    浅识MultipartFile 一.概述 二.对MultipartFile初步理解 1.MultipartFile类的注释说明 2.MultipartFile常用方法解析 三.MultipartFil ...

  7. 初步学习Linux文件基本属性和Cygwin STATUS_ACCESS_VIOLATION 错误

    安装Cygwin,出现下图错误:Cygwin安装使用见之前的相关博文: 安装完成:使用一下:出现下图异常: base-files-mketc.sh exit code 254 bash 8272 ex ...

  8. Linux Ubuntu 修改Grub,添加删除启动项,初步辨析Grub文件。

    使用场景: 由于我的电脑 装Ubuntu 的时候电脑里只有一个Windows 系统,所以Ubuntu就自动将我Windows的启动项添加进取. 后来我的电脑里又装了 Kali 和 Win11 所以想把 ...

  9. 关于RDP协议的分析 附上RDP 协议初步分析.pdf文件

    关于RDP协议的分析和研究                                         -------------- leadgenius 写这个一是便于学习,再就是与网友们共同讨 ...

最新文章

  1. 2021河南省高考文科成绩排名查询,2021年河南高考成绩排名及一分一段表
  2. Vue实现仿音乐播放器2-新建Vue项目vuemusicplayer
  3. 开源监控解决方案OpenFalcon系列(一)
  4. 持续集成部署Jenkins工作笔记0020---20.在GitHub上创建WebHook
  5. 第三周 分队列 mooc 翁恺 c语言
  6. 利用Python K-means实现简单图像聚类
  7. 熊市投身区块链,程序员的出路在哪里?
  8. 《Ruby程序员修炼之道》(第2版)—第1章1.1节进入Ruby的世界
  9. Oracle标准建表语句
  10. 使用计算机辅助翻译的基本流程,计算机辅助翻译不同于机器翻译,计算机辅助翻译的原理和流程...
  11. Contextual Diversity for Active Learning阅读笔记
  12. openbravo erp介绍(一)
  13. 【转】抽象基类与接口,共性与个性的选择!
  14. 当MySQL想恋爱,java和navicate抢着做媒婆 ------ java连接MySQL数据库 navicat for MySQL 连接
  15. mysql必知必会第5版pdf_sql必知必会
  16. 一步一步学习DVWA渗透测试(CSP Bypass绕过内容安全策略)-第十二次课
  17. wpf TextBox日志文本框
  18. distinct (去重)
  19. .exp是什么文件格式
  20. 哈工大2022秋计算机系统大作业-程序人生(Hello‘s P2P)

热门文章

  1. Python面向对象程序设计之抽象工厂模式之二-一个更加pythonic的抽象工厂
  2. JUC——线程同步锁(ReentrantLock)
  3. 简简单单的正则表单验证练习
  4. wordpress hmailserver等相关 3
  5. [转]C#开发ActiveX控件,.NET开发OCX控件案例
  6. 社会大学的作业,活动篇
  7. 去云南品味彝族的砣砣肉
  8. 云间来客 --- Java 目录大纲
  9. html css整理笔记,HTML CSS整理笔记 (八) 定位网页元素
  10. BZOJ1103: [POI2007]大都市meg