Lsof application instance sharing and Oracle Data File Deletion AND RECOVERY TEST

Source: Internet
Author: User
(I) lsof application instance

① Find the program occupying the specified port:

[root@temp ~]# lsof -i :80COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEhttpd   10278   root    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10280 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10281 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10282 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10283 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10284 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10285 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10286 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)httpd   10287 apache    3u  IPv6  37812      0t0  TCP *:http (LISTEN)

② Find out who is using the specified file:

[root@temp ~]# lsof /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbfCOMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF    NODE NAMEoracle  11239 oracle   23uW  REG    8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbforacle  11241 oracle   29u   REG    8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbforacle  11245 oracle   21u   REG    8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbforacle  11251 oracle   22u   REG    8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbforacle  11260 oracle   19u   REG    8,2 83894272 1169914 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_ggs_data_8rq64t53_.dbf

③ Search for files opened by a user

[root@temp ~]# lsof -u oracle COMMAND   PID   USER   FD   TYPE DEVICE  SIZE/OFF    NODE NAMEbash     5601 oracle  cwd    DIR    8,2      4096 1491645 /home/oraclebash     5601 oracle  rtd    DIR    8,2      4096       2 /bash     5601 oracle  txt    REG    8,2    735804 1782911 /bin/bashbash     5601 oracle  mem    REG    8,2      5436  584246 /usr/lib/gconv/ISO8859-1.sobash     5601 oracle  mem    REG    8,2    130860  390859 /lib/ld-2.5.sobash     5601 oracle  mem    REG    8,2   1706072  391064 /lib/i686/nosegneg/libc-2.5.sobash     5601 oracle  mem    REG    8,2     20668  391065 /lib/libdl-2.5.sobash     5601 oracle  mem    REG    8,2     13276  391090 /lib/libtermcap.so.2.0.8bash     5601 oracle  mem    REG    8,2     50848  389032 /lib/libnss_files-2.5.sobash     5601 oracle  mem    REG    8,2     25462  584323 /usr/lib/gconv/gconv-modules.cachebash     5601 oracle  mem    REG    8,2  56449792  491499 /usr/lib/locale/locale-archivebash     5601 oracle    0u   CHR  136,1       0t0       3 /dev/pts/1.....................................

④ Find the file that a program is currently opening

-C: program name-P: PID [root @ temp ~] # Lsof-C initcommand PID user FD type device size/off node nameinit 1 root CWD dir 8, 2 4096 2/init 1 root RTD dir 8, 2 4096 2/init 1 root TXT Reg 8, 2 38652 1620888 /sbin/initinit 1 root mem Reg 8, 2 130860/lib/ld-2.5.soinit 1 root mem Reg 8, 2 390859/lib/i686/nosegneg/libc-2.5.soinit 1 root mem Reg 8, 2 1706072/lib/ libdl-2.5.soinit 1 root mem Reg 245376 391081/lib/libsepol. so.1init 1 root mem Reg 93508 391082/lib/libselinux. so.1init 1 root 10u FIFO 1322 0, 16 0t0/dev/initctl

⑤ Search for all network connections of a user

[root@temp ~]# lsof -a -u oracle -iCOMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEsqlplus  5631 oracle    7u  IPv4  42558      0t0  UDP localhost.localdomain:52493 oracle  11233 oracle   15u  IPv4  42442      0t0  UDP localhost.localdomain:62999 oracle  11255 oracle   14u  IPv4  42529      0t0  UDP localhost.localdomain:18473 oracle  11255 oracle   15u  IPv4  42530      0t0  TCP *:4048 (LISTEN)oracle  11257 oracle   14u  IPv4  42540      0t0  UDP localhost.localdomain:8690 oracle  11260 oracle   22u  IPv4  42728      0t0  UDP *:12147 

⑥ Search for all open network connections

