1.什么是裸设备
裸设备是未经格式化、也未被挂载的磁盘分区,不能由操作系统的文件访问,而只能有应用程序自身负责如何访问裸分区,读写裸设备不会被操作系统缓存。裸设备主要用于提高I/O效率。
2.创建裸设备
1)创建磁盘分区
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
/dev/sdb5 1 16 128457 83 Linux
/dev/sdb6 17 32 128488+ 83 Linux
/dev/sdb7 33 48 128488+ 83 Linux
2)以root用户执行raw命令把分区与裸设备绑定,如下:
[root@localhost ~]# raw
Usage:
raw /dev/raw/rawN <major> <minor>
raw /dev/raw/rawN /dev/<blockdev>
raw -q /dev/raw/rawN
raw -qa
[root@localhost ~]# raw /dev/raw/raw1 /dev/sdb5
/dev/raw/raw1:bound to major 8, minor 21
[root@localhost ~]# raw /dev/raw/raw2 /dev/sdb6
/dev/raw/raw2:bound to major 8, minor 22
[root@localhost ~]# raw /dev/raw/raw3 /dev/sdb7
/dev/raw/raw3:bound to major 8, minor 23
[root@localhost ~]# chown oracle.dba /dev/raw/raw[1-3]
[root@localhost ~]# cd /dev/raw
[root@localhost raw]# ls -l
总计 0
crw------- 1 oracle dba 162, 1 12-04 15:58 raw1
crw------- 1 oracle dba 162, 2 12-04 15:58 raw2
crw------- 1 oracle dba 162, 3 12-04 15:59 raw3
[root@localhost raw]# cd ..
[root@localhost dev]# ls -ld raw
drwxr-xr-x 2 root root 100 12-04 15:59 raw
[root@localhost dev]# cd raw
[root@localhost raw]# ls -l
总计 0
crw------- 1 oracle dba 162, 1 12-04 15:58 raw1
crw------- 1 oracle dba 162, 2 12-04 15:58 raw2
crw------- 1 oracle dba 162, 3 12-04 15:59 raw3
[root@localhost raw]# chmod 660 raw[1-3]
[root@localhost raw]# ls -l
总计 0
crw-rw---- 1 oracle dba 162, 1 12-04 15:58 raw1
crw-rw---- 1 oracle dba 162, 2 12-04 15:58 raw2
crw-rw---- 1 oracle dba 162, 3 12-04 15:59 raw3
3)使用裸设备创建表空间
[root@localhost raw]# su - oracle
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 16:01:44 2013
Copyright (c) 1982, 2009, Oracle.All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> create tablespace rawtest
2'/dev/raw/raw1' size 100m reuse,
3'/dev/raw/raw2' size 100m reuse
4/
'/dev/raw/raw1' size 100m reuse,
*
ERROR at line 2:
ORA-02180: invalid option for CREATE TABLESPACE
SQL> startup
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> ed
Wrote file afiedt.buf
1create tablespace rawtest
2datafile
3'/dev/raw/raw1' size 100m reuse,
4* '/dev/raw/raw2' size 100m reuse
SQL> /
Tablespace created.
SQL>
批注:redhat5之后版本已不再支持开机自动重启裸设备,启动数据库后会出现数据库用户找不到
SQL> conn scott/tiger
ERROR:
ORA-01033: ORACLE initialization or shutdown in progress
Process ID: 0
Session ID: 0 Serial number: 0
使用fdisk �Cl查看分区
对裸设备进行重新绑定
[root@localhost ~]# raw /dev/raw/raw1 /dev/sdb5
/dev/raw/raw1:bound to major 8, minor 21
[root@localhost ~]# raw /dev/raw/raw2 /dev/sdb6
/dev/raw/raw2:bound to major 8, minor 22
[root@localhost ~]# raw /dev/raw/raw3 /dev/sdb7
/dev/raw/raw3:bound to major 8, minor 23
[root@localhost ~]# cd /dev/raw
[root@localhost raw]# ls -l
总计 0
crw------- 1 root root 162, 1 12-05 16:19 raw1
crw------- 1 root root 162, 2 12-05 16:19 raw2
crw------- 1 root root 162, 3 12-05 16:19 raw3
[root@localhost raw]# chown oracle:oinstall raw*
[root@localhost raw]# ls -l
总计 0
crw------- 1 oracle oinstall 162, 1 12-05 16:19 raw1
crw------- 1 oracle oinstall 162, 2 12-05 16:19 raw2
crw------- 1 oracle oinstall 162, 3 12-05 16:19 raw3
[root@localhost raw]#
出现文件丢失也可以这样删除;
SQL> conn /as sysdba
Connected.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/dev/raw/raw1'
SQL> alter database datafile 6 offline drop;
(alter database datafile 6 online ;) #使其上线
Database altered.
alter database open;#打开数据库