溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Postgresql流復(fù)制切換的時(shí)候遇到的一個(gè)小問(wèn)題

發(fā)布時(shí)間:2020-03-08 01:01:07 來(lái)源:網(wǎng)絡(luò) 閱讀:1445 作者:李石巖 欄目:數(shù)據(jù)庫(kù)

Pg10搭建了流復(fù)制主備切換

配置
主庫(kù)10.10.10.13 pghost4
備庫(kù)10.10.10.14 pghost5

測(cè)試主庫(kù)出現(xiàn)問(wèn)題,停止后,備庫(kù)自動(dòng)切換成為新主庫(kù)。老主庫(kù)現(xiàn)在應(yīng)該是備庫(kù)了,啟動(dòng)它驗(yàn)證狀態(tài)。發(fā)現(xiàn)備庫(kù)啟動(dòng)不起來(lái)。通過(guò)以下方法,備庫(kù)啟動(dòng)了。

  1. 新備庫(kù)通過(guò)pg_ctl start啟動(dòng),出現(xiàn)告警日志。

[root@pghost4 ~]# su - pg10
pg10@pghost4->pg_ctl start
waiting for server to start....2019-12-20 21:44:10.004 CST [23416] LOG: listening on IPv4 address "0.0.0.0", port 1921
2019-12-20 21:44:10.004 CST [23416] LOG: listening on IPv6 address "::", port 1921
2019-12-20 21:44:10.006 CST [23416] LOG: listening on Unix socket "/tmp/.s.PGSQL.1921"
2019-12-20 21:44:10.014 CST [23417] LOG: database system was shut down in recovery at 2019-12-20 21:33:31 CST
2019-12-20 21:44:10.014 CST [23417] LOG: entering standby mode
2019-12-20 21:44:10.014 CST [23417] FATAL: requested timeline 2 is not a child of this server's history
2019-12-20 21:44:10.014 CST [23417] DETAIL: Latest checkpoint is at 0/11000028 on timeline 1, but in the history of the requested timeline, the server forked off from that timeline at 0/C000098.
2019-12-20 21:44:10.015 CST [23416] LOG: startup process (PID 23417) exited with exit code 1
2019-12-20 21:44:10.015 CST [23416] LOG: aborting startup due to startup process failure
2019-12-20 21:44:10.016 CST [23416] LOG: database system is shut down
stopped waiting
pg_ctl: could not start server
Examine the log output.

從上邊的意思可以看到,新備庫(kù)pg_wal目錄下的00000002.history 這個(gè)跟新主庫(kù)不一致。

pg10@pghost4->ll
total 273M
-rw------- 1 pg10 pg10 16M Dec 18 22:40 000000010000000000000001
-rw------- 1 pg10 pg10 16M Dec 18 23:01 000000010000000000000002
-rw------- 1 pg10 pg10 16M Dec 18 23:02 000000010000000000000003
-rw------- 1 pg10 pg10 16M Dec 18 23:06 000000010000000000000004
-rw------- 1 pg10 pg10 16M Dec 18 23:39 000000010000000000000005
-rw------- 1 pg10 pg10 16M Dec 18 23:51 000000010000000000000006
-rw------- 1 pg10 pg10 16M Dec 18 23:55 000000010000000000000007
-rw------- 1 pg10 pg10 16M Dec 18 23:58 000000010000000000000008
-rw------- 1 pg10 pg10 16M Dec 19 00:15 000000010000000000000009
-rw------- 1 pg10 pg10 16M Dec 19 00:15 00000001000000000000000A
-rw------- 1 pg10 pg10 16M Dec 19 00:27 00000001000000000000000B
-rw------- 1 pg10 pg10 16M Dec 19 00:29 00000001000000000000000C
-rw------- 1 pg10 pg10 16M Dec 19 00:34 00000001000000000000000D
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000E
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000F
-rw------- 1 pg10 pg10 302 Dec 19 00:36 00000001000000000000000F.00000028.backup
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000010
-rw------- 1 pg10 pg10 16M Dec 20 21:33 000000010000000000000011
-rw------- 1 pg10 pg10 41 Dec 19 00:30 00000002.history
drwx------ 2 pg10 pg10 4.0K Dec 20 21:31 archive_status
pg10@pghost4->more 00000002.history
1 0/C000098 no recovery target specified
pg10@pghost4->

