PostgreSQLHA環(huán)境分析-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“PostgreSQL HA環(huán)境分析”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

建網(wǎng)站原本是網(wǎng)站策劃師、網(wǎng)絡(luò)程序員、網(wǎng)頁設(shè)計師等,應(yīng)用各種網(wǎng)絡(luò)程序開發(fā)技術(shù)和網(wǎng)頁設(shè)計技術(shù)配合操作的協(xié)同工作。創(chuàng)新互聯(lián)專業(yè)提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站制作(企業(yè)站、響應(yīng)式網(wǎng)站、電商門戶網(wǎng)站)等服務(wù),從網(wǎng)站深度策劃、搜索引擎友好度優(yōu)化到用戶體驗的提升,我們力求做到極致!

基于streaming replication搭建的PostgreSQL HA環(huán)境,Old Standby節(jié)點升級為New Master節(jié)點后,時間線會切換為新的時間線,比如從n變?yōu)閚 + 1.而Old Master節(jié)點的時間線仍然為原來的時間線,比如仍為n,通過使用pg_rewind工具,可使原來其實”完好”的Old Master成為New Standby節(jié)點.
圖解
如下圖所示:
PostgreSQL HA環(huán)境分析在執(zhí)行主備切換后,New Master節(jié)點的時間線切換為n + 1,通過pg_rewind可使Old Master在分叉點開始與New Master同步,成為New Standby節(jié)點.

實測
New Master
切換后為New Master后,執(zhí)行以下SQL:

testdb=# create table t_new(id int,flag varchar(40));
CREATE TABLE
testdb=# insert into t_new select c,'flag'||c from generate_series(1,1000000) as c;
INSERT 0 1000000
testdb=#

Old Master
執(zhí)行pg_rewind前,重啟主庫,執(zhí)行以下SQL

testdb=# create table t_fork(id int,flag varchar(40));
CREATE TABLE
testdb=# insert into t_fork select c,'flag'||c from generate_series(1,1000000) as c;
INSERT 0 1000000
testdb=#

執(zhí)行pg_rewind

[xdb@localhost testdb]$ cp /data/archivelog/* ./pg_wal
[xdb@localhost testdb]$ pg_rewind --target-pgdata=$PGDATA --source-server="host=192.168.26.25 port=5432 dbname=testdb" --progress
connected to server
servers diverged at WAL location 0/B41F12B8 on timeline 23
rewinding from last common checkpoint at 0/AFCF99E0 on timeline 23
reading source file list
reading target file list
reading WAL in target
need to copy 360 MB (total source directory size is 501 MB)
369312/369312 kB (100%) copied
creating backup label and updating control file
syncing target data directory
Done!

配置recovery.conf文件

[xdb@localhost testdb]$ mv recovery.done recovery.conf
[xdb@localhost testdb]$ vim recovery.conf 
[xdb@localhost testdb]$ cat recovery.conf 
standby_mode = 'on'
primary_conninfo = 'user=replicator password=replicator host=192.168.26.26 port=5432 sslmode=prefer sslcompression=0 krbsrvname=postgres target_session_attrs=any'
restore_command = 'cp /data/archivelog/%f %p'

重啟數(shù)據(jù)庫

[xdb@localhost testdb]$ pg_ctl start
waiting for server to start....2019-03-28 12:39:31.918 CST [1961] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-03-28 12:39:31.918 CST [1961] LOG:  listening on IPv6 address "::", port 5432
2019-03-28 12:39:31.920 CST [1961] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-03-28 12:39:31.970 CST [1961] LOG:  redirecting log output to logging collector process
2019-03-28 12:39:31.970 CST [1961] HINT:  Future log output will appear in directory "pg_log".
... done
server started

與New Master數(shù)據(jù)同步了,而在原TL上的t_fork數(shù)據(jù)表消失了.

testdb=# select count(*) from t_new;
  count  
---------
 1000000
(1 row)
testdb=# select count(*) from t_old;
  count  
---------
 1000000
(1 row)
testdb=# select count(*) from t_fork;
ERROR:  relation "t_fork" does not exist
LINE 1: select count(*) from t_fork;
                             ^
testdb=#

“PostgreSQL HA環(huán)境分析”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

分享標(biāo)題:PostgreSQLHA環(huán)境分析-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://bm7419.com/article12/iigdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作網(wǎng)站收錄、域名注冊網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司