Oracle数据库使用裸设备及备份与恢复

OS: redhat  Linux 7.6
RDBMS :12.2.0.1
1 在虚拟机上添加2块硬盘,每块大小2G
2 在虚拟机上看到新增加的盘是 sdc,sdd ,进行fdisk分区,sdc1,sdcd1

Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdd: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

3 设置udev规则,并启动udev

ACTION=="add",KERNEL=="sdc1",RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add",KERNEL=="sdd1",RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add",KERNEL=="raw[1-2]",OWNER="oracle", GROUP="oinstall", MODE="660"

重新加载udev配置,udevadm control --reload

[root@wls10306-01 rules.d]# udevadm control --reload
[root@wls10306-01 rules.d]# ls -l /dev/raw/raw*
crw-rw---- 1 oracle oinstall 162, 1 Sep  4 09:04 /dev/raw/raw1
crw-rw---- 1 oracle oinstall 162, 2 Sep  4 09:05 /dev/raw/raw2
crw-rw---- 1 root   disk     162, 0 Sep  4 08:28 /dev/raw/rawctl
[root@wls10306-01 rules.d]# 

查看裸设备

[root@wls10306-01 rules.d]# raw -qa
/dev/raw/raw1:  bound to major 8, minor 33
/dev/raw/raw2:  bound to major 8, minor 49
[root@wls10306-01 rules.d]# 

4 在数据库上创建表空间,直接设置2G 会报错(因为之前fdisk的时候,看到的是2047M,实际使用2047M也不可以),设置1900M 。

create tablespace tbs_raw datafile '/dev/raw/raw1' size 1900M autoextend off ;
alter tablespace tbs_raw add datafile '/dev/raw/raw2' size 1900M autoextend off ;

SYS@test>create tablespace tbs_raw datafile '/dev/raw/raw1' size 2G autoextend off ;
create tablespace tbs_raw datafile '/dev/raw/raw1' size 2G autoextend off
*
ERROR at line 1:
ORA-01119: error in creating database file '/dev/raw/raw1'
ORA-27042: not enough space on raw partition to fullfill request
Additional information: 1

SYS@test>create tablespace tbs_raw datafile '/dev/raw/raw1' size 1900M autoextend off ;

Tablespace created.

SYS@test>alter tablespace tbs_raw add datafile '/dev/raw/raw2' size 1900M autoextend off ;

Tablespace altered.

SYS@test>

5 查询创建的表空间,创建表,插入数据

SYS@test>select file_name,tablespace_name from dba_data_files ;

FILE_NAME                                                                        TABLESPACE_NAME
-------------------------------------------------------------------------------- --------------------
/u01/app/oracle/oradata/test/system01.dbf                                        SYSTEM
/u01/app/oracle/oradata/test/sysaux01.dbf                                        SYSAUX
/u01/app/oracle/oradata/test/undotbs01.dbf                                       UNDOTBS1
/u01/app/oracle/oradata/test/users01.dbf                                         USERS
/u01/app/oracle/oradata/test/example01.dbf                                       EXAMPLE
/u01/app/oracle/oradata/test/IDX_DATA01.DBF                                      IDX_DATA
/u01/app/oracle/oradata/test/TBS_DATA01.DBF                                      TBS_DATA
/u01/app/oracle/oradata/testogg/XTTS_9.dbf                                       XTTS
/dev/raw/raw1                                                                    TBS_RAW
/dev/raw/raw2                                                                    TBS_RAW

10 rows selected.

SYS@test>

SYS@test>create table t_raw(x date) tablespace TBS_RAW;

Table created.

SYS@test>insert into t_raw values(sysdate);

1 row created.

SYS@test>commit;

Commit complete.

SYS@test>select * from t_raw;

X
---------
04-SEP-20

SYS@test>

6 对表空间tbs_raw进行备份

RMAN> backup tablespace TBS_RAW format '/u01/backup/TBS_RAW_%U';

Starting backup at 04-SEP-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=55 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/dev/raw/raw1
input datafile file number=00010 name=/dev/raw/raw2
channel ORA_DISK_1: starting piece 1 at 04-SEP-20
channel ORA_DISK_1: finished piece 1 at 04-SEP-20
piece handle=/u01/backup/TBS_RAW_06v9ibu2_1_1 tag=TAG20200904T093706 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-SEP-20

