PostgreSQL備份之手工備份(Low Level API)

來源:互聯網
上載者:User

標籤:

一、備份1. 需要保證archive_mode = on 和 archive_command是有效2. 在master節點上串連上資料庫並執行
SELECT pg_start_backup(‘label‘, true);

pg_start_backup第二個參數設定為true的好處是備份開始會執行一個檢查點,設定為true能儘快的完成檢查點,並且能減少備份期間產生的wal檔案,但是會對查詢有影響,預設設定的checkpoint_completion_target的一半的時間,半夜的備份建議開啟

3. 把物理檔案複製到別的地方,可進行壓縮或者使用nc,rsync等其他工具傳送到其他地方

排除掉一些檔案:

1) pg_log/下的所有記錄檔,也可以一起備份

2) pg_xlog/下的所有wal檔案

3) pg_xlog/archive_status/*下的所有檔案

4) recovery.conf如果在從庫下備份需要排除

5) postmaster.pid, postmaster.opts

4. 複製完後,串連資料庫執行
SELECT pg_stop_backup();
二、 恢複1. 將備份轉化(解壓或者複製)到要恢複的資料目錄2. 準備recovery.conf
recovery_target_time=‘2015-08-04 12:00:00+8‘ #需要恢複到的時間點pause_at_recovery_target=true                #到恢複目標後暫停recovery_target_inclusive=false              #到恢複目標後是否停止恢複,設定為true會把recovery.conf重新命名為recovery.donerestore_command=‘cp /data/xlog/%f %p‘        #wal檔案歸檔的位置,必須指定

不能設定standby_mode = ‘on’ ,recovery_target_time需要在基礎備份之後,還可以恢複到指定事務id和指定備份位置,詳見:http://www.postgresql.org/docs/9.4/static/recovery-target-settings.html#RECOVERY-TARGET-INCLUSIVE

3. 啟動備份資料庫
pg_ctl -D /data/restore_data start

參考:http://www.postgresql.org/docs/9.4/interactive/continuous-archiving.html

PostgreSQL備份之手工備份(Low Level API)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.