標籤:bsp redo let 恢複 模糊 check als sha -bash-4.1
根據德歌的部落格自己實踐一下:
找到要恢複的前一個事物ID,然後復原到那個時候:
使用pg_xlogdump分析XLOG
-bash-4.1$ pg_xlogdump 000000020000000000000006|less
rmgr: XLOG len (rec/tot): 80/ 106, tx: 0, lsn: 0/06327260, prev 0/06327228, desc: CHECKPOINT_ONLINE redo 0/6327228; tli 2; prev tli 2; fpw true; xid 0/1773; oid 24577; multi 1; offset 0; oldest xid 1740 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 1772; onlinermgr: Standby len (rec/tot): 28/ 54, tx: 0, lsn: 0/063272D0, prev 0/06327260, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1771 oldestRunningXid 1772; 1 xacts: 1772rmgr: Transaction len (rec/tot): 8/ 34, tx: 1772, lsn: 0/06327308, prev 0/063272D0, desc: COMMIT 2017-05-19 17:00:22.037554 CSTrmgr: Standby len (rec/tot): 24/ 50, tx: 0, lsn: 0/06327330, prev 0/06327308, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1772 oldestRunningXid 1773rmgr: Standby len (rec/tot): 24/ 50, tx: 0, lsn: 0/06327368, prev 0/06327330, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1772 oldestRunningXid 1773rmgr: XLOG len (rec/tot): 80/ 106, tx: 0, lsn: 0/063273A0, prev 0/06327368, desc: CHECKPOINT_ONLINE redo 0/6327368; tli 2; prev tli 2; fpw true; xid 0/1773; oid 24577; multi 1; offset 0; oldest xid 1740 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 1773; onlinermgr: Standby len (rec/tot): 24/ 50, tx: 0, lsn: 0/06327410, prev 0/063273A0, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1772 oldestRunningXid 1773rmgr: Standby len (rec/tot): 24/ 50, tx: 0, lsn: 0/06327448, prev 0/06327410, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1772 oldestRunningXid 1773rmgr: XLOG len (rec/tot): 80/ 106, tx: 0, lsn: 0/06327480, prev 0/06327448, desc: CHECKPOINT_ONLINE redo 0/6327448; tli 2; prev tli 2; fpw true; xid 0/1773; oid 24577; multi 1; offset 0; oldest xid 1740 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 1773; onlinermgr: Standby len (rec/tot): 24/ 50, tx: 0, lsn: 0/063274F0, prev 0/06327480, desc: RUNNING_XACTS nextXid 1773 latestCompletedXid 1772 oldestRunningXid 1773
$vi $PGDATA/recovery.conf
recovery_target_inclusive = truerestore_command = ‘cp /tmp/%f %p‘recovery_target_xid = ‘1721‘standby_mode = onpause_at_recovery_target = true
記住大概時間,然後找到對應的checkpoint時間來進行恢複:如果開啟了所有SQL的審計日誌(log_statement = ‘all‘),首先我們可以在日誌中,根據使用者給的模糊時間,找到精準的時間。 將資料庫恢複到這之前的一個時間(最好是給出時間點的上一個檢查點之前的時間),並停止恢複。假設檢查點時5分鐘會做一次的,那麼我們可以選擇5分鐘前的一個時間點。
$vi $PGDATA/recovery.conf recovery_target_inclusive = falserestore_command = ‘cp /tmp/%f %p‘recovery_target_time = ‘2017-05-19 10:00:00 +08‘ standby_mode = onpause_at_recovery_target = true
PostgreSQL恢複誤操作