ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 探索ORACLE之ASM04_维护

探索ORACLE之ASM04_维护

原创 Linux操作系统 作者:wuweilong 时间:2012-04-18 13:49:06 0 删除 编辑

探索ORACLEASM04_维护

作者:吴伟龙

 

一、   ASM实例相关操作:

ASM实例的管理,启动,关闭

ASM实例的启动和数据库实例的启动有严格的先后关系,ASM启动一定早于数据库实例,关闭一定晚于ASM实例,因为它是数据库数据文件存储位置。如果ASM没有起来,起数据库将会报ORA-17503ORA-15077的错误,错误信息如下:

 

SQL> startup

ORA-01078: failure in processing system parameters

ORA-01565: error in identifying file '+ASMGROUP1/WWL/spfileWWL.ora'

ORA-17503: ksfdopn:2 Failed to open file +ASMGROUP1/WWL/spfileWWL.ora

ORA-15077: could not locate ASM instance serving a required diskgroup

SQL>

 

1.1   ASM启动的方法:

 

SQL> startup

ASM instance started

 

Total System Global Area   83886080 bytes

Fixed Size                  1217836 bytes

Variable Size              57502420 bytes

ASM Cache                  25165824 bytes

ASM diskgroups mounted

SQL> select instance_name,status from v$instance;

 

INSTANCE_NAME    STATUS

---------------- ------------

+ASM             STARTED

 

SQL>

 

1.2   ASM关闭的方法  (必须先关闭数据库)

没有关闭RDBMS实例关闭ASM将报错ORA-15097,提示已连接RDBMS实例,无法关闭ASM实例

$ export ORACLE_SID=+ASM

$ sqlplus / as sysdba

SQL> shutdown immediate

ORA-15097: cannot SHUTDOWN ASM instance with connected RDBMS instance

关闭RDBMS实例状态ASM是可以正常关闭的。

$ export ORACLE_SID=WWL    ---先关闭在ASM上运行的RDBMS实例

$ sqlplus / as sysdba

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

$ export ORACLE_SID=+ASM   ---再关闭ASM实例

$ sqlplus / as sysdba

SQL> shutdown immediate

ASM diskgroups dismounted

ASM instance shutdown

SQL>

 

二、   ASM三种磁盘组及磁盘的添加和维护

1、 ASM磁盘的添加及删除

1.1    添加这个步骤所需的磁盘(/dev/sdd -- /dev/sdm  1010G的盘)

1.2    通过root用户查看下当前有几个ASM磁盘,磁盘状态,实例状态

# oracleasm listdisks

VOL1

VOL2

# oracleasm querydisk VOL1

Disk "VOL1" is a valid ASM disk

# oracleasm querydisk VOL2

Disk "VOL2" is a valid ASM disk

# ls -l /dev/oracleasm/disks/*

brw-rw---- 1 oracle dba 8, 17 Apr 12 05:30 /dev/oracleasm/disks/VOL1

brw-rw---- 1 oracle dba 8, 33 Apr 12 05:30 /dev/oracleasm/disks/VOL2

# oracleasm status

Checking if ASM is loaded: yes

Checking if /dev/oracleasm is mounted: yes

     我们已知数据库当有两块通过ASMLiB已经标记了的磁盘,并且状态是正常的

 

1.3    开始通过ASMLib来标记新的磁盘,用于后面的实验:

l  报错了,很经典,是由于没有创建分区导致:

# /etc/init.d/oracleasm createdisk VOL3 /dev/sdd

Marking disk "VOL3" as an ASM disk: [FAILED]

l  先创建分区方法: fdisk /dev/sdd /n/p/1/回车/回车/w,将所有磁盘都创建分区。

# /etc/init.d/oracleasm createdisk VOL3 /dev/sdd1

Marking disk "VOL3" as an ASM disk: [  OK  ]   ---可以看到,能正常创建

            # sh oracleasm   通过执行脚本命令,新建10个磁盘已全部完成标记

