当前位置:网站首页>Postgresql源码(7)Xlog格式
Postgresql源码(7)Xlog格式
2022-07-16 11:29:00 【mingjie】
日志头格式
typedef struct XLogPageHeaderData
{
【校验用magic数字】
uint16 xlp_magic; /* magic value for correctness checks */
【标志位信息】
uint16 xlp_info; /* flag bits, see below */
【时间线信息】
TimeLineID xlp_tli; /* TimeLineID of first record on page */
【当前页面在日志文件中的位置】
XLogRecPtr xlp_pageaddr; /* XLOG address of this page */
【日志跨页面保存,当前页面需要存的剩下的长度】
uint32 xlp_rem_len; /* total len of remaining data for record */
} XLogPageHeaderData;文件结构
XLOG RECORD
日志之间有链接关系,xl_prev指向上一条日志的起始位置,下一条日志的位置用xl_tot_len可以找到,日志之间形成“双向链表”。
typedef struct XLogRecord
{
【日记长度】
uint32 xl_tot_len; /* total len of entire record */
【事务ID】
TransactionId xl_xid; /* xact id */
【上一条日志的LSN】
XLogRecPtr xl_prev; /* ptr to previous record in log */
【产生这个记录的动作】
uint8 xl_info; /* flag bits, see below */
【日志记录对应的资源管理器】
RmgrId xl_rmid; /* resource manager for this record */
/* 2 bytes of padding here, initialize to zero */
pg_crc32c xl_crc; /* CRC for this record */
/* XLogRecordBlockHeaders and XLogRecordDataHeader follow, no padding */
【日志的数据信息】
} XLogRecord;xl_info低4位保存flag信息,高4位保存日志动作信息。
第四位:
/*
* If a WAL record modifies any relation files, in ways not covered by the
* usual block references, this flag is set. This is not used for anything
* by PostgreSQL itself, but it allows external tools that read WAL and keep
* track of modified blocks to recognize such special record types.
*/
#define XLR_SPECIAL_REL_UPDATE 0x01
/*
* Enforces consistency checks of replayed WAL at recovery. If enabled,
* each record will log a full-page write for each block modified by the
* record and will reuse it afterwards for consistency checks. The caller
* of XLogInsert can use this value if necessary, but if
* wal_consistency_checking is enabled for a rmgr this is set unconditionally.
*/
#define XLR_CHECK_CONSISTENCY 0x02高四位:比如HEAP操作,对应8种动作信息
#define XLOG_HEAP_INSERT 0x00
#define XLOG_HEAP_DELETE 0x10
#define XLOG_HEAP_UPDATE 0x20
#define XLOG_HEAP_TRUNCATE 0x30
#define XLOG_HEAP_HOT_UPDATE 0x40
#define XLOG_HEAP_CONFIRM 0x50
#define XLOG_HEAP_LOCK 0x60
#define XLOG_HEAP_INPLACE 0x70
#define XLOG_HEAP_OPMASK 0x70
/*
* When we insert 1st item on new page in INSERT, UPDATE, HOT_UPDATE,
* or MULTI_INSERT, we can (and we do) restore entire page in redo
*/
#define XLOG_HEAP_INIT_PAGE 0x80XLOG RECORD的数据格式
数据主要分两部分:
- 页面信息:没有实际数据,只有页面相关的信息
- 数据信息:紧跟着XlogRecordDataHeader后面存储,
- 实际数据<255字节,使用XLogRecordDataHeaderShort,用1字节保存数据长度
- 否则使用XLogRecordDataHeaderLong,用4字节保存数据长度
typedef struct XLogRecordDataHeaderShort
{
uint8 id; /* XLR_BLOCK_ID_DATA_SHORT */
uint8 data_length; /* number of payload bytes */
} XLogRecordDataHeaderShort;
#define SizeOfXLogRecordDataHeaderShort (sizeof(uint8) * 2)
typedef struct XLogRecordDataHeaderLong
{
uint8 id; /* XLR_BLOCK_ID_DATA_LONG */
/* followed by uint32 data_length, unaligned */
} XLogRecordDataHeaderLong;
#define SizeOfXLogRecordDataHeaderLong (sizeof(uint8) + sizeof(uint32))边栏推荐
- 面试官:为什么 Redis 要有哨兵?我该怎么回答?
- 【付费推广】常见问题合集,基础推广操作FAQ 2
- 浅析websocket劫持
- [harmony OS] [FAQ] Hongmeng application development problem sharing (font / constructor)
- ETCD数据库源码分析——etcdserver bootstrap初始化cluster和raft
- How to use pycharm to make a simple Snake game
- ETCD数据库源码分析——etcdserver bootstrap去除v2store
- 1.4 process control statement
- pytest+allure定制报告
- 深度学习(DL, Deep Learning)入门1——LetNet5网络结构
猜你喜欢

【华为联机对战】下载运行华为官方Unity示例代码,提示鉴权失败并返回错误码100114

【Harmony OS】【FAQ】鸿蒙应用开发问题分享(字体/构造器)

jetlinks平台Mqtt设备接入认证问题

How to multiply bank revenue through customer value analysis

醋酸氯霉素的实验室程序&参考文献

STC8H开发(十四): I2C驱动RX8025T高精度实时时钟芯片

Etcd database source code analysis -- etcdserver bootstrap initialization cluster and raft

OSPF(Open Shortest Path First开放式最短路径优先)防环以及计算错误带来的组网应用隐患
![[learning record] temporarily cancel the control of tpro (simple)](/img/87/7ebc3caa83de11813bf8a1702ac88e.png)
[learning record] temporarily cancel the control of tpro (simple)

SAP Fiori Launchpad 上看不到任何 tile 应该怎么办?
随机推荐
【Golang】函数(一等公民)的使用
ipfs记录
数据湖基本架构
【HMS core】【Wallet Kit】【解决方案】华为钱包的客户端示例代码为何无法运行
1.5.2 数组
mixin\插件\scoped样式
How to design PCB chip heat dissipation pad?
Ceph分布式存储性能调优(六)
[golang] slice
Kotlin classes and interfaces
关于TCP/IP协议漏洞的安全措施
污水排放监控,环保数采仪助力城市黑臭水体治理
Rapport mondial sur le développement de l'industrie de l'enseignement professionnel 2022
【快应用】px和vp单位换算
面试官:为什么 Redis 要有哨兵?我该怎么回答?
多米诺骨牌上演:三箭资本崩盘始末
The use of finally in JS
深度学习(DL, Deep Learning)入门1——LetNet5网络结构
Access authentication of mqtt equipment on jetlinks platform
PCB芯片散热焊盘如何设计?