ストリーミングレプリケーションの動作メモ

動作確認した時の挙動のメモ

create tableの反映を確認

master

template1=# create table test(id serial primary key, comment text);
NOTICE:  CREATE TABLEはシリアル列"test.id"用に暗黙的なシーケンス"test_id_seq"を作成します。
NOTICE:  CREATE TABLE / PRIMARY KEYはテーブル"test"に暗黙的なインデックス"test_pkey"を作成します
CREATE TABLE

slave

template1=# \dt
          リレーションの一覧
 スキーマ | 名前 |    型    |  所有者  
----------+------+----------+----------
 public   | test | テーブル | postgres
(1 行)
alter table

master

template1=# alter table test add add_column1 text;
ALTER TABLE

slave

template1=# select * from test;
 id | comment | add_column1 
----+---------+-------------
(0 行)
insert

master

template1=# insert into test (comment)values('replication test comment');
INSERT 0 1

slave

template1=# select * from test;
 id |         comment          | add_column1 
----+--------------------------+-------------
  1 | replication test comment | 
update

master

template1=# update test set comment = 'updated comment';
UPDATE 1

slave

template1=# select * from test;
 id |     comment     | add_column1 
----+-----------------+-------------
  1 | updated comment | 
(1 行)
slaveの更新

slave

template1=# update test set comment = 'slave update comment';
ERROR:  リードオンリーのトランザクションでは UPDATE を実行できません
slave障害を想定

slave

$ pg_ctl stop -D /var/lib/pgsql/9.2/data

slave障害中にmaser更新

template1=# insert into test (comment)values('slave down test comment');
INSERT 0 1
template1=# insert into test (comment)values('slave down test update comment');
INSERT 0 1
template1=# update test set add_column1 = 'update' where id=3;
UPDATE 1
emplate1=# select * from test;
 id |            comment             | add_column1 
----+--------------------------------+-------------
  1 | updated comment                | 
  2 | slave down test comment        | 
  3 | slave down test update comment | update
(3 行)

slave復旧

-bash-4.1$ pg_ctl start -D /var/lib/pgsql/9.2/data
template1=# select * from test;
 id |            comment             | add_column1 
----+--------------------------------+-------------
  1 | updated comment                | 
  2 | slave down test comment        | 
  3 | slave down test update comment | update
(3 行)

というようにwal、及びwal archiveがあれば自動でマスタのデータに追いつく。