In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
< CheckPointWarning. * 如果checkpoint发生的太频繁(不管是什么原因) * 或者在上次checkpoint启动后某个进程设置了CHECKPOINT_CAUSE_XLOG标志, * 我们都会发出警告. * 请特别注意,此实现不会生成由CheckPointTimeout < CheckPointWarning引起的警告。 */ if (!do_restartpoint && (flags & CHECKPOINT_CAUSE_XLOG) && elapsed_secs < CheckPointWarning) ereport(LOG, (errmsg_plural("checkpoints are occurring too frequently (%d second apart)", "checkpoints are occurring too frequently (%d seconds apart)", elapsed_secs, elapsed_secs), errhint("Consider increasing the configuration parameter \"max_wal_size\"."))); /* * Initialize checkpointer-private variables used during * checkpoint. * 初始化checkpointer进程在checkpoint过程中需使用的私有变量 */ ckpt_active = true; if (do_restartpoint) //执行restartpoint ckpt_start_recptr = GetXLogReplayRecPtr(NULL);//获取Redo pint else //执行checkpoint ckpt_start_recptr = GetInsertRecPtr();//获取checkpoint XLOG Record插入的位置 ckpt_start_time = now;//开始时间 ckpt_cached_elapsed = 0;//消逝时间 /* * Do the checkpoint. * 执行checkpoint. */ if (!do_restartpoint) { //执行checkpoint CreateCheckPoint(flags);//创建checkpoint ckpt_performed = true;//DONE! } else //恢复过程的restartpoint ckpt_performed = CreateRestartPoint(flags); /* * After any checkpoint, close all smgr files. This is so we * won't hang onto smgr references to deleted files indefinitely. * 执行checkpoint完成后,关闭所有的smgr文件. * 这样我们就不需要无限期的持有已删除文件的smgr引用. */ smgrcloseall(); /* * Indicate checkpoint completion to any waiting backends. * 通知等待的进程,checkpoint完成. */ SpinLockAcquire(&CheckpointerShmem->Ckpt_lck); CheckpointerShmem- > ckpt_done = CheckpointerShmem- > ckpt_started; SpinLockRelease (& CheckpointerShmem- > ckpt_lck); if (ckpt_performed) {/ / completed checkpoint / * * Note we record the checkpoint start time not end time as * last_checkpoint_time. This is so that time-driven * checkpoints happen at a predictable spacing. * notice that we recorded the start time of the checkpoint instead of the end time as the last_checkpoint_time. * in this way, time-driven checkpoints appear at predictable intervals. * / last_checkpoint_time = now;} else {/ / * * We were not able to perform the restartpoint (checkpoints * throw an ERROR in case of error). Most likely because we * have not received any new checkpoint WAL records since the * last restartpoint. Try again in 15 s. * did not execute restartpoint successfully (if there is a problem with checkpoint, it will report an error directly and will not enter here). * the most likely reason is that no new restartpoint record was received after the last checkpoint WAL. * try after 15 seconds. * / last_checkpoint_time = now-CheckPointTimeout + 15;} ckpt_active = false;} / * Check for archive_timeout and switch xlog files if necessary. * / / check the archive_timeout and switch the xlog file if necessary. CheckArchiveTimeout (); / * * Send off activity statistics to the stats collector. (The reason * why we re-use bgwriter-related code for this is that the bgwriter * and checkpointer used to be just one process. It's probably not * worth the trouble to split the stats support into two independent * stats message types.) * send activity statistics to the statistics collector. * / pgstat_send_bgwriter (); / * * Sleep until we are signaled or it's time for another checkpoint or * xlog file switch. * hibernate until you receive a signal or need to start a new checkpoint or xlog file switch. * / / reset related variables now = (pg_time_t) time (NULL); elapsed_secs = now-last_checkpoint_time; if (elapsed_secs > = CheckPointTimeout) continue; / * no sleep for us. * / cur_timeout = CheckPointTimeout-elapsed_secs If (XLogArchiveTimeout > 0 & &! RecoveryInProgress ()) {elapsed_secs = now-last_xlog_switch_time; if (elapsed_secs > = XLogArchiveTimeout) continue; / * no sleep for us... * / cur_timeout = Min (cur_timeout, XLogArchiveTimeout-elapsed_secs) / / get the minimum sleep time} (void) WaitLatch (MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, cur_timeout * 1000L / * convert to ms * /, WAIT_EVENT_CHECKPOINTER_MAIN) / / hibernation}} / * * Unix-like signal handler installation * Unix style signal processor * Only called on main thread, no sync required * only needs to be executed in the main thread and does not need sync synchronization. * / pqsigfuncpqsignal (int signum, pqsigfunc handler) {pqsigfunc prevfunc;// function if (signum > = PG_SIGNAL_COUNT | | signum
< 0) return SIG_ERR;//验证不通过,返回错误 prevfunc = pg_signal_array[signum];//获取先前的处理函数 pg_signal_array[signum] = handler;//注册函数 return prevfunc;//返回先前注册的函数}/* * GetInsertRecPtr -- Returns the current insert position. * 返回当前插入位置 * * NOTE: The value *actually* returned is the position of the last full * xlog page. It lags behind the real insert position by at most 1 page. * For that, we don't need to scan through WAL insertion locks, and an * approximation is enough for the current usage of this function. * 注意:返回的值*实际上*是最后一个完整xlog页面的位置. * 它比实际插入位置最多落后1页。 * 为此,我们不需要遍历WAL插入锁,满足该函数的当前使用目的,近似值已足够。 */XLogRecPtrGetInsertRecPtr(void){ XLogRecPtr recptr; SpinLockAcquire(&XLogCtl->Info_lck); recptr = XLogCtl- > LogwrtRqst.Write;// to get the insertion position SpinLockRelease (& XLogCtl- > info_lck); return recptr;} III. Tracking analysis
Create data tables, insert data, and execute checkpoint
Testdb=# drop table tweewalkckptbot drop TABLEtestdb=# create table t_wal_ckpt (C1 int not null,c2 varchar (40), c3 varchar (40)); CREATE TABLEtestdb=# insert into t_wal_ckpt (C1 int not null,c2 varchar, c2 and c3) values; INSERT 0 1testdb=# testdb=# checkpoint;-- > the first checkpoint
Update the data and execute checkpoint.
Testdb=# update t_wal_ckpt set c2 = 'C2pm' | | substr (c2mem4); UPDATE 1testdb=# checkpoint
Start gdb and set signal control
(gdb) handle SIGINT print nostop passSIGINT is used by the debugger.Are you sure you want to change it? (y or n) ySignal Stop Print Pass to program DescriptionSIGINT No Yes Yes Interrupt (gdb) (gdb) b checkpointer.c:441Breakpoint 1 at 0x815197: file checkpointer.c, line 441.( gdb) cContinuing.Program received signal SIGINT, Interrupt.Breakpoint 1, CheckpointerMain () at checkpointer.c:441441 flags | = CheckpointerShmem- > ckpt_flags; (gdb)
View shared memory information CheckpointerShmem
(gdb) p * CheckpointerShmem$1 = {checkpointer_pid = 1650, ckpt_lck = 1'\ 001mm, ckpt_started = 2, ckpt_done = 2, ckpt_failed = 0, ckpt_flags = 44, num_backend_writes = 0, num_backend_fsync = 0, num_requests = 0, max_requests = 65536, requests = 0x7f2cdda07b28} (gdb)
Set related information CheckpointerShmem
441 flags | = CheckpointerShmem- > ckpt_flags; (gdb) n442 CheckpointerShmem- > ckpt_flags = 0; (gdb) 443 CheckpointerShmem- > ckpt_started++; (gdb) 444 SpinLockRelease (& CheckpointerShmem- > ckpt_lck); (gdb) 450 if (flags & CHECKPOINT_END_OF_RECOVERY) (gdb) 460 if (! do_restartpoint & & (gdb) 461 (flags & CHECKPOINT_CAUSE_XLOG) & & (gdb) 460 if (! do_restartpoint & &)
Initialize the private variables that the checkpointer process needs to use during the checkpoint process.
Where ckpt_start_recptr is the insertion point, that is, Redo point,5521180544 is converted to hexadecimal to 0x1 49168780
(gdb) 474 ckpt_active = true; (gdb) 475 if (do_restartpoint) (gdb) 478 ckpt_start_recptr = GetInsertRecPtr (); (gdb) p XLogCtl- > LogwrtRqst$1 = {Write = 5521180544, Flush = 5521180544} (gdb) n479 ckpt_start_time = now; (gdb) p ckpt_start_recptr$2 = 5521180544 (gdb) n480 ckpt_cached_elapsed = 0; (gdb) 485if (! do_restartpoint) (gdb)
Execute checkpoint.OK!
(gdb) 487CreateCheckPoint (flags); (gdb) 488 ckpt_performed = true; (gdb)
Close the resource and set the information in the shared memory
497 smgrcloseall (); (gdb) 502 SpinLockAcquire (& CheckpointerShmem- > ckpt_lck); (gdb) 503 CheckpointerShmem- > ckpt_done = CheckpointerShmem- > ckpt_started; (gdb) 504 SpinLockRelease (& CheckpointerShmem- > ckpt_lck) (gdb) 506 if (ckpt_performed) (gdb) p CheckpointerShmem$3 = (CheckpointerShmemStruct *) 0x7fcecc063b00 (gdb) p * CheckpointerShmem$4 = {checkpointer_pid = 1697, ckpt_lck = 0'\ 000mm, ckpt_started = 1, ckpt_done = 1, ckpt_failed = 0, ckpt_flags = 0, num_backend_writes = 0, num_backend_fsync = 0, num_requests = 0, max_requests = 65536, requests = 0x7fcecc063b28} (gdb)
Checkpoint request has been cleared
(gdb) p CheckpointerShmem- > requests [0] $5 = {rnode = {spcNode = 0, dbNode = 0, relNode = 0}, forknum = MAIN_FORKNUM, segno = 0}
Check the archive_timeout and switch the xlog file as needed.
Hibernate until a signal is received or a new checkpoint or xlog file switch needs to be started.
(gdb) n513 last_checkpoint_time = now; (gdb) 526 ckpt_active = false; (gdb) 530 CheckArchiveTimeout (); (gdb) 539 pgstat_send_bgwriter (); (gdb) 545 now = (pg_time_t) time (NULL); (gdb) 546 elapsed_secs = now-last_checkpoint_time; (gdb) 547 if (elapsed_secs > = CheckPointTimeout) (gdb) p elapsed_secs$7 = 1044 (gdb) p CheckPointTimeout$8 = 900 (gdb) n548 continue / * no sleep for us... * /
Timed out to execute the new checkpoint
(gdb) 569} (gdb) 352 bool do_checkpoint = false; (gdb) 353 int flags = 0; (gdb) n360 ResetLatch (MyLatch); (gdb) 365 AbsorbFsyncRequests (); (gdb) 367 if (got_SIGHUP) (gdb) 385 if (checkpoint_requested) (gdb) 391 if (shutdown_requested) (gdb) 410 now = (pg_time_t) time (NULL); (gdb) 411 elapsed_secs = now-last_checkpoint_time (gdb) 412 if (elapsed_secs > = CheckPointTimeout) (gdb) p elapsed_secs$9 = 1131 (gdb) n414 if (! do_checkpoint) (gdb) 415 BgWriterStats.m_timed_checkpoints++; (gdb) 416 do_checkpoint = true; (gdb) 417 flags | = CHECKPOINT_CAUSE_TIME; (gdb) 423 if (do_checkpoint) (gdb) 425 bool ckpt_performed = false; (gdb) 433 do_restartpoint = RecoveryInProgress () (gdb) 440 SpinLockAcquire (& CheckpointerShmem- > ckpt_lck); (gdb) Breakpoint 1, CheckpointerMain () at checkpointer.c:441441 flags | = CheckpointerShmem- > ckpt_flags; (gdb) 442CheckpointerShmem- > ckpt_flags = 0; (gdb) 443CheckpointerShmem- > ckpt_started++; (gdb) cContinuing. This is the end of "checkpointer Analysis of PostgreSQL background process". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.