Sunday, November 17, 2013

ASMCMD Command in 11gr2

Saving your ASM Spfile.


Check spfile location.

[root@rac1 bin]# su - grid
[grid@rac1 ~]$ echo $ORACLE_SID
+ASM1
[grid@rac1 ~]$ sqlplus / as sysasm

SQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 22 00:46:33 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Real Application Clusters and Automatic Storage Management options

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      +CRS/rac-cluster/asmparameterf
                                                 ile/registry.253.792630659

spfile location can also be found using.

ASMCMD> spget
+CRS/rac-cluster/asmparameterfile/registry.253.792630659


Take backup of spfile using asmcmd to another diskgroup.

SQL> exit

[grid@rac1 ~]$ asmcmd
ASMCMD> spbackup +CRS/rac-cluster/asmparameterfile/registry.253.792630659    +FRA/spfileBackASM.bak


Check the backup

ASMCMD> cd +FRA
ASMCMD> ls
ASM/
DELL/
ORCL/
spfileBackASM.bak


Copy the file to operating system if you want to.

ASMCMD> cp spfileBackASM.bak /tmp/spfileBackASM.bak
copying +FRA/spfileBackASM.bak -> /tmp/spfileBackASM.bak



You can also directly copy the ASM spfile to other diskgroups or operating system.

ASMCMD> spcopy +CRS/rac-cluster/asmparameterfile/registry.253.792630659 /tmp/spfilecopyASM.ora




OTHER ASMCMD COMMANDS.

To list the clients that are connected through V$ASM_CLIENT view.

ASMCMD> lsct -g
Instance_ID  DB_Name  Status     Software_Version  Compatible_version  Instance_Name  Disk_Group
          1  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM1          CRS       
          1  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM1          DATA      
          1  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM1          FRA       
          2  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM2          CRS       
          2  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM2          DATA      
          1  dell     CONNECTED        11.2.0.1.0          11.2.0.0.0  dell1          DATA      
          1  dell     CONNECTED        11.2.0.1.0          11.2.0.0.0  dell1          FRA       
          2  dell     CONNECTED        11.2.0.1.0          11.2.0.0.0  dell2          DATA      
          2  dell     CONNECTED        11.2.0.1.0          11.2.0.0.0  dell2          FRA   


To check only a particular disk group.

ASMCMD> lsct -g CRS
Instance_ID  DB_Name  Status     Software_Version  Compatible_version  Instance_Name  Disk_Group
          1  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM1          CRS       
          2  +ASM     CONNECTED        11.2.0.1.0          11.2.0.1.0  +ASM2          CRS  


To list current ASM operations going on from V$ASM_OPERATION view.


ASMCMD> lsop
Group_Name  Dsk_Num  State  Power
FRA     REBAL    WAIT   5


To list users from ASM password file.


ASMCMD> lspwusr
Username sysdba sysoper sysasm 
     SYS   TRUE    TRUE   TRUE 
 ASMSNMP   TRUE   FALSE  FALSE 

To list disk group information through v$asm_diskgroup.


ASMCMD> lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  NORMAL  N         512   4096  1048576      6141     5215              309            2453              0             N  CRS/
MOUNTED  NORMAL  N         512   4096  1048576     24568    17614                0            8807              0             N  DATA/
MOUNTED  NORMAL  N         512   4096  1048576     24568    20348                0           10174              0             N  FRA/



To list disk information through v$asm_disk. 


ASMCMD> lsdsk
Path
ORCL:VOL1
ORCL:VOL2
ORCL:VOL3
ORCL:VOL4
ORCL:VOL5
ORCL:VOL6
ORCL:VOL7


To Mount and Unmount Disk Groups.

ASMCMD> umount FRA
ASMCMD> lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  NORMAL  N         512   4096  1048576      6141     5215              309            2453              0             N  CRS/
MOUNTED  NORMAL  N         512   4096  1048576     24568    17614                0            8807              0             N  DATA/
ASMCMD> mount FRA
ASMCMD> lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  NORMAL  N         512   4096  1048576      6141     5215              309            2453              0             N  CRS/
MOUNTED  NORMAL  N         512   4096  1048576     24568    17614                0            8807              0             N  DATA/
MOUNTED  NORMAL  N         512   4096  1048576     24568    20344                0           10172              0             N  FRA/


 
To obtain I/O related information related to ASM Diskgroups every 2 secomds.

ASMCMD> iostat -et 2
Group_Name  Dsk_Name  Reads     Writes    Read_Err  Write_Err  Read_Time  Write_Time  
CRS         VOL1      98304     14336     0         0          .187       .055        
CRS         VOL2      61440     4096      0         0          .163       .013        
CRS         VOL7      124928    14336     0         0          .342       .023        
DATA        VOL3      43622400  11500544  0         0          40.484     5.051       
DATA        VOL4      82289152  11500544  0         0          64.281     5.521       
FRA         VOL5      57344     4096      0         0          .133       .009        
FRA         VOL6      61440     4096      0         0          .164       .015        

Only for a particular Disk group.

ASMCMD> iostat -et -G DATA 2
Group_Name  Dsk_Name  Reads     Writes    Read_Err  Write_Err  Read_Time  Write_Time  
DATA        VOL3      43622400  11500544  0         0          40.484     5.051       
DATA        VOL4      82289152  11500544  0         0          64.281     5.521       





chdg
 - Changes existing disk group (add disks, drop disks, or rebalance) 