Marking disk "VOL4" as an ASM disk: [  OK  ]

Marking disk "VOL5" as an ASM disk: [  OK  ]

Marking disk "VOL6" as an ASM disk: [  OK  ]

Marking disk "VOL7" as an ASM disk: [  OK  ]

Marking disk "VOL8" as an ASM disk: [  OK  ]

Marking disk "VOL9" as an ASM disk: [  OK  ]

Marking disk "VOL10" as an ASM disk: [  OK  ]

Marking disk "VOL11" as an ASM disk: [  OK  ]

Marking disk "VOL12" as an ASM disk: [  OK  ]

 

1.4    ASMGROUP1磁盘组添加删除磁盘

l  查看磁盘组的状态

SQL> select GROUP_NUMBER,NAME,STATE,TYPE from v$asm_diskgroup;

 

GROUP_NUMBER   NAME       STATE       TYPE

------------------------  -----------------  --------------    --------

1  ASMGROUP1  CONNECTED   NORMAL

            SQL> SELECT a.name GRPNAME,b.group_number GR_NUMBER,b.disk_number DK_NUMBER,b.name ASMFILE,b.path,b.mount_status,b.state FROM v$asm_diskgroup a,v$asm_disk b;

 

GRPNAME     GR_NUMBER  DK_NUMBER ASMFILE                        PATH                      MOUNT_S STATE

---------- ---------- ---------- ------------------------------ ------------------------- ------- --------

ASMGROUP1  1    0 ASMGROUP1_0000    /dev/oracleasm/disks/VOL1 OPENED  NORMAL

ASMGROUP1  1   1ASMGROUP1_0001     /dev/oracleasm/disks/VOL2 OPENED  NORMAL

 

l  查看磁盘组ASMGROUP1中的成员

SQL> select group_number,disk_number, failgroup,name,path from v$asm_disk where FAILGROUP like 'ASMGROUP1%';

 

GROUP_NUMBER DISK_NUMBER FAILGROUP                      NAME                           PATH

------------ ----------- ------------------------------ ------------------------------ ----------------------------------------

           2           1 ASMGROUP1_0001                 ASMGROUP1_0001                 /dev/oracleasm/disks/VOL2

           2           0 ASMGROUP1_0000                 ASMGROUP1_0000                 /dev/oracleasm/disks/VOL1

 

SQL>

l  添加为ASMGROUP1添加磁盘

SQL> alter diskgroup ASMGROUP1 add disk '/dev/oracleasm/disks/VOL10';

 

Diskgroup altered.

l  我们可以看到已经添加成功了

SQL>  select group_number,disk_number, failgroup,name,path from v$asm_disk where FAILGROUP like 'ASMGROUP1%';

 

GROUP_NUMBER DISK_NUMBER FAILGROUP                      NAME                           PATH

------------ ----------- ------------------------------ ------------------------------ ----------------------------------------

           2           2 ASMGROUP1_0002                 ASMGROUP1_0002                 /dev/oracleasm/disks/VOL10

           2           1 ASMGROUP1_0001                 ASMGROUP1_0001                 /dev/oracleasm/disks/VOL2

           2           0 ASMGROUP1_0000                 ASMGROUP1_0000                 /dev/oracleasm/disks/VOL1

 

