Pgpool-IIの簡単セットアップ機能を試してみよう(2)

pgpool-IIの簡単セットアップ機能を試してみよう(2)

実際に使ってみよう

それでは、pgpool_setupを実際に使ってみましょう。

pgpool_setupは引数なしで起動すると、PostgreSQLを2台使ったストリーミングレプリケーション環境をカレントディレクトリに構築します。カレントディレクトリは空である必要があるので、新しくディレクトリを作ってそこで実行したほうが良いでしょう。

$ pgpool_setup
Satrting set up in streaming replication mode
creating startall and shutdownall
creating failover script
creating database cluster /home/t-ishii/tmp/test/data0...done.
update postgreql.conf
creating pgpool_remote_start
creating basebackup.sh
creating recovery.conf
creating database cluster /home/t-ishii/tmp/test/data1...done.
[中略]
shutdown all

pgpool-II setting for streaming replication mode is done.
To start the whole system, use /home/t-ishii/tmp/test/startall.
To shutdown the whole system, use /home/t-ishii/tmp/test/shutdownall.
pcp command user name is "t-ishii", password is "t-ishii".
Each PostgreSQL, pgpool-II and pcp port is as follows:
#1 port is 11000
#2 port is 11001
pgpool port is 11002
pcp port is 11003
The info above is in README.port.
$ ls
README.port  bashrc.ports*  data1/  log/            pgpool_setup.log  shutdownall*
archivedir/  data0/         etc/    pgpool_reload*  run/              startall*

data0が1台目のPostgreSQL(ストリーミングレプリケーションのプライマリ)用のデータベースディレクトリ、data1が2台目のPostgreSQL(ストリーミングレプリケーションのスタンバイ)用のデータベースディレクトリです。PostgreSQLのスーパユーザはpgpool_setupを起動した人に設定されます。pgpool-IIの設定ファイルはetc/pgpool.conf、ログはlog/pgpool.logに書かれます。archivedir/は、アーカイブログの格納用ディレクトリです。

この状態ではまだ何も起動されていません。"startall"というスクリプトを起動すると、PostgreSQLとpgpool-IIが立ち上がります(停止は"shutdownall"です)。

 $ ./startall
waiting for server to start.... done
server started
waiting for server to start.... done
server started

早速pgpool-IIにアクセスしてみましょう。pgpool-IIのポート番号は、pgpool_setupのメッセージにあるように、ここでは11002となっています。

$ psql -p 11002 test
psql (9.2.4)
Type "help" for help.

test=# \l
                             List of databases
   Name    |  Owner  | Encoding | Collate | Ctype |    Access privileges    
-----------+---------+----------+---------+-------+-------------------------
 postgres  | t-ishii | UTF8     | C       | C     | 
 template0 | t-ishii | UTF8     | C       | C     | =c/"t-ishii"           +
           |         |          |         |       | "t-ishii"=CTc/"t-ishii"
 template1 | t-ishii | UTF8     | C       | C     | =c/"t-ishii"           +
           |         |          |         |       | "t-ishii"=CTc/"t-ishii"
 test      | t-ishii | UTF8     | C       | C     | 
(4 rows)

test=#

このように、あらかじめテスト用のデータベース"test"が作成されていることがわかります。

レプリケーションを試してみる

まずはレプリケーションがきちんと行われているかどうか確認してみましょう。同じくポート11002のpgpool-IIに接続します。

$ psql -p 11002 test
psql (9.2.4)
Type "help" for help.

test=# create table t1(i int, j text);
CREATE TABLE
test=# insert into t1 values(1, '東京');
INSERT 0 1
test=# insert into t1 values(2, 'ニューヨーク');
INSERT 0 1

これで2台のPostgreSQLに同じテーブルができたはずです。確認のために、data0のPostgreSQLに接続します。ポート番号は11000です。

$ psql -p 11000 test
psql (9.2.4)
Type "help" for help.

test=# select * from t1;
 i |      j       
---+--------------
 1 | 東京
 2 | ニューヨーク
(2 rows)

良さそうですね。では、data1ではどうでしょう?

$ psql -p 11001 test
psql (9.2.4)
Type "help" for help.

test=# select * from t1;
 i |      j       
---+--------------
 1 | 東京
 2 | ニューヨーク
(2 rows)

まったく同じ内容が表示されており、きちんとレプリケーションされていることが分かりました。

では次のページではいよいよ自動フェイルオーバ、オンラインリカバリを試してみます。