eygle.com   eygle.com
eygle.com eygle
eygle.com  
 

« 把时间当做朋友 - 记 李笑来 的卓越见解 | Blog首页 | 恩墨科技第二次性能优化培训时间确定 »

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

昨天在一个客户环境,由于空间紧张,删除了一个文件,遇到了文件句柄与空间释放的问题,记录一下。
在系统上,临时表空间扩展到了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

-The End-




历史上的今天...
    >> 2018-10-21文章:
    >> 2011-10-21文章:
    >> 2010-10-21文章:
    >> 2008-10-21文章:
    >> 2007-10-21文章:
           成功升级Dopoda S1的ROM
    >> 2006-10-21文章:
           重新安装Lilina Rss聚合器

By eygle on 2009-10-21 09:04 | Comments (6) | FAQ | 2429 |

6 Comments

rm这个鸟命令在linux和unix上清理空间很危险,很可能清理不出来,特别是对于正在被写的一些log之类的

一般俺们用 >filename
安全保险。
杀人越货的好东西。

最好不要重启db,
用>稳妥一些吧。

如果不从新启动数据库,只能如下,清理文件句柄:
(或者写一个shell脚本,定期调度)

oracle 3894 oracle 22u REG 8,3 34358697984 3808524 /data1/xcrtdb/temp01.dbf (deleted)

#> cat /dev/null > /proc//fd/...

对不起,不够清晰,恕我以后找到原来的工作记录.

括弧了的内容丢了, 再写一遍,
#> cat /dev/null > /proc/process_id/fd/...

长见识,学知识!


CopyRight © 2004~2020 云和恩墨,成就未来!, All rights reserved.
数据恢复·紧急救援·性能优化 云和恩墨 24x7 热线电话:400-600-8755 业务咨询:010-59007017-7040 or 7037 业务合作: marketing@enmotech.com