当前位置:网站首页>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
边栏推荐
- Optimal binary search tree
- 「技术课堂」如何用 VSCode 从 0 到 1 改写 TDengine 代码
- [UVM basics] UVM tree organizational structure
- Use lamda expression and stream flow to traverse map and list
- How to turn off the server terminal name of vscode
- Wechat applet association search
- Market status and development prospect forecast of global triisopropyl chlorosilane industry in 2022
- 推荐几个开源的物联网平台
- 中国工业软件市场研究报告出炉,力控SCADA、MES丰富国产工业软件生态
- Control file related views
猜你喜欢

Electronic smart package tutorial

Common optimization techniques for Web Performance

Wanzhou gold industry: what are the common gold investment and warehouse building modes?

Contest3182 - the 39th individual training match for 2021 freshmen_ E: ringring

如何使用物联网低代码平台进行画面管理?

Bit. Store: long bear market, stable stacking products may become the main theme

Galaxy Kirin V10 system activation

Advanced learning of MySQL -- Application -- view, stored procedure, trigger

All you want to know about large screen visualization is here
![[UVM basics] set a monitor at the input port of the DUT to explain the necessity](/img/72/0cecd17ab2c893b978b0995363cfcf.jpg)
[UVM basics] set a monitor at the input port of the DUT to explain the necessity
随机推荐
TDengine 连接器上线 Google Data Studio 应用商店
ansible环境安装及数据恢复
如何使用物联网低代码平台进行画面管理?
开源之夏 2022 | openGauss 项目中选公布
SQL update批量更新
Application of scaleflux CSD 2000 in Ctrip
Uploading multiple attachments from canvas apps to SharePoint
数据同步工具 DataX 已经正式支持读写 TDengine
Common optimization techniques for Web Performance
Electronic smart package tutorial
Application of tdengine in monitoring of CNC machine tools
详解 OpenTSDB 与 TDengine 在系统功能层面上存在的差异
TP5 generates the most detailed two-dimensional code tp6 (also available)
MySQL数据库登录和退出的两种方式
Study on heritability and field experiment design
JS event binding and common events
leetcode 82. Delete duplicate Element II in the sorting linked list
InfluxDB集群功能不再开源,TDengine集群功能更胜一筹
Oracle的NUMBER长度超过19之后,实体使用Long映射,导致出现问题是为什么?
Shardingsphere sharding proxy actual combat scenario