開啟PG的歸檔模式


開啟PG的歸檔模式

1.查看pg的數據目錄

postgres=# SHOW data_directory;
     data_directory     
------------------------
 /var/lib/pgsql/12/data
(1 row)

2.查看pg的歸檔情況

postgres=# show archive_mode;
 archive_mode 
--------------
 off
(1 行記錄)

可以看到,歸檔模式為OFF。

3.查看歸檔的模式和位置

rpm安裝的pg,配置文件在/var/lib/pgsql/12/data/postgresql.conf

[postgres@localhost data]$ cat postgresql.conf |grep archive_mode
#archive_mode = off             # enables archiving; off, on, or always
[postgres@localhost data]$ cat postgresql.conf |grep archive_command
#archive_command = ''           # command to use to archive a logfile segment

4.建立歸檔目錄

[postgres@localhost ~]$ cd /var/lib/pgsql/12/
[postgres@localhost 12]$ ls -l
總用量 8
drwx------ 20 postgres postgres 4096 6月  17 16:21 data
-rw-------  1 postgres postgres  997 6月  17 16:21 initdb.log
[postgres@localhost 12]$ mkdir arch

5.配置歸檔參數

vi /var/lib/pgsql/12/data/postgresql.conf

# - Archiving -

archive_mode = on              # enables archiving; off, on, or always
                                # (change requires restart)
archive_command = 'DATE=`date +%Y%m%d`;DIR="/var/lib/pgsql/12/arch/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f'             # command to use to archive a logfile segment

6.重啟pg

systemctl stop postgresql-12
systemctl start postgresql-12 

7.查看&&切換歸檔日志

[postgres@localhost ~]$ psql
psql (12.3)
輸入 "help" 來獲取幫助信息.

postgres=# show archive_mode;
 archive_mode 
--------------
 on
(1 行記錄)

postgres=# select pg_switch_wal();
 pg_switch_wal 
---------------
 0/169E208
(1 行記錄)

8.查看目錄位置的歸檔文件

[postgres@localhost ~]$ ls -l /var/lib/pgsql/12/arch/
總用量 4
drwx------ 2 postgres postgres 4096 6月  17 16:55 20200617


[postgres@localhost 20200617]$ ls -l 
總用量 32768
-rw------- 1 postgres postgres 16777216 6月  17 16:55 000000010000000000000001
-rw------- 1 postgres postgres 16777216 6月  17 16:57 000000010000000000000002


免責聲明!

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



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