You are on page 1of 10

ASM CLASS LABS

DAY1

1. Using files to simulate RAW DEVICES with ASM (Loopdevices)


2. create ASM instance
3. create ASM database (dbca)
4. handling disks and diskgoups/redundancy
5. striping
6. rebalance: drop disk (with data)

DAY2

7. Using filesystems to implement ASM (_asm_allow_only_raw_disks)


8. Using ASMLIB to implement ASM

RMAN

9. Restore a controlfile to a second location


10. Restore datafiles from ASM to FS

Dumps

11. blockdump
12. dump metadata using kfed
13. dd
***********************************************************
RAW DEVICES with ASM
file -> loopdev -> rawdev
***********************************************************
important note:
It could be possible, that loopdevice setup was already completed.
check this before:
raw -qa
if so, continue with device permissions and ownership

1. Create the files to be used as ASM DISKS


dd if=/dev/zero of=<path>/fs_disk1 bs=1M count=1000
dd if=/dev/zero of=<path>/fs_disk2 bs=1M count=1000
dd if=/dev/zero of=<path>/fs_disk3 bs=1M count=1000
dd if=/dev/zero of=<path>/fs_disk4 bs=1M count=1000

Note: Make sure oracle user owns the files.

2. As root create the loop device:

 Create the new loop devices:


#losetup /dev/loop1 <path>/fs_disk1
#losetup /dev/loop2 <path>/fs_disk2
#losetup /dev/loop3 <path>/fs_disk3
#losetup /dev/loop4 <path>/fs_disk4

 Bind the loop devices to raw:


# raw –qa -- list the current raw devices used
# raw /dev/raw/raw1 /dev/loop1
# raw /dev/raw/raw2 /dev/loop2
# raw /dev/raw/raw3 /dev/loop3
# raw /dev/raw/raw4 /dev/loop4

#chmod 660 /dev/raw/raw[1-4]


#chown oracle:dba /dev/raw/raw[1-4]

 Change the asm_diskstring to use /dev/raw/raw[1-4] and modify init+ASM.ora file

 Check view v$asm_disk to see if the new disk fs_disk1 was discovered:

Select header_status,path from v$asm_disk;

Kfod can be also used: kfod p='$ORACLE_HOME/dbs/init\+ASM.ora' d=all


*****************************
Create ASM INSTANCE
*****************************

1. Create the init+ASM.ora file


.asm_diskstring=’/dev/raw/raw[1-4] '
*.instance_type='asm'
*.large_pool_size=12M
*.remote_login_passwordfile='SHARED'
*.user_dump_dest='/oracle/10g/admin/+ASM/udump' <- check if directory exists, if not create it
*.background_dump_dest='/oracle/10g/admin/+ASM/bdump' <- check if directory exists, if not create it
*.core_dump_dest='/oracle/10g/admin/+ASM/cdump' <- check if directory exists, if not create it

2. connect to ASM instance

3. startup nomount

4. On the ASM instance, create a diskgroup using LOOP-RAW disks


create diskgroup DG1 external redundancy disk ‘/dev/raw/raw1’, '/dev/raw/raw2';

5. check results
v$asm_disk
v$asm_diskgroup

******************************
create ASM database
******************************

5. Create database using dbca


set ORACLE_HOME correctly
call dbca and follow the steps for db creation
*****************************************
DIFFERENT FEATURES
*****************************************

DISKGROUPS & REDUNDANCY

create diskgroup with external redundancy


add new disks

create diskgroup with normal redundancy


add new disks to FG1
add new disks to FG2

mount/dismount diskgroup
drop diskgroup

ASM INTERNAL SPACE USAGE

check v$asm_disk, v$asm_diskgroup


check internal (metadata) space usage (total_mb, free_mb)

STRIPING

create a DG with external redundancy and 3 disks


create a tablespace with 1 datafile (5 MB)
find out asm_file#
find datafile extents in x$kffxp
how many AU's?
what extent is located at what disk?

REBALANCE

drop a disk from this diskgroup


how data becomes reallocated to remaining disks?

ASM FS mixup

add a datafile to tablespace


use a file in filesystem.
**********************
****** ASMLIB LAB
**********************
#
# Install, configure and create ASMLIB disks
#

1.Download ASMLIB
http://www.oracle.com/technology/tech/linux/asmlib/index.html

Red Hat Enterprise Linux 3 (x86)


oracleasmlib-2.0.1-1.i386.rpm - Userspace library
oracleasm-support-2.0.1-1.i386.rpm - Driver support files
oracleasm-2.4.21-27.EL-1.0.4-2.i686.rpm - Userspace library

2.Install, check dependencies

cd <r> # this is the location for the ASMLIB rpms


su –
# rpm –Uvh oracleasm-support-2.0.1-1.i386.rpm
# rpm –Uvh oracleasm-2.4.21-27.EL-1.0.4-2.i686.rpm
# rpm –Uvh oracleasmlib-2.0.1-1.i386.rpm

3.Configure ASMLIB

As root:

# cd /etc/init.d
# ./oracleasm config

# lsmod
# df –ha
# rpm –qa |grep asm
4.Create disks that will be used by ASMLIB
file -> loop -> asmlib

Reference Note: 303760.1

