Nginx – Why does df -h still show 100% full even after deleting files

dfdufilesystemsnginxUbuntu

The disk space on my Ubuntu web server, running on DigitalOcean, seems to be full. I have already found and deleted the large log file and restarted Nginx. However, it still seems like there is a problem.

df shows that it's still full:

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   47G   22M 100% /

But du shows that it's not full:

$ du -shx /
3.2G    /

What do I need to do to fix this problem?

Best Answer

First check and see if any processes are still referencing the deleted file:

$ sudo lsof / | grep deleted

In my case, it was showing that tail was still using it:

tail      18961       root    3r   REG  253,1 46511271936 1189657 /var/www/myapp/shared/log/production.log (deleted)

Running ps x and filtering by the process name showed me the process id that I needed to kill:

$ ps x | grep tail
 3376 pts/1    S+     0:00 grep --color=auto tail
18961 ?        Ss     0:00 tail -f /var/www/myapp/current/log/production.log

In this case, 18961 was the process id. Now kill the process:

kill 18961

Now df shows that there is free space again:

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  3.3G   44G   7% /
Related Topic