環境は、OSにubuntu 10.04 LTS Serverを使ってみました。
ESXi4.1に仮想PCを2台用意して、それぞれにubuntuを入れて、PostgreSQLをソースからビルドしておきます。
■レプリケーション元のPostgreSQLの設定を変更
まず、PostgreSQLを停止します。
$ sudo /etc/init.d/postgresql stop
$ su - postgres
$ cd /usr/local/pgsql/data
listen_addresses = '*'
port = 5432
wal_level = hot_standby
archive_mode = on
archive_command = 'cp %p /usr/local/pgsql/data/pg_archive/%f'
max_wal_senders = 3
host    replication     all             192.168.168.0/24        trust
$ mkdir pg_archive
$ exit
■レプリケーション先のPostgreSQLの設定を変更
まず、PostgreSQLを停止します。
$ sudo /etc/init.d/postgresql stop
$ su - postgres
$ cd /usr/local/pgsql/data
listen_addresses = '*'
port = 5432
wal_level = hot_standby
archive_mode = on
archive_command = 'cp %p /usr/local/pgsql/data/pg_archive/%f'
max_wal_senders = 3
hot_standby = on
host    replication     all             192.168.168.0/24        trust
standby_mode = 'on'
primary_conninfo = 'host=レプリケーション元のホスト port=5432 user=postgres'
restore_command = 'cp /usr/local/pgsql/data/pg_archive/%f %p'
trigger_file = '/usr/localpgsql/data/trigger'
$ mkdir pg_archive
$ exit
■レプリケーション元のPostgreSQLを起動して、データベースを作成
$ sudo /etc/init.d/postgresql start
$ su - postgres
$ createdb testdb
$ psql -l
                              List of databases
   Name    |  Owner   | Encoding | Collation | Ctype |   Access privileges
-----------+----------+----------+-----------+-------+-----------------------
 postgres  | postgres | UTF8     | C         | C     |
 template0 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 testdb    | postgres | UTF8     | C         | C     |
(4 rows)
■レプリケーション元のデータをレプリケーション先にコピー
レプリケーション元のデータをレプリケーション先にコピーします。
$ cd /usr/local/pgsql
$ tar zcvf data.tar.gz data
$ scp data.tar.gz レプリケーション先のホスト:/usr/local/pgsql/
$ su - postgres
$ cd /usr/local/pgsql
$ mkdir ~/conf_backup
$ cp -a data/*.conf ~/conf_backup/
$ tar zxvf data.tar.gz
$ cp -a ~/conf_backup/*.conf data/
$ rm -f data/postmaster.pid
$ exit
$ sudo /etc/init.d/postgresql start
■確認
レプリケーション元でtestdbにテーブルを作成してみます。
$ su - postgres
$ psql testdb
testdb=# create table table1 (id integer, create_date timestamp default current_timestamp);
testdb=# \d
         List of relations
 Schema |  Name  | Type  |  Owner
--------+--------+-------+----------
 public | table1 | table | postgres
(1 row)
testdb=# \d table1
                   Table "public.table1"
   Column    |            Type             |   Modifiers
-------------+-----------------------------+---------------
 id          | integer                     |
 create_date | timestamp without time zone | default now()
$ su - postgres
$ psql testdb
testdb=# \dt
         List of relations
 Schema |  Name  | Type  |  Owner
--------+--------+-------+----------
 public | table1 | table | postgres
(1 row)
testdb=# \d table1
                   Table "public.table1"
   Column    |            Type             |   Modifiers
-------------+-----------------------------+---------------
 id          | integer                     |
 create_date | timestamp without time zone | default now()
$ createdb testdb2
$ psql -l
                              List of databases
   Name    |  Owner   | Encoding | Collation | Ctype |   Access privileges
-----------+----------+----------+-----------+-------+-----------------------
 postgres  | postgres | UTF8     | C         | C     |
 template0 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 testdb    | postgres | UTF8     | C         | C     |
 testdb2   | postgres | UTF8     | C         | C     |
(5 rows)
$ psql -l
                              List of databases
   Name    |  Owner   | Encoding | Collation | Ctype |   Access privileges
-----------+----------+----------+-----------+-------+-----------------------
 postgres  | postgres | UTF8     | C         | C     |
 template0 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C         | C     | =c/postgres          +
           |          |          |           |       | postgres=CTc/postgres
 testdb    | postgres | UTF8     | C         | C     |
 testdb2   | postgres | UTF8     | C         | C     |
(5 rows)
割と簡単に設定できました。
そのうち、レプリケーション先の追加や、レプリケーション先の昇格などやってみたいと思います。
 
0 コメント :
コメントを投稿