PostgreSQL – Why Remove or Add WAL Files?

postgresqlwrite-ahead-logging

I have experiences of administration with MySQL and Oracle Database.
I started to work with PostgreSQL recently and cannot find the reason why PostgreSQL managing WAL files by removing or adding
according to setting with wal_keep_segments, max_wal_size and min_wal_size.

MySQL just keeps on generaing new transaction files and Oracle rotates the trancation files with REDO log files and also archiving.
I don't know why PostgreSQL managing WAL by changing the number of WAL files. Why not just keep the fixed number of WAL files?

Best Answer

Postgres temporarily adds WAL segments beyond max_wal_size to absorb peak transaction loads without forcing a checkpoint -- unlike Oracle.

It removes unneeded WAL seqments to avoid using up the log file system unnecessarily.

There's always a trade-off between performance and resource (in this case log disk space) utilization, and different DBMSes use different approaches to addressing this issue. In this case PostgreSQL lets you find the balance that works best for you by allowing you to play with the values of wal_keep_segments, max_wal_size and min_wal_size.