PostgreSQL的clog属于日志还是数据,需要遵守write-WAL-before-data吗?:世界快资讯
(资料图片仅供参考)
总结
从原理上来看,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吗?:世界快资讯
2023-03-06 -
世界热点评!用风力传播种子的植物_靠风传播种子的植物
2023-03-06 -
报道:号称「工业元宇宙」,数字孪生工厂真那么神?
2023-03-06 -
观天下!《三生三世》被嘲小鲜肉团队:拍不像就不要拍,这次小鲜肉不背锅
2023-03-06 -
虞书欣王耀庆演的是什么电视剧
2023-03-06 -
每日动态!各得其所的意思_喜出望外的意思
2023-03-06 -
环球快报:买房子除了首付款还有哪些费用_买房子
2023-03-06 -
【节气里的大美中国】惊蛰丨又如春雷动 初惊蛰龙蛇
2023-03-06 -
铭普光磁3月6日快速反弹
2023-03-06 -
高速别车
2023-03-06 -
焦点关注:商丘梁园法院:送法进卫校 数千师生聆听
2023-03-06 -
吃什么可以减肥最快瘦肚子_吃什么可以减肥最快:世界热资讯
2023-03-06 -
毕畅_说一说毕畅的简介
2023-03-05 -
环球资讯:水龙头漏水维修方法
2023-03-05 -
小桂湾
2023-03-05 -
实时:甲鱼的杀法
2023-03-05 -
八月英文全称_八月 英文
2023-03-05 -
黑甲第二季_黑甲第2季
2023-03-05 -
焦点短讯!8人上双火箭掀翻马刺结束11连败 伊森替补20+5
2023-03-05 -
全球热推荐:花红柳绿不是什么生肖_柳绿花红是什么生肖
2023-03-05 -
03月05日06时甘肃张掖昨日累计报告阳性感染者确诊19例 怎么判断自己是否属于轻型感染者
2023-03-05 -
应收账款在贷方表示什么负债吗_应收账款在贷方表示什么
2023-03-04 -
即时看!二刀肉在超市叫什么_二刀肉
2023-03-04 -
中国空间站成功实施首次点火实验_天天快播
2023-03-04 -
视点|导师不接电话就不停打?考研复试“套磁”别丢底线|微动态
2023-03-04 -
[刀剑乱舞+阴阳师]这个婶婶是SSR
2023-03-04 -
康宁杰瑞制药-B(09966.HK)3月2日收盘跌3.95%,主力资金净流出341.25万港元
2023-03-02 -
对接台青百余人落地金额上亿元 “台湾青年广东创业行活动”成果展示会在粤举办
2023-03-02 -
【一切工作高标准、高效率、高效益】淇县法院:关爱+救助为困难妇女撑起一片法治晴空
2023-03-02 -
几号是圣诞节日_几号是圣诞节
2023-03-02
-
守住网络直播的伦理底线
2021-12-16 -
石窟寺文化需要基于保护的“新开发”
2021-12-16 -
电影工作者不能远离生活
2021-12-16 -
提升隧道安全管控能力 智慧高速让司乘安心
2021-12-16 -
人民财评:提升消费体验,服务同样重要
2021-12-16 -
卫冕?突破?旗手?——武大靖留给北京冬奥会三大悬念
2021-12-16 -
新能源车险专属条款出台“三电”系统、起火燃烧等都可保
2021-12-16 -
美术作品中的党史 | 第97集《窗外》
2021-12-16 -
基金销售业务违规!浦发银行厦门分行等被厦门证监局责令改正
2021-12-16 -
保持稳定发展有支撑——从11月“成绩单”看中国经济走势
2021-12-16