--//查看測試表數據
[postgres@postgres ~]$ p
psql (11.1)
Type "help" for help.
postgres=# select * from tbl;
id | ival | description | created_time
----+------+-------------+-------------------------------
1 | 1 | | 2020-04-02 11:02:33.039506-04
34 | 2 | | 2020-04-02 13:52:24.368258-04
67 | 3 | | 2020-04-02 14:32:05.711384-04
68 | 4 | | 2020-04-02 14:40:01.597981-04
69 | 5 | | 2020-04-02 15:19:29.752758-04
70 | 6 | | 2020-04-02 15:21:49.947237-04
(6 rows)
postgres=#
postgres=# \df pg_create_restore_point
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+-------------------------+------------------+---------------------+------
pg_catalog | pg_create_restore_point | pg_lsn | text | func
(1 row)
postgres=#
--//創建還原點
postgres=# SELECT pg_create_restore_point('restore_point');
pg_create_restore_point
-------------------------
0/19000630
(1 row)
postgres=#
--//刪除數據
postgres=# DELETE FROM tbl ;
DELETE 6
postgres=#
postgres=# select pg_switch_wal();
pg_switch_wal
---------------
0/19000A28
(1 row)
--//關閉數據庫
[postgres@postgres ~]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres@postgres ~]$
--//刪除數據庫
[postgres@postgres ~]$ rm -rf /home/postgres/pg11/
[postgres@postgres ~]$ mkdir -p /home/postgres/pg11/
[postgres@postgres ~]$ chmod 0700 /home/postgres/pg11/
[postgres@postgres ~]$ ls -ltr /home/postgres/11/backups/new
total 2952
-rw------- 1 postgres postgres 433 Apr 2 15:21 16387.tar.gz
-rw------- 1 postgres postgres 3015440 Apr 2 15:21 base.tar.gz
[postgres@postgres ~]$
--//恢復
tar -xvf /home/postgres/11/backups/new/base.tar.gz -C /home/postgres/pg11/
backup_label
tablespace_map
current_logfiles
pg_multixact/
pg_multixact/offsets/
pg_multixact/offsets/0000
pg_multixact/members/
.
.
--//啓動數據庫
cp /home/postgres/recovery.done /home/postgres/pg11/recovery.conf
[postgres@postgres ~]$ cp /home/postgres/recovery.done /home/postgres/pg11/recovery.conf
[postgres@postgres ~]$
[postgres@postgres ~]$ grep -v '^#' /home/postgres/pg11/recovery.conf
restore_command = 'cp /home/postgres/archivedir/%f %p'
recovery_target_name = 'restore_point' # e.g. 'daily backup 2011-01-26'
[postgres@postgres ~]$
[postgres@postgres ~]$ pg_ctl start
waiting for server to start....2020-04-02 15:53:30.520 EDT [52399] LOG: listening on IPv4 address "0.0.0.0", port 5442
2020-04-02 15:53:30.520 EDT [52399] LOG: listening on IPv6 address "::", port 5442
2020-04-02 15:53:30.523 EDT [52399] LOG: listening on Unix socket "/tmp/.s.PGSQL.5442"
2020-04-02 15:53:30.534 EDT [52399] LOG: redirecting log output to logging collector process
2020-04-02 15:53:30.534 EDT [52399] HINT: Future log output will appear in directory "on".
done
server started
[postgres@postgres ~]$ p
psql (11.1)
Type "help" for help.
postgres=# select * from tbl;
id | ival | description | created_time
----+------+-------------+-------------------------------
1 | 1 | | 2020-04-02 11:02:33.039506-04
34 | 2 | | 2020-04-02 13:52:24.368258-04
67 | 3 | | 2020-04-02 14:32:05.711384-04
68 | 4 | | 2020-04-02 14:40:01.597981-04
69 | 5 | | 2020-04-02 15:19:29.752758-04
70 | 6 | | 2020-04-02 15:21:49.947237-04
(6 rows)
postgres=#
--//詳細日誌
2020-04-02 15:53:30.569 EDT,,,52401,,5e8642ba.ccb1,2,,2020-04-02 15:53:30 EDT,,0,LOG,00000,"starting point-in-time recovery to ""restore_point""",,,,,,,,,""
2020-04-02 15:53:30.571 EDT,,,52401,,5e8642ba.ccb1,3,,2020-04-02 15:53:30 EDT,,0,LOG,00000,"restored log file ""00000009.history"" from archive",,,,,,,,,""
2020-04-02 15:53:30.590 EDT,,,52401,,5e8642ba.ccb1,4,,2020-04-02 15:53:30 EDT,,0,LOG,00000,"restored log file ""000000090000000000000018"" from archive",,,,,,,,,""
2020-04-02 15:53:30.619 EDT,,,52401,,5e8642ba.ccb1,5,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"redo starts at 0/18000028",,,,,,,,,""
2020-04-02 15:53:30.620 EDT,,,52401,,5e8642ba.ccb1,6,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"consistent recovery state reached at 0/180000F8",,,,,,,,,""
2020-04-02 15:53:30.620 EDT,,,52399,,5e8642ba.ccaf,2,,2020-04-02 15:53:30 EDT,,0,LOG,00000,"database system is ready to accept read only connections",,,,,,,,,""
2020-04-02 15:53:30.636 EDT,,,52401,,5e8642ba.ccb1,7,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"restored log file ""000000090000000000000019"" from archive",,,,,,,,,""
2020-04-02 15:53:30.679 EDT,,,52401,,5e8642ba.ccb1,8,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"restored log file ""00000009000000000000001A"" from archive",,,,,,,,,""
2020-04-02 15:53:30.704 EDT,,,52401,,5e8642ba.ccb1,9,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"redo done at 0/1A000060",,,,,,,,,""
2020-04-02 15:53:30.704 EDT,,,52401,,5e8642ba.ccb1,10,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"last completed transaction was at log time 2020-04-02 15:22:00.054457-04",,,,,,,,,""
2020-04-02 15:53:30.719 EDT,,,52401,,5e8642ba.ccb1,11,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"restored log file ""00000009000000000000001A"" from archive",,,,,,,,,""
2020-04-02 15:53:30.750 EDT,,,52401,,5e8642ba.ccb1,12,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"restored log file ""0000000A.history"" from archive",,,,,,,,,""
2020-04-02 15:53:30.751 EDT,,,52401,,5e8642ba.ccb1,13,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"selected new timeline ID: 11",,,,,,,,,""
2020-04-02 15:53:30.783 EDT,,,52401,,5e8642ba.ccb1,14,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"archive recovery complete",,,,,,,,,""
2020-04-02 15:53:30.785 EDT,,,52401,,5e8642ba.ccb1,15,,2020-04-02 15:53:30 EDT,1/0,0,LOG,00000,"restored log file ""00000009.history"" from archive",,,,,,,,,""
2020-04-02 15:53:30.889 EDT,,,52399,,5e8642ba.ccaf,3,,2020-04-02 15:53:30 EDT,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,""