Tuesday, August 25, 2015

Difference between du and df outputs

Sometimes people say they performed cleanup but filesystem is still (almost) full and df is giving different results than du:

$ df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        20G   19G     0 100% /tmp

$ du -sm /tmp
1       /tmp


To find the missing bit you need to check if the deleted files are still in use (in other words those files might be still open):
# lsof | grep deleted
mysqld    2456     mysql    5u   REG       0,19        0  2025554220 (deleted) /tmp/iboy1WVS
mysqld    2456     mysql    6u   REG       0,19        0  2025554284 (deleted) /tmp/ibwlUTGy
mysqld    2456     mysql    7u   REG       0,19        0  2025554322 (deleted) /tmp/ibecOavf
[..]


To reclaim the space you need to bounce the process which is still using those files.
If you can't or don't want to kill running proceses you can try to truncate those "deleted" files:
cat /dev/null > /proc/2456/fd/5
cat /dev/null > /proc/2456/fd/6
cat /dev/null > /proc/2456/fd/7

No comments:

Post a Comment