PostgreSQL WAL解析:构建WAL记录准备
发表于:2024-09-30 作者:千家信息网编辑
千家信息网最后更新 2024年09月30日,以heap_insert为例,简述WAL的插入过程。在构建WAL日志记录的过程中主要涉及2个数据变量:static XLogRecData *rdatas数组和static registered_bu
千家信息网最后更新 2024年09月30日PostgreSQL WAL解析:构建WAL记录准备
以heap_insert为例,简述WAL的插入过程。
在构建WAL日志记录的过程中主要涉及2个数据变量:static XLogRecData *rdatas数组和static registered_buffer *registered_buffers数组。这两个数组分别用来保存WAL数据和管理rdatas链表。
主要涉及3个重要的函数:XLogRegisterData、XLogRegisterBuffer和XLogRegisterBufData。这三个函数的作用分别是将WAL记录的特殊结构体数据注册到WAL,比如heap_insert中的xl_heap_insert结构体;将涉及到的buf注册到wal记录,比如heap_insert中page页赋予regbuf->page;将元组内容注册到WAL记录,比如insert语句的元组数据等。
下面首先介绍相关数据结构。
1、数据结构
HeapTupleData
typedef struct HeapTupleData{ uint32 t_len; /* length of *t_data */ ItemPointerData t_self; /* SelfItemPointer */ Oid t_tableOid; /* table the tuple came from */ HeapTupleHeader t_data; /* -> tuple header and data */} HeapTupleData;
xl_heap_header
/* * We don't store the whole fixed part (HeapTupleHeaderData) of an inserted * or updated tuple in WAL; we can save a few bytes by reconstructing the * fields that are available elsewhere in the WAL record, or perhaps just * plain needn't be reconstructed. These are the fields we must store. * NOTE: t_hoff could be recomputed, but we may as well store it because * it will come for free due to alignment considerations. */typedef struct xl_heap_header{ uint16 t_infomask2; uint16 t_infomask; uint8 t_hoff;} xl_heap_header;
xl_heap_insert
/* This is what we need to know about insert */typedef struct xl_heap_insert{ OffsetNumber offnum; /* inserted tuple's offset */ uint8 flags; /* xl_heap_header & TUPLE DATA in backup block 0 */} xl_heap_insert;
XLogRecData
/* * The functions in xloginsert.c construct a chain of XLogRecData structs * to represent the final WAL record. */typedef struct XLogRecData{ struct XLogRecData *next; /* next struct in chain, or NULL */ char *data; /* start of rmgr data to include */ uint32 len; /* length of rmgr data to include */} XLogRecData;
registered_buffer
/* * For each block reference registered with XLogRegisterBuffer, we fill in * a registered_buffer struct. */typedef struct{bool in_use; /* is this slot in use? */uint8 flags; /* REGBUF_* flags */RelFileNode rnode; /* identifies the relation and block */ForkNumber forkno;BlockNumber block;Page page; /* page content */uint32 rdata_len; /* total length of data in rdata chain */XLogRecData *rdata_head; /* head of the chain of data registered with this block */XLogRecData *rdata_tail; /* last entry in the chain, or &rdata_head if empty */XLogRecData bkp_rdatas[2]; /* temporary rdatas used to hold references to * backup block data in XLogRecordAssemble() *//* buffer to store a compressed version of backup block image */char compressed_page[PGLZ_MAX_BLCKSZ];} registered_buffer;
2、heap_insert涉及WAL的流程
第一步中,得到如下结果,mainrdata_last保存rdata[0],存储的是xl_heap_insert结构:
第二步,得到如下结果,取registered_buffer[0],其rdata_head->next指向rdata[1],存储tuple记录的头信息:
接着进入第三步,取rdata[2],将其放到rdata[1]->next中,即加入registered_buffers[0]的rdata_head链表中,存储TUPLE值:
以上是构建WAL记录的准备阶段,下一节介绍WAL的构建及其通用结构。
数据
结构
数组
存储
函数
数据结构
结果
过程
准备
特殊
重要
三个
两个
作用
信息
内容
变量
指向
日志
流程
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
手游ea服务器连不上
2b2 t服务器是谁开发的
web数据库哪个安全
参观网络安全基地 方案
sr650服务器管理口ip
测量数据库实训报告
莳涧软件开发
Ovid数据库下载文献
2020年360网络安全
青岛app软件开发报价
数据库第六范式
谷歌恶意软件开发者
农民互联网金融科技
数据库连接状态失败
剪辑软件开发大神
网络安全为主题微小说
如何部署项目到服务器上
ie 代理服务器 搭建
网络安全发展要
取出数据库表里的数据
创途网络技术有限公司
数据库埋点设计
最前沿的互联网科技
k8s 服务器基本配置
余姚易泓网络技术有限公司
酒店网络安全审查
hp服务器主板灯
信息网络安全知识新青年
激战2一直与服务器断开连接
网络安全审计厂家