標籤:http 使用 io strong 檔案 ar 資料 art 問題
PS:前些時間有童鞋問我,為什麼他的伺服器裡用df和du命令查詢的檔案大小顯示不一樣。其實這兩個命令查詢原理是不一樣的,簡析如下:
1、正常情況下,df和du輸出結果都會有差距
du -sh命令通過將指定檔案系統中所有的目錄、符號連結和檔案使用的塊數累加得到該檔案系統使用的總塊數;
而df命令通過查看檔案系統磁碟塊分配圖得出總塊數與剩餘塊數。
檔案系統分配其中的一些磁碟塊用來記錄它自身的一些資料,如i節點,磁碟分布圖,間接塊,超級塊等。這些資料對大多數使用者級的程式來說是不可見的,通常稱為Meta Data。
du命令是使用者級的程式,它不考慮Meta Data,而df命令則查看檔案系統的磁碟分配圖並考慮Meta Data。
因此正常情況下,df計算的USED空間會比du計算的結果要稍大。
2、異常情況下,df計算的USED空間會比du大很多
這也是之前碰到的問題,df查看結果檔案系統100%使用了,而du的結果是還有6GB閒置,就這麼個問題硬體廠商一個SUPPORT居然不知道怎麼解釋,這也是讓我好奇晚上回來查查看究竟的原因,結果GOOGLE一下就有了。
原因在於du是以檔案名稱、目錄名為依據計算空間使用的,而df是以硬碟塊使用方式來計算空間使用的。
當一個應用程式正在寫一個大檔案的時候,我們RM或者MV了這個檔案(UNIX是允許這麼乾的,WINDOWS在這一點上傻有傻福),應用程式會佔有控制代碼,並根據控制代碼所指磁碟位置直接寫磁碟,而不會檢查該檔案是否被刪除。
因此就會產生上述的問題。具體到Oracle層面,可能發生這種情況的有:Oracle因為某種原因在產生很大的TRACE檔案,可能導致oracle等目錄滿,如果此時直接RM或MV掉該TRACE檔案會發現空間並不會釋放,進而可能導致Oracle資料庫DOWN機。
解決辦法:使用“> tracefile.trc”命令清空掉該檔案,如果需要保留TRACE檔案便於事後分析問題,可以使用CP先複製該檔案到其他地方,然後清空掉原來的檔案。
關於df和du的輸出差別原文解釋如下:
Problem Definition
This section gives the technical explanation of why du and df sometimes report
different totals of disk space usage.
When a program that is running in the background writes to a file while the
process is running, the file to which this process is writing is deleted.
Running df and du shows a discrepancy in the amount of disk space usage. The
df command shows a higher value.
Explanation Summary
When you open a file, you get a pointer. Subsequent writes to this file
references this file pointer. The write call does not check to see if the file
is there or not. It just writes to the specified number of characters starting
at a predetermined location. Regardless of whether the file exist or not, disk
blocks are used by the write operation.
The df command reports the number of disk blocks used, while du goes through the
file structure and reports the number of blocks used by each directory. As
far as du is concerned, the file used by the process does not exist, so it does
not report blocks used by this phantom file. But df keeps track of disk blocks
used, and it reports the blocks used by this phantom file.
更多精彩linux視頻教程,盡在51CTO學院:http://edu.51cto.com/course/courseList/id-48.html
Linux下df與du命令輸出區別簡析