溫馨提示×

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

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

PostgreSQL的pg_promote有什么作用

發(fā)布時(shí)間:2021-11-09 11:07:34 來(lái)源:億速云 閱讀:574 作者:iii 欄目:關(guān)系型數(shù)據(jù)庫(kù)

這篇文章主要講解了“PostgreSQL的pg_promote有什么作用”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“PostgreSQL的pg_promote有什么作用”吧!

在PG 12以前的版本,備庫(kù)提升為主庫(kù)需在備庫(kù)主機(jī)上執(zhí)行命令或者通過(guò)生成觸發(fā)文件進(jìn)行觸發(fā),在PG 12中,可通過(guò)客戶端連接到數(shù)據(jù)庫(kù)后執(zhí)行pg_promote函數(shù)實(shí)現(xiàn).

下面以一個(gè)簡(jiǎn)單的例子進(jìn)行說(shuō)明.

搭建流復(fù)制環(huán)境
參照 PostgreSQL DBA(31) - Backup&Recovery#4(搭建流復(fù)制) ,注意在PG 12,recovery.conf文件已廢棄,相關(guān)的配置信息已合并至postgresql.conf文件中.
下面是搭建完畢后,在主庫(kù)創(chuàng)建數(shù)據(jù)表t1后,備庫(kù)的情況.
備庫(kù)

[pg12@localhost pg12db1]$ pg_ctl start
waiting for server to start....2019-06-20 17:04:04.361 CST [23158] LOG:  starting PostgreSQL 12beta1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
2019-06-20 17:04:04.362 CST [23158] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-06-20 17:04:04.362 CST [23158] LOG:  listening on IPv6 address "::", port 5432
2019-06-20 17:04:04.365 CST [23158] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-06-20 17:04:04.422 CST [23158] LOG:  redirecting log output to logging collector process
2019-06-20 17:04:04.422 CST [23158] HINT:  Future log output will appear in directory "pg_log".
 done
server started
[pg12@localhost pg12db1]$ psql -d testdb
psql (12beta1)
Type "help" for help.
testdb=# select count(*) from t1;
psql: ERROR:  relation "t1" does not exist
LINE 1: select count(*) from t1;
                             ^
testdb=# select count(*) from t1;
 count 
-------
     0
(1 row)

下面通過(guò)遠(yuǎn)程客戶端連接到備庫(kù),執(zhí)行函數(shù)pg_promote提升備庫(kù)為主庫(kù).

[pg12@localhost pg12db1]$ psql -h 192.168.26.27 -U pg12 -d testdb
psql (12beta1)
Type "help" for help.
testdb=# -- Wait for at most 30 seconds.
testdb=# SELECT pg_promote(true, 30);
 pg_promote 
------------
 t
(1 row)

日志輸出

",,,,,"SELECT pg_promote(true, 30);",,,"psql"
2019-06-20 17:14:22.584 CST,,,23160,,5d0b4c04.5a78,5,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"received promote request",,,,,,,,,""
2019-06-20 17:14:22.584 CST,,,23167,,5d0b4c04.5a7f,2,,2019-06-20 17:04:04 CST,,0,FATAL,57P01,"terminating walreceiver process due to administrator command",,,,,,,,,""
2019-06-20 17:14:22.625 CST,,,23160,,5d0b4c04.5a78,6,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"invalid record length at 0/5016D48: wanted 24, got 0",,,,,,,,,""
2019-06-20 17:14:22.625 CST,,,23160,,5d0b4c04.5a78,7,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"redo done at 0/5016D10",,,,,,,,,""
2019-06-20 17:14:22.625 CST,,,23160,,5d0b4c04.5a78,8,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"last completed transaction was at log time 2019-06-20 17:04:49.180746+08",,,,,,,,,""
2019-06-20 17:14:22.649 CST,,,23160,,5d0b4c04.5a78,9,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"selected new timeline ID: 2",,,,,,,,,""
2019-06-20 17:14:22.738 CST,,,23160,,5d0b4c04.5a78,10,,2019-06-20 17:04:04 CST,1/0,0,LOG,00000,"archive recovery complete",,,,,,,,,""
2019-06-20 17:14:22.755 CST,,,23158,,5d0b4c04.5a76,3,,2019-06-20 17:04:04 CST,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,""
2019-06-20 17:14:22.764 CST,,,23277,,5d0b4e6e.5aed,1,,2019-06-20 17:14:22 CST,,0,FATAL,XX000,"archive command failed with exit code 127","The failed archive command was: /home/pg12/archive.sh",,,,,,,,""
2019-06-20 17:14:22.766 CST,,,23158,,5d0b4c04.5a76,4,,2019-06-20 17:04:04 CST,,0,LOG,00000,"archiver process (PID 23277) exited with exit code 1",,,,,,,,,""
2019-06-20 17:15:22.779 CST,,,23329,,5d0b4eaa.5b21,1,,2019-06-20 17:15:22 CST,,0,FATAL,XX000,"archive command failed with exit code 127","The failed archive command was: /home/pg12/archive.sh",,,,,,,,""
2019-06-20 17:15:22.781 CST,,,23158,,5d0b4c04.5a76,5,,2019-06-20 17:04:04 CST,,0,LOG,00000,"archiver process (PID 23329) exited with exit code 1",,,,,,,,,""
[pg12@localhost pg_log]$

pg_control中的狀態(tài)

[pg12@localhost pg12db1]$ pg_controldata|grep state
Database cluster state:               in production

從日志&狀態(tài)可看出,備庫(kù)已提升為主庫(kù)(出錯(cuò)提示是沒(méi)有找到歸檔命令).

感謝各位的閱讀,以上就是“PostgreSQL的pg_promote有什么作用”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)PostgreSQL的pg_promote有什么作用這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向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