最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
怎么使用pg_rewind-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“怎么使用pg_rewind”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么使用pg_rewind”吧!

創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括同仁網(wǎng)站建設(shè)、同仁網(wǎng)站制作、同仁網(wǎng)頁制作以及同仁網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,同仁網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到同仁省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

pg_rewind

  是postgresql主叢數(shù)據(jù)庫之同步數(shù)據(jù)目錄的工具。需要目標(biāo)服務(wù)器在postgresql.conf 中允許wal_log_hints,或者在 initdb初始化集群時(shí)允許 checksums ,full_page_writes也必須為on

  pg_rewind只復(fù)制表數(shù)據(jù)文件中更改的塊;所有其他文件都被完整復(fù)制,包括配置文件。pg_rewind相對(duì)于使用pg_basebackup備份或rsync等工具的優(yōu)勢(shì)在于,pg_rewind不需要讀取數(shù)據(jù)庫中未更改的塊。這使得在數(shù)據(jù)庫很大且之間只有一小部分塊不同的情況下,速度會(huì)快得多。

  pg_rewind [option...] { -D | --target-pgdata } directory { --source-pgdata=directory | --source-server=connstr

參數(shù):

-D directory --target-pgdata=directory

  此選項(xiàng)指定與源同步的目標(biāo)數(shù)據(jù)目錄。在運(yùn)行pg_rewind之前,必須干凈關(guān)閉目標(biāo)服務(wù)器

--source-pgdata=directory

  指定要與之同步的源服務(wù)器的數(shù)據(jù)目錄的文件系統(tǒng)路徑。此選項(xiàng)要求干凈關(guān)閉源服務(wù)器

--source-server=connstr

  指定要連接到源PostgreSQL服務(wù)器的libpq連接字符串。連接必須是具有超級(jí)用戶訪問權(quán)限的正常(非復(fù)制)連接。此選項(xiàng)要求源服務(wù)器正在運(yùn)行,而不是處于恢復(fù)模式。

-n --dry-run

  除了實(shí)際修改目標(biāo)目錄之外,執(zhí)行所有操作。

-P --progress

  使進(jìn)展報(bào)告。

實(shí)驗(yàn)使用兩臺(tái)主機(jī),都安裝postgresql-10.7,已配置流復(fù)制

  • 主:192.168.56.5 m1

  • 叢:192.168.56.25 m7

m1(主):創(chuàng)建測(cè)試表和數(shù)據(jù)

postgres=# create table test (id int,e_name varchar(100),e_mail varchar(100),d_id int);
CREATE TABLE
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | test | table | postgres
(1 row)
postgres=# insert into test values(1,'zbs','[email protected]',10);
INSERT 0 1
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
(1 row)

m7 (叢):查詢數(shù)據(jù)復(fù)制成功

[postgres@z_leader ~]$ psql postgres
psql (10.7)
Type "help" for help.
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | test | table | postgres
(1 row)
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
(1 row)

提升叢庫為新主庫

[postgres@z_leader data]$ pg_ctl promote -D /usr/local/pg/data
waiting for server to promote.... done
server promoted
[postgres@z_leader data]$ psql postgres
psql (10.7)
Type "help" for help.
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)

m1(原主庫)插入一條記錄,模擬原主庫上的數(shù)據(jù)沒有復(fù)制到原叢庫上

postgres=# insert into test values(2,'zbs1','[email protected]',10);
INSERT 0 1
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
2 | zbs1 | [email protected] | 10
(2 rows)

m7:在原叢庫上(已提升為主庫)插入一條記錄并查看結(jié)果

postgres=# insert into test values(3,'zbs2','[email protected]',10);
INSERT 0 1
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
3 | zbs2 | [email protected] | 10
(2 rows)

m1 將原主庫變?yōu)樾轮鲙斓膮矌?/p>

[postgres@localhost ~]$ kill -INT `head -1 /usr/local/pg/data/postmaster.pid`

--配置流復(fù)制文件和參數(shù)

