Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Interpretation of PostgreSQL Source Code-background process # 3 (checkpointer process # 2)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

< ControlFile->

< ControlFile->

CheckPointCopy.nextXid) (gdb) 8876 LWLockAcquire (OidGenLock, LW_SHARED); (gdb) 8877 checkPoint.nextOid = ShmemVariableCache- > nextOid (gdb) p checkPoint$13 = {redo = 5521451392, ThisTimeLineID = 1, PrevTimeLineID = 1, fullPageWrites = true, nextXidEpoch = 0, nextXid = 2308, nextOid = 0, nextMulti = 0, nextMultiOffset = 0, oldestXid = 561, oldestXidDB = 16400, oldestMulti = 0, oldestMultiDB = 0, time = 1546933255, oldestCommitTsXid = 0, newestCommitTsXid = 0, oldestActiveXid = 0} (gdb) n8878 if (! shutdown) (gdb) 8879 checkPoint.nextOid + = ShmemVariableCache- > oidCount; (gdb) 8880 LWLockRelease (OidGenLock) (gdb) p * ShmemVariableCache$14 = {nextOid = 42575, oidCount = 8189, nextXid = 2308, oldestXid = 561, xidVacLimit = 200000561, xidWarnLimit = 2136484208, xidStopLimit = 2146484208, xidWrapLimit = 2147484208, oldestXidDB = 16400, oldestCommitTsXid = 0, newestCommitTsXid = 0, latestCompletedXid = 2307, oldestClogXid = 561} (gdb) n8882 MultiXactGetCheckptMulti (shutdown, (gdb))

Look at the checkpoint structure again

(gdb) p checkPoint$15 = {redo = 5521451392, ThisTimeLineID = 1, PrevTimeLineID = 1, fullPageWrites = true, nextXidEpoch = 0, nextXid = 2308, nextOid = 50764, nextMulti = 1, nextMultiOffset = 0, oldestXid = 561, oldestXidDB = 16400, oldestMulti = 1, oldestMultiDB = 16402, time = 1546933255, oldestCommitTsXid = 0, newestCommitTsXid = 0, oldestActiveXid = 0} (gdb)

End CRIT_SECTION

(gdb) 8896 END_CRIT_SECTION ()

Get virtual transaction ID (invalid information)

(gdb) n8927 vxids = GetVirtualXIDsDelayingChkpt (& nvxids); (gdb) 8928 if (nvxids > 0) (gdb) p vxids$16 = (VirtualTransactionId *) 0x2f4eb20 (gdb) p * vxids$17 = {backendId = 2139062143, localTransactionId = 2139062143} (gdb) p nvxids$18 = 0 (gdb) (gdb) n8935 pfree (vxids); (gdb)

Brush the data in the shared memory to disk and execute fsync

(gdb) 8937 CheckPointGuts (checkPoint.redo, flags); (gdb) p flags$19 = 44 (gdb) n8947 if (! shutdown & & XLogStandbyInfoActive ()) (gdb)

Enter critical section.

(gdb) n8950 START_CRIT_SECTION (); (gdb)

You can now insert checkpoint record into XLOG.

(gdb) 8955 XLogBeginInsert (); (gdb) n8956 XLogRegisterData ((char *) (& checkPoint), sizeof (checkPoint)); (gdb) 8957 recptr = XLogInsert (RM_XLOG_ID, (gdb) 8961 XLogFlush (recptr); (gdb) 8970 if (shutdown) (gdb))

Update the control file (pg_control), first record the REDO ptr of the previous checkpoint for UpdateCheckPointDistanceEstimate ()