based on XML configuration file. You can use ALTER DISKGROUP... commands
 for same too, but here we are learning ASMCMD commands extensions in 
11gr2. The chdg command add disks, delete disks or set rebalance power 
level on an existing disk group. 



          Syntax : chdg {config_file.xml | 'contents_of_xml_file'}



XML configuration template



<chdg> update disk clause (add/delete disks/failure groups)

      name disk group to change

      power power to perform rebalance



<add> items to add are placed here

</add>

<drop> items to drop are placed here

</drop>

<fg> failure group

name failure group name

</fg>

<dsk> diskname disk name

path disk path

size size of the disk to add

</dsk>

</chdg>

 

Example:

We will add disk /dev/disk/disk61 to existing disk group DISK and set rebalance power level to 4.

find existing disk in a disk group DATA



SQL> select name,path from v$asm_disk where group_number=1;

NAME          PATH

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

DATA_0000 /dev/rdisk/disk50

DATA_0001 /dev/rdisk/disk51

DATA_0002 /dev/rdisk/disk60



Create following XML configuration file and save it as adddsk.xml



<chdg name="data" power="4">

<add>

<dsk string="/dev/rdisk/disk61"/>

</add>

</chdg>



and execute following



$asmcmd

ASMCMD>chdg adddsk.xml

ASMCMD>



Now check again to see disks in DATA disk group



SQL> select name,path from v$asm_disk where group_number=1;

NAME          PATH

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

DATA_0000 /dev/rdisk/disk50

DATA_0001 /dev/rdisk/disk51

DATA_0002 /dev/rdisk/disk60

DATA_0003 /dev/rdisk/disk61 <--- New disk added



Lets drop this disk with chdg command. You can use ALTER DISKGROUP DATA DROP DISK command too.



Create a XML file



<chdg name="data" power="4">

<drop>

<dsk name="DATA_0003"/>

</drop>

</chdg>



and save it as dropdsk.xml and execute following.



$asmcmd

ASMCMD>chdg adddsk.xml

ASMCMD>



Now check again to see disks in DATA disk group



SQL> select name,path from v$asm_disk where group_number=1;

NAME          PATH

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

DATA_0000 /dev/rdisk/disk50

DATA_0001 /dev/rdisk/disk51

DATA_0002 /dev/rdisk/disk60

 

DATA_003 disk name no longer exits!!!

 

chkdg - Checks or repairs a disk group.



The 11gR2 ASM CHECK command checks for

  • The disks consistency
  • The alias directory is linked correctly
  • All metadata directories and internal consistency of ASM disk group metadata.
It writes findings in alert logs and display them on database control page too.In 11gR2 the default is norepair        Syntax : chkdg [--repair] <<diskgroupname>> 

Example:
 

ASMCMD> chkdg data
 
ASMCMD> 


The following are the contents from ASM alert log file 

...
 
...
 
SQL> /* ASMCMD */ALTER DISKGROUP data CHECK NOREPAIR
 
NOTE: starting check of diskgroup DATA
 
kfdp_checkDsk(): 6
 
kfdp_checkDsk(): 7
 
kfdp_checkDsk(): 8
 
SUCCESS: check of diskgroup DATA found no errors
 
SUCCESS: /* ASMCMD */ALTER DISKGROUP data CHECK NOREPAIR
 
...
 
...
 
 
 
mkdg 
-Creates a disk group based on XML configuration file
 
 
     Syntax : mkdg {config_file.xml | 'contents_of_xml_file'}


XML configuration template
 

<dg> disk group name disk group name
 
  redundancy normal, external, high

<fg> failure group name failure group name
 
</fg>
 
<dsk> disk name disk name
 
path disk path
 
size size of the disk to add
 
</dsk>
 
<a> attribute
 
name attribute name
 
value attribute value
 
</a>
 
</dg>
 

 
 
Example:
 Create new disk group DATA2

First, create a XML configuration file with external redundancy and save it as mkdg.xml 

 
 
<dg name="data2" redundancy="external">
 
<dsk string="/dev/rdisk/disk61"/>
 
<a name="compatible.rdbms" value="10.2"/>
 
</dg>
 

$ls -l mkdg.xml
 
-rw-r--r-- 1 oracle oinstall 86 Nov 20 10:59 mkdg.xml
 

$asmcmd
 
ASMCMD>mkdg mkdg.xml
 
ASMCMD>
 
ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/
 
 
 
lsdsk
 - Lists Oracle ASM Disks. It runs in connected mode first and pulls information from v$ASM_DISK_STAT and v$ASM_DISK dynamic views otherwise it runs in disconnected mode and pulls information from disk header. The -I option forces non-connected mode.

Syntax :  lsdsk {-kptgMHI}{-G diskgroup } { --member|--candidate}
 
   {--discovery}{--statistics}{pattern}

-k:Displays the TOTAL_MB, FREE_MB, OS_MB,NAME, FAILGROUP, LIBRARY, LABEL, UDID, PRODUCT, REDUNDANCY, and PATH columns of the V$ASM_DISK view.
 

--statistics: Displays the READS, WRITES, READ_ERRS, WRITE_ERRS, READ_TIME, WRITE_TIME, BYTES_READ, BYTES_WRITTEN, and the PATH columns of the V$ASM_DISK view.
 

-p:Displays the GROUP_NUMBER, DISK_NUMBER, INCARNATION, MOUNT_STATUS, HEADER_STATUS, MODE_STATUS, STATE, and the PATH columns of the V$ASM_DISK view.
 