* Pick a directory with plenty of space and create the file with 'dd' command.
500Mb each file
$ dd if=/dev/zero of=loop_disk5 bs=1M count=500
$ dd if=/dev/zero of=loop_disk6 bs=1M count=500
$ ls -l
total 200208
-rw-r--r-- 1 oracle dba 524288000 Apr 5 14:16 loop_disk5
-rw-r--r-- 1 oracle dba 524288000 Apr 5 14:17 loop_disk6

* With second step using 'losetup' command, we will associate a loop device
with a file. This time, as root execute these commands:

$ su -
# losetup /dev/loop5 loop_disk5
# losetup /dev/loop6 loop_disk6

checking to see if the device has been created :


# losetup /dev/loop5
/dev/loop2: [0305]:1161029 (loop_disk5) offset 0, no encryption
# losetup /dev/loop6
/dev/loop2: [0305]:1161029 (loop_disk6) offset 0, no encryption

If device does not exist:


[root@arlnx2 root]# losetup /dev/loop1
loop: can't get info on device /dev/loop1: No such device or address

To delete a loop device use losetup –d /dev/loopX

5. Mark the ASMLIB disks

cd /etc/init.d
./oracleasm createdisk DISK1 /dev/loop1
./oracleasm createdisk DISK2 /dev/loop2

ls –l /dev/oracleasm/disks
ls –l /dev/loop1 /dev/loop2

6. Adjust asm_diskstring

ORCL:*
**********************************************
Using filesystems to implement ASM
_asm_allow_only_raw_disks = FALSE
**********************************************

#
# Reference Note: 293095.1

1. Create a directory to store the files that will be used as ASM DISKS.

Mkdir <path>

2. Create the files to be used as ASM DISKS


dd if=/dev/zero of=<path>/fs_disk1 bs=1m count=100

Note: Make sure oracle user owns the files.

3. Include <path> into asm_diskstring parameter . Make the change in the init+ASM.ora
Alter system set asm_diskstring=’ORCL:*’,’<path>’

Instance has to be restarted with parameter _asm_allow_only_raw_disks = FALSE.

4. Check view v$asm_disk to see if the new disk fs_disk1 was discovered:

Select header_status,path from v$asm_disk;

Kfod can be also used: kfod p='$ORACLE_HOME/dbs/init\+ASM.ora'

5. Create a diskgroup using the new file

Create diskgroup dg_fs disk ‘<path>/fs_disk1’;

SQL> select TOTAL_MB, FREE_MB, NAME from v$asm_diskgroup;

6. Create a tablespace using this diskgroup:

create tablespace ts_fs datafile ‘+dg_fs’;


******************************************************************************
RMAN: Restore a controlfile to a second location (DISKGROUP)
******************************************************************************
# Duplicate the controlfile to a second diskgroup.
# If there is not a second diskgroup available, create it first.

1. On the ASM instance, identify the structure for the new location
Directories can be created on a diskgroup.
use asmcmd

Note: You can use any path under the diskgroup name.

2. Copy the controlfile using RMAN - Use the target database


* stop the target database
sql)shutdown normal
* modify init.ora/spfile to include new control_file value
+DG2/P10G/CONTROLFILE/control02.ctl
* start nomount
sql)startup nomount

* Call RMAN
rman nocatalog
rman>connect target

* Copy controlfile:
rman>restore controlfile to <new location> from <old location>;
rman>sql 'alter database mount';
rman>sql 'alter database open.

Example: rman>restore controlfile to '+DG2/P10G/CONTROLFILE/control02.ctl'


from '+DG1/P10G/CONTROLFILE/Current.264.1';

3. Verify in the ASM instance the new files created


check v$asm_file where type='CONTROLFILE'
****************************************************************
RMAN: Restore datafiles from ASM to filesystem
****************************************************************

1. Restore the datafile from the diskgroup to a filesystem

Example: This the file to be restored: +DG2/p10g/datafile/testx_267_5

* Set offline the datafile

sql) alter database datafile '+DG2/p10g/datafile/testx_267_5' offline;

* Restore as a copy file

rman nocatalog
rman>connect target
rman>backup as copy datafile 8 format '/oradata2/p10g/backup/testx_%f.dbf'

RMAN> connect target

connected to target database: P10G (DBID=3847367817)


using target database controlfile instead of recovery catalog
RMAN> backup as copy datafile 8 format '/oradata2/p10g/backup/testx_%f.dbf';

Starting backup at 15-APR-05

using channel ORA_DISK_1


channel ORA_DISK_1: starting datafile copy
input datafile fno=00008 name=+DG2/p10g/datafile/testx_267_5
output filename=/oradata2/p10g/backup/testx_8.dbf tag=TAG20050415T063654 recid=1 stamp=555662216
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
Finished backup at 15-APR-05
************************
DUMPS
************************

BLOCKDUMP

create a small table using asmfile


find out datablock and filenumber
perform ORACLE blockdump:

alter system dump datafile '+DG/file_NAME'

check tracefile

shutdown database and ASM instance

DUMP DISKHEADER METADATA USING KFED


e.g.
kfed read /dev/raw/raw4

DD SAME DISKHEADER
e.g.
dd if=/dev/raw/raw4 of=dumpraw4 count=100

compare kfed and dd results

You might also like