日期:2014-05-16  浏览次数:20709 次

linux命令的oracle运用(一)

    1 dd

    模拟物理坏块


SQL> select * from v$database_block_corruption;

no rows selected

SQL> select * from v$backup_corruption;

no rows selected

SQL> select * from v$copy_corruption;

no rows selected

SQL> create tablespace physical_corrupt datafile size 10m autoextend on;

Tablespace created.

SQL> conn hr/hr
Connected.
SQL> create table tt (i int)  tablespace physical_corrupt;

Table created.
SQL> insert into tt values(1);

1 row created.

SQL> insert into tt values(2);

1 row created.

SQL> commit;

Commit complete.
SQL> select tt.*,dbms_rowid.rowid_block_number(rowid) from tt;

	 I DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
---------- ------------------------------------
	 1				     15
	 2				     15

SQL> select tablespace_name,file_name from dba_data_files where tablespace_name='PHYSICAL_CORRUPT';

TABLESPACE_NAME
------------------------------
FILE_NAME
--------------------------------------------
PHYSICAL_CORRUPT
/u01/app/oracle/oradata/ORCL/datafile/o1_mf_physical_88gkb4l9_.dbf

[oracle@Think ~]$ dd of=/u01/app/oracle/oradata/ORCL/datafile/o1_mf_physical_88gkb4l9_.dbf bs=8192 conv=notrunc seek=15 <<!
> my name is think
> !
0+1 records in
0+1 records out
17 bytes (17 B) copied, 9.9193e-05 s, 171 kB/s

用rman向oracle注册,报告填充v$database_block_corruption
RMAN> backup validate tablespace physical_corrupt;

Starting backup at 24-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=140 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/u01/app/oracle/oradata/ORCL/datafile/o1_mf_physical_88gkb4l9_.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-OCT-12

SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#	  BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
	 6	   15	       1		  0 CORRUPT

SQL> select * from tt;
select * from tt
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 15)
ORA-01110: data file 6:
'/u01/app/oracle/oradata/ORCL/datafile/o1_mf_physical_88gkb4l9_.dbf'

    2 diff

       逐行比较两个文本文件,列出差异行
       通常的输出格式:
       n1 a n2
       n1 c n2
       n1 d n2
       字母(a、d和c)之前的行号(n1)是针对file1的,其后面的行号(n2)是针对file2的。
       字母a、d和c分别表示附加、删除和修改操作。
       以”<”打头的行属于第一个文件,以”>”打头的行属于第二个文件。
       例如:

[oracle@Think udump]$ diff orcl_ora_18900.trc orcl_ora_19032.trc
1c1
< /u01/app/oracle/admin/orcl/udump/orcl_ora_18900.trc
---
> /u01/app/oracle/admin/orcl/udump/orcl_ora_19032.trc
11,13c11,13
< Redo thread mounted by this instance: 0 <none>
< Oracle process number: 0
< Unix process pid: 18900, image: oracle@Think
---
> Redo thread mounted by this instance: 1
> Oracle process number: 17
> Unix process pid: 19032, image: oracle@Think (TNS V1-V3)
15,17c15,19
< KCCDEBUG_LEVEL = 0
< Dynamic strand is set to TRUE
< Running with 2 shared and 18 private strand(s). Zero-copy redo is FALSE
---
> *** 2012-10-23 20:37:12.033