-t:Displays the CREATE_DATE, MOUNT_DATE, REPAIR_TIMER, and the PATH columns of the V$ASM_DISK view.
 

-g:Selects from GV$ASM_DISK_STAT, or from GV$ASM_DISK if the --discovery flag is also specified. GV$ASM_DISK.INST_ID is included in the output.
 

--discovery:Selects from V$ASM_DISK, or from GV$ASM_DISK if the -g flag is also specified. This option is always enabled if the Oracle ASM instance is version 10.1 or earlier. This flag is disregarded if lsdsk is running in non-connected mode.
 

-H:Suppresses column headings.
 

-I:Scans disk headers for information rather than extracting the information from an Oracle ASM instance. This option forces non-connected mode.
 

-G:Restricts results to only those disks that belong to the group specified by diskgroup.
 

-M:Displays the disks that are visible to some but not all active instances. These are disks that, if included in a disk group, cause the mount of that disk group to fail on the instances where the disks are not visible.
 

--candidate: Restricts results to only disks having membership status equal to CANDIDATE.
 

--member:Restricts results to only disks having membership status equal to MEMBER.
 

pattern: Returns only information about the specified disks that match the supplied pattern.
 

Example 1:
 

$ asmcmd
 
ASMCMD> lsdsk
 
Path
 
/dev/rdisk/disk50
 
/dev/rdisk/disk51
 
/dev/rdisk/disk60
 
/dev/rdisk/disk61
 

Example 2:
 
The following command display disk attached to disk group DATA2 and their space information.
 

ASMCMD> lsdsk -k -G DATA2
 
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
 
76800 76750 76800 DATA2_0000 DATA2_0000 System UNKNOWN /dev/rdisk/disk61
 

Example 3:
 
The following shows io statistics for disks in DATA2 disk group
 

ASMCMD> lsdsk -t -G DATA2 --statistics
 
Reads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read Bytes_Written Voting_File Create_Date Mount_Date Repair_Timer Path
 
18 447 0 0 .026287 3.841985 77824 1830912 N 20-NOV-10 20-NOV-10 0 /dev/rdisk/disk61
 

Example 4:
 
The following displays disks attached to DATA2 and DATA disk groups
 

ASMCMD> lsdsk -G DATA2
 
Path
 
/dev/rdisk/disk61
 
ASMCMD> lsdsk -G DATA
 
Path
 
/dev/rdisk/disk50
 
/dev/rdisk/disk51
 
/dev/rdisk/disk60
 
ASMCMD> 

 
 
dropdg 
-Drops a disk group. DROP diskgroup command marks the headers of disks belonging to a diskgroup that cannot be mounted by ASM as FORMER. If diskgroup is being used by any other nodes or ASM instance then this dropdg command fails.

The -r (INCLUDING CONTENTS) option of dropdg will drop the diskgroup and files if diskgroup is empty . The -f(Force) with INCLUDING CONTENTS should be used with caution as this will not check if diskgroup is being used by any other ASM instance and it will clear all disks in that diskgroup.
 
   Syntax:  dropdg { -r -f } { -r } <<diskgroup>>
 
 

Example:
 

ASMCMD> dropdg data2
 
ORA-15039: diskgroup not dropped
 
ORA-15053: diskgroup "DATA2" contains existing files (DBD ERROR: OCIStmtExecute)
 
ASMCMD>dropdg -r data2
 
ASMCMD>
 
 
 
iostat -
 Displays I/O statistics for disks.

lsdg -
 Displays disk groups and their information.The lsdg command queries V$ASM_DISKGROUP_STAT by default. If the --discovery flag is specified, the V$ASM_DISKGROUP is queried instead.

Example:
 

ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/
 


umount
 -Dismounts a disk group        Syntax:  umount { -a | [-f] diskgroup }

-a Dismounts all mounted disk groups.
 


-f Forces the dismount operation.
 


Example:
 The following example first checks the disk group with lsdg command and then unmount the data2 diskgroup. You will see data2 is unmounted if you run lsdg command again.

ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/
 
ASMCMD> umount data2
 
ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
ASMCMD> 

 
 
mount 
: Mounts a disk group.You can mount ASM diskgroup in restrict mode for mainitance/rebalnace operations and during this mode client cannot access files in that diskgroup. If you are running RAC then MOUNT RESTRICT will mount diskgroup exclusively on that instance and clients cannot access files in that diskgroup until it mounted back in normal mode.

Why in restricted mode?
 
It improve the rebalance operation performace as there are no external connections to the disk group.
 

Syntax: mount [--restrict] { [-a] | [-f] diskgroup[ diskgroup ...] }
 

-a Mounts all disk groups.
 

--restrict Mounts in restricted mode.
 

-f Forces the mount operation.
 

Example:
 
In the previous example of unmount command we left DATA2 in unmounted stage. lets mount DATA2 disk group in restrict mode again and then unmount and mount in normal mode.
 

ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
ASMCMD> 


ASMCMD> mount --restrict DATA2 

ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
RESTRICTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/
 
The state in above showing output showing RESTRICTED for DATA2 

ASMCMD> umount data2
 
ASMCMD> mount data2
 
ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/
 
DATA2 is removed from RESTRICTED mode.
 
 
 
offline -
  Offline disks or failure groups that belong to a disk group. You won't be able to take disk offline in a disk group with external redundancy

