久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Postgresql主從搭建

 jas0n_liu 2018-10-12

1. 安裝PG數(shù)據(jù)庫(kù)

安裝過(guò)程略。注:slave端可以只裝數(shù)據(jù)庫(kù),,不初始化數(shù)據(jù)庫(kù)

2. 創(chuàng)建流復(fù)制用戶(hù)

master端執(zhí)行

CREATE USER repuser replication LOGIN CONNECTION LIMIT 2 ENCRYPTED PASSWORD 'repuser';

3. 配置Master端的訪問(wèn)文件

vi  pg_hba.conf

增加一行:

host replication repuser 192.168.2.129/16 md5

4. 配置MASTER端配置文件

listen_addresses = '*'

max_wal_senders = 1

wal_level = hot_standby

archive_mode = on

archive_command = 'cd ./'

wal_keep_segments = 64

注:max_wal_sendersSlave庫(kù)的節(jié)點(diǎn)數(shù),,有多少個(gè)slave庫(kù)就設(shè)多少,

   wal_levelwrite ahead log參數(shù)值,設(shè)置流復(fù)制務(wù)必將此值更新成hot_standby

   wal_keep_segments默認(rèn)值是16,PG_XLOG下的日志文件大小

archive也可以選擇關(guān)閉,歸檔是定時(shí)恢復(fù)用的,,流復(fù)制不是必須的 

5. 主庫(kù)備份(Master端)

5.1. 開(kāi)啟文件備份

前提是wal_level參數(shù)值必須是archive或者hot_standby

執(zhí)行命令:select pg_start_backup('Replition work');

5.2. 拷貝數(shù)據(jù)文件

拷貝$PGDATA文件,,并復(fù)制到Slave服務(wù)器上,排除pg_xlog內(nèi)容

tar czvf pgdata.tar.gz pgdata --exclude=pgdata/pg_xlog

遠(yuǎn)程拷貝至slave端并在備機(jī)端解壓

scp pgdata.tar.gz [email protected]:/database/

tar xzvf pgdata.tar.gz

5.3. 結(jié)束master端的備份

上述步驟完成后,結(jié)束master端的備份

select pg_stop_backup(), current_timestamp;

6. 修改Slave端配置信息

6.1.  postgresql.conf文件

修改postgresql.conf文件

hot_standby = on

6.2.  recovery.conf文件

拷貝recovery.conf文件

$cp $PGHOME/share/recovery.conf.sample $PGDATA/recovery.conf

修改recovery.conf文件,,新增以下三行

$ vi recovery.conf  

  standby_mode = 'on'

  trigger_file = '/database/pgdata/postgresql.trigger.1949'

  primary_conninfo = 'host=192.168.2.130 port=1949 user=repuser password=repuser keepalives_idle=60'

6.3.  配置.pgpass文件(slave端)

新增slave訪問(wèn)master的密碼文件,,可以不用輸密碼

192.168.2.130:1949:postgres:repuser:repuser

6.4. 刪除pid文件

刪除slave(master端拷過(guò)來(lái)的)pid文件和pg_xlog

$ rm -rf  $PGDATA/pg_xlog

$ rm -f $PGDATA/postmaster.pid

$ mkdir  $PGDATA/pg_xlog

7. 啟動(dòng)Slave庫(kù)

正常啟動(dòng)備庫(kù)(pg_ctl -D $PGDATA -l pg.log start),有異常可以看log復(fù)制完成后,,可以通過(guò)CSV日志去查看,,本處未設(shè),直接查看進(jìn)程,。

7.1.  查看master進(jìn)程:

[postgres@localhost ~]$ ps -ef|grep postgres

root      2454  2438  0 20:25 pts/0    00:00:00 su - postgres

postgres  2461  2454  0 20:25 pts/0    00:00:00 -bash

postgres  2535  1 0 20:26 pts/1 00:00:00 /home/postgres/bin/postgres -D /database/pgdata

postgres  2537  2535  0 20:26 ?        00:00:00 postgres: writer process                       

postgres  2538  2535  0 20:26 ?        00:00:00 postgres: wal writer process                   

postgres  2539  2535  0 20:26 ?        00:00:00 postgres: autovacuum launcher process          

postgres  2540  2535  0 20:26 ?        00:00:00 postgres: archiver process                     

postgres  2541  2535  0 20:26 ?        00:00:00 postgres: stats collector process              

postgres  3079  2535  0 21:56 ?        00:00:00 postgres: wal sender process repuser 192.168.2.129(45446) streaming 0/C01EDB8

 

7.2.  查看slave進(jìn)程:

[postgres@localhost ~]$ ps -ef|grep postgres

postgres  2856     1  0 21:54 pts/2    00:00:00 /home/postgres/bin/postgres -D /database/pgdata

postgres  2858  2856  0 21:54 ?        00:00:00 postgres: startup process   recovering 000000010000000000000003

postgres  2859  2856  0 21:54 ?        00:00:00 postgres: writer process                       

postgres  2860  2856  0 21:54 ?        00:00:00 postgres: stats collector process              

postgres  2899  2856  0 21:56 ?        00:00:00 postgres: wal receiver process   streaming 0/C01ED28

 

此時(shí)在slave端的pg_xlog下面也產(chǎn)生了日志文件,并且之前pg_start_backup生成的文件名也變成了old的了.

 

查看日志內(nèi)容:

[postgres@localhost ~]$ more pgsql.log

LOG:  database system was shut down in recovery at 2012-04-23 18:33:25 PDT

LOG:  entering standby mode

LOG:  streaming replication successfully connected to primary

LOG:  redo starts at 0/8000020

LOG:  consistent recovery state reached at 0/C000000

LOG:  database system is ready to accept read only connections

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多