[postgres@localhost data]$ mv recovery.done recovery.conf
[postgres@localhost data]$ cat recovery.conf
standby_mode = 'on'
restore_command = 'cp /usr/local/pg/arch/%f'
primary_conninfo = 'host=192.168.56.25 port=5432 user=rep'
recovery_target_timeline = 'latest'
[postgres@localhost data]$

--啟動(dòng)數(shù)據(jù)庫

[postgres@localhost ~]$ /usr/local/pg/bin/pg_ctl -D /usr/local/pg/data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost data]$ psql postgres
psql (10.7)
Type "help" for help.
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
2 | zbs1 | [email protected] | 10
(2 rows)

--在m7上插入的記錄未能復(fù)制過來

---日志信息

2019-03-02 09:15:17.415 CST [2492] LOG: consistent recovery state reached at 0/D000098
2019-03-02 09:15:17.415 CST [2492] LOG: invalid record length at 0/D000098: wanted 24, got 0
2019-03-02 09:15:17.415 CST [2490] LOG: database system is ready to accept read only connections
2019-03-02 09:15:17.429 CST [2500] LOG: fetching timeline history file for timeline 6 from primary server
2019-03-02 09:15:17.460 CST [2500] FATAL: could not start WAL streaming: ERROR: requested starting point 0/D000000 on timeline 5 is not in this
server's history
DETAIL: This server's history forked from timeline 5 at 0/C003168.
cp: missing destination file operand after `/usr/local/pg/arch/00000006.history'
Try `cp --help' for more information.
cp: missing destination file operand after `/usr/local/pg/arch/00000007.history'
Try `cp --help' for more information.
cp: missing destination file operand after `/usr/local/pg/arch/00000006.history'
Try `cp --help' for more information.
2019-03-02 09:15:17.469 CST [2492] LOG: new timeline 6 forked off current database system timeline 5 before current recovery point 0/D000098
cp: missing destination file operand after `/usr/local/pg/arch/00000005000000000000000D
[postgres@localhost ~]$ kill -INT `head -1 /usr/local/pg/data/postmaster.pid`

---使得pg_rewind 同步數(shù)據(jù)庫時(shí)間線

[[postgres@localhost ~]$ pg_rewind --target-pgdata /usr/local/pg/data --source-server='host=192.168.56.25 port=5432 user=postgres dbname=postgres' -P
connected to server
servers diverged at WAL location 0/C003168 on timeline 5
rewinding from last common checkpoint at 0/C003010 on timeline 5
reading source file list
reading target file list
reading WAL in target
need to copy 100 MB (total source directory size is 118 MB)
102599/102599 kB (100%) copied
creating backup label and updating control file
syncing target data directory
Done!

--pg_rewind后此文件需要重新配置

[postgres@localhost data]$ cat recovery.conf
standby_mode = 'on'
restore_command = 'cp /usr/local/pg/arch/%f'
primary_conninfo = 'host=192.168.56.25 port=5432 user=rep'
recovery_target_timeline = 'latest'
[postgres@localhost ~]$ /usr/local/pg/bin/pg_ctl -D /usr/local/pg/data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost ~]$ psql postgres
psql (10.7)
Type "help" for help.
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
3 | zbs2 | [email protected] | 10
(2 rows)
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)

--原主庫沒有復(fù)制到叢庫的記錄消失,在新主庫上插入的記錄已同步

m7(新主庫)
[postgres@z_leader ~]$ psql postgres
psql (10.7)
Type "help" for help.
postgres=# insert into test values(4,'zbs2','[email protected]',10);
INSERT 0 1
postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
3 | zbs2 | [email protected] | 10
4 | zbs2 | [email protected] | 10
(3 rows)

m1(新叢庫)

postgres=# select * from test;
id | e_name | e_mail | d_id
----+--------+-------------+------
1 | zbs | [email protected] | 10
3 | zbs2 | [email protected] | 10
4 | zbs2 | [email protected] | 10
(3 rows)

到此,相信大家對(duì)“怎么使用pg_rewind”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!


分享名稱:怎么使用pg_rewind-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://fisionsoft.com.cn/article/cesces.html