PostgreSQL的clog属于日志还是数据,需要遵守write-WAL-before-data吗? 全球速看料
时间:2023-03-05 17:11:51
来源:腾讯云
(资料图片仅供参考)
总结
从原理上来看,MVCC需要给定事务ID后,能查询到事务的状态。
在PG中事务状态可以从几个路径获取:
在快照中查询(活跃事务)在元组头的状态为查询(不活跃事务)在CLOG中查询(不活跃事务)如果不看实现只看概念,不活跃事务提交状态也可以在XLOG中查询,CLOG可以视作一种XLOG commit/rollback日志的缓存、映射,一种事务提交状态的快速查询方式。
所以在write-WAL-before-data中,CLOG也会按照data来处理,只有XLOG属于WAL。
Postgresql中clog写盘实现SlruPhysicalWritePage
postgresql中clog使用SLRU机制读写,在Slru写盘前,会有保证xlog先写的机制:
group_lsn表示32个事务一组中最大的日志序列号(LSN)。group_lsn主要用于事务提交非同步落盘的场景。static boolSlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruWriteAll fdata){...if (shared->group_lsn != NULL){/* * We must determine the largest async-commit LSN for the page. This * is a bit tedious, but since this entire function is a slow path * anyway, it seems better to do this here than to maintain a per-page * LSN variable (which"d need an extra comparison in the * transaction-commit path). */XLogRecPtrmax_lsn;intlsnindex,lsnoff;lsnindex = slotno * shared->lsn_groups_per_page;max_lsn = shared->group_lsn[lsnindex++];for (lsnoff = 1; lsnoff < shared->lsn_groups_per_page; lsnoff++){XLogRecPtrthis_lsn = shared->group_lsn[lsnindex++];if (max_lsn < this_lsn)max_lsn = this_lsn; <<<<<<<<<<<<<<<<<<<<<<<<< 找到最大的LSN}if (!XLogRecPtrIsInvalid(max_lsn)){/* * As noted above, elog(ERROR) is not acceptable here, so if * XLogFlush were to fail, we must PANIC. This isn"t much of a * restriction because XLogFlush is just about all critical * section anyway, but let"s make sure. */START_CRIT_SECTION();XLogFlush(max_lsn); <<<<<<<<<<<<<<<<<<<<<<<<< 先保证XLOG写到这个位点!END_CRIT_SECTION();}} ... if (pg_pwrite(fd, shared->page_buffer[slotno], BLCKSZ, offset) != BLCKSZ) { ... }}Postgresql中用户数据写盘实现FlushBuffer
数据页面同理,也是先找到页面lsn,刷xlog,在写数据。
static voidFlushBuffer(BufferDesc *buf, SMgrRelation reln){...buf_state = LockBufHdr(buf);/* * Run PageGetLSN while holding header lock, since we don"t have the * buffer locked exclusively in all cases. */recptr = BufferGetLSN(buf); <<<<<<<<<<<<<<<<<<<<<<<<< 找到页面的LSN/* To check if block content changes while flushing. - vadim 01/17/97 */buf_state &= ~BM_JUST_DIRTIED;UnlockBufHdr(buf, buf_state);/* * Force XLOG flush up to buffer"s LSN. This implements the basic WAL * rule that log updates must hit disk before any of the data-file changes * they describe do. * * However, this rule does not apply to unlogged relations, which will be * lost after a crash anyway. Most unlogged relation pages do not bear * LSNs since we never emit WAL records for them, and therefore flushing * up through the buffer LSN would be useless, but harmless. However, * GiST indexes use LSNs internally to track page-splits, and therefore * unlogged GiST pages bear "fake" LSNs generated by * GetFakeLSNForUnloggedRel. It is unlikely but possible that the fake * LSN counter could advance past the WAL insertion point; and if it did * happen, attempting to flush WAL through that location would fail, with * disastrous system-wide consequences. To make sure that can"t happen, * skip the flush if the buffer isn"t permanent. */if (buf_state & BM_PERMANENT)XLogFlush(recptr); <<<<<<<<<<<<<<<<<<<<<<<<< 先保证XLOG写到这个位点! ...smgrwrite(reln, BufTagGetForkNum(&buf->tag), buf->tag.blockNum, bufToWrite, false); ...} 标签: PostgreSQL
- PostgreSQL的clog属于日志还是数据,需要遵守write-WAL-before-data吗? 全球速看料
- 图纸比例怎么算1:150_图纸比例怎么算|焦点信息
- 焦点速看:潍坊滨海公安“警”跟雷锋步伐 志愿服务护万家
- 锅炉中水垢的主要成分_水垢的主要成分|当前滚动
- safe and sound吉他谱_safe and sound歌词-世界观热点
- 姆巴佩:对拜仁的欧冠不会决定我的未来,只一心想让巴黎变得伟大|每日资讯
- 当前动态:重庆最大的海洋馆是哪里
- 拒绝第六!武汉女篮申请降至第八 “让贤”成美谈却也引发反思 微资讯
- 克里斯关门是什么
- 大桥:在太阳时我在进攻端角色很重 被交易后这对我有帮助
- 林希妤近5场亚洲挥杆赛均列前15!再战圣淘沙能否取得突破?| 拉姆已具备征服湾丘的所有条件?| 高尔夫频道VIP新价格
- 环球百事通!合肥建成“科里科气”地名词库
- 1100kV高压交流断路器技术规范
- 未能签订购房合同定金如何处理
- 全球资讯:台湾不仅缺鸡蛋连药品也缺,蓝营批民进党“不要成天只想着选举”
- 宫玉振:为什么《孙子兵法》在西方有巨大影响力?
- 一刀传世法宝怎么搭配_一刀传世法宝搭配|热消息
- 酸奶什么时候喝最减肥瘦身_酸奶什么时候喝最减肥|今日热议
- 每日精选:广东湛江妇联联合霞山消防开展“我是小小消防员”生命教育实践活动
- u盘无法打开卷直接使用是什么情况_U盘无法停止通用卷怎么办_全球观焦点
- (新华全媒+)环新英湾地区:建设海南自贸港产业新城
- 环球今热点:曼联在商业上确实是常胜将军
- 环球实时:senator香烟红盒_senator香烟
- 2月26日起自贡市民观灯会旅游专线调整(附具体措施) 环球快看
- 艺术设计专业学什么_艺术设计主修课程有哪些
- 特斯拉潮州事故鉴定结果已出,已给到潮州警方
- 大连联合心理咨询中心怎么样_大连联合心理咨询
- 给过载的社交媒体减减负
- 925银和999银的区别_925银和999银的区别哪个不容易变黑|快资讯
- 人工上下结构念什么字_人工上下结构念什么
x
广告
x
广告