然后看新主庫(kù)該路徑下的目錄

pg10@pghost4->ll
total 132K
-rw------- 1 pg10 pg10 206 Dec 19 00:36 backup_label.old
drwx------ 5 pg10 pg10 4.0K Dec 19 00:36 base
drwx------ 2 pg10 pg10 4.0K Dec 20 21:27 global
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_commit_ts
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_dynshmem
-rw------- 1 pg10 pg10 4.6K Dec 19 00:36 pg_hba.conf
-rw------- 1 pg10 pg10 1.6K Dec 19 00:36 pg_ident.conf
drwx------ 4 pg10 pg10 4.0K Dec 19 00:38 pg_logical
drwx------ 4 pg10 pg10 4.0K Dec 19 00:36 pg_multixact
drwx------ 2 pg10 pg10 4.0K Dec 19 00:37 pg_notify
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_replslot
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_serial
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_snapshots
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_stat
drwx------ 2 pg10 pg10 4.0K Dec 20 21:48 pg_stat_tmp
drwx------ 2 pg10 pg10 4.0K Dec 19 00:38 pg_subtrans
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_tblspc
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_twophase
-rw------- 1 pg10 pg10 3 Dec 19 00:36 PG_VERSION
drwx------ 3 pg10 pg10 4.0K Dec 19 00:38 pg_wal
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_xact
-rw------- 1 pg10 pg10 88 Dec 19 00:36 postgresql.auto.conf
-rw------- 1 pg10 pg10 23K Dec 19 00:36 postgresql.conf
-rw------- 1 pg10 pg10 31 Dec 19 00:37 postmaster.opts
-rw------- 1 pg10 pg10 74 Dec 19 00:38 postmaster.pid
-rw-r--r-- 1 pg10 pg10 5.8K Dec 19 00:37 recovery.done
pg10@pghost4->cd pg_wal/pg10@pghost4->ll
br/>pg10@pghost4->ll
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000F
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000010
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000011.partial
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000020000000000000011
-rw------- 1 pg10 pg10 42 Dec 19 00:38 00000002.history
drwx------ 2 pg10 pg10 4.0K Dec 19 00:38 archive_statuspg10@pghost4->pwd
br/>pg10@pghost4->pwd
pg10@pghost4->more 00000002.history
1 0/11000098 no recovery target specified

將新備庫(kù)的00000002.history 備份,然后刪除。
將新主庫(kù)的傳遞到新備庫(kù)。
然后啟動(dòng)。
pg10@pghost4->scp 00000002.history 10.10.10.13:/data/pg10/data/pg_wal/
pg10@10.10.10.13's password:
00000002.history 100% 42 0.0KB/s 00:00
pg10@pghost4->

pg10@pghost4->pg_ctl start
waiting for server to start....2019-12-20 21:51:25.142 CST [23486] LOG: listening on IPv4 address "0.0.0.0", port 1921
2019-12-20 21:51:25.142 CST [23486] LOG: listening on IPv6 address "::", port 1921
2019-12-20 21:51:25.144 CST [23486] LOG: listening on Unix socket "/tmp/.s.PGSQL.1921"
2019-12-20 21:51:25.155 CST [23487] LOG: database system was shut down in recovery at 2019-12-20 21:33:31 CST
2019-12-20 21:51:25.155 CST [23487] LOG: entering standby mode
2019-12-20 21:51:25.171 CST [23487] LOG: consistent recovery state reached at 0/11000098
2019-12-20 21:51:25.171 CST [23487] LOG: invalid record length at 0/11000098: wanted 24, got 0
2019-12-20 21:51:25.171 CST [23486] LOG: database system is ready to accept read only connections
2019-12-20 21:51:25.179 CST [23491] LOG: started streaming WAL from primary at 0/11000000 on timeline 2
2019-12-20 21:51:25.225 CST [23487] LOG: redo starts at 0/11000098
done
server started
pg10@pghost4->

發(fā)現(xiàn)已經(jīng)啟動(dòng)。

pg10@pghost4->pg_controldata|grep cluster
Database cluster state: in archive recovery
pg10@pghost4->

可以看到新備庫(kù)處于備庫(kù)模式。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI