LoginSignup
9
9

More than 5 years have passed since last update.

PostgreSQL 9.5 によるレプリケーション構成(同期)

Last updated at Posted at 2016-05-31

今回の内容はPostgreSQL 9.5 によるレプリケーション構成(非同期)の続編になります。

前提

  • 非同期レプリケーションを構築した環境を使用します。
  • 2台のPostgreSQLは停止した状態になっている。

1. 同期レプリケーションに必要な設定を行う

非同期レプリケーションの環境ができていれば、同期レプリケーションするための設定は少しだけです。

1-1. postgresql.confを修正する(マスタのみで実施)

非同期レプリケーションのときに設定した内容に、以下の内容を追記します。

postgresql.conf
synchronous_standby_names = 'green'

1-2. recovery.confを修正する(スレーブのみで実施)

recovery.confのprimary_conninfoの接続文字列application_nameを設定します。

recovery.conf
standby_mode = 'on'
primary_conninfo = 'user=postgres host=192.168.1.1 port=5432 application_name=green'

2. PostgreSQL(マスタ、スレーブ)を起動する。

起動が終わったら、マスタの統計情報ビュー「pg_stat_replication」のapplication_nameやsync_stateを確認します。

$ psql postgres -c "SELECT * FROM pg_stat_replication" -x
-[ RECORD 1 ]----+------------------------------
pid              | 21620
usesysid         | 10
usename          | postgres
application_name | green
client_addr      | 192.168.1.2
client_hostname  | 
client_port      | 51078
backend_start    | 2016-06-01 00:45:17.080761+09
backend_xmin     | 
state            | streaming
sent_location    | 0/3014688
write_location   | 0/3014688
flush_location   | 0/3014688
replay_location  | 0/3014688
sync_priority    | 1
sync_state       | sync

sync_state:syncとなっており、同期レプリケーションされていることが確認できました。

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9