Similar: lsof-I tcp lsof-I udp lsof-I TCP: 80 [root @ temp ~] # Lsof-icommand PID user FD type device size/off node namecupsd 3062 root 4u IPv4 8720 0t0 TCP localhost. localdomain: IPP (Listen) cupsd 3062 root 6u IPv4 8723 0t0 udp *: IPP Portmap 3600 RPC 3u IPv4 9798 0t0 udp *: SunRPC Portmap 3600 RPC 4u IPv4 9799 0t0 tcp *: sunRPC (Listen) RPC. STATD 3636 rpcuser 3u IPv4 9992 0t0 udp *: dhcp-failover2 RPC. STATD 3636 rpcuser 6u IPv4 9978 0t0 udp *: 844 RPC. STATD 3636 rpcuser 7u IPv4 10005 0t0 tcp *: 850 (Listen) hpiod 3890 root 0u IPv4 12249 0t0 TCP localhost. localdomain: 2208 (Listen) hpssd. PY 3895 root 4u IPv4 12267 0t0 TCP localhost. localdomain: 2207 (Listen) sshd 3908 root 3u IPv6 12303 0t0 tcp *: SSH (Listen) sshd 3908 root 4u IPv4 12305 0t0 tcp *: SSH (Listen) sendmail 3939 root 4u IPv4 12415 0t0 TCP localhost. localdomain: SMTP (Listen) avahi-dae 4149 avahi 13u IPv4 12875 0t0 udp *: mdns avahi-dae 4149 avahi 14u IPv6 12876 0t0 udp *: mdns avahi-dae 4149 avahi 15u IPv4 12877 0t0 udp *: 8990 avahi-dae 4149 avahi 16u IPv6 12878 0t0 udp *: 6857 dnsmasq 4169 nobody 5u IPv4 13032 0t0 udp *: bootps dnsmasq 4169 nobody 6u IPv4 13038 0t0 TCP 192.168.122.1: domain (Listen) dnsmasq 4169 nobody 7u IPv4 13039 0t0 UDP 192.168.122.1: domain cimserver 4172 cimsrvr 7u IPv6 13141 0t0 tcp *: WBEM-HTTPS (Listen) dhclient 4721 root 5u IPv4 13899 0t0 udp *: bootpc sqlplus 5631 Oracle 7u IPv4 42558 0t0 UDP localhost. localdomain: 52493 httpd 10278 root 3u IPv6 37812 0t0 tcp *: HTTP (Listen)

(Ii) Data File recovery test


Principle:

The background process maintains a file list and locks open files.
For Oracle, if the file is deleted but the file handle is not closed, you can see the file marked as deleted through the lsof output.
Through the proc file directory, you can find the file handle information. This is the Oracle data file.

