postgresql清理归档wal日志

时间:2023-01-16 15:00:14

读取控制文件,找到哪个文件是可以被清理的

$ pg_controldata /pgdata/5433
pg_control version number:            1201
Catalog version number:               201909212
Database system identifier:           6924185130379164934
Database cluster state:               in production
pg_control last modified:             Thu 22 Dec 2022 03:00:09 PM CST
Latest checkpoint location:           3D3/7FB3EAF0
Latest checkpoint's REDO location:    3D2/FA9A1638
Latest checkpoint's REDO WAL file:    00000003000003D2000000FA
Latest checkpoint's TimeLineID:       3
Latest checkpoint's PrevTimeLineID:   3
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID:          0:398293544
Latest checkpoint's NextOID:          49156
Latest checkpoint's NextMultiXactId:  1
Latest checkpoint's NextMultiOffset:  0
Latest checkpoint's oldestXID:        199658550
Latest checkpoint's oldestXID's DB:   16389
Latest checkpoint's oldestActiveXID:  398293537
Latest checkpoint's oldestMultiXid:   1
Latest checkpoint's oldestMulti's DB: 16389
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint:            Thu 22 Dec 2022 02:56:39 PM CST
Fake LSN counter for unlogged rels:   0/3E8
Minimum recovery ending location:     0/0
Min recovery ending loc's timeline:   0
Backup start location:                0/0
Backup end location:                  0/0
End-of-backup record required:        no
wal_level setting:                    replica
wal_log_hints setting:                on
max_connections setting:              4000
max_worker_processes setting:         28
max_wal_senders setting:              10
max_prepared_xacts setting:           0
max_locks_per_xact setting:           64
track_commit_timestamp setting:       off
Maximum data alignment:               8
Database block size:                  16384
Blocks per segment of large relation: 65536
WAL block size:                       16384
Bytes per WAL segment:                16777216
Maximum length of identifiers:        64
Maximum columns in an index:          32
Maximum size of a TOAST chunk:        4044
Size of a large-object chunk:         4096
Date/time type storage:               64-bit integers
Float4 argument passing:              by value
Float8 argument passing:              by value
Data page checksum version:           1
Mock authentication nonce:            12e75f147694c5cbba620c4fb46b45b9b6d19b5e778fd025d448a3f24249f4bb

从上面得到 00000003000003D2000000FA之前的可以删除,执行:

pg_archivecleanup -d  /pgdata/wal_archive_5433 00000003000003D2000000FA