Syntax: offline -G diskgroup { -F failgroup |-D disk} [-t {minutes | hours}]
 

-G diskgroup Disk group name.
 


-F failgroup Failure group name.
 


-D disk Specifies a single disk name.
 


-t minutes | hours Specifies the time before the specified disk is dropped as nm or nh, where m specifies minutes and h specifies hours. The default unit is hours.
 


Example:
 
Lets add a disk to disk group2 with chdg command.
 

ASMCMD> chdg adddsk.xml
 
ASMCMD> lsdsk -G DATA2
 
Path
 
/dev/rdisk/disk61
 
/dev/rdisk/disk62 <-- New disk added
 
ASMCMD> 

ASMCMD> lsdsk -k -G data2
 
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
 
76800 76774 76800 DATA2_0000 DATA2_0000 System UNKNOWN /dev/rdisk/disk61
 
76800 76774 76800 DATA2_0001 DATA2_0001 System UNKNOWN /dev/rdisk/disk62
 
ASMCMD> offline -G data2 -D data2_0001
 
ORA-15067: command or option incompatible with diskgroup redundancy (DBD ERROR: OCIStmtExecute)
 
ASMCMD>
 
 
 
 
 
online
 - Online all disks, a single disk, or a failure group that belongs to a disk group.
 
 
 Syntax : online { [-a] -G diskgroup | -F failgroup |-D disk} [-w]

-a Online all offline disks in the disk group.
 


-G diskgroup Disk group name.
 


-F failgroup Failure group name.
 


-D disk Disk name.
 


-w Wait option. Causes ASMCMD to wait for the disk group to be rebalanced before returning control to the user. The default is not waiting.
 

 
 
rebal
 - Rebalances a disk group and it's useful if you have added some disks to a diskgroups to load balance I/O.The power level can be set from 0 to 11. A value of 0 disables rebalancing. If the rebalance power is not specified, the value defaults to the setting of the ASM_POWER_LIMIT initialization parameter.
You can determine if a rebalance operation is occurring with the ASMCMD lsop command
 

Syntax: rebal [--power power] [-w] diskgroup
 

--power power Power setting (0 to 11).
 


-w Wait option. Causes ASMCMD to wait for the disk group to be rebalanced before returning control to the user. The default is not waiting.
 

Example:
 
The following example rebalance the data2 disk group power level set to 4 from 0.
 
 
 
ASMCMD> lsop
 
Group_Name Dsk_Num State Power <--- means no rebalance activity is going on
 
ASMCMD> lsdg
 
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
 
MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/
 
MOUNTED EXTERN N 1024 4096 1048576 153600 153548 0 153548 0 N DATA2/
 
ASMCMD> 

ASMCMD> rebal --power 4 data2
 
ASMCMD> lsop
 
Group_Name Dsk_Num State Power 

DATA2 REBAL WAIT 4 <--- rebalance is currently running...
 
ASMCMD> lsop
 
Group_Name Dsk_Num State Power <--- means no rebalance activity completed.
 


The STATE can be one of the followings:
  - Wait : No rebalance is running or wait period is specified by Admins
  - Run   : Rebalance is running.
  - REAP : Rebalance operation stopped.
  - HALT : Halted by Admins.
  - ERRORS : Errors during rebalance operations and halted.
 

md_backup, md_restore:
 Create backup file on a filesystem for asm disk group metadata information you can restore this backup file by md_restore command of ASMCMD.

Syntax: md_backup -b <<backupfilename>> -G <<diskgroup>>
 
 
 
When you restore RMAN backup to a lost diskgroup or to a different server you will get errors something like 


ORA-01119: error in creating database file ...
 
ORA-17502: ksfdcre:4 Failed to create file ...
 
ORA-15001: diskgroup "DATA" does not exist or is not mounted
 

You have two options to restore :
 

1. Use SET newname for datafile <<fileno#>> to <<new diskgroup>> or db_file_name_convert option to restore these files to new disk group.
 

2. Recreate ASM diskgroup manually and other user defined directory structures inside that diskgroup.
 
Let try this with this example.
 

Example:
  For this example I will create different directories paths and one tablespace ts1 with 2 datafiles on DATA2 disk group. We will take a tablespace backup, DATA2 diskgroup metadata backup. We will restore DATA2 and it's directory tree with md_restore and tablespace datafiles from the RMAN backup.


ASMCMD> cd DATA2
 
ASMCMD>mkdir mydir1
 
ASMCMD>mkdir mydir2
 
ASMCMD>ls -l
 
Type Redund Striped Time Sys Name
 
                                            N mydir2/
                                            N mydir1/

ASMCMD> cd mydir1
 
ASMCMD> cd mydir1
 
ASMCMD> ls -l
 
ASMCMD>mkdir ts1_dir
 
ASMCMD>mkdir ts2_dir
 
ASMCMD>ls -l
 
Type Redund Striped Time Sys Name
 
                                            N ts1_dir/
                                            N ts2_dir/

Create a tablespace and create one table inside it.
 
SQL> create tablespace ts1 datafile '+DATA2/test1.dbf' size 1m;
 
Tablespace created.
 

SQL> alter tablespace ts1 add datafile '+DATA2/ts2.dbf' size 2m;
 
Tablespace altered
 

SQL> connect scott/tiger
 

SQL> create table test tablespace ts1
 
as select * from user_objects;
 
Table created
 

SQL> select count(1) from test;
 
COUNT(1)
 
----------
 
7
 

