Tuesday, 16 January 2018

Configuring ASM for single Instance DB

Automatic Storage Management (ASM)

ASM is advance feature provided by Oracle for management of storage devices and data placed on it form 10g ownwards. ASM combines the storage disks to form a disk groups, used
for storing of Data. It is automatic in the sense that you can add disks and remove disks from Disk group even its online and data is written on it live. Other features are stripping
mirroring of data across different disks. There are other storage management tool as well but Oracle ASM is best of them all is because it provides you with
Oracle Automatic Storage Management Cluster File System (Oracle ACFS).

ASM can be implemented in 2 ways: i.e ASMLib drivers and through Raw Devices

 1) ASM configuration through ASMLib: (Below method is use to configure ASM in all most all environments)

--First of All you'll Install rpm, 3 rpms

1) oracleasm-support-2.1.7-1.el5.i386.rpm
2) oracleasm-2.6.18-92.el5-2.0.4-1.el5.i686.rpm
3) oracleasmlib-2.0.4-1.el5.i386.rpm

-- Partition Harddisk

#fdisks -l


#fdisk /dev/sda

n for new partition
P for primary partition
1 starts
enter
enter
wq to write quite

similarly you'll partition all the disks

--Now configure ASM 

#/etc/init.d/oracleasm configure

than will ask for user : oracle
                       : oinstall
                       : y
                       : y 

-- Naming ASM Disks

/etc/init.d/oracleasm createdisk vol1 /dev/sda1
/etc/init.d/oracleasm createdisk vol2 /dev/sda2
/etc/init.d/oracleasm createdisk vol3 /dev/sda3
/etc/init.d/oracleasm createdisk vol4 /dev/sda4
/etc/init.d/oracleasm createdisk vol4 /dev/sda5

--Listing all the diks created

/etc/init.d/oracleasm listdisks
vol1
vol2
vol3
vol4
vol4

Once the formating is done execute runinstaller


2)  Raw Device Configuration: (These days its not configured but one should have knowledge)

In linux disk are partitioned but not formated for raw formate

# fdisk -l 

/dev/sda1
/dev/sda2
/dev/sda3 etc...

In some release of linux raw devices configuration are depreciated
If you don't have raw devices attached to  than you can check it by command:


(i)  service rawdevices start
     (unrecognised command)
(ii) ll /etc/sysconfig/raw*
      (no such file or directory)
 
  You above commands didn't return any result please follow the below procedure:
 

cd /etc/udev/rules.d
(rules file are executed when machine startups )
these are called udev rules

vi 60-raw.rules
paste :

ACTION=="add", KERNEL=="sdb1", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdc1", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdd1", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sde1", RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", KERNEL=="sdf1", RUN+="/bin/raw /dev/raw/raw5 %N"
KERNEL=="raw[1-2]*", OWNER="root", GROUP="oinstall", MODE="640"
KERNEL=="raw[3-5]*", OWNER="oracle", GROUP="oinstall", MODE="644"

if you want that it will be effected immediate use this command :

/bin/raw /dev/raw/raw1 /dev/sdb1
/bin/raw /dev/raw/raw2 /dev/sdc1
/bin/raw /dev/raw/raw3 /dev/sdd1
/bin/raw /dev/raw/raw4 /dev/sde1
/bin/raw /dev/raw/raw5 /dev/sdf1

keep in mind that this is the drawback of rawdevices that after restart these permisstion reset to root but keeping the 2 lines in 60-raw files keep it static.