Starting Control File and SPFILE Autobackup at 04-SEP-20
piece handle=/u01/app/oracle/fast_recovery_area/TEST/autobackup/2020_09_04/o1_mf_s_1050226627_ho36l3tb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 04-SEP-20

RMAN> 

7 使用dd命令,对裸设备进行破坏,模拟故障

[root@wls10306-01 trace]# dd if=/dev/zero of=/dev/raw/raw2 bs=2M count=1000
1000+0 records in
1000+0 records out
2097152000 bytes (2.1 GB) copied, 5.40737 s, 388 MB/s
[root@wls10306-01 trace]# dd if=/dev/zero of=/dev/raw/raw1 bs=2M count=1000
1000+0 records in
1000+0 records out
2097152000 bytes (2.1 GB) copied, 4.6995 s, 446 MB/s
[root@wls10306-01 trace]#

在关闭数据库的时候,提示文件损坏

SYS@test>shutdown immediate
ORA-01122: database file 9 failed verification check
ORA-01110: data file 9: '/dev/raw/raw1'
ORA-01210: data file header is media corrupt
SYS@test>!

在alert log中看到的信息,提示文件坏块

2020-09-04T09:50:29.232476+08:00
Read of datafile '/dev/raw/raw1' (fno 9) header failed with ORA-01210
Hex dump of (file 9, block 1) in trace file /u01/app/oracle/diag/rdbms/test/test/trace/test_ckpt_9585.trc

Corrupt block relative dba: 0x02400001 (file 9, block 1)
Completely zero block found during datafile header read

Rereading datafile 9 header failed with ORA-01210
Hex dump of (file 9, block 1) in trace file /u01/app/oracle/diag/rdbms/test/test/trace/test_ckpt_9585.trc

Corrupt block relative dba: 0x02400001 (file 9, block 1)
Completely zero block found during datafile header read

Read of datafile '/dev/raw/raw1' (fno 9) header failed with ORA-01210
Hex dump of (file 9, block 1) in trace file /u01/app/oracle/diag/rdbms/test/test/trace/test_ckpt_9585.trc

Corrupt block relative dba: 0x02400001 (file 9, block 1)
Completely zero block found during datafile header read

Rereading datafile 9 header failed with ORA-01210
Hex dump of (file 9, block 1) in trace file /u01/app/oracle/diag/rdbms/test/test/trace/test_ckpt_9585.trc

8 进行restore、recover (因为此时表空间TBS_RAW的数据文件出现了坏块,无法进行offline,所以恢复的时候,需要将数据库启动到mount下,如果可以offline,则不需要将数据库启动到mount状态)

RMAN> restore tablespace TBS_RAW;

Starting restore at 04-SEP-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00009 to /dev/raw/raw1
channel ORA_DISK_1: restoring datafile 00010 to /dev/raw/raw2
channel ORA_DISK_1: reading from backup piece /u01/backup/TBS_RAW_06v9ibu2_1_1
channel ORA_DISK_1: piece handle=/u01/backup/TBS_RAW_06v9ibu2_1_1 tag=TAG20200904T093706
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 04-SEP-20
RMAN> recover tablespace TBS_RAW;

Starting recover at 04-SEP-20
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 04-SEP-20

RMAN> 

9 验证数据

RMAN> alter database open;

Statement processed

RMAN> select open_mode from v$database;

OPEN_MODE           
--------------------
READ WRITE          

RMAN> select * from t_raw;

X        
---------
04-SEP-20

RMAN> 

10 清理,表空间的删除。删除表空间后,再次使用裸设备创建表空间,是可以正常创建表空间的。

SYS@test>drop tablespace TBS_RAW including contents and datafiles;

Tablespace dropped.

SYS@test>

[oracle@wls10306-01 trace]$ ll /dev/raw/raw*
crw-rw---- 1 oracle oinstall 162, 1 Sep  4 10:11 /dev/raw/raw1
crw-rw---- 1 oracle oinstall 162, 2 Sep  4 10:11 /dev/raw/raw2
crw-rw---- 1 root   disk     162, 0 Sep  4 09:23 /dev/raw/rawctl
[oracle@wls10306-01 trace]$ 

再次创建表空间

SYS@test>create tablespace tbs_raw datafile '/dev/raw/raw1' size 2040M autoextend off;

Tablespace created.

SYS@test>alter tablespace tbs_raw add datafile '/dev/raw/raw2' size 2040M autoextend off;

Tablespace altered.

END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值