可能很多朋友都遇到過這樣的情況,在UNIX/Linux上定期清理Oracle日志文件夾時可能刪除到仍被后臺進程open著的trace文件,即某些后臺進程一直持有著這些”被已經(jīng)誤刪了的“打開文件的描述符(fd),這種情況下文件系統(tǒng)上該文件實際占用的空間是不會被釋放的,這就造成使用df命令查看文件系統(tǒng)剩余空間和用du命令查看文件夾空間使用量時數(shù)值不一致的問題。此外因為是后臺進程持有這些打開文件描述符,所以我們無法像kill服務進程一樣來解決該問題(部分后臺進程是可以kill的,不建議這樣做)。oradebug是sqlplus中威力強大的debug命令,我們可以通過該命令發(fā)起多種trace/dump,其中也包括了close_trace事件;close_trace事件可以讓指定進程關閉其正持有的trace文件。-
下面我們就來演示下相關操作:
[maclean@rh2 ~]$ ps -ef|grep ora_|grep -v grep
maclean 7281 1 0 16:35 ? 00:00:00 ora_pmon_PROD
maclean 7283 1 0 16:35 ? 00:00:00 ora_psp0_PROD
maclean 7285 1 0 16:35 ? 00:00:00 ora_mman_PROD
maclean 7287 1 0 16:35 ? 00:00:00 ora_dbw0_PROD
maclean 7289 1 0 16:35 ? 00:00:00 ora_lgwr_PROD
maclean 7291 1 0 16:35 ? 00:00:00 ora_ckpt_PROD
maclean 7293 1 0 16:35 ? 00:00:00 ora_smon_PROD
maclean 7295 1 0 16:35 ? 00:00:00 ora_reco_PROD
maclean 7297 1 0 16:35 ? 00:00:00 ora_cjq0_PROD
maclean 7299 1 0 16:35 ? 00:00:00 ora_mmon_PROD
maclean 7301 1 0 16:35 ? 00:00:00 ora_mmnl_PROD
maclean 7303 1 0 16:35 ? 00:00:00 ora_d000_PROD
maclean 7305 1 0 16:35 ? 00:00:00 ora_s000_PROD
maclean 7313 1 0 16:35 ? 00:00:00 ora_qmnc_PROD
maclean 7430 1 0 16:35 ? 00:00:00 ora_q000_PROD
maclean 7438 1 0 16:36 ? 00:00:00 ora_q001_PROD
/* lgwr是著名的Oracle后臺進程,在這個啟動的實例中其系統(tǒng)進程號為7289*/
[maclean@rh2 ~]$ ls -l /proc/7289/fd /* linux上的proc文件系統(tǒng)可以很方便我們探測進程信息*/
total 0
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 0 -> /dev/null
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 1 -> /dev/null
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 10 -> /dev/zero
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 11 -> /dev/zero
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 12 -> /s01/rac10g/rdbms/mesg/oraus.msb
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 13 -> /s01/rac10g/dbs/hc_PROD.dat
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 14 -> /s01/rac10g/dbs/lkPROD
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 15 -> /s01/rac10g/oradata/PROD/controlfile/o1_mf_64q6xphj_.ctl
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 16 -> /s01/rac10g/flash_recovery_area/PROD/controlfile/o1_mf_64q6xpms_.ctl
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 17 -> /s01/rac10g/oradata/PROD/onlinelog/o1_mf_1_64q6xrsr_.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 18 -> /s01/rac10g/flash_recovery_area/PROD/onlinelog/o1_mf_1_64q6xsoy_.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 19 -> /s01/rac10g/oradata/PROD/onlinelog/o1_mf_2_64q6xths_.log
l-wx------ 1 maclean oinstall 64 Jul 26 16:38 2 -> /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 20 -> /s01/rac10g/flash_recovery_area/PROD/onlinelog/o1_mf_2_64q6xv9o_.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 21 -> /s01/rac10g/oradata/PROD/onlinelog/o1_mf_3_64q6xw1b_.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 22 -> /s01/rac10g/flash_recovery_area/PROD/onlinelog/o1_mf_3_64q6xwv0_.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 23 -> /s01/rac10g/oradata/PROD/datafile/o1_mf_system_64q6wd5j_.dbf
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 24 -> /s01/rac10g/oradata/PROD/datafile/o1_mf_undotbs1_64q6wd7f_.dbf
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 25 -> /s01/rac10g/oradata/PROD/datafile/o1_mf_sysaux_64q6wd5m_.dbf
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 26 -> /s01/rac10g/oradata/PROD/datafile/o1_mf_users_64q6wd89_.dbf
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 27 -> /s01/rac10g/oradata/PROD/datafile/o1_mf_temp_64q6xyox_.tmp
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 28 -> /s01/rac10g/rdbms/mesg/oraus.msb
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 3 -> /dev/null
lr-x------ 1 maclean oinstall 64 Jul 26 16:38 4 -> /dev/null
l-wx------ 1 maclean oinstall 64 Jul 26 16:38 5 -> /s01/rac10g/admin/PROD/udump/prod_ora_7279.trc
l-wx------ 1 maclean oinstall 64 Jul 26 16:38 6 -> /s01/rac10g/admin/PROD/bdump/alert_PROD.log
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 7 -> /s01/rac10g/dbs/lkinstPROD (deleted)
lrwx------ 1 maclean oinstall 64 Jul 26 16:38 8 -> /s01/rac10g/dbs/hc_PROD.dat
l-wx------ 1 maclean oinstall 64 Jul 26 16:38 9 -> /s01/rac10g/admin/PROD/bdump/alert_PROD.log
/*可以看到lgwr進程相關trace文件為/s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc,對應打開文件描述符為2*/
[maclean@rh2 ~]$ ls -lh /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc
-rw-r----- 1 maclean oinstall 1.7M Jul 26 16:37 /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc
[maclean@rh2 ~]$ rm -f /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc
/*嘗試刪除該trace文件*/
[maclean@rh2 ~]$ ls -l /proc/7289/fd|grep lgwr
l-wx------ 1 maclean oinstall 64 Jul 26 16:38 2 -> /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc (deleted)
/*文件已處在deleted狀態(tài),但lgwr進程仍持有該文件相關的文件描述符,這個時候該文件占有的空間并不會被釋放*/
[maclean@rh2 ~]$ lsof|grep lgwr
Oracle 7289 maclean 2w REG 8,2 1702391 3867134 /s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc (deleted)
[maclean@rh2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Mon Jul 26 17:03:04 2010
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> oradebug setospid 7289;
Oracle pid: 6, Unix process pid: 7289, image: oracle@rh2 (LGWR)
SQL> oradebug flush; /*寫出trace buffer內(nèi)容到trace文件*/
Statement processed.
SQL> oradebug close_trace;
Statement processed.
/*close_trace能夠釋放指定Oracle進程正打開著的文件,To close the current trace file use*/
SQL> host
[maclean@rh2 ~]$ lsof|grep lgwr
[maclean@rh2 ~]$ ls -l /proc/7289/fd/|grep lgwr
[maclean@rh2 ~]$
/* 從進程相關的fd文件夾中查找不到原來的trace文件;close_trace命令成功釋放了該文件,并回收了磁盤空間。*/
本文出自:億恩科技【mszdt.com】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|