Sunday, February 14, 2016

Manually Migrate a single instance Oracle 12cR1 database with file system storage to an Oracle RAC environment with ASM Storage

Part III - Convert your single instance database to a RAC database

1. Relink the oracle binary with RAC option to enable RAC enable Oracle Real Application Clusters

-- Execute the following on all nodes where the ORACLE_HOME exists:

-- Log in as the ORACLE_HOME owner.

cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk rac_on ioracle



 2. Add RAC specific parameters to the single instance database

-- Startup the single instance DB in SQLPlus and execute the following commands:

SQL> [oracle@testrac1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sun Feb 14 18:59:21 2016

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 834666496 bytes
Fixed Size 2929888 bytes
Variable Size 624954144 bytes
Database Buffers 201326592 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SQL> select instance_name,status from gv$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN

SQL>

 -- create an pfile from your current spfile and use it to create your RAC spfile in ASM

SQL> create pfile='initRACDB_bkp.ora' from spfile;

File created.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup pfile='initRACDB_bkp.ora'
ORACLE instance started.

Total System Global Area 834666496 bytes
Fixed Size 2929888 bytes
Variable Size 624954144 bytes
Database Buffers 201326592 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SQL> select instance_name,status from gv$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN

SQL> create spfile='+DATA' from pfile='initRACDB_bkp.ora';

File created.

SQL>

Get the value of your newly created spfile using "asmcmd" and use it to create the initRACDB1.ora file under the dbs directory
[oracle@testrac2 ~]$ asmcmd
ASMCMD> ls
DATA/
FRA/
OCR/
ASMCMD> cd DATA/RACDB/PARAMETERFILE
ASMCMD> pwd
+DATA/RACDB/PARAMETERFILE
ASMCMD> ls
spfile.287.903813031
ASMCMD>

-- So your newly created initRACDB1.ora file will look like this
spfile='+DATA/RACDB/PARAMETERFILE/spfile.287.903813031'

-- Shutdown the DB instance again and bring it up with the newly created spfile.
SQL> show parameter pfile

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup
ORACLE instance started.

Total System Global Area 834666496 bytes
Fixed Size 2929888 bytes
Variable Size 624954144 bytes
Database Buffers 201326592 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SQL>
SQL> show parameter pfile

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/RACDB/PARAMETERFILE/spfil
e.287.903813031
SQL>

-- Now add the Oracle RAC-specific parameters to this spfile and use it to start your RAC database

SQL> alter system set cluster_database=TRUE scope=spfile;

System altered.

SQL> alter system set instance_number=1 scope=spfile sid='*';

System altered.

SQL> alter system set instance_number=2 scope=spfile sid='*';

System altered.

SQL> alter system set thread=1 scope=spfile sid='*';

System altered.

SQL> alter system set thread=2 scope=spfile sid='*';

System altered.

SQL> alter system set undo_tablespace='UNDOTBS1' scope=spfile sid='*';

System altered.

SQL> alter system set undo_tablespace='UNDOTBS2' scope=spfile;

System altered.

SQL>

-- Copy over the initRACDB1 to the second node in the appropriate directory
[oracle@testrac1 dbs]$ scp initRACDB1.ora oracle@testrac2:/u01/app/oracle/product/12.0.1/db_1/dbs/initRACDB2.ora
initRACDB1.ora 100% 55 0.1KB/s 00:00
[oracle@testrac1 dbs]$

-- Shutdown the single instance and bring it up as an Oracle RAC database after adding it and its accompanying instances to Oracle Restart

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
[oracle@testrac1 dbs]$ srvctl add db -d RACDB -o /u01/app/oracle/product/12.0.1/db_1 -p '+DATA/RACDB/PARAMETERFILE/spfile.287.902596077'
[oracle@testrac1 dbs]$ srvctl add instance -d RACDB -i RACDB1 -n testrac1.brontechsolutions.com
[oracle@testrac1 dbs]$ srvctl add instance -d RACDB -i RACDB2 -n testrac2.brontechsolutions.com
[oracle@testrac1 dbs]$ srvctl start db -d RACDB
[oracle@testrac2 dbs]$ srvctl status db -d RACDB
Instance RACDB1 is running on node testrac1
Instance RACDB2 is running on node testrac2
[oracle@testrac2 dbs]$
SQL> select instance_name,status from gv$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN
RACDB2 OPEN

SQL>

Have fum - Your feedback is always welcome...

Sunday, January 31, 2016

Manually Migrate a single instance Oracle 12cR1 database with file system storage to an Oracle RAC environment with ASM Storage

Part II - Convert database files from filesystem to ASM Storage

1. Prepare the ORACLE_HOME environment for the 2nd node (.bash_proofile & ORACLE_HOME)


[oracle@testRAC2 ~]$ vi .bash_profile
[oracle@testRAC2 ~]$ . ./.bash_profile
[oracle@testRAC2 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/12.0.1/db_1
[oracle@testRAC2 ~]$ cd $ORACLE_HOME
-bash: cd: /u01/app/oracle/product/12.0.1/db_1: No such file or directory
[oracle@testRAC2 ~]$ cd $ORACLE_BASE
[oracle@testRAC2 ~]$ ll
total 8
-rw-r--r-- 1 oracle oinstall   50 Sep 19 13:00 afiedt.buf
drwxr----- 3 oracle oinstall 4096 Sep 15 14:07 oradiag_oracle
[oracle@testRAC2 ~]$ mkdir -p product/12.0.1/db_1


2. Copy over the zipped ORACLE_HOME to the newly created directory and unzip/untar to create your ORACLE_HOME in the second node and relink the binaries


[oracle@testRAC2 12.0.1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC2 12.0.1]$ scp oracle@student190:/oradata/backup/DB12c_HOME.tar.gz .
The authenticity of host 'student190 (192.168.x.x)' can't be established.
RSA key fingerprint is 56:6c:41:17:2d:9e:a8:0a:a9:2f:08:a9:b8:9a:e1:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'student190,192.168.x.x' (RSA) to the list of known hosts.
oracle@student190's password:
DB12c_HOME.tar.gz                                                                          4%  115MB   9.5MB/s   04:27 ETA
DB12c_HOME.tar.gz                                                                        100% 2661MB   7.9MB/s   05:36
[oracle@testRAC2 12.0.1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC2 12.0.1]$ ll
total 2727320
-rw-r--r-- 1 oracle oinstall 2790039829 Jan 30 21:12 DB12c_HOME.tar.gz
[oracle@testRAC2 12.0.1]$ gunzip DB12c_HOME.tar.gz
[oracle@testRAC2 12.0.1]$ ll
total 5403744
-rw-r--r-- 1 oracle oinstall 5528023040 Jan 30 21:12 DB12c_HOME.tar
[oracle@testRAC2 12.0.1]$ tar -xvf DB12c_HOME.tar
db_1/
db_1/lib/
db_1/lib/sscoreed.o
db_1/lib/libsql12.a
db_1/lib/libclntsh.so.11.1
db_1/lib/libons.so
db_1/lib/libsrvmhas12.so
db_1/lib/libclsce12.so
:
:
[oracle@testRAC2 12.0.1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC2 12.0.1]$ ll
total 5403748
drwxr-xr-x 70 oracle oinstall       4096 Jan 30 09:30 db_1
-rw-r--r--  1 oracle oinstall 5528023040 Jan 30 21:12 DB12c_HOME.tar
[oracle@testRAC2 12.0.1]$ rm -f DB12c_HOME.tar
[oracle@testRAC2 12.0.1]$ cd db_1/bin
[oracle@testRAC2 bin]$ pwd
/u01/app/oracle/product/12.0.1/db_1/bin
[oracle@testRAC2 bin]$ ./relink all
writing relink log to: /u01/app/oracle/product/12.0.1/db_1/install/relink.log
[oracle@testRAC2 bin]$


3. Switch over to node 1 & login as the grid user & install the 12cR1 Grid Infrastructure software (See screen shots)
[grid@testRAC1 ~]$ cd /downloads/ORACLE_12C/GridInfrastructure/grid
[grid@testRAC1 grid]$ pwd
/downloads/ORACLE_12C/GridInfrastructure/grid
[grid@testRAC1 grid]$ ll
total 44
drwxrwxrwx  4 500 student01 4096 Jul  1  2015 install
drwxrwxrwx  2 500 student01 4096 Jul  7  2014 response
drwxrwxrwx  2 500 student01 4096 Jul  7  2014 rpm
-rwxrwxrwx  1 500 student01 5085 Dec 20  2013 runcluvfy.sh
-rwxrwxrwx  1 500 student01 8534 Jul  7  2014 runInstaller
drwxrwxrwx  2 500 student01 4096 Jul  7  2014 sshsetup
drwxrwxrwx 14 500 student01 4096 Jul  7  2014 stage
-rwxrwxrwx  1 500 student01  500 Feb  6  2013 welcome.html
[grid@testRAC1 grid]$ ./runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 415 MB.   Actual 10629 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3999 MB    Passed
Checking monitor: must be configured to display at least 256 colors.    Actual 16777216    Passed
[grid@testRAC1 grid]$
Install and Configure Grid Infrastructure for a Cluster
Too bad we can't install a Flex Cluster (One of the 12cR1 new features as I have just 2 nodes to play with)


4. Use the ASM Configuration Assistant (asmca) to create DATA & FRA disk groups (see creen shots)


5. Check the status of the clusterware and related high availability resources on both nodes.

[grid@testRAC1 ~]$ crsctl check crs
CRS-4638: Oracle High Availability Services is online
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
[grid@testRAC1 ~]$
[grid@testRAC1 ~]$ crsctl check cluster -all
**************************************************************
testRAC1:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************
testRAC2:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************


6. Create ASM diskgroups and add appropriate diskgroups for your DB storage and backup/recovery in ASM using asmca (see screen shots)


7. Convert your database files from filesystem to ASM storage using RMAN
 - Switch user to "oracle", login to the DB and take an inventory of all the database files to be converted

SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/controlfile/o1_mf_c985pl01_.ctl
/u01/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_c985ploz_.ctl
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/datafile/o1_mf_system_c985kcf0_.dbf
/u01/oradata/ORCL/datafile/o1_mf_sysaux_c985g9fz_.dbf
/u01/oradata/ORCL/datafile/o1_mf_undotbs1_c985o01b_.dbf
/u01/oradata/ORCL/datafile/o1_mf_users_c985nyqx_.dbf
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/datafile/temp01.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/oradata/ORCL/onlinelog/o1_mf_3_c985q5oy_.log
/u01/oradata/ORCL/onlinelog/o1_mf_2_c985pxxc_.log
/u01/oradata/ORCL/onlinelog/o1_mf_1_c985pq3w_.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo01.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo02.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo03.log
6 rows selected.
 - Convert the above files to ASM files

SQL> select instance_name,status from gv$instance;
INSTANCE_NAME    STATUS
---------------- ------------
ORCL             OPEN
SQL>


 - Disable block change tracking if you're using it


SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
ALTER DATABASE DISABLE BLOCK CHANGE TRACKING
*
ERROR at line 1:
ORA-19759: block change tracking is not enabled
 - I'm not using BCT hence command fails
SQL>  select * from v$block_change_tracking;
STATUS     FILENAME                                                               BYTES     CON_ID
---------- ----------------------------------------------------------------- ---------- ----------
DISABLED


 - Create a pfile and add/modify the below parameters in the initORCL.ora file created


SQL> create pfile from spfile;
File created.
*.control_files=(+DATA, +FRA)
*.db_recovery_file_dest=+FRA
*.db_create_file_dest=+DATA
*.db_create_online_log_dest_1=+FRA
*.db_create_online_log_dest_2=+DATA -- optional if you want another online redo logs dest.


 - With the target database open, edit the initialization parameter control_files and db_create_file_dest to point to the ASM disk group +DATA.
 - Also configure db_recovery_file_dest to point to the ASM disk group +FRA


SQL> ALTER SYSTEM SET control_files='+DATA','+FRA' scope=spfile;
System altered.
SQL> ALTER SYSTEM SET db_create_file_dest='+DATA' scope=spfile;
System altered.
SQL> ALTER SYSTEM SET db_recovery_file_dest='+FRA' scope=spfile;
System altered.
SQL> ALTER SYSTEM SET db_create_online_log_dest_1='+FRA' scope=spfile;
System altered.

 - shutdown the database cleanly and bring it backup NOMOUNT mode:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup nomount
ORACLE instance started.
Total System Global Area  834666496 bytes
Fixed Size                  2929888 bytes
Variable Size             557845280 bytes
Database Buffers          268435456 bytes
Redo Buffers                5455872 bytes
SQL>


 - From an RMAN session, copy one of your controlfiles from the local file system to its new location in ASM.
  - The new controlfile will be copied to the value specified in the initialization parameter control_files:


RMAN> RESTORE CONTROLFILE FROM '/u01/oradata/ORCL/controlfile/o1_mf_c985pl01_.ctl';
Starting restore at 31-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
channel ORA_DISK_1: copied control file copy
output file name=+DATA/ORCL/CONTROLFILE/current.276.902588359
output file name=+FRA/ORCL/CONTROLFILE/current.257.902588361
Finished restore at 31-JAN-16
RMAN>


 - mount the database in your RMAN session

RMAN> alter database mount;
Statement processed
released channel: ORA_DISK_1
RMAN>


 -  Use RMAN to copy the database files from the local file system to ASM

RMAN> configure device type disk parallelism 4;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
RMAN> BACKUP AS COPY DATABASE FORMAT '+DATA';
Starting backup at 31-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=7 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=30 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=31 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/oradata/ORCL/datafile/o1_mf_sysaux_c985g9fz_.dbf
channel ORA_DISK_2: starting datafile copy
input datafile file number=00001 name=/u01/oradata/ORCL/datafile/o1_mf_system_c985kcf0_.dbf
channel ORA_DISK_3: starting datafile copy
input datafile file number=00004 name=/u01/oradata/ORCL/datafile/o1_mf_undotbs1_c985o01b_.dbf
channel ORA_DISK_4: starting datafile copy
input datafile file number=00006 name=/u01/oradata/ORCL/datafile/o1_mf_users_c985nyqx_.dbf
output file name=+DATA/ORCL/DATAFILE/users.281.902588631 tag=TAG20160131T150349 RECID=10 STAMP=902588632
channel ORA_DISK_4: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_4: starting datafile copy
copying current control file
output file name=+DATA/ORCL/CONTROLFILE/backup.282.902588635 tag=TAG20160131T150349 RECID=11 STAMP=902588635
channel ORA_DISK_4: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_4: starting full datafile backup set
channel ORA_DISK_4: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_4: starting piece 1 at 31-JAN-16
channel ORA_DISK_4: finished piece 1 at 31-JAN-16
piece handle=+DATA/ORCL/BACKUPSET/2016_01_31/nnsnf0_tag20160131t150349_0.283.902588637 tag=TAG20160131T150349 comment=NONE
channel ORA_DISK_4: backup set complete, elapsed time: 00:00:01
output file name=+DATA/ORCL/DATAFILE/undotbs1.280.902588631 tag=TAG20160131T150349 RECID=12 STAMP=902588638
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:08
output file name=+DATA/ORCL/DATAFILE/sysaux.278.902588631 tag=TAG20160131T150349 RECID=13 STAMP=902588641
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:12
output file name=+DATA/ORCL/DATAFILE/system.279.902588631 tag=TAG20160131T150349 RECID=14 STAMP=902588644
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:20
Finished backup at 31-JAN-16
RMAN>

 - Switch the database now to the copy in RMAN


RMAN> SWITCH DATABASE TO COPY;
using target database control file instead of recovery catalog
datafile 1 switched to datafile copy "+DATA/ORCL/DATAFILE/system.279.902588631"
datafile 3 switched to datafile copy "+DATA/ORCL/DATAFILE/sysaux.278.902588631"
datafile 4 switched to datafile copy "+DATA/ORCL/DATAFILE/undotbs1.280.902588631"
datafile 6 switched to datafile copy "+DATA/ORCL/DATAFILE/users.281.902588631"
RMAN>


 - From an SQL*Plus session, perform incomplete recovery and open the database using the RESETLOGS option.
 - When prompted for three options, type "CANCEL"
  
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;
ORA-00279: change 3120135 generated at 01/31/2016 14:56:47 needed for thread 1
ORA-00289: suggestion : +FRA
ORA-15173: entry 'ARCHIVELOG' does not exist in directory 'ORCL'
ORA-00280: change 3120135 for thread 1 is in sequence #71
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
SQL>
SQL> ALTER DATABASE OPEN RESETLOGS;
Database altered.
SQL>


 - Recreate any tempfiles that are still on filesystem storage

SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/datafile/temp01.dbf
SQL> alter tablespace temp add tempfile '+DATA' size 128M reuse;
Tablespace altered.
SQL> alter tablespace temp drop tempfile '/u01/oradata/ORCL/datafile/temp01.dbf';
Tablespace altered.
 -  Determine the current online redo logfiles to move to ASM by examining the file names (and sizes) from V$LOGFILE

SQL> select a.group#, a.member, b.bytes from v$logfile a, v$log b where a.group# = b.group#;
    GROUP# MEMBER                                                                 BYTES
---------- ----------------------------------------------------------------- ----------
         3 /u01/oradata/ORCL/onlinelog/o1_mf_3_c985q5oy_.log                   52428800
         2 /u01/oradata/ORCL/onlinelog/o1_mf_2_c985pxxc_.log                   52428800
         1 /u01/oradata/ORCL/onlinelog/o1_mf_1_c985pq3w_.log                   52428800
         1 /u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo01.log        52428800
         2 /u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo02.log        52428800
         3 /u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo03.log        52428800
6 rows selected.


Force a log switch until the last redo log is marked "CURRENT"


SQL> select group#, status from v$log;
    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 ACTIVE
         3 ACTIVE
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.


 - Drop the first online redolog file

SQL> select group#, status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT
SQL> alter database drop logfile group 1;
Database altered.


 - Recreate the first online redo log group in ASM for a RAC DB instance and do same for all redo log files

SQL> alter database add logfile group 1 '+FRA' size 128M reuse;
Database altered.
SQL> alter database drop logfile group 2;
Database altered.
SQL> alter database add logfile group 2 '+FRA' size 128M reuse;
Database altered.
SQL> alter system switch logfile;
SQL> alter database drop logfile group 3;
Database altered.
SQL> alter database add logfile group 3 '+FRA' size 128M reuse;
Database altered.
SQL> select a.group#, a.member, b.bytes from v$logfile a, v$log b where a.group# = b.group#;
    GROUP# MEMBER                                                                 BYTES
---------- ----------------------------------------------------------------- ----------
         3 +FRA/ORCL/ONLINELOG/group_3.260.902589839                          134217728
         2 +FRA/ORCL/ONLINELOG/group_2.259.902589793                          134217728
         1 +FRA/ORCL/ONLINELOG/group_1.258.902589727                          134217728
 - Multiplex the online redo logs

SQL> alter database add logfile member '+DATA' to group 1;
Database altered.
SQL> alter database add logfile member '+DATA' to group 2;
Database altered.
SQL> alter database add logfile member '+DATA' to group 3;
Database altered.
SQL> select a.group#, a.member, b.bytes from v$logfile a, v$log b where a.group# = b.group#;
    GROUP# MEMBER                                                                 BYTES
---------- ----------------------------------------------------------------- ----------
         3 +FRA/ORCL/ONLINELOG/group_3.260.902589839                          134217728
         2 +FRA/ORCL/ONLINELOG/group_2.259.902589793                          134217728
         1 +FRA/ORCL/ONLINELOG/group_1.258.902589727                          134217728
         1 +DATA/ORCL/ONLINELOG/group_1.285.902589995                         134217728
         2 +DATA/ORCL/ONLINELOG/group_2.286.902590003                         134217728
         3 +DATA/ORCL/ONLINELOG/group_3.287.902590007                         134217728
6 rows selected.

 -  Relocate the SPFILE from the local file system to an ASM disk group


 SQL> show parameter pfile
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/12.0.1
                                                 /db_1/dbs/spfileORCL.ora
SQL> create spfile='+DATA/ORCL/spfileORCL.ora' from pfile='initORCL.ora';
File created.
 - Shutdown the DB instance
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>


 - Update the text-based initORCL.ora file with the new location of the SPFILE in ASM

[oracle@testRAC1 dbs]$ echo "SPFILE='+DATA/ORCL/spfileORCL.ora'" > $ORACLE_HOME/dbs/initORCL.ora


 - Rename the old SPFILE on the local file system so that the new text-based initORCL.ora will be used

[oracle@testRAC1 dbs]$ mv $ORACLE_HOME/dbs/spfileORCL.ora $ORACLE_HOME/dbs/intORCL_bkp.ora


 - Open the Oracle database using the new SPFILE

SQL> startup
ORACLE instance started.
Total System Global Area  834666496 bytes
Fixed Size                  2929888 bytes
Variable Size             557845280 bytes
Database Buffers          268435456 bytes
Redo Buffers                5455872 bytes
Database mounted.
Database opened.
SQL>
SQL> show parameter pfile;
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      +DATA/ORCL/spfileorcl.ora
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
+DATA/ORCL/CONTROLFILE/current.276.902588359
+FRA/ORCL/CONTROLFILE/current.257.902588361
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/ORCL/DATAFILE/system.279.902588631
+DATA/ORCL/DATAFILE/sysaux.278.902588631
+DATA/ORCL/DATAFILE/undotbs1.280.902588631
+DATA/ORCL/DATAFILE/users.281.902588631
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
+DATA/ORCL/TEMPFILE/temp.284.902589053

- We have now completely migrated all our database files to ASM storage. Take a full backup of your database at this point


[oracle@testRAC1 ~]$ rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Sun Jan 31 15:59:34 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1428644494)
RMAN>  configure device type disk parallelism 4;
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
RMAN>
RMAN> RMAN> alter database archivelog;
Statement processed
RMAN> backup database archivelog all;
Starting backup at 31-JAN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=31 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=32 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=33 device type=DISK
specification does not match any archived log in the repository
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=+DATA/ORCL/DATAFILE/sysaux.278.902588631
channel ORA_DISK_1: starting piece 1 at 31-JAN-16
:
:
piece handle=+FRA/ORCL/BACKUPSET/2016_01_31/nnndf0_tag20160131t160139_0.262.902592101 tag=TAG20160131T160139 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:18
Finished backup at 31-JAN-16


 - You can do a cleanup of your filesystem on disk at this point as well as delete backup copies from RMAN which your created earlier


Thanks for reading. Your feedback is always welcome...

Saturday, January 30, 2016

Manually Migrate a single instance Oracle 12cR1 database with file system storage to an Oracle RAC environment with ASM Storage

Part I - Move your single instance database over to a RAC environment

1. Take a backup directory of your ORACLE_HOME for the ORCL database under the oradata directory
[oracle@testserver01 12.2.0]$ cd /oradata
[oracle@testserver01 12.2.0]$ mkdir backup
[oracle@testserver01 12.2.0]$ cd $ORACLE_HOME
[oracle@testserver01 12.2.0]$ cd ../
[oracle@testserver01 12.2.0]$tar -cvf /oradata/backup/DB12c_HOME.tar db_1



2. zip up the backup file to make it more light weight
[oracle@testserver01 12.2.0]$ cd /oradata/backup
[oracle@testserver01 backup]$ ll
total 5403744
-rw-r--r-- 1 oracle oinstall 5528023040 Jan 30 09:58 DB12c_HOME.tar
[oracle@testserver01 backup]$ gzip DB12c_HOME.tar



3. Make the appropriate ORACLE_HOME directory in the RAC server
[oracle@testRAC1 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1
[oracle@testRAC1 ~]$
[oracle@testRAC1 ~]$ cd $ORACLE_HOME
[oracle@testRAC1 db_1]$ pwd
/u01/app/oracle/product/11.2.0/db_1
[oracle@testRAC1 db_1]$ cd ../../
[oracle@testRAC1 product]$ pwd
/u01/app/oracle/product
[oracle@testRAC1 product]$ mkdir 12.0.1
[oracle@testRAC1 product]$ cd 12.0.1
[oracle@testRAC1 db_1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC1 db_1]$



4. Move the zipped file to the RAC server
[oracle@testserver01 backup]$ ll
total 2727320
-rw-r--r-- 1 oracle oinstall 2790039829 Jan 30 09:58 DB12c_HOME.tar.gz
[oracle@testserver01 backup]$ pwd
/oradata/backup
[oracle@testserver01 backup]$ scp DB12c_HOME.tar.gz oracle@testRAC1:/u01/app/oracle/product/12.0.1
The authenticity of host 'testRAC1 (192.168.x.x)' can't be established.
RSA key fingerprint is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'testRAC1,192.168.x.x' (RSA) to the list of known hosts.
oracle@testRAC1's password:
DB12c_HOME.tar.gz                                                                        100% 2661MB   8.6MB/s   05:11
[oracle@testserver01 backup]$



5. unzip & untar the 12c HOME under the appropriate location in the RAC server
[oracle@testRAC1 12.0.1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC1 12.0.1]$ ll
total 2727320
-rw-r--r-- 1 oracle oinstall 2790039829 Jan 30 10:36 DB12c_HOME.tar.gz
[oracle@testRAC1 12.0.1]$ gunzip DB12c_HOME.tar.gz
[oracle@testRAC1 12.0.1]$ ll
total 5403744
-rw-r--r-- 1 oracle oinstall 5528023040 Jan 30 10:36 DB12c_HOME.tar
[oracle@testRAC1 12.0.1]$ tar -xvf DB12c_HOME.tar
db_1/
db_1/lib/
db_1/lib/sscoreed.o
db_1/lib/libsql12.a
db_1/lib/libclntsh.so.11.1
db_1/lib/libons.so
db_1/lib/libsrvmhas12.so
db_1/lib/libclsce12.so

You now have your db_1 directory created for the 12c ORACLE_HOME



6. Remove the large tar file from your system
[oracle@testRAC1 12.0.1]$ ll
total 5403748
drwxr-xr-x 70 oracle oinstall       4096 Jan 30 09:30 db_1
-rw-r--r--  1 oracle oinstall 5528023040 Jan 30 10:36 DB12c_HOME.tar
[oracle@testRAC1 12.0.1]$ rm -f DB12c_HOME.tar
[oracle@testRAC1 12.0.1]$ ll
total 4
drwxr-xr-x 70 oracle oinstall 4096 Jan 30 09:30 db_1
[oracle@testRAC1 12.0.1]$



7. Go to the 12c ORACLE_HOME/bin directory as and link the Oracle 12c Software binaries to your new OS (This simulates the process of a clean Oracle Software install).
   Tail the logfile generated on a separate terminal & see the linking that's being done (just so you know how to tail log files when running processes)
[oracle@testRAC1 12.0.1]$ pwd
/u01/app/oracle/product/12.0.1
[oracle@testRAC1 12.0.1]$ ll
total 4
drwxrwxr-x 70 oracle oinstall 4096 Jan 30 09:30 db_1
[oracle@testRAC1 12.0.1]$ cd db_1
[oracle@testRAC1 db_1]$ pwd
/u01/app/oracle/product/12.0.1/db_1
[oracle@testRAC1 db_1]$ export ORACLE_HOME=/u01/app/oracle/product/12.0.1/db_1
[oracle@testRAC1 db_1]$ cd $ORACLE_HOME/bin
[oracle@testRAC1 bin]$ pwd
/u01/app/oracle/product/12.0.1/db_1/bin
[oracle@testRAC1 bin]$ ./relink all
writing relink log to: /u01/app/oracle/product/12.0.1/db_1/install/relink.log
[oracle@testRAC1 bin]$
[oracle@testRAC1 bin]$ tail -f /u01/app/oracle/product/12.0.1/db_1/install/relink.log

When the command prompt returns, your relinking is done.
STOP!! Go back to your single instance environment !!

8. Take an inventory of all your controlfiles, datafiles any archived redo log files from your single instance env't to the RAC server
- First, take an inventory of all the files in your single instance environment

SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oradata/ORCL/controlfile/o1_mf_c985pl01_.ctl
/u01/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_c985ploz_.ctl

SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oradata/ORCL/onlinelog/o1_mf_3_c985q5oy_.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/o1_mf_3_c985q5t1_.log
/oradata/ORCL/onlinelog/o1_mf_2_c985pxxc_.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/o1_mf_2_c985pzj6_.log
/oradata/ORCL/onlinelog/o1_mf_1_c985pq3w_.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/o1_mf_1_c985pqfh_.log

SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oradata/ORCL/datafile/o1_mf_system_c985kcf0_.dbf
/oradata/ORCL/datafile/o1_mf_sysaux_c985g9fz_.dbf
/oradata/ORCL/datafile/o1_mf_undotbs1_c985o01b_.dbf
/oradata/ORCL/datafile/o1_mf_users_c985nyqx_.dbf

SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/oradata/ORCL/datafile/o1_mf_temp_c985rt8m_.tmp

STOP!! Go back to your RAC environment & create the appropriate parent directories for all the DB files above

[oracle@testRAC1 ~]$ cd /u01
[oracle@testRAC1 u01]$ ll
total 4
drwxrwxr-x 8 oracle oinstall 4096 Jan 28 18:23 app
[oracle@testRAC1 u01]$ mkdir -p oradata/ORCL
[oracle@testRAC1 u01]$ cd /u01/app/oracle
[oracle@testRAC1 oracle]$ mkdir -p fast_recovery_area/ORCL

STOP!! Go back to your single instance environment and move the files over !! Will take a while to transfer all directories and files depending on how large your database is



[oracle@testserver01 ORCL]$ scp -r /oradata/ORCL/* oracle@testRAC1:/u01/oradata/ORCL/
oracle@testRAC1's password:
o1_mf_c985pl01_.ctl                                                                 100% 9808KB   9.6MB/s   00:01
o1_mf_users_c985nyqx_.dbf                                                           100% 5128KB   1.0MB/s   00:05
o1_mf_temp_c985rt8m_.tmp                                                            100%   60MB  12.0MB/s   00:05
o1_mf_sysaux_c985g9fz_.dbf                                                          100% 1010MB   7.5MB/s   02:15
o1_mf_system_c985kcf0_.dbf                                                          100%  810MB   6.5MB/s   02:05
o1_mf_undotbs1_c985o01b_.dbf                                                        100%   75MB  10.7MB/s   00:07
o1_mf_1_c985pq3w_.log                                                               100%   50MB  12.5MB/s   00:04
o1_mf_2_c985pxxc_.log                                                               100%   50MB   4.6MB/s   00:11
o1_mf_3_c985q5oy_.log                                                               100%   50MB   6.3MB/s   00:08
[oracle@testserver01 ORCL]$
[oracle@testserver01 ORCL]$ scp -r /u01/app/oracle/fast_recovery_area/ORCL/* oracle@testRAC1:/u01/app/oracle/fast_recovery_area/ORCL
oracle@testRAC1's password:
o1_mf_c985ploz_.ctl                                                                 100% 9808KB 576.9KB/s   00:17
o1_mf_3_c985q5t1_.log                                                               100%   50MB   1.0MB/s   00:50
o1_mf_1_c985pqfh_.log                                                               100%   50MB   3.3MB/s   00:15
o1_mf_2_c985pzj6_.log                                                               100%   50MB   4.2MB/s   00:12
[oracle@testserver01 ORCL]$
[oracle@testserver01 ORCL]$



STOP!! Go back to your RAC environment & bring up the single instance database



9. create a pfile from the spfile, then modify the controlfile and db_create_file_dest to point to their new locations
Also create the adump directory
[oracle@testRAC1 ~]$ cd $ORACLE_HOME/dbs
[oracle@testRAC1 dbs]$ ll
total 44
-rwxrwxr-x 1 oracle oinstall 1544 Jan 30 11:33 hc_ORCL.dat
-rwxrwxr-x 1 oracle oinstall 1544 Jan 13 21:50 hc_ZFPRD1.dat
-rwxrwxr-x 1 oracle oinstall 2992 Feb  3  2012 init.ora
-rwxrwxr-x 1 oracle oinstall   24 Jan 11 15:50 lkORCL
-rwxrwxr-x 1 oracle oinstall   24 Jan 13 20:39 lkZFPRD1
-rwxrwxr-x 1 oracle oinstall 7680 Jan 11 15:58 orapwORCL
-rwxrwxr-x 1 oracle oinstall 7680 Jan 13 21:33 orapwZFPRD1
-rwxrwxr-x 1 oracle oinstall 3584 Jan 30 09:30 spfileORCL.ora
-rwxrwxr-x 1 oracle oinstall 3584 Jan 13 23:52 spfileZFPRD1.ora
[oracle@testRAC1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jan 30 12:58:06 2016

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

Connected to an idle instance.
SQL> create pfile from spfile;

File created.

SQL> !
[oracle@testRAC1 dbs]$ ls -ltr
total 48
-rwxrwxr-x 1 oracle oinstall 2992 Feb  3  2012 init.ora
-rwxrwxr-x 1 oracle oinstall   24 Jan 11 15:50 lkORCL
-rwxrwxr-x 1 oracle oinstall 7680 Jan 11 15:58 orapwORCL
-rwxrwxr-x 1 oracle oinstall   24 Jan 13 20:39 lkZFPRD1
-rwxrwxr-x 1 oracle oinstall 7680 Jan 13 21:33 orapwZFPRD1
-rwxrwxr-x 1 oracle oinstall 1544 Jan 13 21:50 hc_ZFPRD1.dat
-rwxrwxr-x 1 oracle oinstall 3584 Jan 13 23:52 spfileZFPRD1.ora
-rwxrwxr-x 1 oracle oinstall 3584 Jan 30 09:30 spfileORCL.ora
-rwxrwxr-x 1 oracle oinstall 1544 Jan 30 12:58 hc_ORCL.dat
-rw-r--r-- 1 oracle oinstall  989 Jan 30 12:58 initORCL.ora
[oracle@testRAC1 dbs]$
[oracle@testRAC1 dbs]$ vi initORCL.ora
*control_files='/u01/oradata/ORCL/controlfile/o1_mf_c985pl01_.ctl','/u01/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_c985ploz_.ctl'
*.db_create_file_dest='/u01/oradata'

[oracle@testRAC1 ~]$ cd $ORACLE_BASE/admin/ORCL
[oracle@testRAC1 ORCL]$ mkdir adump
[oracle@testRAC1 ORCL]$ ll
total 8
drwxr-xr-x 2 oracle oinstall 4096 Jan 30 13:11 adump
drwxr-xr-x 2 oracle oinstall 4096 Jan 30 13:09 xdb_wallet
[oracle@testRAC1 ORCL]$



10. create a new controlfile for your database with your basic redo & datafile information using a script similar to the following

[oracle@testRAC1 dbs]$ vi create_controlfile.sql
[oracle@testRAC1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sat Jan 30 14:41:33 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> @create_controlfile.sql
SQL> spool create_controlfile.log
SQL>
SQL> STARTUP NOMOUNT
ORACLE instance started.

Total System Global Area  834666496 bytes
Fixed Size                  2929888 bytes
Variable Size             557845280 bytes
Database Buffers          268435456 bytes
Redo Buffers                5455872 bytes
SQL>
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
  2      MAXLOGFILES 32
  3      MAXLOGMEMBERS 2
  4      MAXDATAFILES 32
  5      MAXINSTANCES 1
  6      MAXLOGHISTORY 449
  7  LOGFILE
  8    GROUP 1 '/u01/oradata/ORCL/onlinelog/o1_mf_1_c985pq3w_.log',
  9    GROUP 2 '/u01/oradata/ORCL/onlinelog/o1_mf_2_c985pxxc_.log',
 10    GROUP 3 '/u01/oradata/ORCL/onlinelog/o1_mf_3_c985q5oy_.log'
 11  DATAFILE
 12    '/u01/oradata/ORCL/datafile/o1_mf_system_c985kcf0_.dbf',
 13    '/u01/oradata/ORCL/datafile/o1_mf_sysaux_c985g9fz_.dbf',
 14    '/u01/oradata/ORCL/datafile/o1_mf_undotbs1_c985o01b_.dbf',
 15    '/u01/oradata/ORCL/datafile/o1_mf_users_c985nyqx_.dbf'
 16  CHARACTER SET WE8MSWIN1252
 17  ;

Control file created.

SQL>
SQL> recover database;
Media recovery complete.
SQL>
SQL> alter database open;

Database altered.

SQL>
SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
ORCL             OPEN

SQL>

11. Take a backup of your spfile

SQL> create pfile from spfile;

File created.

SQL>



11. Take an inventory of all your datafiles, compare with the one you took earlier and add those that are missing. Also multiplex as needed
SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/controlfile/o1_mf_c985pl01_.ctl
/u01/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_c985ploz_.ctl

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/ORCL/datafile/o1_mf_system_c985kcf0_.dbf
/oradata/ORCL/datafile/o1_mf_sysaux_c985g9fz_.dbf
/oradata/ORCL/datafile/o1_mf_undotbs1_c985o01b_.dbf
/oradata/ORCL/datafile/o1_mf_users_c985nyqx_.dbf

SQL> alter database add logfile member '/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo01.log' to group 1;

Database altered.

SQL> alter database add logfile member '/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo02.log ' to group 2;

Database altered.

SQL> alter database add logfile member '/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo03.log' to group 3;

Database altered.
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/oradata/ORCL/onlinelog/o1_mf_3_c985q5oy_.log
/u01/oradata/ORCL/onlinelog/o1_mf_2_c985pxxc_.log
/u01/oradata/ORCL/onlinelog/o1_mf_1_c985pq3w_.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo01.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo02.log
/u01/app/oracle/fast_recovery_area/ORCL/onlinelog/redo03.log

6 rows selected.



12. Add a tempfile to the TEMP tablespace
SQL> select name from v$tempfile;
no rows selected
SQL> alter tablespace TEMP add tempfile '/u01/oradata/ORCL/datafile/temp01.dbf' size 128M reuse;
Tablespace altered.
SQL>
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/ORCL/datafile/temp01.dbf
SQL>
13. Bounce the database to ensure a "clean" startup
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>
SQL> startup
ORACLE instance started.
Total System Global Area  834666496 bytes
Fixed Size                  2929888 bytes
Variable Size             557845280 bytes
Database Buffers          268435456 bytes
Redo Buffers                5455872 bytes
Database mounted.
Database opened.
SQL>
SQL>
SQL> select instance_name,status from v$instance;
INSTANCE_NAME    STATUS
---------------- ------------
ORCL             OPEN
SQL> select name,log_mode,open_mode,database_role from v$database;
NAME      LOG_MODE     OPEN_MODE            DATABASE_ROLE
--------- ------------ -------------------- ----------------
ORCL      NOARCHIVELOG READ WRITE           PRIMARY
SQL>
Your ORCL database is now up and running in the RAC enironment. Part II of this article will be to convert this single instance
that uses filesystem storage to an Oracle RAC database using ASM.
Thanks for reading. Your feedback is very welcome