当前位置:网站首页>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
边栏推荐
- Contest3182 - the 39th individual training match for 2021 freshmen_ E: ringring
- Explain in detail the differences between opentsdb and tdengine in system functions
- Why migrate from opentsdb to tdengine
- Part 30 supplement (30) ECMAScript object
- Simple anti shake for wechat applet
- JS event binding and common events
- 实现时序数据库(Time Series Database)在特定场景下“远超”通用数据库的难点
- 「技术课堂」如何用 VSCode 从 0 到 1 改写 TDengine 代码
- TP5 restrict access frequency
- Analysis of shardingsphere core source code
猜你喜欢
![[UVM foundation] UVM_ Is in agent_ Active variable definition](/img/55/a14fbde43b25ccdc5a7996121396f9.jpg)
[UVM foundation] UVM_ Is in agent_ Active variable definition

PostgreSQL数据库WAL——资源管理器RMGR

leetcode 69. Square root of X

银河麒麟V10系统激活

国内首家!EMQ加入亚马逊云科技“初创加速-全球合作伙伴网络计划”

leetcode 82. Delete duplicate Element II in the sorting linked list

Asemi rectifier bridge kbp210 parameters, kbp210 specifications, kbp210 dimensions

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

New products, new personnel and new services, Infiniti will continue to plough into China's future!

Allocate aligned heap space
随机推荐
Asemi rectifier bridge kbp310 function pin diagram
leetcode 82. Delete duplicate Element II in the sorting linked list
Dark horse programmer - software testing foundation class -02-30-45 tools open browser running code, audio, video, test points, audio and video labels, layout labels. Advanced hyperlink syntax, absolu
How to create a login interface
Project team management - Tuckman ladder theory
如何使用物联网低代码平台进行画面管理?
Hash encryption
Why migrate from opentsdb to tdengine
Lvgl8.x migrating to stm32f4
喜讯丨英方软件2022获得10项发明专利!
Repeatedly recognized by authoritative organizations! Smartbi was selected into the top three lists of high-tech and high growth enterprises
Jeesite 4.0 replaces the default view style and customizes the theme
Advanced learning of MySQL -- Application -- view, stored procedure, trigger
详解 OpenTSDB 与 TDengine 在系统功能层面上存在的差异
About redis master-slave replication
GAC Mitsubishi's new outlander made its first domestic debut in the year, and its product strength was fully renewed
Android kotlin learning
阿里巴巴的使命、愿景、核心价值观
[UVM foundation] build of UVM_ Phase execution sequence
新产品新人事新服务,英菲尼迪继续深耕中国未来可期!