Postgresql主备快照同步流程

2022-05-12 11:02:28 浏览数 (3)

备库读涉及快照的流程

rbreak procarray.c:.

比较简单,直接拿快照就好了。

堆栈:

备库更新procarray流程

主库的事务状态会拼成xlog发送给备库:

  • 主库上有三个事务在运行
  • 备库收到info == XLOG_RUNNING_XACTS类型xlog,解析后还原为RunningTransactionsData running
  • 使用running刷新备库snapshot状态

备库 【1】

代码语言:javascript复制
(gdb) bt
#0  RecordKnownAssignedTransactionIds (xid=612) at procarray.c:3199
#1  0x0000000000549019 in StartupXLOG () at xlog.c:7279
#2  0x00000000007e181f in StartupProcessMain () at startup.c:230
#3  0x000000000055d5c9 in AuxiliaryProcessMain (argc=2, argv=0x7ffe04557c20) at bootstrap.c:426
#4  0x00000000007e0710 in StartChildProcess (type=StartupProcess) at postmaster.c:5463
#5  0x00000000007db5bb in PostmasterMain (argc=3, argv=0x1a79c80) at postmaster.c:1377
#6  0x00000000007195f6 in main (argc=3, argv=0x1a79c80) at main.c:228

【2】

代码语言:javascript复制
#0  KnownAssignedXidsAdd (from_xid=612, to_xid=612, exclusive_lock=0 '00') at procarray.c:3478
#1  0x0000000000851a23 in RecordKnownAssignedTransactionIds (xid=612) at procarray.c:3247
#2  0x0000000000549019 in StartupXLOG () at xlog.c:7279
#3  0x00000000007e181f in StartupProcessMain () at startup.c:230
#4  0x000000000055d5c9 in AuxiliaryProcessMain (argc=2, argv=0x7ffe04557c20) at bootstrap.c:426
#5  0x00000000007e0710 in StartChildProcess (type=StartupProcess) at postmaster.c:5463
#6  0x00000000007db5bb in PostmasterMain (argc=3, argv=0x1a79c80) at postmaster.c:1377
#7  0x00000000007195f6 in main (argc=3, argv=0x1a79c80) at main.c:228

【3】

代码语言:javascript复制
#0  RecordKnownAssignedTransactionIds (xid=612) at procarray.c:3199
#1  0x000000000053d080 in xact_redo_commit (parsed=0x7ffe04557010, xid=612, lsn=4169788496, origin_id=0) at xact.c:5483
#2  0x000000000053d3ed in xact_redo (record=0x1aa3d50) at xact.c:5671
#3  0x0000000000549048 in StartupXLOG () at xlog.c:7282
#4  0x00000000007e181f in StartupProcessMain () at startup.c:230
#5  0x000000000055d5c9 in AuxiliaryProcessMain (argc=2, argv=0x7ffe04557c20) at bootstrap.c:426
#6  0x00000000007e0710 in StartChildProcess (type=StartupProcess) at postmaster.c:5463
#7  0x00000000007db5bb in PostmasterMain (argc=3, argv=0x1a79c80) at postmaster.c:1377
#8  0x00000000007195f6 in main (argc=3, argv=0x1a79c80) at main.c:228

主库在哪发快照信息

在BackgroundWriterMain进程中拼RunningTransactions,并写xlog,后面就交给wal sender了。

代码语言:javascript复制
(gdb) bt
#0  LogStandbySnapshot () at standby.c:1040
#1  0x00000000007ceffc in BackgroundWriterMain () at bgwriter.c:336
#2  0x000000000055d5ce in AuxiliaryProcessMain (argc=2,	argv=0x7ffd48dd6cc0) at bootstrap.c:431
#3  0x00000000007e0710 in StartChildProcess (type=BgWriterProcess) at postmaster.c:5463
#4  0x00000000007ddadd in reaper (postgres_signal_arg=17) at postmaster.c:2936
#5  <signal handler called>
#6  0x00007f66847f4793 in __select_nocancel () from /lib64/libc.so.6
#7  0x00000000007dbe9f in ServerLoop ()	at postmaster.c:1741
#8  0x00000000007db602 in PostmasterMain (argc=3, argv=0xf8dc70) at postmaster.c:1385
#9  0x00000000007195f6 in main (argc=3,	argv=0xf8dc70) at main.c:228

1 人点赞