2、 ASM三种磁盘组的创建及删除(High  Normal  Extermal

2.1   创建High级别的ASM磁盘组,最少需要三块磁盘来创建。

SQL> create diskgroup asmhigh high redundancy disk '/dev/oracleasm/disks/VOL3','/dev/oracleasm/disks/VOL4','/dev/oracleasm/disks/VOL5';

 

Diskgroup created.

 

2.2   创建Normal级别的ASM磁盘,最少需要两个磁盘来创建。

SQL> create diskgroup asmnormal normal redundancy disk '/dev/oracleasm/disks/VOL6','/dev/oracleasm/disks/VOL7';

 

Diskgroup created.

 

 

2.3   创建Extermal级别的ASM磁盘,最少需要一个磁盘来创建。

SQL> create diskgroup asmexternal external redundancy disk '/dev/oracleasm/disks/VOL8';

 

Diskgroup created.

                                                                       

2.4   查看刚才创建的磁盘状态

SQL> select name,state,type from v$asm_diskgroup;

 

NAME            STATE       TYPE

--------------- ----------- ------

ASMGROUP1       MOUNTED    NORMAL

ASMHIGH         MOUNTED     HIGH

ASMNORMAL      MOUNTED     NORMAL

ASMEXTERNAL     MOUNTED     EXTERN

2.5          ASM磁盘组添加成员,在这里我们就以Normal磁盘组来进行成员添加的例子:

SQL> alter diskgroup ASMNORMAL add disk '/dev/oracleasm/disks/VOL9';

 

Diskgroup altered.

 

SQL> select group_number,disk_number, failgroup,name,path from v$asm_disk where FAILGROUP like 'ASMNORMAL%';

 

GROUP_NUMBER DISK_NUMBER FAILGROUP                      NAME                           PATH

------------ ----------- ------------------------------ ------------------------------ ----------------------------------------

           4           2 ASMNORMAL_0002                 ASMNORMAL_0002                 /dev/oracleasm/disks/VOL9

           4           1 ASMNORMAL_0001                 ASMNORMAL_0001                 /dev/oracleasm/disks/VOL7

           4           0 ASMNORMAL_0000                 ASMNORMAL_0000                 /dev/oracleasm/disks/VOL6

 

SQL>

2.6          删除磁盘组成员,在这里我们同样以NORMAL磁盘组来进行成员删除的例子:

SQL> alter diskgroup ASMNORMAL drop disk ASMNORMAL_0002;

 

Diskgroup altered.

 

SQL> select group_number,disk_number, failgroup,name,path from v$asm_disk where FAILGROUP like 'ASMNORMAL%';

 

GROUP_NUMBER DISK_NUMBER FAILGROUP                      NAME                           PATH

------------ ----------- ------------------------------ ------------------------------ ----------------------------------------

           4           1 ASMNORMAL_0001                 ASMNORMAL_0001                 /dev/oracleasm/disks/VOL7

           4           0 ASMNORMAL_0000                 ASMNORMAL_0000                 /dev/oracleasm/disks/VOL6

 

SQL>

 

 

三、   模拟磁盘故障

3.1      AMSGROUP1(NORMAL类型)磁盘组中写数据

SQL> select tablespace_name,file_name,bytes/1024/1024 M from dba_data_files;

 

TABLESPACE_NAME FILE_NAME                                              M

--------------- --------------------------------------------- ----------

USERS           +ASMGROUP1/wwl/datafile/users.259.780215953            5

SYSAUX          +ASMGROUP1/wwl/datafile/sysaux.257.780215951         230

UNDOTBS1        +ASMGROUP1/wwl/datafile/undotbs1.258.78021595         25

                3

 

SYSTEM          +ASMGROUP1/wwl/datafile/system.256.780215951         480

ASM             +ASMGROUP1/wwl/datafile/asm.270.780300769            100

ASM             +ASMGROUP1/wwl/datafile/asm.271.780300809            100

 

6 rows selected.

如上我们可以看到,我们所有的表空间均是放在ASMGROUP1中的,一会儿我们将对表空间写如数据,并删除一磁盘。

 

3.2      我们查看下该表空间的默认用户

SQL> select username,default_tablespace from dba_users where DEFAULT_TABLESPACE='ASM';

 

USERNAME                       DEFAULT_TABLESPACE

------------------------------ ------------------------------

WWL                            ASM

3.3      ASM表空间写入数据。

通过WWL用户登录到系统创建一张表,用来测试.

SQL> conn wwl/wwl

Connected.

SQL> create table wwl (id varchar(5),name varchar(10));

 

Table created.

 

SQL>  begin

  2  for i in 1..1000 loop

  3  insert into wwl values (15,'wwl15');

  4  end loop;

  5  end;

  6  /

 

PL/SQL procedure successfully completed.

我们创建了一张wwl的表,并且插入了1000行数据

SQL> select count(*) from wwl;

 

  COUNT(*)

----------

      1000

3.4      模拟磁盘突然损坏

[root@wwl ~]# oracleasm deletedisk VOL2;

Clearing disk header: done

Dropping disk: done

[root@wwl ~]#

仔细看下面,我们通过如上的命令删除了VOL2后,现在只认到一个磁盘了。

SQL> select group_number,disk_number, failgroup,name,path from v$asm_disk where FAILGROUP like 'ASMGROUP%';

 

GROUP_NUMBER DISK_NUMBER FAILGROUP                      NAME                           PATH

------------ ----------- ------------------------------ ------------------------------ ----------------------------------------

           2           0 ASMGROUP1_0000                 ASMGROUP1_0000                 /dev/oracleasm/disks/VOL1

 

SQL>

但是我们的实例和我们刚才创建的表数据都没有丢失,这就是冗余的好处,NORMAL模式它是用牺牲一块磁盘的空间来保障数据的安全性的,hight模式是至少牺牲一块硬盘来保障数据的安全性。

SQL> select count(*) from wwl;

 

  COUNT(*)

----------

      1000

3.5       而且业务是不会中断的,但是在日志和硬盘指示灯上会有告警:

ASM日志信息如下:

WARNING: offlining disk 2.3916240783 (ASMGROUP1_0002) with mask 0x1

NOTE: PST update: grp = 2, dsk = 2, mode = 0x6

NOTE: cache closing disk 2 of grp 2: ASMGROUP1_0002

NOTE: PST update: grp = 2

NOTE: erasing header on grp 2 disk ASMGROUP1_0002

 

3.6      这个时候我们需要尽快更换新的硬盘,因为发生这问题之后如果另外一个磁盘再损坏的话那将是不可弥补的数据丢失,更换新硬盘后,数据将会再次进行同步。

3.7       

四、   ASM别名管理

别名就是外号,比如说当系统自动产生的名称太过复杂不怎么好记,DBA可以通过别名,为它创建一个简单化的名称,而又不会对其现有名称造成任何影响。ASM中创建别名是通过alter diskgroupalias子句实现,支持增加/修改/删除等多项操作。V$ASM_ALIAS视图中可以查询到当前实例中创建的别名。

4.1    添加别名

SQL> alter diskgroup ASMGROUP1 add alias '+ASMGROUP1/wwl/datafile/asm01.dbf' for '+ASMGROUP1/wwl/datafile/asm.270.780300769';

 

Diskgroup altered.

4.2    修改别名

SQL> alter diskgroup ASMGROUP1 rename alias '+ASMGROUP1/wwl/datafile/asm01.dbf' for '+ASMGROUP1/wwl/datafile/asm.270.780300769';

 

Diskgroup altered.

4.3    删除别名

SQL> alter diskgroup ASMGROUP1 drop alias '+ASMGROUP1/wwl/datafile/asm01.dbf' for '+ASMGROUP1/wwl/datafile/asm.270.780300769';

 

Diskgroup altered.

   无论是添加、删除或是修改别名,对原文件路径均不会有影响。

 

五、   目录及目录文件管理

5.1   创建目录

SQL> alter diskgroup ASMGROUP1 add directory '+ASMGROUP1/WWL1';

 

Diskgroup altered.

5.2   修改目录

SQL> alter diskgroup ASMGROUP1 rename directory '+ASMGROUP1/WWL1' to '+ASMGROUP1/WWL2';

 

Diskgroup altered.

5.3   删除目录

SQL> alter diskgroup ASMGROUP1 drop directory '+ASMGROUP1/WWL2';

 

Diskgroup altered.

 

六、   手动平衡磁盘组

一般情况下ASM都会自动对其下的磁盘组进行平衡,不过ORACLE也提供了手动平衡磁盘组的方式,通过alter diskgroup ... power 语句。前面提到过磁盘组的平衡度有011多个级别,默认是按照ASM_POWER_LIMIT初始化参数中设置的值,手动平衡的话,设置的平衡度可以与初始化参数中并不相同,例如,设置磁盘组平衡度为5,语句如下:

     SQL> alter diskgroup asmgroup1 rebalance power 5;

Diskgroup altered.

 

七、   通过ASMCMD工具管理ASM

[oracle@wwl ~]$ which asmcmd

/oracle/orahome/10.2.0/db_1/bin/asmcmd

[oracle@wwl ~]$ cd /oracle/orahome/10.2.0/db_1/bin/

ASMCMD> ls 

ASMEXTERNAL/

ASMGROUP1/

ASMHIGH/

ASMNORMAL/

ASMCMD>

ASMCMD> help

        asmcmd [-p] [command]

 

        The environment variables ORACLE_HOME and ORACLE_SID determine the

        instance to which the program connects, and ASMCMD establishes a

        bequeath connection to it, in the same manner as a SQLPLUS / AS

        SYSDBA.  The user must be a member of the SYSDBA group.

 

        Specifying the -p option allows the current directory to be displayed

        in the command prompt, like so:

 

        ASMCMD [+DATAFILE/ORCL/CONTROLFILE] >

 

        [command] specifies one of the following commands, along with its

        parameters.

 

        Type "help [command]" to get help on a specific ASMCMD command.

 

        commands:

        --------

cd------------------------------------------进入下级目录或进入所需要的目录

du------------------------------------------显示指定的ASM目录下ASM文件占用的所有磁盘空间

find-----------------------------------------查找所需的文件

help-----------------------------------------显示帮助信息

ls---------------------------------------------列出ASM目录下的内容及其属性

lsct-------------------------------------------列出当前ASM客户端的信息

lsdg-------------------------------------------列出所有磁盘组及其属性

mkalias--------------------------------------为系统生成的文件名创建别名

mkdir----------------------------------------创建新目录

pwd------------------------------------------显示当前目录路径

rm--------------------------------------------删除ASM目录下的某个文件或文件夹

rmalias--------------------------------------删除别名

ASMCMD>

要查看某个命令的相信通过在命令前添加help来查看,如下:

ASMCMD> help cd

        cd

 

        Change the current directory to

.

ASMCMD> help du

        du [-H] [dir]

 

        Display total space used for files located recursively under [dir],

        similar to "du -s" under UNIX; default is the current directory.  Two

        values are returned, both in units of megabytes.  The first value does

        not take into account mirroring of the diskgroup while the second does.

        For instance, if a file occupies 100 MB of space, then it actually

        takes up 200 MB of space on a normal redundancy diskgroup and 300 MB

        of space on a high redundancy diskgroup. 

 

        [dir] can also contain wildcards.

 

        The -H flag suppresses the column headers from the output.

ASMCMD> help find

        find [-t ]

 

        Find the absolute paths of all occurrences of under

.

        can be a directory and may include wildcards. 

may also

        include wildcards.  Note that directory names in the results have the

        "/" suffix to clarify their identity.

 

        The -t option allows searching by file type.  For instance, one can

        search for all the control files at once.  must be one of the

        valid values in V$ASM_FILE.TYPE.

ASMCMD>

 

八、   oracleasm工具的使用和语法介绍

[root@wwl ~]# oracleasm --help

Usage: oracleasm [--exec-path=] [ ]

       oracleasm --exec-path

       oracleasm -h

       oracleasm -V

 

The basic oracleasm commands are:

    configure        Configure the Oracle Linux ASMLib driver

    init             Load and initialize the ASMLib driver

    exit             Stop the ASMLib driver

    scandisks        Scan the system for Oracle ASMLib disks

    status           Display the status of the Oracle ASMLib driver

    listdisks        List known Oracle ASMLib disks

    querydisk        Determine if a disk belongs to Oracle ASMlib

    createdisk       Allocate a device for Oracle ASMLib use

    deletedisk       Return a device to the operating system

    renamedisk       Change the label of an Oracle ASMlib disk

    update-driver    Download the latest ASMLib driver

[root@wwl ~]#

 

 

九、   ASM相关视图(V$)和数据字典(X$

ASM由于其高度的封装性,使得我们很难知道窥探其内部的原理。可以通过一下视图和数据字典来来查看ASM 的信息。

相关视图和数据字典

View Name

X$ Table name

Description

V$ASM_DISKGROUP

X$KFGRP

performs disk discovery and lists diskgroups

V$ASM_DISKGROUP_STAT

X$KFGRP_STAT

diskgroup stats without disk discovery

V$ASM_DISK

X$KFDSK, X$KFKID

performs disk discovery, lists disks and their usage metrics

V$ASM_DISK_STAT

X$KFDSK_STAT, X$KFKID

lists disks and their usage metrics

V$ASM_FILE

X$KFFIL

lists ASM files, including metadata/asmdisk files

V$ASM_ALIAS

X$KFALS

lists ASM aliases, files and directories

V$ASM_TEMPLATE

X$KFTMTA

lists the available templates and their properties

V$ASM_CLIENT

X$KFNCL

lists DB instances connected to ASM

V$ASM_OPERATION

X$KFGMG

lists rebalancing operations

N.A.

X$KFKLIB

available libraries, includes asmlib path

N.A.

X$KFDPARTNER

lists disk-to-partner relationships

N.A.

X$KFFXP

extent map table for all ASM files

N.A.

X$KFDAT

extent list for all ASM disks

N.A.

X$KFBH

describes the ASM cache (buffer cache of ASM in blocks of 4K (_asm_blksize)

N.A.

X$KFCCE

a linked list of ASM blocks. to be further investigated

This list is obtained querying v$fixed_view_definitionwhere view_name like '%ASM%' which exposes all the v$ and gv$ views with theirdefinition. Fixed tables are exposed by querying v$fixed_table where name like'x$kf%' (ASM fixed tables use the 'X$KF' prefix).

SQL>select * fromv$fixed_view_definition whereview_name like '%ASM%';

SQL>select * from sys.v$fixed_tablewhere name like 'X$KF%' ;

 

十、   ASM常见的错误处理

错误一、

ORA-15097cannot SHUTDOWN ASM instance with connected RDBMS instance

解决办法:

发生这个问题,唯一的一个原因就是Oracle实例没有关闭,或ORACLE实例正在关闭或处于挂起状态,导致ASM实例无法关闭,解决办法,关闭RDBMS实例后再关闭ASM实例。

错误二、

[root@wwl ~]# /etc/init.d/oracleasm createdisk VOL3 /dev/sdd

Marking disk "VOL3" as an ASM disk: [FAILED]

   报这个错的原因在于磁盘为分区导致。在创建ASM的之前必须线将磁盘分区,但不能格式化,后执行创建就不会有问题了。

 

十一、        ASM 扩展性

  • 最多支持63个磁盘组;
  • 最多支持10000个磁盘;
  • 最大支持4pb/磁盘;
  • 最大支持40 exabyte/ASM存储;
  • 最大支持1W个文件/磁盘组;
  • 外部冗余时单个文件最大35tb,标准冗余时单个文件最大5.8tb,高冗余度时单个文件最大3.9tb

 

十二、        ASM其它信息请参考如下连接:

http://docs.oracle.com/cd/E11882_01/server.112/e16102/asmfiles.htm

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20674423/viewspace-721524/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2010-01-08

  • 博文量
    249
  • 访问量
    1959043