(gdb) 8982 if (shutdown & & checkPoint.redo! = ProcLastRecPtr) (gdb) 8990 PriorRedoPtr = ControlFile- > checkPointCopy.redo; (gdb) 8995 LWLockAcquire (ControlFileLock, LW_EXCLUSIVE); (gdb) p ControlFile- > checkPointCopy.redo$20 = 5521450856 (gdb) n8996 if (shutdown) (gdb) 8998 ControlFile- > checkPoint = ProcLastRecPtr; (gdb) 8999 ControlFile- > checkPointCopy = checkPoint; (gdb) 9000 ControlFile- > time = (pg_time_t) time (NULL) (gdb) 9002 ControlFile- > minRecoveryPoint = InvalidXLogRecPtr; (gdb) 9003 ControlFile- > minRecoveryPointTLI = 0; (gdb) 9010 SpinLockAcquire (& XLogCtl- > ulsn_lck); (gdb) 9011 ControlFile- > unloggedLSN = XLogCtl- > unloggedLSN; (gdb) 9012 SpinLockRelease (& XLogCtl- > ulsn_lck); (gdb) 9014 UpdateControlFile (); (gdb) 9015 LWLockRelease (ControlFileLock); (gdb) 9018 SpinLockAcquire (& XLogCtl- > info_lck) (gdb) p * ControlFile$21 = {system_identifier = 6624362124887945794, pg_control_version = 1100, catalog_version_no = 201809051, state = DB_IN_PRODUCTION, time = 1546934255, checkPoint = 5521451392, checkPointCopy = {redo = 5521451392, ThisTimeLineID = 1, PrevTimeLineID = 1, fullPageWrites = true, nextXidEpoch = 0, nextXid = 2308, nextOid = 50764, nextMulti = 1, nextMultiOffset = 0, oldestXid = 561, oldestXidDB = 16400, oldestMulti = 1, oldestMultiDB = 16402, time = 1546933255, oldestCommitTsXid = 0, newestCommitTsXid = 0, oldestActiveXid = 0}, unloggedLSN = 1 MinRecoveryPoint = 0, minRecoveryPointTLI = 0, backupStartPoint = 0, backupEndPoint = 0, backupEndRequired = false, wal_level = 0, wal_log_hints = false, MaxConnections = 100, max_worker_processes = 8, max_prepared_xacts = 0, max_locks_per_xact = 64, track_commit_timestamp = false, maxAlign = 8, floatFormat = 1234567, blcksz = 8192, relseg_size = 131072, xlog_blcksz = 8192, xlog_seg_size = 16777216, nameDataLen = 64, indexMaxKeys = 32, toast_max_chunk_size = 1996, loblksize = 2048 Float4ByVal = true, float8ByVal = true, data_checksum_version = 0, mock_authentication_nonce = "\ 220\ 277\ 067Vg\ 003\ 205\ 232U {\ 177 h\ 216\ 271D\ 266\ 063 [\ = 6\ 365S\ tA\ 353\ 361w\ 301", crc = 930305687} (gdb)

Update the shared memory copy of checkpoint XID/epoch, exit critical section, and let smgr perform checkpoint finalization (such as deleting old files, etc.).

(gdb) n9019 XLogCtl- > ckptXidEpoch = checkPoint.nextXidEpoch; (gdb) 9020 XLogCtl- > ckptXid = checkPoint.nextXid; (gdb) 9021 SpinLockRelease (& XLogCtl- > info_lck); (gdb) 9027 END_CRIT_SECTION (); (gdb) 9032 smgrpostckpt (); (gdb)

Delete old log files that are no longer needed since the last checkpoint to prevent the disk that saved the xlog from filling up.

(gdb) n9038 if (PriorRedoPtr! = InvalidXLogRecPtr) (gdb) p PriorRedoPtr$23 = 5521450856 (gdb) n9039 UpdateCheckPointDistanceEstimate (RedoRecPtr-PriorRedoPtr); (gdb) 9045 XLByteToSeg (RedoRecPtr, _ logSegNo, wal_segment_size); (gdb) 9046 KeepLogSeg (recptr, & _ logSegNo); (gdb) p RedoRecPtr$24 = 5521451392 (gdb) p _ logSegNo$25 = 329 (gdb) p wal_segment_size$26 = 16777216 (gdb) n9047 _ logSegNo--; (gdb) 9048 RemoveOldXlogFiles (_ logSegNo, RedoRecPtr, recptr) (gdb) 9054 if (! shutdown) (gdb) p recptr$27 = 5521451504 (gdb)

Perform other related closing work

(gdb) n9055 PreallocXlogFiles (recptr); (gdb) 9064 if (! RecoveryInProgress ()) (gdb) 9065 TruncateSUBTRANS (GetOldestXmin (NULL, PROCARRAY_FLAGS_DEFAULT)); (gdb) 9068 LogCheckpointEnd (false); (gdb) 9070 TRACE_POSTGRESQL_CHECKPOINT_DONE (CheckpointStats.ckpt_bufs_written, (gdb) 9076 LWLockRelease (CheckpointLock); (gdb) 9077} (gdb))

Complete the call

(gdb) CheckpointerMain () at checkpointer.c:488488 ckpt_performed = true; (gdb)

DONE!

IV. Reference materials

Checkpointer.c

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report