可能很多朋友都遇到過這樣的情況,在UNIX/Linux上定期清理Oracle日志文件夾時(shí)可能刪除到仍被后臺(tái)進(jìn)程open著的trace文件,即某些后臺(tái)進(jìn)程一直持有著這些”被已經(jīng)誤刪了的“打開文件的描述符(fd),這種情況下文件系統(tǒng)上該文件實(shí)際占用的空間是不會(huì)被釋放的,這就造成使用df命令查看文件系統(tǒng)剩余空間和用du命令查看文件夾空間使用量時(shí)數(shù)值不一致的問題。此外因?yàn)槭呛笈_(tái)進(jìn)程持有這些打開文件描述符,所以我們無(wú)法像kill服務(wù)進(jìn)程一樣來(lái)解決該問題(部分后臺(tái)進(jìn)程是可以kill的,不建議這樣做)。oradebug是sqlplus中威力強(qiáng)大的debug命令,我們可以通過該命令發(fā)起多種trace/dump,其中也包括了close_trace事件;close_trace事件可以讓指定進(jìn)程關(guān)閉其正持有的trace文件。-
下面我們就來(lái)演示下相關(guān)操作:
[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ái)進(jìn)程,在這個(gè)啟動(dòng)的實(shí)例中其系統(tǒng)進(jìn)程號(hào)為7289*/
[maclean@rh2 ~]$ ls -l /proc/7289/fd /* linux上的proc文件系統(tǒng)可以很方便我們探測(cè)進(jìn)程信息*/
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進(jìn)程相關(guān)trace文件為/s01/rac10g/admin/PROD/bdump/prod_lgwr_7289.trc,對(duì)應(yīng)打開文件描述符為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進(jìn)程仍持有該文件相關(guān)的文件描述符,這個(gè)時(shí)候該文件占有的空間并不會(huì)被釋放*/
[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進(jìn)程正打開著的文件,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 ~]$
/* 從進(jìn)程相關(guān)的fd文件夾中查找不到原來(lái)的trace文件;close_trace命令成功釋放了該文件,并回收了磁盤空間。*/
本文出自:億恩科技【1tcdy.com】
服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|