Take the ASM DATA2 diskgroup metadata backup 


ASMCMD> md_backup data2asm_backup -G DATA2
 
Disk group metadata to be backed up: DATA2
 
Current alias directory path: mydir1/ts2_dir
 
Current alias directory path: mydir1
 
Current alias directory path: mydir2
 
Current alias directory path: mydir1/ts1_dir
 
Current alias directory path: TEST
 
Current alias directory path: TEST/DATAFILEST/DATAFILE
 

ASMCMD> exit
 

$ ls -lt
 
-rw-r--r-- 1 oracle oinstall 13418 Nov 20 13:03 data2aasm_backup
 

Take RMAN tablespace ts1 backup with following commands.
 

RMAN> run {
 
2> allocate channel c1 type disk;
 
3> backup tablespace ts1 format "/backup/test/ts1_%s_%t";
 
4> }
 
using target database control file instead of recovery catalog
 
allocated channel: c1
 
channel c1: sid=51 instance=TEST1 devtype=DISK
 
Starting backup at 20-NOV-10
 
channel c1: starting full datafile backupset
 
channel c1: specifying datafile(s) in backupset
 
input datafile fno=00007 name=+DATA2/ts2.dbf
 
input datafile fno=00006 name=+DATA2/ts1.dbf
 
channel c1: starting piece 1 at 20-NOV-10
 
channel c1: finished piece 1 at 20-NOV-10
 
piece handle=/backup/test/ts1_11_735580273 tag=TAG20101120T155112 comment=NONE
 
channel c1: backup set complete, elapsed time: 00:00:01
 
Finished backup at 20-NOV-10
 
released channel: c1
 
RMAN> 

RMAN> 

RMAN> **end-of-file**
 
 
 
 
 
SQL> alter tablespace ts1 offline;
 
Tablespace altered.
 
 
 
Now drop the DATA2 disk group with force option.
 

$asmcmd
 
ASMCMD> dropdg data2
 
ORA-15039: diskgroup not dropped
 
ORA-15053: diskgroup "DATA2" contains existing files (DBD ERROR: OCIStmtExecute)
 
ASMCMD>dropdg -r data2
 
ASMCMD>
 
 
 
SQL>connect scott/tiger
 
 
 
SQL> select * from test;
 
select * from test
 
*
 
ERROR at line 1:
 
ORA-00376: file 6 cannot be read at this time
 
ORA-01110: data file 6: '+DATA2/ts1.dbf'
 

It's time to restore ts1 tablespace files from RMAN backup.
 

RMAN> run {
 
2> allocate channel c1 type disk format '/backup/test/ts1_%s_%t' ;
 
3> restore tablespace ts1 ;
 
4> }
 
using target database control file instead of recovery catalog
 
allocated channel: c1
 
channel c1: sid=169 instance=TEST1 devtype=DISK
 
Starting restore at 20-NOV-10
 
channel c1: starting datafile backupset restore
 
channel c1: specifying datafile(s) to restore from backup set
 
restoring datafile 00006 to +DATA2/ts1.dbf
 
restoring datafile 00007 to +DATA2/ts2.dbf
 
channel c1: reading from backup piece /backup/test/ts1_11_735580273
 
ORA-19870: error reading backup piece /backup/test/ts1_11_735580273
 
ORA-19504: failed to create file "+DATA2/ts2.dbf"
 
ORA-17502: ksfdcre:3 Failed to create file +DATA2/ts2.dbf
 
ORA-15001: diskgroup "DATA2" does not exist or is not mounted <---- No diskgroup exists
 
ORA-15001: diskgroup "DATA2" does not exist or is not mounted <---- No such diskgroup exists 

failover to previous backup
 
creating datafile fno=7 name=+DATA2/ts2.dbf
 
released channel: c1
 
RMAN-00571: ===========================================================
 
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
 
RMAN-00571: ===========================================================
 
RMAN-03002: failure of restore command at 11/20/2010 15:57:13
 
ORA-01119: error in creating database file '+DATA2/ts2.dbf'
 
ORA-17502: ksfdcre:4 Failed to create file +DATA2/ts2.dbf
 
ORA-15001: diskgroup "DATA2" does not exist or is not mounted
 
ORA-15001: diskgroup "DATA2" does not exist or is not mounted
 
 
 
Lets use ASM md_restore command to create DATA2 diskgroup from backup. This will restore all the metadata information and create directory structure.
 
 
 
$ asmcmd
 
ASMCMD> md_restore disk2asm_backup
 
Current Diskgroup metadata being restored: DATA2
 
Diskgroup DATA2 created!
 
System template ONLINELOG modified!
 
System template AUTOBACKUP modified!
 
System template ASMPARAMETERFILE modified!
 
System template OCRFILE modified!
 
System template ASM_STALE modified!
 
System template OCRBACKUP modified!
 
System template PARAMETERFILE modified!
 
System template ASMPARAMETERBAKFILE modified!
 
System template FLASHFILE modified!
 
System template XTRANSPORT modified!
 
System template DATAGUARDCONFIG modified!
 
System template TEMPFILE modified!
 
System template ARCHIVELOG modified!
 
System template CONTROLFILE modified!
 
System template DUMPSET modified!
 
System template BACKUPSET modified!
 
System template FLASHBACK modified!
 
System template DATAFILE modified!
 
System template CHANGETRACKING modified!
 
Directory +DATA2/mydir1 re-created!
 
Directory +DATA2/TEST re-created!
 
