PostgreSQL 之wal、pg_log配置


日志有三種:

pg_xlog目錄pg_wal  在線重做日志

pg_clog目錄pg_xact  事務日志文件,記錄哪些事務已完成

pg_log 數據庫日志, 記錄host,db,慢SQL信息

歸檔或者流復制發生異常的時候,事務日志會不斷生成,有可能會造成磁盤空間被塞滿,最終導致DB掛掉或者起不來。

遇到這種情況,可以先關閉歸檔或者流復制功能,備份pg_xlog日志到其他地方,不要刪除。然后刪除較早時間的的pg_xlog,有一定空間后再試着啟動Postgres。 

 

postgresql.log只保留一周的日志,進行循環覆蓋

logging_collector = on#啟動日志

log_destination = 'csvlog'#日志格式,值為stderr,csvlog,syslog,and eventlog之一

log_filename = ‘postgresql-%a.log’
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0

wal日志增長量過大的問題處理,已經配置優化

$ du -sh pg_wal
395G pg_wal

$ pg_controldata
pg_control version number: 1201
Catalog version number: 201909212
Database system identifier: 6831009729171842643
Database cluster state: in production
pg_control last modified: Mon 19 Apr 2021 02:19:49 PM CST
Latest checkpoint location: 341/A0000060
Latest checkpoint's REDO location: 341/A0000028
Latest checkpoint's REDO WAL file: 0000000100000341000000A0

檢查點 341/A0000028已經執行,對應wal日志文件為0000000100000341000000A0,在這之前的日志可清理

1、mv清理到其他盤  2、pg_archivecleanup

例如:

$ ll /data/pgsql_5432/data/pg_wal/ |grep -C 10 0000000100000341000000A0
-rw------- 1 postgres postgres 16777216 Apr 19 14:11 000000010000034100000096
-rw------- 1 postgres postgres 16777216 Apr 19 14:12 000000010000034100000097
-rw------- 1 postgres postgres 16777216 Apr 19 14:13 000000010000034100000098
-rw------- 1 postgres postgres 16777216 Apr 19 14:14 000000010000034100000099
-rw------- 1 postgres postgres 16777216 Apr 19 14:15 00000001000003410000009A
-rw------- 1 postgres postgres 16777216 Apr 19 14:16 00000001000003410000009B
-rw------- 1 postgres postgres 16777216 Apr 19 14:17 00000001000003410000009C
-rw------- 1 postgres postgres 16777216 Apr 19 14:18 00000001000003410000009D
-rw------- 1 postgres postgres 16777216 Apr 19 14:19 00000001000003410000009E
-rw------- 1 postgres postgres 16777216 Apr 19 14:19 00000001000003410000009F
-rw------- 1 postgres postgres 16777216 Apr 19 14:20 0000000100000341000000A0
-rw------- 1 postgres postgres 353 Apr 19 14:56 0000000100000341000000A0.00000028.backup
-rw------- 1 postgres postgres 16777216 Apr 19 14:21 0000000100000341000000A1
-rw------- 1 postgres postgres 16777216 Apr 19 14:22 0000000100000341000000A2
-rw------- 1 postgres postgres 16777216 Apr 19 14:23 0000000100000341000000A3
-rw------- 1 postgres postgres 16777216 Apr 19 14:24 0000000100000341000000A4
-rw------- 1 postgres postgres 16777216 Apr 19 14:25 0000000100000341000000A5
-rw------- 1 postgres postgres 16777216 Apr 19 14:26 0000000100000341000000A6
-rw------- 1 postgres postgres 16777216 Apr 19 14:27 0000000100000341000000A7
-rw------- 1 postgres postgres 16777216 Apr 19 14:28 0000000100000341000000A8
-rw------- 1 postgres postgres 16777216 Apr 19 14:29 0000000100000341000000A9
-rw------- 1 postgres postgres 16777216 Apr 19 14:30 0000000100000341000000AA

0000000100000341000000A0之前的日志,可以進行清理

 pg_archivecleanup 0000000100000341000000A0

wal優化配置

shared_buffers = 32GB
checkpoint_completion_target = 0.1
checkpoint_timeout = 60min
min_wal_size = 4GB
max_wal_size = 64GB
wal_log_hints = on
wal_level = replica
wal_keep_segments = 1000

並開啟wal壓縮,

wal_compression = on

參考閱讀:
http://www.postgres.cn/index.php/news/viewone/1/273

 


免責聲明!

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



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