Checking disk space - DF or DU

Posted under » Linux on 1 October 2015

Why df shows over 200G space used, while du only shows 50G used?

Most probably this is caused by open files being deleted. When a file is opened by a process, deleting the file won't release the space occupied by it. we also need to terminate the process, otherwise df and du will show different filesystem usage.

Those two tools were meant for different propose.

DU is to report the file space usage. du works from files.
root@taik:/var/www# du -csh *
109M    aaindex
14M    markers
945M    defend
4.9G    docs
32M    drupal
20K    html
43M    lego
1.6M    mirf
1.1M    ossd
57M    shampod
12K    ssl
233M    wildcat
4.0K    wwwtyk
7G    total
DF is to show the file system usage, DF works at filesystem level, reporting what the kernel says it has available.
# df -h
Filesystem            Size  Used Avail Use% Mounted on

/dev/vx/dsk/datadg/apps
                     503G  278G  211G  57% /apps

To see what file was meant to delete and still holding on by the process id

#lsof /apps | grep deleted

oracle   5332 oracle    7u   REG 199,65533         0 18418 /apps/VRT/dbs/lkinstorcl (deleted)
oracle   5334 oracle    7u   REG 199,65533         0 18418 /apps/VRT/dbs/lkinstorcl (deleted)
oracle   5348 oracle    7u   REG 199,65533         0 18418 /apps/VRT/dbs/lkinstorcl (deleted)

You can use the following commands to get all pid

#PIDLIST=`lsof /apps | grep delete | awk ' { print $2 } '`
#ps -p $PIDLIST
 PID TTY      STAT   TIME COMMAND
5332 ?        Ss     1:25 ora_pmon_orcl
5334 ?        Ss     0:46 ora_psp0_orcl
5336 ?        Ss     0:04 ora_mman_orcl
5338 ?        Ss     2:55 ora_dbw0_orcl
5340 ?        Ss     2:01 ora_lgwr_orcl
5342 ?        Ss     6:00 ora_ckpt_orcl
5344 ?        Ss     9:19 ora_smon_orcl
5346 ?        Ss     0:01 ora_reco_orcl
5348 ?        Ss    11:54 ora_cjq0_orcl
5350 ?        Ss     8:57 ora_mmon_orcl
5352 ?        Ss     2:24 ora_mmnl_orcl
5475 ?        Ss     4:21 ora_q001_orcl
12952 ?        Ss     0:00 ora_j000_orcl

Normally, unmount and remount the file system will flush the inode structure and will provide the correct usage. In case if you can not unmount the file system, you can kill these processes with permission from cust , all these open file can be remove and df and du will show a correct usage.

Refer to latest article.
 

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data