当前位置:网站首页>PostgreSQL database Wal - resource manager rmgr
PostgreSQL database Wal - resource manager rmgr
2022-06-27 18:44:00 【Ink Sky Wheel】
XLog Logs are divided into multiple types of resource managers , Each resource manager only needs to be responsible for its own log processing ( Abstract out the operation function , Different logs implement different operation functions ). The definition of the resource manager is as follows :
typedef struct RmgrData {const char *rm_name; Resource namevoid (*rm_redo) (XLogReaderState *record); Redo functionvoid (*rm_desc) (StringInfo buf, XLogReaderState *record); Responsible for parsing the corresponding resource transaction logconst char *(*rm_identify) (uint8 info); // analysis xlog In record Info Fieldvoid (*rm_startup) (void); // Initialization at startupvoid (*rm_cleanup) (void); // Clean up at the endvoid (*rm_mask) (char *pagedata, BlockNumber blkno); // Before checking the page for consistency , Whether some parts of the page need to be masked} RmgrData;extern const RmgrData RmgrTable[];
Multiple types of resource managers are defined in src/include/access/rmgrlist.h in , Their functions and operation functions are as follows .

Operation function call process
rm_identify Interface and rm_desc The interface is used for pg_waldump Tool pair WAL Log reverse parsing ( Parse binary log records into strings ).rm_startup、rm_redo、rm_mask and rm_cleanup be used for startup Process execution StartupXLOG Function XLOG Initialization resource manager in log playback RMGR、 The playback xlog、 Check the consistency of the page and clean it up , The execution process is as follows :
void StartupXLOG(void){.../* Initialize resource managers */ // Initialize the resource manager RMGRfor (rmid = 0; rmid <= RM_MAX_ID; rmid++) {if (RmgrTable[rmid].rm_startup != NULL)RmgrTable[rmid].rm_startup();}.../* main redo apply loop */ // Main playback logicdo {.../* Now apply the WAL record itself */ // call rm_redo The playback xlogRmgrTable[record->xl_rmid].rm_redo(xlogreader);/* After redo, check whether the backup pages associated with the WAL record are consistent with the existing pages. This check is done only if consistency check is enabled for this record. */ // redo after , Check with WAL Record whether the associated backup page is consistent with the existing page . This check is only performed if consistency checking is enabled for this record .if ((record->xl_info & XLR_CHECK_CONSISTENCY) != 0)checkXLogConsistency(xlogreader);...record = ReadRecord(xlogreader, LOG, false); /* Else, try to fetch the next WAL record */} while (record != NULL);/* Allow resource managers to do any required cleanup. */ // Clean upfor (rmid = 0; rmid <= RM_MAX_ID; rmid++) {if (RmgrTable[rmid].rm_cleanup != NULL)RmgrTable[rmid].rm_cleanup();}}
1.rm_startup For different types xlog Resources call different initialization functions to initialize the resource manager RMGR.
2. according to xlog Medium xl_rmid Call the... Of different resources in the resource manager rm_redo Playback function for playback .
3. We know startup process recovery In the process , because wal replay BUG Or the physical data block of the standby database is abnormal wal replay The playback block is incorrect .PostgreSQL 10.0 Newly added wal_consistency_checking Parameters , It can be used to find such problems .wal_consistency_checking Parameters can be set to the following values :all, heap, heap2, btree, hash, gin, gist, sequence, spgist, brin, and generic.

wal_consistency_checking (string)
This parameter is intended to be used to check for bugs in the WAL redo routines. When enabled, full-page images of any buffers modified in conjunction with the WAL record are added to the record. If the record is subsequently replayed, the system will first apply each record and then test whether the buffers modified by the record match the stored images. In certain cases (such as hint bits), minor variations are acceptable, and will be ignored. Any unexpected differences will result in a fatal error, terminating recovery. The default value of this setting is the empty string, which disables the feature. It can be set to all to check all records, or to a comma-separated list of resource managers to check only records originating from those resource managers. Currently, the supported resource managers are heap, heap2, btree, hash, gin, gist, sequence, spgist, brin, and generic. Only superusers can change this setting.
StartupXLOG --> checkXLogConsistency For different resource management ID, Execute the corresponding function , Its main logic is as follows :
RmgrId rmid = XLogRecGetRmid(record); // record The type of XLogReaderState *if (RmgrTable[rmid].rm_mask != NULL) {RmgrTable[rmid].rm_mask(replay_image_masked, blkno);RmgrTable[rmid].rm_mask(primary_image_masked, blkno);}
4. For different resource management ID, Call its corresponding function rm_cleanup Clean up resources
From the above process, we can see that the playback process is wal_consistency_check, Depending on xlog info Whether to set XLR_CHECK_CONSISTENCY, The setting process is in XLogRecordAssemble Function , If wal_consistency_checking The array corresponds to the resource ID Set to true(wal_consistency_checking Array in GUC Module assign_wal_consistency_checking Function according to wal_consistency_checking Parameter setting ), Corresponding xlog info Set XLR_CHECK_CONSISTENCY sign .
static XLogRecData *XLogRecordAssemble(RmgrId rmid, uint8 info, XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr *fpw_lsn, int *num_fpi){/* Enforce consistency checks for this record if user is looking for it. Do this before at the beginning of this routine to give the possibility for callers of XLogInsert() to pass XLR_CHECK_CONSISTENCY directly for a record.*/ // If the user is looking for this record , Then the consistency check is enforced . Do this before this routine starts , In order to make XLogInsert() The caller of can directly pass XLR_CHECK_CONSISTENCY To get recordsif (wal_consistency_checking[rmid])info |= XLR_CHECK_CONSISTENCY;}
reference :
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=a507b86900f695aacc8d52b7d2cfcb65f58862a2
https://www.postgresql.org/docs/devel/static/runtime-config-developer.html
边栏推荐
- Application of scaleflux CSD 2000 in Ctrip
- New products, new personnel and new services, Infiniti will continue to plough into China's future!
- Oracle的NUMBER长度超过19之后,实体使用Long映射,导致出现问题是为什么?
- [elt.zip] openharmony paper Club - witness file compression system erofs
- SQL update batch update
- Application of scaleflux CSD 2000 in Ctrip
- PostgreSQL数据库WAL——资源管理器RMGR
- Teach you to use elastic search: run the first hello world search command
- 中国工业软件市场研究报告出炉,力控SCADA、MES丰富国产工业软件生态
- InfluxDB集群功能不再开源,TDengine集群功能更胜一筹
猜你喜欢

Tdengine connector goes online Google Data Studio store

新产品新人事新服务,英菲尼迪继续深耕中国未来可期!

MySQL中的行转列和列转行
![[UVM foundation] UVM_ Is in agent_ Active variable definition](/img/55/a14fbde43b25ccdc5a7996121396f9.jpg)
[UVM foundation] UVM_ Is in agent_ Active variable definition

Teach you how to realize pynq-z2 bar code recognition

开源之夏 2022 | openGauss 项目中选公布

电子智慧套装教程

Application of tdengine in monitoring of CNC machine tools

Contest3182 - the 39th individual training match for 2021 freshmen_ F: ss

SQL update batch update
随机推荐
All you want to know about large screen visualization is here
(5) SPI application design and simulation verification 1 - logic sorting
MySQL数据库登录和退出的两种方式
VSCode 建议你启用 gopls,它到底是个什么东东?
GAC Mitsubishi's new outlander made its first domestic debut in the year, and its product strength was fully renewed
1. introduction to MariaDB
Redis系列2:数据持久化提高可用性
Push NFT out of the regulatory dilemma, and BSN launched NFT supporting infrastructure network
Can the selectforupdateexecution in Seata obtain the global lock before executing SQL?
Mise à jour SQL mise à jour par lots
Hikvision Tools Manager海康威视工具大全(含SADP、录像容量计算等工具)百万安防从业者的实用工具
Offline disk group
电子智慧套装教程
New products, new personnel and new services, Infiniti will continue to plough into China's future!
Contest3182 - the 39th individual training match for 2021 freshmen_ C: [string] ISBN number
Hospital reservation and registration system - system structure
Anfulai embedded weekly report (issue 252): February 7, 2022 to February 13, 2022
Analysis of shardingsphere core source code
Part 31 supplement (31) ECMAScript conversion to string and number
技术分享 | kubernetes pod 简介