Directory +DATA2/mydir2 re-created!
 
Directory +DATA2/mydir1/ts2_dir re-created!
 
Directory +DATA2/mydir1/ts1_dir re-created!
 
Directory +DATA2/TEST/DATAFILE re-created!
 

ASMCMD> 

Restore tablespace ts1 datafiles from RMAN backups
 

RMAN> run {
 
2> allocate channel c1 type disk format '/backup/test/ts1_%s_%t' ;
 
3> restore tablespace ts1 ;
 
4> }
 
using target database control file instead of recovery catalog
 
allocated channel: c1
 
channel c1: sid=167 instance=TEST1 devtype=DISK
 
Starting restore at 20-NOV-10
 
channel c1: starting datafile backupset restore
 
channel c1: specifying datafile(s) to restore from backup set
 
restoring datafile 00006 to +DATA2/ts1.dbf
 
restoring datafile 00007 to +DATA2/ts2.dbf
 
channel c1: reading from backup piece /backup/test/ts1_11_735580273
 
channel c1: restored backup piece 1
 
piece handle=/backup/test/ts1_11_735580273 tag=TAG20101120T155112
 
channel c1: restore complete, elapsed time: 00:00:01
 
Finished restore at 20-NOV-10
 
released channel: c1
 
RMAN> 

RMAN> 


SQL> alter tablespace ts1 online;
 
alter tablespace ts1 online
 
*
 
ERROR at line 1:
 
ORA-01113: file 6 needs media recovery
 
ORA-01110: data file 6: '+DATA2/ts1.dbf'
 
 
 
SQL> recover tablespace ts1;
 
Media recovery complete.
 
SQL> alter tablespace ts1 online;
 
Tablespace altered.
 
SQL> alter tablespace ts1 online;
 
Tablespace altered.
 
SQL> connect scott/tiger
 
Connected.
 
SQL> select count(1) from test;
 
COUNT(1)
 
----------
 
7
 
 
 
cp 
- It's going to make your life so easy when moving database across different servers. It allows you to copy files between ASM diskgroup and OS filesystem. In eairler release you have to use either RMAN command or setup FTP to move files between.

10g Example:
 

In 10gR2 this is how you need to setup FTP with Oracle XMLDB
 

- Connect to Oracle instance as sys and execute 


@ORACLE_HOME/rdbms/admin/catxdbdbca 7777 8080
 
This will enable ftp on port 7777 and http service on port 8080
 
- use ftp to move files between ASM and filesystem
 

FTP> open <<hostname>> 7777
 

331 pass required for SYSTEM
 
Password:
230 SYSTEM logged in
ftp>
Relax! in 11g you can move files just by using cp command
 
11gR2 example
 
 
 
11gR2 Example:
 

$ ls -l
 
-rw-r----- 1 oracle oinstall 212992 Nov 20 15:51 ts1_11_735580273
 

$ asmcmd
 
ASMCMD> cp /backup/test/ts1_11_735580273 +DATA/
 
copying /backup/test/ts1_11_735580273 -> +DATA/ts1_11_735580273
 
ASMCMD> cd +DATA
 
ASMCMD> ls -l
 
Type Redund Striped Time Sys Name
 
Y ASM/
 
Y TEST/
 
N archlogs/
 
Y test-mvip/
 
N ts1_11_735580273 => +DATA/ASM/BACKUPSET/ts1_11_735580273.304.735585509
 
ASMCMD> 

 
 [oracle@Rac1 ~]$ grid_env
[oracle@Rac1 ~]$ asmcmd
ASMCMD> ls -l
State Type Rebal Name
MOUNTED EXTERN N DATA/
ASMCMD> pwd
+
ASMCMD> du
Used_MB Mirror_used_MB
2020 2020
ASMCMD> cd DATA
ASMCMD> du
Used_MB Mirror_used_MB
2030 2030
ASMCMD> ld
commands:
——–

md_backup, md_restore

lsattr, setattr

cd, cp, du, find, help, ls, lsct, lsdg, lsof, mkalias
mkdir, pwd, rm, rmalias

chdg, chkdg, dropdg, iostat, lsdsk, lsod, mkdg, mount
offline, online, rebal, remap, umount

dsget, dsset, lsop, shutdown, spbackup, spcopy, spget
spmove, spset, startup

chtmpl, lstmpl, mktmpl, rmtmpl

chgrp, chmod, chown, groups, grpmod, lsgrp, lspwusr, lsusr
mkgrp, mkusr, orapwusr, passwd, rmgrp, rmusr

volcreate, voldelete, voldisable, volenable, volinfo
volresize, volset, volstat

ASMCMD> ls
RAC/
scan-ip/
ASMCMD> cd RAC
ASMCMD> du
Used_MB Mirror_used_MB
1767 1767
ASMCMD> cd ..
ASMCMD> du scan-ip
Used_MB Mirror_used_MB
263 263
ASMCMD> chkdg +DATA
ORA-15100: invalid or missing diskgroup name (DBD ERROR: error possibly near <*> indicator at char 28 in ‘/* ASMCMD */ALTER DISKGROUP <*>+DATA CHECK NOREPAIR’)
ASMCMD> chkdg DATA
ASMCMD> iostat -G DATA
Group_Name Dsk_Name Reads Writes
DATA DISK2 63483904 5197824
DATA DISK3 26458624 5493248
DATA DISK4 27652096 5262848
DATA DISK5 83670016 14486528
DATA DISK6 35110912 6680576
ASMCMD> iostat -G DATA 5
Group_Name Dsk_Name Reads Writes
DATA DISK2 64786432 5218304
DATA DISK3 26458624 5493248
DATA DISK4 27652096 5262848
DATA DISK5 84505600 14586880
DATA DISK6 35110912 6680576

