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

PostgreSQL checkpoint--shutdown

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

Share

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

PostgreSQL will do checkpoint when shutdown. The process is as follows.

1. In the main process, a signal processing function reaper is registered first, which is used to send signals to child processes such as checkpoint. Send SIGUSR2 signals to the checkpoint process

PostmasterMain (int argc, char argv [])

Pqsignal_no_restart (SIGCHLD, reaper); / handle child termination * /

Reaper:

While ((pid = waitpid (- 1, & exitstatus, WNOHANG)) > 0) {

...

If (pid = = CheckpointerPID) {

...

SignalChildren (SIGUSR2)

}

...

}

...

PostmasterStateMachine (); / / send a SIGUSR2 signal to the checkpoint process

|

| | if (pmState = = PM_WAIT_BACKENDS) {|

| | if (CountChildren (BACKEND_TYPE_NORMAL | BACKEND_TYPE_WORKER)) = = 0 &

| | StartupPID = = 0 & &

| | WalReceiverPID = = 0 & &

| | BgWriterPID = = 0 & &

| (CheckpointerPID = = 0 | | (! FatalError & & Shutdown)

< ImmediateShutdown)) && | WalWriterPID == 0 && | AutoVacPID == 0){ | //pg_ctl stop -m immediate不会向checkpoint进程发送信号,即不会做checkpoint | if (Shutdown >

= ImmediateShutdown | | FatalError) {

| | pmState = PM_WAIT_DEAD_END |

| |} else {|

| | if (CheckpointerPID! = 0) {|

| | signal_child (CheckpointerPID, SIGUSR2) |

| | pmState = PM_SHUTDOWN |

| |}

}

| |}

| | -} |

2. The checkpoint process will also register a signal processing function ReqShutdownHandler, which is used to process the SIGUSR2 signal sent by the main process. When the signal is received, shutdown_requested is set to TRUE. In the for loop of the checkpoint process, if shutdown_requested is TRUE, enter the shutdown process: stop each sender process, and after all sender processes stop, checkpoint:CreateRestartPoint the latter CreateCheckPoint according to the conditions

CheckpointerMain (void)->

/ / install the signal processing function ReqShutdownHandler for the signal SIGUSR2

Pqsignal (SIGUSR2, ReqShutdownHandler); / request shutdown /

...

For (;;) {

If (shutdown_requested) {

/ Close down the database /

ShutdownXLOG (0,0)

| |-- WalSndInitStopping (); / / send a signal to each sender process to modify the stopping status |

| | WalSndWaitStopping () |

| | if (RecoveryInProgress ()) |

| | CreateRestartPoint (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE) |

| | else {|

| | if (XLogArchivingActive () & & XLogArchiveCommandSet ()) |

| | RequestXLogSwitch (false) |

| | CreateCheckPoint (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE) |

| |}

|--.

Proc_exit (0)

}

...

Checkpoint

}

3. The ReqShutdownHandler function sets shutdown_requested to TRUE.

ReqShutdownHandler (SIGNAL_ARGS)

{

Shutdown_requested = true

SetLatch (MyLatch)

}

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

Wechat

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

12
Report