chown oracle:oinstall /dev/raw/raw*
chmod 640 /dev/raw/*

Now Run the runinstaller  

Moving Data from one ASM DG with EXTERNAL redundancy to another ASM DG with NORMAL redundancy (Offline approach)

Moving Data from one ASM DG to another ASM DG Offline approach.

If we are having diskgroup with redundancy EXTERNAL and want to configure another ASM DG with redundancy Level NORMAL, so its no other way to create new Disk group and move all your
from old ASM DG wiht EXTERNAL to New ASM DG with NORMAL redundancy.

--Check all the datafiles of the DB and their location:

select file_id,bytes/1024/1024 MB,tablespace_name,file_name from dba_data_files;

File Size(MB) Tablespace            Datafile Name
---- -------- --------------------  ------------------------
1    3072     SYSTEM                +PRE_TEST_DATA/dbTESTq/datafile/system.266.864839123
2    3072     SYSAUX                +PRE_TEST_DATA/dbTESTq/datafile/sysaux.265.864839135
3    4470     UNDOTBS1              +PRE_TEST_DATA/dbTESTq/datafile/undotbs1.258.864839143
4    5445     UNDOTBS2              +PRE_TEST_DATA/dbTESTq/datafile/undotbs2.264.864839153
5    5        USERS                 +PRE_TEST_DATA/dbTESTq/datafile/users.263.864839157
6    1024     vr_TEST_DATA          +PRE_TEST_DATA/dbTESTq/datafile/vr_TEST_data.dbf
7    1024     TS_DATA_TESTIKMS       +PRE_TEST_DATA/dbTESTq/datafile/ts_data_TESTikms.dbf
8    1024     TS_INDEX_TESTIKMS      +PRE_TEST_DATA/dbTESTq/datafile/ts_index_TESTikms.dbf
9    1024     TS_KSA_TEST_DAT        +PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_dat_1.dbf
10   1024     TS_KSA_TEST_IDX        +PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_idx_1.dbf
11   1024     TS_KSA_TEST_LOB        +PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_lob_1.dbf
12   1024     TS_KSA_TEST_LOG        +PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_log_1.dbf
13   1024     TS_KSA_TEST_LOG_LOB    +PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_log_lob_1.dbf

-- Checking all Temp files location

select file_id,bytes/1024/1024 MB,tablespace_name,maxbytes/1024/1024 Maxsize(MB),file_name from dba_temp_files;

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    73       TEMP                 32767       +PRE_TEST_DATA/dbTESTq/tempfile/temp.257.864839147

-- Check Controlfile Location

SQL> show parameter control

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      +PRE_TEST_DATA/dbTESTq/controlfi
                                                 le/current.267.864839117, +PRE
                                                 _TEST_FRA/dbTESTq/controlfile/cu
                                                 rrent.256.864839117
control_management_pack_access       string      DIAGNOSTIC+TUNING
SQL>

-- Check below parameters if any of them pointing to Old disk group

Show parameter DB_CREATE_FILE_DEST
Show parameter DB_CREATE_ONLINE_LOG_DEST_n
Show parameter DB_RECOVERY_FILE_DEST
Show parameter LOG_ARCHIVE_DEST_n
Show parameter LOG_ARCHIVE_DEST
Show parameter STANDBY_ARCHIVE_DEST

-- Changing location of backup controlfile to new ASM DG having normal redundancy

sql> alter database backup controlfile to '+PRE_TEST_DATA_01';

Database altered.

SQL> alter system set control_files='+PRE_TEST_DATA_01/DBTESTQ/CONTROLFILE/Backup.256.912776299' scope=spfile;

System altered.

--Now restoring current Controlfile status to newly move controlfile (offline so that it should be synced with original one)

rman target TESTqrman/RmanTEST11q catalog catqrman/Rmanora11q@dboemq1

rman target /
shutdown immediate;

RMAN> restore controlfile from '+PRE_TEST_DATA/dbTESTq/controlfile/current.267.864839117';

Starting restore at 25-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=122 instance=DBTESTQ1 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=+PRE_TEST_DATA_01/dbTESTq/controlfile/backup.256.912776299
Finished restore at 25-MAY-16

--Moving Datafiles thorugh RMAN to new ASM Disk Group through RMAN backup as copy

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> backup as copy database format '+PRE_TEST_DATA_01';

Starting backup at 25-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=152 instance=DBTESTQ1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+PRE_TEST_DATA/dbTESTq/datafile/undotbs2.264.864839153
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/undotbs2.257.912777743 tag=TAG20160525T132222 RECID=4 STAMP=912777794
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+PRE_TEST_DATA/dbTESTq/datafile/undotbs1.258.864839143
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/undotbs1.258.912777797 tag=TAG20160525T132222 RECID=5 STAMP=912777835
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+PRE_TEST_DATA/dbTESTq/datafile/system.266.864839123
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/system.259.912777843 tag=TAG20160525T132222 RECID=6 STAMP=912777869
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+PRE_TEST_DATA/dbTESTq/datafile/sysaux.265.864839135
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/sysaux.260.912777877 tag=TAG20160525T132222 RECID=7 STAMP=912777910
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=+PRE_TEST_DATA/dbTESTq/datafile/vr_TEST_data.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/vr_TEST_data.261.912777913 tag=TAG20160525T132222 RECID=8 STAMP=912777926
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_data_TESTikms.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_data_TESTikms.262.912777929 tag=TAG20160525T132222 RECID=9 STAMP=912777937
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00008 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_index_TESTikms.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_index_TESTikms.263.912777943 tag=TAG20160525T132222 RECID=10 STAMP=912777950
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_dat_1.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_dat.264.912777959 tag=TAG20160525T132222 RECID=11 STAMP=912777964
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00010 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_idx_1.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_idx.265.912777965 tag=TAG20160525T132222 RECID=12 STAMP=912777972
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00011 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_lob_1.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_lob.266.912777981 tag=TAG20160525T132222 RECID=13 STAMP=912777990
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00012 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_log_1.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_log.267.912777995 tag=TAG20160525T132222 RECID=14 STAMP=912778003
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00013 name=+PRE_TEST_DATA/dbTESTq/datafile/ts_TEST_log_lob_1.dbf
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_log_lob.268.912778011 tag=TAG20160525T132222 RECID=15 STAMP=912778017
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=+PRE_TEST_DATA_01/dbTESTq/controlfile/backup.269.912778019 tag=TAG20160525T132222 RECID=16 STAMP=912778019
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=+PRE_TEST_DATA/dbTESTq/datafile/users.263.864839157
output file name=+PRE_TEST_DATA_01/dbTESTq/datafile/users.270.912778021 tag=TAG20160525T132222 RECID=17 STAMP=912778020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 25-MAY-16
channel ORA_DISK_1: finished piece 1 at 25-MAY-16
piece handle=+PRE_TEST_DATA_01/dbTESTq/backupset/2016_05_25/nnsnf0_tag20160525t132222_0.271.912778021 tag=TAG20160525T132222 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-MAY-16

--Updating location of all DATAFILES in controlfile from old ASM DG to new ASM DG

RMAN> switch database to copy;

datafile 1 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/system.259.912777843"
datafile 2 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/sysaux.260.912777877"
datafile 3 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/undotbs1.258.912777797"
datafile 4 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/undotbs2.257.912777743"
datafile 5 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/users.270.912778021"
datafile 6 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/vr_TEST_data.261.912777913"
datafile 7 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_data_TESTikms.262.912777929"
datafile 8 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_index_TESTikms.263.912777943"
datafile 9 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_dat.264.912777959"
datafile 10 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_idx.265.912777965"
datafile 11 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_lob.266.912777981"
datafile 12 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_log.267.912777995"
datafile 13 switched to datafile copy "+PRE_TEST_DATA_01/dbTESTq/datafile/ts_ksa_TEST_log_lob.268.912778011"

RMAN>

RMAN> exit

--Opening the DATABASE from new ASM DG

[oracle@TESTQDB09 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed May 25 13:28:16 2016

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters and Automatic Storage Management options

SQL>
SQL> alter database open;

Database altered.

SQL> select open_mode from v$database;

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

SQL>

--Setting location to NEW FRA Disk group wiht normal redundancy

SQL> alter system set db_recovery_file_dest='+PRE_TEST_FRA_01' scope=both;

System altered.

SQL>
-- Creating new temp file as it is not backup through Rman


SQL> create temporary tablespace temp01 tempfile '+PRE_TEST_DATA_01' size 32767M;

Tablespace created.

SQL> alter database default temporary tablespace temp01;

Database altered.

--Droping Old Temporary TABLESPACE

SQL> DROP TABLESPACE TEMP INCLUDING CONTENTS AND DATAFILES;

Tablespace dropped.

SQL> exit


[oracle@TESTQDB09 ~]$ cd /u01/app/oracle/product/11.2.0/dbs/
[oracle@TESTQDB09 dbs]$ ls -ltr
total 47540

-rw-r----- 1 oracle oinstall       47 Nov 28  2014 initDBTESTQ1.ora

-- Moving Spfile from Current ASM Disk Group and Updating Spfile location to NEW ASM DG


[oracle@TESTQDB09 dbs]$ cat initDBTESTQ1.ora
SPFILE='+PRE_TEST_DATA/DBTESTQ/spfileDBTESTQ.ora'
[oracle@TESTQDB09 dbs]$ pwd
/u01/app/oracle/product/11.2.0/dbs
[oracle@TESTQDB09 dbs]$
SQL> create pfile='/u01/app/oracle/product/11.2.0/dbs/initMIGTESTq.ora' from spfile;

File created.

SQL>
oracle@TESTQDB09 dbs]$ ls -ltr /u01/app/oracle/product/11.2.0/dbs/initMIGTESTq.ora
-rw-r--r-- 1 oracle asmadmin 1987 May 25 15:08 /u01/app/oracle/product/11.2.0/dbs/initMIGTESTq.ora
[oracle@TESTQDB09 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed May 25 15:10:25 2016

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters and Automatic Storage Management options

SQL> create spfile='+PRE_TEST_DATA_01' from pfile='/u01/app/oracle/product/11.2.0/dbs/initMIGTESTq.ora';

File created.

SQL> exit

[[oracle@TESTQDB09 dbs]$ cat initDBTESTQ1.ora
SPFILE='+PRE_TEST_DATA_01/DBTESTQ/spfileDBTESTQ.ora'

-- Moving Redo Log files

If your redo log group are having 2 members drop 1 from each group

select * from v$logfile;

select * from v$log;

alter database drop logfile member '+PRE_TEST_FRA/dbTESTq/onlinelog/group_2.259.864839121';
alter database drop logfile member '+PRE_TEST_FRA/dbTESTq/onlinelog/group_3.258.864840619';
alter database drop logfile member '+PRE_TEST_FRA/dbTESTq/onlinelog/group_1.260.864839119';
alter database drop logfile member '+PRE_TEST_FRA/dbTESTq/onlinelog/group_4.257.864840621';

-- Now creating new redo log Group at new ASM DG having NORMAL redundancy

alter database add logfile member '+PRE_TEST_DATA_01' to group 1;
alter database add logfile member '+PRE_TEST_DATA_01' to group 2;
alter database add logfile member '+PRE_TEST_DATA_01' to group 3;
alter database add logfile member '+PRE_TEST_DATA_01' to group 4;


-- Drop Second log member from group and also drop the old redo log group as well

alter database drop logfile member '+PRE_TEST_DATA/dbTESTq/onlinelog/group_1.256.864839119';
alter database drop logfile member '+PRE_TEST_DATA/dbTESTq/onlinelog/group_2.262.864839121';
alter database drop logfile member '+PRE_TEST_DATA/dbTESTq/onlinelog/group_3.261.864840617';
alter database drop logfile member '+PRE_TEST_DATA/dbTESTq/onlinelog/group_4.260.864840619';


-- updating configuration at in Services

  ./srvctl config database -d DBTESTQ
  ./srvctl modify database -d DBTESTQ -a 'PRE_TEST_DATA_01,PRE_TEST_FRA_01'
 ./srvctl start instance -d dbTESTq -i DBTESTQ1

Installing Oracle 11g on Linux

Unpack Files Unzip the files. # 11.2.0.1 unzip linux.x64_11gR2_database_1of2.zip unzip linux.x64_11gR2_database_2of2.zip #11.2.0.2 u...