** Before the test, *** [Oracle @ temp datafile] $ LS-alhtotal 1.20.drwxr-x --- 2 Oracle oinstall 4.0 K May 9. drwxr-XR-x 5 Oracle oinstall 4.0 K Jul 17 2012 .. -RW-r ----- 1 Oracle oinstall 101 m Jun 19 14:19 o1_mf_example_8050jhm7 _. DBF-RW-r ----- 1 Oracle oinstall 81 m Jun 19 14:19 o1_mf_ggs_data_8rq64t53 _. DBF-RW-r ----- 1 Oracle oinstall 271 m Jun 19 19:00 o1_mf_sysaux_8050fk3w _. DBF-RW-r ----- 1 Oracle oinstall 491 m Jun 19 18:56 o1_mf_system_8050fk2z _. DBF-RW-r ----- 1 Oracle oinstall 33 m JUN 17 o1_mf_temp_8050j34j _. TMP-RW-r ----- 1 Oracle oinstall 236 m Jun 19 18:59 o1_mf_undotbs1_8050fkc6 _. DBF-RW-r ----- 1 Oracle oinstall 47 M Jun 19 17:12 o1_mf_users_8050fkdh _. DBF ** check all files opened by dbwr ** [root @ temp ~] # Ps-Ef | grep dbworacle 5643 1 0 14:19? 00:00:00 ora_dbw0_orclroot 10741 8274 0 00:00:00 pts/3 grep dbw ** use lsof to list all files opened by dbwr ** [root @ temp ~] # Lsof-P 5643 command PID user FD type device size/off node nameoracle 5643 Oracle CWD dir 4096 1556206 5643/u01/APP/Oracle/product/10.2.0/db_1/dbsoracle Oracle RTD dir 8, 2 4096 2/Oracle 5643 Oracle TXT Reg 8, 2 93362427 1557452/u01/APP/Oracle/product/10.2.0/db_1/bin/oracleoracle 5643 Oracle mem Reg 8, 2 70077 1565448/u01/APP /Oracle/product/10.2.0/db_1/lib/libclsra10.sooracle 5643 Oracle mem Reg 50848 389032/lib/libnss_files-2.5.sooracle 5643 Oracle mem Reg 1544 1555978/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_orcl.datoracle 5643 Oracle mem Reg 20668 391065/lib /libdl-2.5.sooracle 5643 Oracle mem Reg 216560 391071/lib/i686/nosegneg/libm-2.5.sooracle 5643 Oracle mem Reg 1211519 1565413/u01/APP/Oracle/product/10.2.0/db_1/lib/libocrb10.sooracle 5643 Oracle mem re G 8, 2 130860/lib/ld-2.5.sooracle 390859 Oracle mem Reg 8, 2 5643/usr/lib/libaio. so.1.0.1oracle 5643 Oracle mem Reg 728411 1565414/u01/APP/Oracle/product/10.2.0/db_1/lib/libocrutl10.sooracle 5643 Oracle mem Reg 137960 391066/lib/i686/nosegneg/libpthread-2.5.sooracle 5643 oracle mem Reg 1706072 391064/lib/i686/nosegneg/libc-2.5.sooracle 5643 Oracle mem Reg 143485 1006 037/u01/APP/Oracle/product/10.2.0/db_1/lib/libskgxp10.sooracle 5643 Oracle mem Reg 8, 2 109740 391078/lib/libnsl-2.5.sooracle 5643 Oracle mem Reg 8, 2 854560 1565412/u01/APP/ oracle/product/10.2.0/db_1/lib/libocr10.sooracle 5643 Oracle mem Reg 8, 2 98079 1560689/u01/APP/Oracle/product/10.2.0/db_1/lib/libdb1_10.sooracle 5643 Oracle mem Reg 8, 2 2365801 1565447/u01/APP/Oracle/product/10.2.0/db_1/Li B/libhasgen10.sooracle 5643 Oracle mem Reg 8069 1560800/u01/APP/Oracle/product/10.2.0/db_1/lib/libskgxn2.sooracle 5643 Oracle mem Reg 5480533 1565995/u01/APP/Oracle/ product/10.2.0/db_1/lib/libnnz10.sooracle 5643 Oracle mem Reg 8, 2 9017903 1558479/u01/APP/Oracle/product/10.2.0/db_1/lib/libjox10.sooracle 5643 Oracle del Reg 5603346/sysvbe3bb918oracle 5643 Oracle mem CHR 1559/dev /Zerooracle 5643 Oracle 0r CHR 1, 3, 0t0 1557/dev/nulloracle 5643 Oracle 1R CHR 1, 3, 0t0 1557/dev/nulloracle 5643 Oracle 2R CHR 1, 3, 0t0 1557/dev/nulloracle 5643 Oracle 3R Chr 0t0 1557/dev/nulloracle 5643 Oracle 4R CHR 1, 3 0t0 1557/dev/nulloracle 5643 Oracle 5 W Reg 8, 2 624 1206137/u01/APP/Oracle/admin/orcl/udump/orcl_ora_5634.trcoracle 5643 oracle 6 W Reg 232742 324300/u01/APP/Oracle/Adm In/orcl/bdump/alert_orcl.logoracle 5643 Oracle 7u Reg 8, 2 0 1169911/u01/APP/Oracle/product/10.2.0/db_1/dbs/lkinstorcl (Deleted) oracle 5643 Oracle 8 W Reg 232742 324300 5643/u01/APP/Oracle/admin/orcl/bdump/alert_orcl.logoracle 1544 Oracle 9u Reg 1555978/u01/APP/Oracle/product/10.2.0 /db_1/dbs/hc_orcl.datoracle 5643 Oracle 10u Reg 8, 2 1298 230930/u01/APP/Oracle/admin/orcl/adump/ora_5634.au Doracle 5643 Oracle 11r CHR 1559 5643 0t0 1559/dev/zerooracle 5643 Oracle 12r CHR 834560 1565481 0t0/dev/zerooracle Oracle 13r REG/u01/APP/Oracle/product/10.2.0 /db_1/rdbms/mesg/oraus. msboracle 5643 Oracle 14u Reg 8, 2 1544 1555978/u01/APP/Oracle/product/10.2.0/db_1/dbs/hc_orcl.datoracle 5643 Oracle 15ur Reg 8, 2 24 1555979/u01/APP/Oracle/product/ 10.2.0/db_1/dbs/lkorcloracle 5643 ora CLE 16u Reg 7094272 1977496/u01/APP/Oracle/oradata/orcl/controlfile/o1_mf_823mrrdo _. ctloracle 5643 Oracle 17u Reg 7094272 1851190/u01/APP/Oracle/flash_recovery_area/orcl/controlfile/o1_mf_823mrrrp _. ctloracle 5643 Oracle 18uw Reg 513810432 1977493/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_system_8050fk2z _. dbforacle 5643 Oracle 19uw Reg 246423552 1977494/u01/APP/Oracle/oradata/o RCL/datafile/o1_mf_undotbs1_8050fkc6 _. dbforacle 5643 Oracle 20uw Reg 283123712 1977489/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_sysaux_8050fk3w _. dbforacle 5643 Oracle 21uw Reg 48504832 1977490/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_users_8050fkdh _. dbforacle 5643 Oracle 22uw Reg 104865792 1977491/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_example_8050jhm7 _. dbforacle 5643 Oracle 23uw Reg 83894272 1977501/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_ggs_data_8rq64t53 _. DBF (Deleted) Oracle 5643 Oracle 24uw Reg 33562624 1977492/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_temp_8050j34j _. tmporacle 5643 Oracle 25r Reg 834560 1565481/u01/APP/Oracle/product/10.2.0/db_1/rdbms/mesg/oraus. MSB ** sets o1_mf_ggs_data_8rq64t53 _. DBF Delete ** [Oracle @ temp datafile] $ Rm-RF ow.mf_ggs _ Data_8rq64t53 _. DBF ** lists information about the handle to file 23. *** [root @ temp ~] # Ls-ALH/proc/5643/FD/23lrwx ------ 1 Oracle oinstall 64 06-19/proc/5643/FD/23->/u01/APP/Oracle/oradata/ orcl/datafile/o1_mf_ggs_data_8rq64t53 _. DBF (Deleted) ** just copy it. ** [root @ temp ~] # Cp/proc/5643/FD/23/u01/APP/Oracle/oradata/orcl/datafile/[root @ temp ~] # Chown-r ORACLE: oinstall/u01/APP/Oracle/oradata/orcl/datafile/23 ***** rename ***** [Oracle @ temp datafile] $ LS-ltotal 1283716-rw-r ----- 1 Oracle oinstall 83894272 jun 19 23-rw-r ----- 1 Oracle oinstall 104865792 Jun 19 o1_mf_example_8050jhm7 _. DBF-RW-r ----- 1 Oracle oinstall 283123712 Jun 19 o1_mf_sysaux_8050fk3w _. DBF-RW-r ----- 1 Oracle oinstall 513810432 Jun 19 o1_mf_system_8050fk2z _. DBF-RW-r ----- 1 Oracle oinstall 33562624 JUN 17 o1_mf_temp_8050j34j _. TMP-RW-r ----- 1 Oracle oinstall 246423552 Jun 19 o1_mf_undotbs1_8050fkc6 _. DBF-RW-r ----- 1 Oracle oinstall 48504832 Jun 19 o1_mf_users_8050fkdh _. DBF [Oracle @ temp datafile] $ MV 23 o1_mf_ggs_data_8rq64t53 _. DBF [Oracle @ temp datafile] $ LS-alhtotal 1.20.drwxr-x --- 2 Oracle oinstall 4.0 K Jun 19. drwxr-XR-x 5 Oracle oinstall 4.0 K Jul 17 2012 .. -RW-r ----- 1 Oracle oinstall 101 m Jun 19 14:19 o1_mf_example_8050jhm7 _. DBF-RW-r ----- 1 Oracle oinstall 81 m Jun 19 19:11 o1_mf_ggs_data_8rq64t53 _. DBF-RW-r ----- 1 Oracle oinstall 271 m Jun 19 19:13 o1_mf_sysaux_8050fk3w _. DBF-RW-r ----- 1 Oracle oinstall 491 M Jun 19 19:13 o1_mf_system_8050fk2z _. DBF-RW-r ----- 1 Oracle oinstall 33 m JUN 17 o1_mf_temp_8050j34j _. TMP-RW-r ----- 1 Oracle oinstall 236 m Jun 19 19:13 o1_mf_undotbs1_8050fkc6 _. DBF-RW-r ----- 1 Oracle oinstall 47 M Jun 19 17:12 o1_mf_users_8050fkdh _. DBF ** view status ** sys @ orcl> shutdown immediatedatabase closed. database dismounted. oracle instance shut down. sys @ orcl> startuporacle instance started. total system global area 419430400 bytesfixed size 1219760 bytesvariable size 104858448 bytesdatabase buffers 310378496 bytesredo buffers 2973696 bytesdatabase mounted. ORA-01113: file 6 needs media recoveryORA-01110: data file 6: '/u01/APP/Oracle/oradata/orcl/datafile/o1_mf_ggs_data_8rq64t53 _. dbf'sys @ orcl> recover datafile 6; media recovery complete. sys @ orcl> alter database open; database altered. sys @ orcl> select file_name, status from dba_data_files where file_id = 6; file_name status certificate ---------/u01/APP/Oracle/oradata/orcl/datafile/ow.mf_ggs_data_8rq64t53 _. DBF available

By David Lin

2013-06-

Always be a first-rate version of yourself, instead of a second-rate version of someone else.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.