In PostgreSQL, the Write-Ahead Log (WAL) files are critical for ensuring data integrity and durability. However, they can also take up a lot of disk space, especially if your database is large or your server is busy. If your wal_archive files are taking up too much space and causing your server to run out of disk space, you may delete that folder manually after taking a proper backup of application or can use a script to clear out old wal_archive files.
The wal_archive folder will be cleaned up once a backup is taken successfully. This feature had a framework issue, which is fixed in build 14202 (Ref Issue Id : SD-109229).
In this article, we will introduce a script that clears out wal_archive files that
are older than a particular date after taking a backup thereby solving the above problem
Working of script
- As wal_archive folder used to retrieve data if there is no backup is found. Hence at the first step to prevent data loss, we are triggering the manual full backup script. It deletes the wal_archive files, only if two new backup files are created after the script invocation time.
Warning
- Do not use this script when the setup has inconsistencies in the database, say for example a upgrade failed setup. Use this script when the application is running successfully without any inconsistencies.
How to Use?
- Download the attached zip, extract the scripts and place the file directly in <servicedeskplus_home>\bin directory.
- Invoke the script file with priviliges to read/write all the directories of ServiceDeskPlus. If possible with administrator privileges.
- "bash <script_name>.sh" for linux
- "<script_name>.bat" for windows
After invoking the script, check whether the size of your wal_archive is reduced.
This script will usually clears the wal_archive files older than 30 days. If you want to modify that time, change the value as number of days to "DAYS_TO_KEEP" in that script.