Linux / Unix 下文件删除、句柄 与空间释放问题


昨天在一个客户环境,由于空间紧张,删除了一个文件,遇到了文件句柄与空间释放的问题,记录一下。
在系统上,临时表空间扩展到了32G,我新建了一个临时表空间,并切换了数据库设置:[oracle@corde tdb]$ ls -sort

total 35101212
   51264 -rw-r-----  1 oracle    52429312 Oct 20 08:58 redo02.log
   51264 -rw-r-----  1 oracle    52429312 Oct 20 10:24 redo03.log
    5144 -rw-r-----  1 oracle     5251072 Oct 20 10:29 users01.dbf
32943240 -rw-r-----  1 oracle 34358697984 Oct 20 10:35 temp01.dbf
 1035268 -rw-r-----  1 oracle  1059069952 Oct 20 10:39 undotbs01.dbf
  430516 -rw-r-----  1 oracle   440410112 Oct 20 10:39 sysaux01.dbf
  512516 -rw-r-----  1 oracle   524296192 Oct 20 10:40 system01.dbf
   51264 -rw-r-----  1 oracle    52429312 Oct 20 10:40 redo01.log
    6912 -rw-r-----  1 oracle     7061504 Oct 20 10:40 control03.ctl
    6912 -rw-r-----  1 oracle     7061504 Oct 20 10:40 control02.ctl
    6912 -rw-r-----  1 oracle     7061504 Oct 20 10:40 control01.ctl

之前空间已经使用了88%:

/dev/sda3             80632188  66675432   9860584  88% /data1

然后删除这个文件,发现空间并未释放:

[oracle@corder tdb]$ rm temp01.dbf
[oracle@corder tdb]$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       5611984    160272   5166632   4% /
/dev/sda1               101086     12495     83372  14% /boot
/dev/sda3             80632188  66675432   9860584  88% /data1

这是由于Linux/Unix上,该文件可能仍被其他进程使用的缘故,文件句柄未完全释放,空间无法释放出来,属于常见问题,可以通过lsof工具来查看哪些进程锁定了该文件:

[root@db]# lsof|grep temp
oracle     3167 oracle   38uW     REG        8,2  1048584192    4497986 /data3/oradata/temp01.dbf
oracle     3173 oracle   35u      REG        8,2  1048584192    4497986 /data3/oradata/temp01.dbf
oracle     3894 oracle   22u      REG        8,3 34358697984    3808524 /data1/xcrtdb/temp01.dbf (deleted)
oracle     3894 oracle   25u      REG        8,2  1048584192    4497986 /data3/oradata/temp01.dbf
oracle    12576 oracle   15u      REG        8,3 34358697984    3808524 /data1/xcrtdb/temp01.dbf (deleted)
oracle    24544 oracle   11u      REG        8,3 34358697984    3808524 /data1/xcrtdb/temp01.dbf (deleted)

我们可以看到虽然文件标记为删除(deleted),但是仍然被几个进程锁定:

[root@XcorderDB xcrtdb]# ps -ef|grep 3894
oracle    3894     1 10 07:35 ?        00:19:38 ora_j000_xcrtdb
root     18974 16849  0 10:49 pts/3    00:00:00 grep 3894
[root@XcorderDB xcrtdb]# ps -ef|grep 12576
oracle   12576     1  0 Oct19 ?        00:00:24 oraclexcrtdb (LOCAL=NO)
root     18992 16849  0 10:49 pts/3    00:00:00 grep 12576
[root@XcorderDB xcrtdb]# ps -ef|grep 24544
oracle   24544     1  0 Oct19 ?        00:00:19 oraclexcrtdb (LOCAL=NO)
root     19018 16849  0 10:49 pts/3    00:00:00 grep 24544

如果可以kill这些进程,句柄就可以释放出来,否则可以重启数据库,之后即会释放。

Aix上lsof的参考文档: http://www.ibm.com/developerworks/aix/library/au-lsof.html


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3