PostgreSQL恢複誤操作

來源:互聯網
上載者:User

標籤: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恢複誤操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.