Database tables filling up /var disk space

Last Updated : Jun 01, 2023 |
Prolog information

Condition

Incident tables in the postgres database are not being cleaned up, causing the /var directory to run out of space.

Cause

An archival script should normally clean up this file space, but other issues may cause unneeded tables to be left in the /var directory and might require manual cleanup.
Caution:
Cleaning up postgres database tables might cause service interruptions and performance issues. Do this procedure during low or no traffic times, or during a normal maintenance window.

Solution

  1. Log on as root to the operating system.
  2. Enter the following command:
    ADDITIONAL INFORMATION:
    df -h
    Look for output similar to the following example for the /var directory:
    Filesystem   Size   Used   Avail   Use%   Mounted on
    /dev/sda8             4.7G   4.5G    248M    95%      /var
  3. If the amount of space being used is 95% or more, enter the following command to see if any postgres tables are using up 1 GB or more storage in the /var directory:
    ADDITIONAL INFORMATION:
    ls -hltr XXXX*
    STEP RESULT:
    For example, there are three postgres tables that are taking up 1 GB of disk space, and another that is taking up almost 1 GB of disk space in this example.
    ------ 1 postgres postgres 1.0G Dec 13 2019 XXXX
    ------ 1 postgres postgres 1.0G Mar 11 22:47 XXXX.1
    ------ 1 postgres postgres 1.0G Jun 2 19:45 XXXX.2
    ------ 1 postgres postgres 1016K Aug 11 09:38 XXXX_fsm
    ------ 1 postgres postgres 882M Aug 11 09:40 XXXX.3
  4. Before cleaning up any files, do a backup of the current database using the following command:
    ADDITIONAL INFORMATION:
    /usr/local/ipcs/db/scripts/dbmanage.py --takedb-backup
    STEP RESULT:
    A backup of the database is saved in the /archive/backup/db/ directory.
  5. Enter the following command:
    ADDITIONAL INFORMATION:
    vacuumdb -U postgres --all --freeze --echo --analyze
    STEP RESULT:
    This command cleans up any large postgres database table files and frees up space in the /var directory.