このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
01_linux:11_データベース:02_postgresql:01_streaming_replica [2022/07/11 06:03] – matsui | 01_linux:11_データベース:02_postgresql:01_streaming_replica [2022/07/11 08:08] (現在) – matsui | ||
---|---|---|---|
行 3: | 行 3: | ||
WALをスタンバイサーバへ転送する事で高可用性と読取に対するスケールアウトを実現するストリーミングレプリケーションを作成 | WALをスタンバイサーバへ転送する事で高可用性と読取に対するスケールアウトを実現するストリーミングレプリケーションを作成 | ||
+ | |||
+ | ^hostname^IP^ | ||
+ | |pg1001|172.16.0.51| | ||
+ | |pg1002|172.16.0.52| | ||
+ | |pg1003|172.16.0.53| | ||
===== インストール ===== | ===== インストール ===== | ||
行 193: | 行 198: | ||
| | ||
| | ||
+ | </ | ||
+ | |||
+ | Primaryではwalsenderプロセスが存在する。 | ||
+ | < | ||
+ | # ps auxw| grep [w]alsender | ||
+ | postgres 19068 0.0 0.0 398732 | ||
+ | postgres 19071 0.0 0.0 398228 | ||
</ | </ | ||
行 213: | 行 225: | ||
| | ||
| | ||
+ | </ | ||
+ | |||
+ | |||
+ | Secondaryでは、walreceiverも動いている | ||
+ | < | ||
+ | # ps auxw| grep [w]alreceiver | ||
+ | postgres 19711 0.0 0.0 408884 | ||
+ | </ | ||
+ | |||
+ | ==== 更新確認 ==== | ||
+ | |||
+ | === Primary更新 === | ||
+ | |||
+ | Primaryが更新されると、Secondaryもちゃんとデータ更新されている。 | ||
+ | < | ||
+ | $ psql -h 172.16.0.51 -U postgres | ||
+ | UPDATE 1 | ||
+ | |||
+ | |||
+ | $ psql -h 172.16.0.52 -U postgres | ||
+ | | ||
+ | ----------+------------+-----------+---------------------------- | ||
+ | 1 | BBB | Guiness | ||
+ | (1 row) | ||
+ | |||
+ | $ psql -h 172.16.0.53 -U postgres | ||
+ | | ||
+ | ----------+------------+-----------+---------------------------- | ||
+ | 1 | BBB | Guiness | ||
+ | (1 row) | ||
+ | |||
+ | </ | ||
+ | |||
+ | Primary以外では更新できない。 | ||
+ | < | ||
+ | ubuntu@jump: | ||
+ | ERROR: | ||
+ | </ | ||
+ | |||
+ | ===== Primary障害時 ===== | ||
+ | |||
+ | pg1001が障害発生で、落ちた事を想定 | ||
+ | |||
+ | [root@pg1001 ~]# systemctl stop postgresql-13.service | ||
+ | |||
+ | |||
+ | pg1002, | ||
+ | < | ||
+ | $ psql -h 172.16.0.52 -U postgres | ||
+ | | ||
+ | ----------+------------+-----------+---------------------------- | ||
+ | 1 | CCC | Guiness | ||
+ | (1 row) | ||
+ | |||
+ | $ psql -h 172.16.0.53 -U postgres | ||
+ | | ||
+ | ----------+------------+-----------+---------------------------- | ||
+ | 1 | CCC | Guiness | ||
+ | </ | ||
+ | |||
+ | pg1002をPrimaryへ昇格させる | ||
+ | |||
+ | Secondaryの要素をコメントアウト | ||
+ | < | ||
+ | [root@pg1002 ~]# vi / | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | Primaryの要素を追加 | ||
+ | < | ||
+ | [root@pg1002 ~]# vi / | ||
+ | synchronous_standby_names = ' | ||
+ | </ | ||
+ | |||
+ | |||
+ | Primaryへ昇格 | ||
+ | < | ||
+ | [root@pg1002 ~]# systemctl reload postgresql-13.service | ||
+ | [root@pg1002 ~]# su - postgres | ||
+ | -bash-4.2$ / | ||
+ | waiting for server to promote.... done | ||
+ | server promoted | ||
+ | </ | ||
+ | |||
+ | 他のSecondaryの接続先を変更しリロード | ||
+ | < | ||
+ | [root@pg1003 ~]# vi / | ||
+ | host=172.16.0.52 | ||
+ | ↓ | ||
+ | host=172.16.0.51 | ||
+ | |||
+ | [root@pg1003 ~]# systemctl reload postgresql-13.service | ||
</ | </ | ||
===== 参考 ===== | ===== 参考 ===== |