- 在 PostgreSQL 10 架設 Replication 機制!
快速操作流程
-
Master Server 上的設定!
-
建立 Replication 專用帳號:
#su - postgres $createuser --replication -P replica Enter password for new role: (請輸入兩次相同密碼!) Enter it again:
-
修改 PostgreSQL Server 相關設定:
$vim /var/lib/pgsql/10/data/postgresql.conf (只修改下列設定:) listen_addresses = '*' wal_level = replica synchronous_commit = on archive_command = 'cp %p /var/lib/pgsql/10/archive/%f' max_wal_senders = 2 wal_keep_segments = 10 synchronous_standby_names = '*'
-
設定 pg_hba.conf 檔:
$vim /var/lib/pgsql/10/data/pg_hba.conf ### 在檔尾追加下列設定 ### # host replication [replication user] [allowed IP addresses] password host replication replica 127.0.0.1/32 password host replication replica 192.168.5.244/32 password host replication replica 192.168.5.243/32 password
-
重新啟動 PostgreSQL Server:
$pg_ctl restart
-
Slave Server 上的設定!
-
切換成 postgres 使用者:
#su - postgres
-
由 Master 備份資料到 Slave (需要 replica 的密碼):
$rm -rf /var/lib/pgsql/10/data $pg_basebackup -h 192.168.5.244 -U replica -D /var/lib/pgsql/10/data -P Password:
-
修改 PostgreSQL 相關設定:
$vim /var/lib/pgsql/10/data/postgresql.conf (只修改下列設定,其餘設定保留) hot_standby = on
-
從範例檔複製設定檔:
$cp /usr/pgsql-10/share/recovery.conf.sample /var/lib/pgsql/10/data/recovery.conf
-
編修設定檔 /var/lib/pgsql/10/data/recovery.conf:
$vim /var/lib/pgsql/10/data/recovery.conf (只修改下列設定,其餘設定保留) restore_command = 'scp 192.168.5.244:/var/lib/pgsql/10/archive/%f %p' standby_mode = on ### 設定 Master Server 相關設定 ### primary_conninfo = 'host=192.168.5.244 port=5432 user=replica password=a123456 application_name=slave01'
-
重新啟動 PostgreSQL Server:
$pg_ctl restart
- https://tecadmin.net/install-postgresql-server-centos/