./bin/initdb --pgdata=/data1/9.5/data -W
listen_addresses = '*' # what IP address(es) to listen on;
port = 5435 # (change requires restart)
wal_level = hot_standby # minimal, archive, hot_standby, or logical
wal_log_hints = on # also do full page writes of non-critical updates
archive_mode = on # enables archiving; off, on, or always
archive_command = 'test ! -f /backup1/9.5/pg_arc/%f && cp %p /backup1/9.5/pg_arc/%f' # command to use to archive a logfile segment
max_wal_senders = 3 # max number of walsender processes
wal_keep_segments = 64 # in logfile segments, 16MB each; 0 disables
hot_standby = on # "on" allows queries during recovery
logging_collector = on # Enable capturing of stderr and csvlog
host replication postgres ::1/128 trust
pg_ctl -D /data1/9.5/data start
pg_basebackup -D /data1/9.5s1/data --xlog --progress --verbose -h localhost -p 5435
listen_addresses = '*' # what IP address(es) to listen on;
port = 5445 # (change requires restart)
wal_level = hot_standby # minimal, archive, hot_standby, or logical
wal_log_hints = on # also do full page writes of non-critical updates
archive_mode = on # enables archiving; off, on, or always
archive_command = 'test ! -f /backup1/9.5s1/pg_arc/%f && cp %p /backup1/9.5s1/pg_arc/%f' # command to use to archive a logfile segment
max_wal_senders = 3 # max number of walsender processes
wal_keep_segments = 64 # in logfile segments, 16MB each; 0 disables
hot_standby = on # "on" allows queries during recovery
logging_collector = on # Enable capturing of stderr and csvlog
host replication postgres ::1/128 trust
standby_mode = 'on'
primary_conninfo = 'host=localhost port=5435'
restore_command = 'cp /backup1/9.5/pg_arc/%f %p'
recovery_target_timeline = 'latest'
trigger_file = '/tmp/trigger_file_0'
@server 1
touch /tmp/trigger_file_0
@server2
tail -f pg_log/postgresql-2016-06-10_123437.log
pgbench -i -s 10 postgres
@server1
[postgres@pgvm1 data]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres@pgvm1 data]$ pg_rewind --source-server='host=::1 port=5445 user=postgres' --target-pgdata=$PGDATA -P
connected to server
servers diverged at WAL position 0/220003E0 on timeline 5
rewinding from last common checkpoint at 0/22000338 on timeline 5
reading source file list
reading target file list
reading WAL in target
need to copy 458 MB (total source directory size is 482 MB)
469734/469734 kB (100%) copied
creating backup label and updating control file
Done!
[postgres@pgvm1 data]$ cp recovery.done recovery.conf
[postgres@pgvm1 data]$ vi recovery.conf
standby_mode = 'on'
primary_conninfo = 'host=localhost port=5445'
restore_command = 'cp /backup1/9.5s1/pg_arc/%f %p'
recovery_target_timeline = 'latest'
trigger_file = '/tmp/trigger_file_0'
[postgres@pgvm1 data]$ vi postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
port = 5435 # (change requires restart)
wal_level = hot_standby # minimal, archive, hot_standby, or logical
wal_log_hints = on # also do full page writes of non-critical updates
archive_mode = on # enables archiving; off, on, or always
archive_command = 'test ! -f /backup1/9.5/pg_arc/%f && cp %p /backup1/9.5/pg_arc/%f' # command to use to archive a logfile segment
max_wal_senders = 3 # max number of walsender processes
wal_keep_segments = 64 # in logfile segments, 16MB each; 0 disables
hot_standby = on # "on" allows queries during recovery
logging_collector = on # Enable capturing of stderr and csvlog
[postgres@pgvm1 data]$ pg_ctl start
server starting
@server1(new slave)
#pg_log/로그파일 확인
LOG: database system was interrupted while in recovery at log time 2016-06-10 12:35:31 GMT-10
HINT: If this has occurred more than once some data might be corrupted and you might need to choose an earlier recovery target.
cp: cannot stat `/backup1/9.5s1/pg_arc/00000007.history': No such file or directory
LOG: entering standby mode
LOG: restored log file "00000006.history" from archive
LOG: restored log file "000000060000000000000022" from archive
cp: cannot stat `/backup1/9.5s1/pg_arc/00000005.history': No such file or directory
LOG: redo starts at 0/22000300
LOG: restored log file "000000060000000000000023" from archive
LOG: restored log file "000000060000000000000024" from archive
LOG: restored log file "000000060000000000000025" from archive
LOG: restored log file "000000060000000000000026" from archive
LOG: restored log file "000000060000000000000027" from archive
LOG: restored log file "000000060000000000000028" from archive
cp: cannot stat `/backup1/9.5s1/pg_arc/000000060000000000000029': No such file or directory
LOG: consistent recovery state reached at 0/29B41898
LOG: database system is ready to accept read only connections
LOG: invalid record length at 0/29B41898
LOG: started streaming WAL from primary at 0/29000000 on timeline 6
@server2(new master)
[postgres@pgvm1 data]$ psql
Timing is on.
psql (9.5.1)
Type "help" for help.
postgres=# select * from pg_stat_replication ;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_l ocation | write_location | flush_location | replay_location | sync_priority | sync_state
------+----------+----------+------------------+-------------+-----------------+ -------------+-------------------------------+--------------+-----------+------- --------+----------------+----------------+-----------------+---------------+------------
2692 | 10 | postgres | wal_receiver1 | ::1 | | 48059 | 2016-06-10 12:39:21.203712+10 | | streaming | 0/29B4 2588 | 0/29B42588 | 0/29B42588 | 0/29B418C8 | 0 | async
(1 row)
Time: 6.919 ms
postgres=#