Group_Name Dsk_Name Reads Writes
DATA DISK2 29491.20 1638.40
DATA DISK3 0.00 0.00
DATA DISK4 0.00 1638.40
DATA DISK5 16384.00 3379.20
DATA DISK6 0.00 1638.40

Group_Name Dsk_Name Reads Writes
DATA DISK2 26214.40 1638.40
DATA DISK3 0.00 13107.20
DATA DISK4 0.00 0.00
DATA DISK5 19660.80 6758.40
DATA DISK6 0.00 0.00

q
Group_Name Dsk_Name Reads Writes
DATA DISK2 50790.40 819.20
DATA DISK3 0.00 0.00
DATA DISK4 0.00 0.00
DATA DISK5 33587.20 6553.60
DATA DISK6 0.00 0.00

ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 42991 40819 0 40819 0 N DATA/
ASMCMD> lstmpl -G DATA
Group_Name Group_Num Name
DATA 1 ARCHIVELOG
DATA 1 ASMPARAMETERBAKFILE
DATA 1 ASMPARAMETERFILE
DATA 1 ASM_STALE
DATA 1 AUTOBACKUP
DATA 1 BACKUPSET
DATA 1 CHANGETRACKING
DATA 1 CONTROLFILE
DATA 1 DATAFILE
DATA 1 DATAGUARDCONFIG
DATA 1 DUMPSET
DATA 1 FLASHBACK
DATA 1 FLASHFILE
DATA 1 OCRBACKUP
DATA 1 OCRFILE
DATA 1 ONLINELOG
DATA 1 PARAMETERFILE
DATA 1 TEMPFILE
DATA 1 XTRANSPORT
ASMCMD> !stty erase ^H
commands:
——–

md_backup, md_restore

lsattr, setattr

cd, cp, du, find, help, ls, lsct, lsdg, lsof, mkalias
mkdir, pwd, rm, rmalias

chdg, chkdg, dropdg, iostat, lsdsk, lsod, mkdg, mount
offline, online, rebal, remap, umount

dsget, dsset, lsop, shutdown, spbackup, spcopy, spget
spmove, spset, startup

chtmpl, lstmpl, mktmpl, rmtmpl

chgrp, chmod, chown, groups, grpmod, lsgrp, lspwusr, lsusr
mkgrp, mkusr, orapwusr, passwd, rmgrp, rmusr

volcreate, voldelete, voldisable, volenable, volinfo
volresize, volset, volstat

ASMCMD> lsdsk DATA
ASMCMD> lsdsk
Path
ORCL:DISK2
ORCL:DISK3
ORCL:DISK4
ORCL:DISK5
ORCL:DISK6
ASMCMD> pwd
+DATA
ASMCMD>
ASMCMD> ls -lrt
WARNING:option ‘r’ is deprecated for ‘ls’
please use ‘reverse’

Type Redund Striped Time Sys Name
Y RAC/
Y scan-ip/
ASMCMD> cd RAC
ASMCMD> ls -lrt
WARNING:option ‘r’ is deprecated for ‘ls’
please use ‘reverse’

Type Redund Striped Time Sys Name
Y CONTROLFILE/
Y DATAFILE/
Y ONLINELOG/
Y PARAMETERFILE/
Y TEMPFILE/
N spfileRAC.ora => +DATA/RAC/PARAMETERFILE/spfile.268.783818137
ASMCMD> exit
[oracle@Rac1 ~]$ echo $ORACLE_SID
+ASM1
[oracle@Rac1 ~]$ asmcmd
ASMCMD> ls -lrt
WARNING:option ‘r’ is deprecated for ‘ls’
please use ‘reverse’

State Type Rebal Name
MOUNTED EXTERN N DATA/
ASMCMD> ls
DATA/
ASMCMD> cd +CRS
ASMCMD-08001: diskgroup ‘CRS’ does not exist or is not mounted
ASMCMD> cd +DATA/RAC
ASMCMD> cd asmparameterfile
ASMCMD-08002: entry ‘asmparameterfile’ does not exist in directory ‘+DATA/RAC/’
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
spfileRAC.ora
ASMCMD> cd parameterfile
ASMCMD> ls
spfile.268.783818137
ASMCMD> exit
[oracle@Rac1 ~]$ srvctl config asm -a
ASM home: /u01/app/11.2.0/grid
ASM listener: LISTENER
ASM is enabled.
[oracle@Rac1 ~]$ asmcmd
ASMCMD> exit
[oracle@Rac1 ~]$ cd $ORACLE_HOME
[oracle@Rac1 grid]$ cd gpnp
[oracle@Rac1 gpnp]$ cd profiles
[oracle@Rac1 profiles]$ cd peer
[oracle@Rac1 peer]$ ls -lrt
total 8
-rw-r–r– 1 oracle oinstall 1872 May 20 18:26 profile_orig.xml
-rw-r–r– 1 oracle oinstall 1871 May 20 18:29 profile.xml
[oracle@Rac1 peer]$ vi profile.xml

