« JAVA连接池导致的超高回滚率 - rlbk=1 | Blog首页 | 数据安全 - 从CSDN网站数据泄露说开去 »
Oracle数据恢复 - 使用 lsof 查看进程打开的文件列表
作者:eygle | 【转载请注出处】|【云和恩墨 领先的zData数据库一体机 | zCloud PaaS云管平台 | SQM SQL审核平台 | ZDBM 数据库备份一体机】
链接:https://www.eygle.com/archives/2011/12/oracle_lsof_recovery_database.html
在Unix、Linux系统上,Oracle数据库启动之后,后台进程会维护一个文件列表,锁定打开的文件。链接:https://www.eygle.com/archives/2011/12/oracle_lsof_recovery_database.html
这个进程文件列表,可以通过lsof命令查看。
对于Solaris平台,可以从 SUNFreeWare 站点获得lsof的安装包,不同版本安装源不同,也可以通过源码自行编译:
http://sunfreeware.com/indexsparc9.html
以下是在Solaris 9上安装的过程:
Pro:tmp eygle$ wget ftp://ftp.sunfreeware.com/pub/freeware/sparc/9/lsof-4.80-sol9-sparc-local.gz
--09:38:42-- ftp://ftp.sunfreeware.com/pub/freeware/sparc/9/lsof-4.80-sol9-sparc-local.gz
=> `lsof-4.80-sol9-sparc-local.gz'
Resolving ftp.sunfreeware.com... 66.193.208.66
Connecting to ftp.sunfreeware.com[66.193.208.66]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/freeware/sparc/9 ... done.
==> PORT ... done. ==> RETR lsof-4.80-sol9-sparc-local.gz ... done.
Length: 489,916 (unauthoritative)
100%[=================================================================================>] 489,916 93.36K/s ETA 00:00
09:38:55 (93.24 KB/s) - `lsof-4.80-sol9-sparc-local.gz' saved [489916]
然后执行安装:
root@db2 # pwd接下来就可以使用lsof了,首先选取一个进程,如 dbwr 进程:
/tmp
root@db2 # gzip -d lsof-4.80-sol9-sparc-local.gz
root@db2 # pkgadd -d lsof-4.80-sol9-sparc-local
The following packages are available:
1 SMClsof lsof
(sparc) 4.80
Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: all
Processing package instance <SMClsof> from </tmp/lsof-4.80-sol9-sparc-local>
lsof
(sparc) 4.80
This appears to be an attempt to install the same architecture and
version of a package which is already installed. This installation
will attempt to overwrite this package.
Vic Abell
Using </usr/local> as the package base directory.
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
The following files are already installed on the system and are being
used by another package:
/usr/local/bin <attribute change only>
/usr/local/bin/sparcv7 <attribute change only>
/usr/local/bin/sparcv9 <attribute change only>
/usr/local/doc <attribute change only>
/usr/local/man <attribute change only>
/usr/local/man/man8 <attribute change only>
Do you want to install these conflicting files [y,n,?,q] y
## Checking for setuid/setgid programs.
The following files are being installed with setuid and/or setgid
permissions:
*/usr/local/bin/lsof <setgid sys>
*/usr/local/bin/sparcv7/lsof <setgid sys>
*/usr/local/bin/sparcv9/lsof <setgid sys>
* - overwriting a file which is also setuid/setgid.
Do you want to install these as setuid/setgid files [y,n,?,q] y
Installing lsof as <SMClsof>
## Installing part 1 of 1.
/usr/local/bin/lsof
/usr/local/bin/sparcv7/lsof
/usr/local/bin/sparcv9/lsof
/usr/local/doc/lsof/00.README.FIRST
/usr/local/doc/lsof/00CREDITS
/usr/local/doc/lsof/00DCACHE
/usr/local/doc/lsof/00DIALECTS
/usr/local/doc/lsof/00DIST
/usr/local/doc/lsof/00FAQ
/usr/local/doc/lsof/00LSOF-L
/usr/local/doc/lsof/00MANIFEST
/usr/local/doc/lsof/00PORTING
/usr/local/doc/lsof/00QUICKSTART
/usr/local/doc/lsof/00README
/usr/local/doc/lsof/00TEST
/usr/local/doc/lsof/00XCONFIG
/usr/local/doc/lsof/lsof.man
/usr/local/man/man8/lsof.8
[ verifying class <none> ]
Installation of <SMClsof> was successful.
root@db2 # ps -ef|grep dbw对于Oracle数据库来说,如果有文件被删除,只要文件句柄未关闭,则就可以在lsof的输出中看到标记为deleted的状态标记.
root 14348 9859 0 10:15:50 pts/3 0:00 grep dbw
oracle 762 1 0 Jun 10 ? 202:01 ora_dbw0_cinms
root@db2 # lsof -p 762
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
oracle 762 oracle cwd VDIR 85,8272 2048 106800 /u01/app/oracle/product/9.2.0/dbs
oracle 762 oracle txt VREG 85,8272 66187776 10258 /u01/app/oracle/product/9.2.0/bin/oracle
oracle 762 oracle txt VREG 118,1 13280 18580 /usr/lib/sparcv9/libmd5.so.1
oracle 762 oracle txt VREG 118,1 24336 18582 /usr/lib/sparcv9/libmp.so.2
oracle 762 oracle txt VREG 118,1 262112 19762 /usr/lib/sparcv9/libm.so.1
oracle 762 oracle txt VREG 118,1 13936 18568 /usr/lib/sparcv9/libkstat.so.1
oracle 762 oracle txt VREG 118,1 48768 18597 /usr/lib/sparcv9/librt.so.1
oracle 762 oracle txt VREG 118,1 48544 18545 /usr/lib/sparcv9/libaio.so.1
oracle 762 oracle txt VREG 118,1 971872 18523 /usr/lib/sparcv9/libc.so.1
oracle 762 oracle txt VREG 118,1 5160 18551 /usr/lib/sparcv9/libdl.so.1
oracle 762 oracle txt VREG 118,1 47816 18564 /usr/lib/sparcv9/libgen.so.1
oracle 762 oracle txt VREG 118,1 915320 45739 /usr/lib/sparcv9/libnsl.so.1
oracle 762 oracle txt VREG 85,8272 7519968 1234 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle txt VREG 118,1 75224 18605 /usr/lib/sparcv9/libsocket.so.1
oracle 762 oracle txt VREG 85,8272 38616 1293 /u01 -- libskgxn9.so
oracle 762 oracle txt VREG 85,8272 12256 814 /u01 -- libskgxp9.so
oracle 762 oracle txt VREG 85,8272 9064 1296 /u01 -- libodmd9.so
oracle 762 oracle txt VREG 118,1 4760 43126 /usr/platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
oracle 762 oracle txt VREG 118,1 234296 94651 /usr/lib/sparcv9/ld.so.1
oracle 762 oracle 0r VCHR 13,2 0t0 11044 /devices/pseudo/mm@0:null
oracle 762 oracle 1r VCHR 13,2 0t0 11044 /devices/pseudo/mm@0:null
oracle 762 oracle 2r VCHR 13,2 0t0 11044 /devices/pseudo/mm@0:null
oracle 762 oracle 3r VCHR 13,2 0t0 11044 /devices/pseudo/mm@0:null
oracle 762 oracle 4r VCHR 13,2 0t0 11044 /devices/pseudo/mm@0:null
oracle 762 oracle 5w VREG 85,8272 583 111252 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 6w VREG 85,8272 85019992 111002 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 7w VREG 85,8272 85019992 111002 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 8r VCHR 13,12 0t0 11046 /devices/pseudo/mm@0:zero
oracle 762 oracle 9r VCHR 13,12 0t0 11046 /devices/pseudo/mm@0:zero
oracle 762 oracle 10r DOOR 338,0 0t0 53 /var/run (swap) (door to nscd[332])
oracle 762 oracle 11r VREG 85,8272 657920 6421 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 12u VREG 85,8272 923 109747 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 13uR VREG 85,8272 24 109060 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 14u IPv4 0x35f15674040 0t0 UDP *:38127 (Idle)
oracle 762 oracle 256uW VREG 85,8272 1859584 110979 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 257uW VREG 85,8272 1859584 110980 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 258uW VREG 85,8272 1859584 110981 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 259uW VREG 85,8272 414195712 110986 /u01/oradata/cinms/system01.dbf
oracle 762 oracle 260uW VREG 85,8272 6291464192 110993 /u01/oradata/cinms/undotbs01.dbf
oracle 762 oracle 261uW VREG 85,8272 161488896 110999 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 262uW VREG 85,8272 20979712 111000 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 263uW VREG 85,8272 26222592 111001 /u01/oradata/cinms/indx01.dbf
oracle 762 oracle 264uW VREG 85,8272 10493952 111151 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 265uW VREG 85,8272 473178112 111152 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 266uW VREG 118,0 1048584192 192549 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 267uW VREG 118,0 1048584192 192550 / -- data_res10.dbf
oracle 762 oracle 268uW VREG 118,0 1048584192 192551 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 269uW VREG 118,0 1048584192 192552 / -- data_res12.dbf
oracle 762 oracle 270uW VREG 85,8252 1048584192 5 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 271uW VREG 85,8252 1048584192 6 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 272uW VREG 85,8252 1375739904 9 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 273uW VREG 85,8252 1376788480 10 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 274uW VREG 85,8242 1048584192 5 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 275uW VREG 85,8242 1048584192 6 /u04/oradata/cnnc_hist02.dbf
oracle 762 oracle 276uW VREG 85,8242 1048584192 8 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 277uW VREG 85,8242 1048584192 9 /u04/oradata_res/data_res02.dbf
oracle 762 oracle 278uW VREG 85,8242 1048584192 10 /u04/oradata_res/data_res03.dbf
oracle 762 oracle 279uW VREG 85,8242 1048584192 11 /u04/oradata_res/data_res04.dbf
oracle 762 oracle 280uW VREG 85,8252 1048584192 11 /u03/oradata_res/idx_res01.dbf
oracle 762 oracle 281uW VREG 85,8272 524296192 111198 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 282uW VREG 85,8272 104865792 111200 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 283uW VREG 85,8252 1048584192 12 /u03/oradata/cnnc_user05.dbf
oracle 762 oracle 284uW VREG 85,8242 1048584192 12 /u04/oradata/cnnc_user06.dbf
oracle 762 oracle 285uW VREG 118,0 1377837056 192553 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 286uW VREG 118,0 1377312768 192554 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 287uW VREG 118,0 1048584192 192538 /u02/oradata/cnnc_user01.dbf
oracle 762 oracle 288uW VREG 118,0 1048584192 192539 /u02/oradata/cnnc_user02.dbf
oracle 762 oracle 289uW VREG 118,0 1048584192 192540 /u02/oradata/cnnc_user03.dbf
oracle 762 oracle 290uW VREG 85,8252 1048584192 13 /u03/oradata/cnnc_user12.dbf
oracle 762 oracle 291uW VREG 85,8252 1048584192 14 /u03/oradata/cnnc_user13.dbf
oracle 762 oracle 292uW VREG 85,8242 1048584192 13 /u04/oradata/cnnc_user15.dbf
oracle 762 oracle 293uW VREG 85,8252 1048584192 15 /u03/oradata/cnnc_user14.dbf
oracle 762 oracle 294uW VREG 118,0 1048584192 192541 /u02/oradata/cnnc_user04.dbf
oracle 762 oracle 295uW VREG 118,0 1048584192 192542 /u02/oradata/cnnc_user07.dbf
oracle 762 oracle 296uW VREG 85,8252 1048584192 16 /u03/oradata/cnnc_user17.dbf
oracle 762 oracle 297uW VREG 85,8252 1048584192 17 /u03/oradata/cnnc_user18.dbf
oracle 762 oracle 298uW VREG 85,8242 1048584192 14 /u04/oradata/cnnc_user19.dbf
oracle 762 oracle 299uW VREG 85,8242 1048584192 15 /u04/oradata_res/data_res05.dbf
oracle 762 oracle 300uW VREG 85,8242 1048584192 16 /u04/oradata_res/data_res06.dbf
oracle 762 oracle 301uW VREG 85,8242 1048584192 17 /u04/oradata_res/data_res07.dbf
oracle 762 oracle 302uW VREG 85,8242 1048584192 18 /u04/oradata_res/data_res08.dbf
oracle 762 oracle 303uW VREG 85,8252 1048584192 18 /u03/oradata/cnnc_user20.dbf
oracle 762 oracle 304uW VREG 85,8252 1048584192 19 /u03/oradata/cnnc_user21.dbf
oracle 762 oracle 305uW VREG 85,8252 1048584192 20 /u03/oradata/cnnc_user22.dbf
oracle 762 oracle 306uW VREG 85,8242 1048584192 19 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 307uW VREG 85,8242 1048584192 20 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 308uW VREG 118,0 1048584192 192543 /u02/oradata/cnnc_user08.dbf
oracle 762 oracle 309uW VREG 118,0 1073750016 192544 /u02/oradata/cnnc_user09.dbf
oracle 762 oracle 310uW VREG 118,0 1073750016 192545 /u02/oradata/cnnc_user10.dbf
oracle 762 oracle 311uW VREG 118,0 1073750016 192546 /u02/oradata/cnnc_user11.dbf
oracle 762 oracle 312uW VREG 85,8252 1073750016 21 /u03/oradata/cnnc_user24.dbf
oracle 762 oracle 313uW VREG 118,0 1048584192 192547 /u02/oradata/cnnc_user15.dbf
oracle 762 oracle 314uW VREG 118,0 1048584192 192548 /u02/oradata/cnnc_user16.dbf
oracle 762 oracle 315uW VREG 85,8252 1048584192 22 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 316uW VREG 85,8252 1048584192 23 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 317uW VREG 85,8242 1048584192 21 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 318uW VREG 85,8242 1048584192 22 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 319uW VREG 118,0 1048584192 192555 /u02/oradata/cnnc_indexes05.dbf
oracle 762 oracle 320uW VREG 85,8242 1048584192 23 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 321uW VREG 118,0 1048584192 192556 /u02/oradata/cnnc_user25.dbf
oracle 762 oracle 322uW VREG 85,8252 1048584192 24 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 323uW VREG 85,8252 1048584192 25 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 324uW VREG 85,8252 1048584192 26 /u03 (/dev/md/OraDG/dsk/d60)
oracle 762 oracle 325uW VREG 118,0 1048584192 192557 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 326uW VREG 118,0 1048584192 192558 /u02/oradata/cnnc_user27.dbf
oracle 762 oracle 327uW VREG 85,8252 1048584192 27 /u03/oradata/cnnc_user28.dbf
oracle 762 oracle 328uW VREG 85,8242 1048584192 24 /u04/oradata/cnnc_user29.dbf
oracle 762 oracle 329uW VREG 85,8242 1048584192 25 /u04/oradata/cnnc_user30.dbf
oracle 762 oracle 330uW VREG 85,8272 104865792 111088 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 331uW VREG 85,8272 104865792 111089 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 332uW VREG 85,8272 104865792 111090 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 333uW VREG 85,8272 104865792 111091 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 334uW VREG 85,8272 104865792 111092 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 335uW VREG 85,8272 104865792 111093 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 336uW VREG 85,8272 104865792 111094 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 337uW VREG 85,8272 104865792 111095 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 338uW VREG 85,8272 104865792 111096 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 339uW VREG 85,8272 104865792 111097 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 340uW VREG 85,8242 1048584192 26 /u04/oradata_res/data_res13.dbf
oracle 762 oracle 341uW VREG 85,8242 1048584192 27 /u04 (/dev/md/OraDG/dsk/d50)
oracle 762 oracle 342uW VREG 85,8252 1048584192 28 /u03/oradata_res/idx_res02.dbf
oracle 762 oracle 343uW VREG 85,8272 1409294336 111241 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 344uW VREG 118,0 1048584192 192559 / (/dev/dsk/c1t0d0s0)
oracle 762 oracle 345uW VREG 118,0 1073750016 192560 /u02/oradata/cnnc_indexes11.dbf
oracle 762 oracle 346uW VREG 118,0 1073750016 192561 /u02/oradata/cnnc_indexes12.dbf
oracle 762 oracle 347uW VREG 85,8272 52436992 111150 /u01 (/dev/md/OraDG/dsk/d80)
oracle 762 oracle 348uW VREG 85,8252 8388616192 8 /u03 (/dev/md/OraDG/dsk/d60)
通过 proc 下的文件目录,可以找到文件句柄信息,这个就是Oracle的数据文件:
root@db2 # ls -l /proc/762/fd/329
-rw-r----- 1 oracle dba 1048584192 Dec 20 10:16 /proc/762/fd/329
可以通过复制拷贝恢复这个文件。
-The End-
历史上的今天...
>> 2008-12-21文章:
>> 2006-12-21文章:
>> 2005-12-21文章:
>> 2004-12-21文章:
By eygle on 2011-12-21 09:45 | Comments (0) | Backup&Recovery | 2932 |