Data master node goes down, the standby database data recovery
background
In the node out of service, and then continue to write data to the main library, then put away the host is down, start from the library, copy the log during an incremental wal down to the main library from the archive catalog, execute recovery script, it will put additional incremental data down to the host database.
- surroundings
server | Character |
---|---|
10.10.56.16 | master |
10.10.56.18 | slave |
- 16 master's configuration pg_hba,conf
file
host all all 10.10.56.0/0 md5
host replication all 10.10.56.0/0 trust
"pg_hba.conf" 96L, 4652C
- 16 master's configuration
postgresql.conf
listen_addresses = '*'
max_connections = 1000
wal_level = logical
archive_mode = on
archive_command = '/bin/true'
log_destination = 'csvlog'
logging_collector = on
log_filename = 'postgresql-%Y-%m-%d.log'
log_rotation_size = 20MB
log_statement = 'mod'
log_replication_commands = on
deadlock_timeout = 100ms
- Configuration 18 slave, initialize the database from the master pg_basebackup
/opt/pgsql-10/bin/pg_basebackup -h 10.10.56.16 -U repl -W -Fp -Pv -Xs -R -D /pgdata/10/poc/data/
- 18 configuration
recovery.conf
, restore data from the archive directory
#standby_mode = 'on'
#primary_conninfo = 'user=repl password=123456 host=10.10.56.16 port=5432 sslmode=disable sslcompression=1 target_session_attrs=any'
restore_command = 'cp /pgdata/10/archive/%f %p'
Above to achieve the main stream from the asynchronous replication
Started 16 inquiries, the main library for the f
pocdb=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)
Time: 0.786 ms
pocdb=#
Create a user repl in 16, create a table, slightly
When the main reservoir 16 is normally, p is the data table
pocdb=# select max(id) from p;
max
---------
3774121
(1 row)
- Data from the database table 18 p
pocdb=# select max(id) from p;
max
---------
3774121
(1 row)
- Main library down the front (16)
pocdb=# select max(id) from p;
max
---------
4005263
(1 row)
Primary library (16) back down, after recovery from the library, data has been added:
postgres@clw-db3:/pgdata/10/poc/data> /opt/pgsql-10/bin/psql pocdb
psql (10.3)
Type "help" for help.
pocdb=# select max(id) from p;
max
---------
4005263
(1 row)