<?xml version=”1.0″ encoding=”UTF-8″?><gpnp:GPnP-Profile Version=”1.0″ xmlns=”http://www.grid-pnp.org/2005/11/gpnp-profile” xmlns:gpnp=”http://www.grid-pnp.org/2005/11/gpnp-profile” xmlns:orcl=”http://www.oracle.com/gpnp/2005/11/gpnp-profile” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.grid-pnp.org/2005/11/gpnp-profile gpnp-profile.xsd” ProfileSequence=”6″ ClusterUId=”08d3b14b95e0df64ff2ea3e34b342b74″ ClusterName=”scan-ip” PALocation=”"><gpnp:Network-Profile><gpnp:HostNetwork id=”gen” HostName=”*”><gpnp:Network id=”net1″ IP=”192.168.1.0″ Adapter=”eth0″ Use=”public”/><gpnp:Network id=”net2″ IP=”192.168.0.0″ Adapter=”eth1″ Use=”cluster_interconnect”/></gpnp:HostNetwork></gpnp:Network-Profile><orcl:CSS-Profile id=”css” DiscoveryString=”+asm” LeaseDuration=”400″/><orcl:ASM-Profile id=”asm” DiscoveryString=”" SPFile=”+DATA/scan-ip/asmparameterfile/registry.253.783800931″/><ds:Signature xmlns:ds=”http://www.w3.org/2000/09/xmldsig#”><ds:SignedInfo><ds:CanonicalizationMethod Algorithm=”http://www.w3.org/2001/10/xml-exc-c14n#”/><ds:SignatureMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#rsa-sha1″/><ds:Reference URI=”"><ds:Transforms><ds:Transform Algorithm=”http://www.w3.org/2000/09/xmldsig#enveloped-signature”/><ds:Transform Algorithm=”http://www.w3.org/2001/10/xml-exc-c14n#”> <InclusiveNamespaces xmlns=”http://www.w3.org/2001/10/xml-exc-c14n#” PrefixList=”gpnp orcl xsi”/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#sha1″/><ds:DigestValue>aBq6aQSHpKQxVLP1GsXCHUiSs+0=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>gTD0fTRa7QG+dFImQ/pzCjUYZ0y3GAgfemsvegp0HVwQn5JF1nrUR8WGtVQizdxawCdVK6rVUa2SJlBZoewfZ+a1uoGSR+1f5KUs6WdcM5GE/uK2mT3OkiDRPEw0d2RNYwzcDHSW2B7cjF4mY1Koa+YwqMgPefc2qNp5dMgFa+c=</ds:SignatureValue></ds:Signature></gpnp:GPnP-Profile>

[oracle@Rac1 ~]$ asmcmd
ASMCMD> cd DATA
ASMCMD> cd scan-ip
ASMCMD> ls -lrt
WARNING:option ‘r’ is deprecated for ‘ls’
please use ‘reverse’

Type Redund Striped Time Sys Name
Y ASMPARAMETERFILE/
Y OCRFILE/
ASMCMD> cd asmparameterfile
ASMCMD> ls
REGISTRY.253.783800931
ASMCMD> cd
usage: cd <dir>
help: help cd
ASMCMD> pwd
+DATA/scan-ip/asmparameterfile
ASMCMD> cd ../..
ASMCMD> cd asm*
ASMCMD-08002: entry ‘asm*’ does not exist in directory ‘+DATA/’
ASMCMD> cd sc*
ASMCMD> cd asm*
ASMCMD> ls
REGISTRY.253.783800931
ASMCMD> cp /home/oracle/asm.txt
usage: cp [-if] <[\@connect_identifier:]src> <[\@connect_identifier:]tgt>
help: help cp
ASMCMD> cp REGISTRY.253.783800931 /home/oracle/
copying +DATA/scan-ip/ASMPARAMETERFILE/REGISTRY.253.783800931 -> /home/oracle//REGISTRY.253.783800931
ASMCMD-08016: copy source->’+DATA/scan-ip/ASMPARAMETERFILE/REGISTRY.253.783800931′ and target->’/home/oracle//REGISTRY.253.783800931′ failed
ORA-15091: operation incompatible with open handle in this session
ORA-06512: at “SYS.X$DBMS_DISKGROUP”, line 397
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)
ASMCMD> pwd
+DATA/scan-ip/ASMPARAMETERFILE
ASMCMD> spbackup REGISTRY.253.783800931 /home/oracle/asm.txt
ASMCMD> exit

[oracle@Rac1 ~]$ ls -lrt asm*
-rw-r—– 1 oracle oinstall 1536 Jun 16 09:38 asm.txt
[oracle@Rac1 ~]$ strings asm.txt > newasm.txt
[oracle@Rac1 ~]$ cat newasm.txt
+ASM1.__oracle_base=’/u01/app/oracle’#ORACLE_BASE set from in memory value
+ASM2.__oracle_base=’/u01/app/oracle’#ORACLE_BASE set from in memory value
*.asm_power_limit=1
*.diagnostic_dest=’/u01/app/oracle’
*.instance_type=’asm’
*.large_pool_size=12M
*.remote_login_passwordfile=’EXCLUSIVE’

[oracle@Rac1 ~]$ asmcmd
cdASMCMD> DATA
ASMCMD> ls
RAC/
scan-ip/
ASMCMD> cd sca*
ASMCMD> ls
ASMPARAMETERFILE/
OCRFILE/
ASMCMD> cd OCRFILE
ASMCMD> ls
REGISTRY.255.783800935

No comments:

Post a Comment