PostgreSQL 開啟歸檔


修改postgresql.conf

archive_mode =on
%p = path of file to archive
%f = file name only

archive_command ='cp %p /u01/pgsql/archive/pg_%f'

重啟postgresql

pg_ctl  stop

pg_ctl start 

查看歸檔

[postgres@redis01 archive]$ ls -lrt
total 32772
-rw------- 1 postgres postgres 16777216 Sep 22 18:49 pg_000000010000000000000001
-rw------- 1 postgres postgres 16777216 Sep 22 18:50 pg_000000010000000000000002
-rw------- 1 postgres postgres 329 Sep 22 18:50 pg_000000010000000000000002.00000060.backup
[postgres@redis01 archive]$ pwd
/u01/pgsql/archive

command 使用邏輯運算符

1. 命令1 && 命令2    命令1執行成功后才會執行命令2
2. 命令1 || 命令2    命令1執行失敗后才會執行命令2

每天生成一個歸檔目錄
archive_command = 'DIR=/u01/pgsql/archive/`date +%F`; sudo test ! -d $DIR && sudo mkdir $DIR; sudo test ! -f $DIR/%f && sudo cp %p $DIR/%f'

查看歸檔設置

postgres=# select name,setting from pg_settings where name like 'archive%' or name = 'wal_level';
      name       |            setting             
-----------------+--------------------------------
 archive_command | cp %p /u01/pgsql/archive/pg_%f
 archive_mode    | on
 archive_timeout | 0
 wal_level       | replica
(4 rows)

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM