Master
-IP: 192.168.1.1
-TCP Port: 5432
-Data directory: /var/lib/pgsql/9.0/data
-WAL directory: /var/lib/pgsql/9.0/data/wals
Slave
-IP: 192.168.1.2
-TCP Port: 5432
-Data directory: /var/lib/pgsql/9.0/data
-WAL directory: /var/lib/pgsql/9.0/data/wals
Master configuration: ($ /var/lib/pgsql/9.0/data/postgresql.conf)
-listen_addresses = '*'
-port = 5432
-archive_mode = on
-archive_command = 'cp "%p" /var/lib/pgsql/9.0/data/wals/"%f" < /dev/null'
-max_wal_senders = 1
-wal_level = hot_standby
-hot_standby = on
Authentication Configuration: ($ /var/lib/pgsql/9.0/data/pg_hba.conf)
-host replication all 10.16.35.213/23 trust
Start Up the Master
/usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data &
Make a Base Backup for stand by from the master (Snapshot)
$ psql -c "SELECT pg_start_backup('base_backup')"
$ cd 9.0/data
$ scp -rp x postgres@10.16.35.213:/var/lib/pgsql/9.0/data
$ psql -c "SELECT pg_stop_backup()"
Slave Configuration ($ /var/lib/pgsql/9.0/data/postgresql.conf)
-listen_addresses = '*'
-port = 5432
-archive_mode = on
-archive_command = 'cp "%p" /var/lib/pgsql/9.0/data/wals/"%f" < /dev/null'
-max_wal_senders = 1
-wal_level = hot_standby
-hot_standby = on
$ rm -fr /var/lib/pgsql/9.0/data/postmaster.pid
$ rm -fr /var/lib/pgsql/9.0/data/pg_xlog/000*
$ rm -fr /var/lib/pgsql/9.0/data/pg_xlog/archive_status/*
$ rm -fr /var/lib/pgsql/9.0/data/wals/*
Recovery configuration on the slave: (/var/lib/pgsql/9.0/data/recovery.conf)
standby_mode = 'on'
primary_conninfo = 'host=192.168.1.1 port=5432 user=postgres password=postgres'
restore_command = 'cp -i /var/lib/pgsql/9.0/data/wals/%f %p < /dev/null'
Start up the slave
/usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data &
Check the process
$ ps -fea | grep postgres
root 12121 11960 0 19:43 pts/1 00:00:00 su - postgres
postgres 12122 12121 0 19:43 pts/1 00:00:00 -bash
postgres 12823 12122 0 20:23 pts/1 00:00:00 /usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data
postgres 12824 12823 0 20:23 ? 00:00:00 postgres: logger process
postgres 12825 12823 0 20:23 ? 00:00:00 postgres: startup process recovering 00000001000000000000000C
postgres 12828 12823 0 20:23 ? 00:00:00 postgres: wal receiver process streaming 0/C024038
postgres 12829 12823 0 20:23 ? 00:00:00 postgres: writer process
postgres 12830 12823 0 20:23 ? 00:00:00 postgres: stats collector process
postgres 12901 12122 0 20:59 pts/1 00:00:00 ps -fea
postgres 12902 12122 0 20:59 pts/1 00:00:00 grep postgres
Test it
Insert some data in the master:
$ psql
postgres=# create table t (i int);
postgres=# insert into t values(1);
postgres=# insert into t values(2);
postgres=# select * from t;
i
---
1
2
(2 rows)
Check in the Slave
$ psql
postgres=# select * from t;
i
---
1
2
(2 rows)
Friday, October 8, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment