Thursday, May 15, 2014

How to configure database with Oracle 12c Restart

##################################################
How to configure database with Oracle 12c Restart
#################################################

Note: Although the Oracle Grid Infrastructure automatically registers database if GI is installed prior to DB but
in my case, I already had Oracle database created and GI was added later on.
Now I need to register my Oracle database with Oracle Restart (Grid Infrastructure on Standalone)


============================
Current configuration
============================
SQL> !srvctl config database

Note: The srvctl command is running from Oracle database ORACLE_HOME/bin


============================
Add database 
============================
SQL> !/u03/app/oracle/12.1.0/12cR1/bin/srvctl add database -d cdbdemo -o /u03/app/oracle/12.1.0/12cR1


SQL> !/u03/app/oracle/12.1.0/12cR1/bin/srvctl config
cdbdemo


SQL> !/u03/app/oracle/12.1.0/12cR1/bin/srvctl config database -d cdbdemo
Database unique name: cdbdemo
Database name:
Oracle home: /u03/app/oracle/12.1.0/12cR1
Oracle user: oracle
Spfile:
Password file:
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Database instance: cdbdemo
Disk Groups:
Services:



============================
Testing
============================
[root@dbtrmrk init.d]# ps -ef | grep smon | grep -v grep
oracle   20922     1  0 03:48 ?        00:00:00 asm_smon_+ASM
oracle   21824     1  0 05:17 ?        00:00:00 ora_smon_cdbdemo


[root@dbtrmrk init.d]# kill -9 21824
[root@dbtrmrk init.d]# ps -ef | grep smon | grep -v grep
oracle   20922     1  0 03:48 ?        00:00:00 asm_smon_+ASM

NOte: Oracle Database was not started by Restart....

hmm...what is missing? spfile ???? let's try





SQL> !srvctl modify database -db cdbdemo -spfile /u03/app/oracle/12.1.0/12cR1/dbs/spfilecdbdemo.ora


SQL> !srvctl config database -db cdbdemo
Database unique name: cdbdemo
Database name:
Oracle home: /u03/app/oracle/12.1.0/12cR1
Oracle user: oracle
Spfile: /u03/app/oracle/12.1.0/12cR1/dbs/spfilecdbdemo.ora
Password file:
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Database instance: cdbdemo
Disk Groups: DATA
Services:




[root@dbtrmrk init.d]# ps -ef | grep pmon
oracle   23317     1  0 06:09 ?        00:00:00 asm_pmon_+ASM
oracle   24267     1  0 06:14 ?        00:00:00 ora_pmon_cdbdemo

[root@dbtrmrk init.d]# kill -9 24267

Fri May 09 06:29:34 2014
Instance started by oraagent
Completed: ALTER DATABASE MOUNT /* db agent *//* {0:9:7} */
Fri May 09 06:30:32 2014
CJQ0 started with pid=56, OS id=27907
Completed: ALTER DATABASE OPEN /* db agent *//* {0:9:7} */



[root@dbtrmrk init.d]# /u10/app/gridbase/product/grid/12gR1/bin/crsctl status resource -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMDG.dg
               ONLINE  ONLINE       dbtrmrk                  STABLE
ora.DATA.dg
               ONLINE  ONLINE       dbtrmrk                  STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       dbtrmrk                  STABLE
ora.asm
               ONLINE  ONLINE       dbtrmrk                  Started,STABLE
ora.ons
               OFFLINE OFFLINE      dbtrmrk                  STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cdbdemo.db
      1        ONLINE  ONLINE       dbtrmrk                  Open,STABLE
ora.cssd
      1        ONLINE  ONLINE       dbtrmrk                  STABLE
ora.diskmon
      1        OFFLINE OFFLINE                               STABLE
ora.evmd
      1        ONLINE  ONLINE       dbtrmrk                  STABLE
--------------------------------------------------------------------------------

Enjoy....Abid Malik




How to Move SPFILE & Password file into different ASM DISKGROUP

###############################################################
How to Move SPFILE & Password file into different ASM DISKGROUP
###############################################################


===============
Password File
==============
ASMCMD> pwget --asm
+DATA/ASM/PASSWORD/pwdasm.270.847074049

ASMCMD> pwcopy +DATA/ASM/PASSWORD/pwdasm.270.847074049 +ASMDG/orapwasm
copying +DATA/ASM/PASSWORD/pwdasm.270.847074049 -> +ASMDG/orapwasm

ASMCMD> ls -ltr +ASMDG/orapwasm


Type      Redund  Striped  Time             Sys  Name
PASSWORD  UNPROT  COARSE   MAY 09 03:00:00  N    orapwasm => +ASMDG/ASM/PASSWORD/pwdasm.256.847078823

ASMCMD> pwset --asm +ASMDG/ASM/PASSWORD/pwdasm.256.847078823

ASMCMD> pwget --asm
+ASMDG/ASM/PASSWORD/pwdasm.256.847078823


===============
SPFILE File
==============
ASMCMD> spget
+DATA/ASM/ASMPARAMETERFILE/REGISTRY.253.847072573

Note: I did not create ASM/ASMPFILE folder
ASMCMD> spcopy +DATA/ASM/ASMPARAMETERFILE/REGISTRY.253.847072573 +ASMDG/ASM/ASMPFILE/

ORA-15056: additional error message
ORA-17502: ksfdcre:4 Failed to create file +ASMDG/REGISTRY.253.847072573
ORA-15221: ASM operation requires compatible.asm of 11.2.0.0.0 or higher
ORA-06512: at line 7 (DBD ERROR: OCIStmtExecute)
ASMCMD> exit


SQL>ALTER DISKGROUP ASMDG SET ATTRIBUTE 'compatible.asm'='12.1';

Diskgroup altered.


ASMCMD> ls -ltr +ASMDG/ASM/ASMPARAMETERFILE/

Type              Redund  Striped  Time             Sys  Name
ASMPARAMETERFILE  UNPROT  COARSE   MAY 09 03:00:00  Y    REGISTRY.253.847078307


ASMCMD> spset +ASMDG/ASM/ASMPARAMETERFILE/REGISTRY.253.847078307


ASMCMD> spget --asm
+DATA/ASM/ASMPARAMETERFILE/REGISTRY.253.847072573


============
Verification
============
ASMCMD> shutdown --immediate
ASM diskgroups dismounted
ASM instance shutdown
Connected to an idle instance.


SQL> !crsctl stop has
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'dbtrmrk'
CRS-2673: Attempting to stop 'ora.evmd' on 'dbtrmrk'
CRS-2673: Attempting to stop 'ora.LISTENER.lsnr' on 'dbtrmrk'
CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'dbtrmrk' succeeded
CRS-2677: Stop of 'ora.evmd' on 'dbtrmrk' succeeded
CRS-2673: Attempting to stop 'ora.cssd' on 'dbtrmrk'
CRS-2677: Stop of 'ora.cssd' on 'dbtrmrk' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'dbtrmrk' has completed
CRS-4133: Oracle High Availability Services has been stopped.

SQL> !crsctl start has
CRS-4123: Oracle High Availability Services has been started.



ASMCMD> startup
ASM instance started

Total System Global Area 1135747072 bytes
Fixed Size                  2297344 bytes
Variable Size            1108283904 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted

NAME                           STATE
------------------------------ -----------
ASMDG                          MOUNTED
DATA                           MOUNTED


SQL> !asmcmd spget --asm
+ASMDG/ASM/ASMPARAMETERFILE/REGISTRY.253.847078307

SQL>  !asmcmd pwget --asm
+ASMDG/ASM/PASSWORD/pwdasm.256.847078823



============
Remove old
============
ASMCMD> rm -r DATA/orapwasm
You may delete multiple files and/or directories.
Are you sure? (y/n) y


ASMCMD> rm -r DATA/ASM/ASMPARAMETERFILE
You may delete multiple files and/or directories.
Are you sure? (y/n) y

Enjoy....Abid Malik

Wednesday, May 14, 2014

How to Migrate Oracle 12c Database to ASM

###############################################
How to Migrate Oracle 12c Database to ASM
###############################################


======================================================
Step 1. Install Grid Infrastructure in new ORACLE_HOME
======================================================
Note: Already done (Read my post about it).



======================================================
Step 2. Creast ASM Instance
======================================================
Note: Already done (Read my post about it).



======================================================
Step 3. Create PFILE and modify control_file parameter
======================================================
SQL> create pfile from spfile;

File created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> !vi $ORACLE_HOME/dbs/initcdbdemo.ora

control_files='+DATA'

SQL> CREATE SPFILE FROM PFILE;

File created.



========================================================
Step 4. Note down the location of Current Control Files
========================================================
SQL> select name from v$controlfile;

NAME
------------------------------------------------------------
/u03/oradata/cdbdemo/control01.ctl
/u01/app/oracle/fast_recovery_area/cdbdemo/control02.ctl




========================================================
Step 5. Startup in NOMOUNT
========================================================
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             788530952 bytes
Database Buffers          452984832 bytes
Redo Buffers                8859648 bytes



========================================================
Step 6. Restore Controlfile and MOUNT
========================================================
SQL> !rman target /

Recovery Manager: Release 12.1.0.1.0 - Production on Thu May 8 03:25:17 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CDBDEMO (not mounted)


RMAN> restore controlfile from '/u03/oradata/cdbdemo/control01.ctl';

Starting restore at 08-MAY-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=126 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=+DATA/CDBDEMO/CONTROLFILE/current.256.846991571
Finished restore at 08-MAY-14


RMAN> alter database mount;

Statement processed
released channel: ORA_DISK_1


========================================================
Step 7. Backup database into ASM
========================================================
RMAN> backup as copy database format '+DATA';

Starting backup at 08-MAY-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=126 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u03/oradata/cdbdemo/system01.dbf
output file name=+DATA/CDBDEMO/DATAFILE/system.257.846991607 tag=TAG20140508T032646 RECID=3 STAMP=846991644
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u03/oradata/cdbdemo/undotbs01.dbf
output file name=+DATA/CDBDEMO/DATAFILE/undotbs1.258.846991651 tag=TAG20140508T032646 RECID=4 STAMP=846991697
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=/u03/oradata/cdbdemo/sysaux01.dbf
output file name=+DATA/CDBDEMO/DATAFILE/sysaux.259.846991707 tag=TAG20140508T032646 RECID=5 STAMP=846991740
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u03/oradata/cdbdemo/pdbseed/sysaux01.dbf
output file name=+DATA/CDBDEMO/F84403ED7DE357E2E043C9A8A8C0FB1F/DATAFILE/sysaux.260.846991743 tag=TAG20140508T032646 RECID=6 STAMP=846991771
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u03/oradata/cdbdemo/pdbseed/system01.dbf
output file name=+DATA/CDBDEMO/F84403ED7DE357E2E043C9A8A8C0FB1F/DATAFILE/system.261.846991777 tag=TAG20140508T032646 RECID=7 STAMP=846991790
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u03/oradata/cdbdemo/users01.dbf
output file name=+DATA/CDBDEMO/DATAFILE/users.262.846991793 tag=TAG20140508T032646 RECID=8 STAMP=846991792
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 08-MAY-14

Starting Control File and SPFILE Autobackup at 08-MAY-14
piece handle=/u01/app/oracle/fast_recovery_area/CDBDEMO/autobackup/2014_05_08/o1_mf_s_846990695_9ppdmoxb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 08-MAY-14



========================================================
Step 8. Switch to ASM
========================================================
RMAN> switch database to copy;

datafile 1 switched to datafile copy "+DATA/CDBDEMO/DATAFILE/system.257.846991607"
datafile 3 switched to datafile copy "+DATA/CDBDEMO/DATAFILE/sysaux.259.846991707"
datafile 4 switched to datafile copy "+DATA/CDBDEMO/DATAFILE/undotbs1.258.846991651"
datafile 5 switched to datafile copy "+DATA/CDBDEMO/F84403ED7DE357E2E043C9A8A8C0FB1F/DATAFILE/system.261.846991777"
datafile 6 switched to datafile copy "+DATA/CDBDEMO/DATAFILE/users.262.846991793"
datafile 7 switched to datafile copy "+DATA/CDBDEMO/F84403ED7DE357E2E043C9A8A8C0FB1F/DATAFILE/sysaux.260.846991743"



========================================================
Step 9. Open Database
========================================================
RMAN> alter database open;

Statement processed




========================================================
Step 10. Move Online Redo Log Files
========================================================
RMAN> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/redo03.log
/u03/oradata/cdbdemo/redo02.log
/u03/oradata/cdbdemo/redo01.log

RMAN> ALTER DATABASE DROP LOGFILE GROUP 2;

Statement processed


RMAN> ALTER DATABASE ADD LOGFILE GROUP 2 ('+DATA/CDBDEMO/redo02.log') SIZE 10M;

Statement processed


RMAN> SELECT group#,status from V$LOG;

    GROUP# STATUS
---------- ----------------
         1 ACTIVE
         2 CURRENT
         3 UNUSED
         4 UNUSED

RMAN> ALTER SYSTEM CHECKPOINT;

Statement processed



========================================================
Step 11. Move TEMP Files - CDB
========================================================
SQL> select name from v$tempfile;

NAME
------------------------------------------------------------
/u03/oradata/cdbdemo/temp01.dbf
/u03/oradata/cdbdemo/pdbseed/pdbseed_temp01.dbf

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA' SIZE 10M;

Tablespace altered.



========================================================
Step 12. Move TEMP Files - PDBS
========================================================
SQL> ALTER SESSION SET CONTAINER=PDB$SEED;

Session altered.

SQL> select name from v$tempfile;

NAME
------------------------------------------------------------
/u03/oradata/cdbdemo/pdbseed/pdbseed_temp01.dbf


SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA' SIZE 20M;

Tablespace altered.




============================================
MOVE DATAFILE ONLINE to ASM (Oracle 12c)
===========================================
SQL> SELECT FILE_NAME,Round( BYTES/1024/1024) "SizeMB",STATUS,ONLINE_STATUS FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME = 'USERS';

FILE_NAME                                                   SizeMB STATUS          ONLINE_STATUS
------------------------------------------------------- ---------- --------------- ---------------
+DATA/CDBDEMO/DATAFILE/users.262.846991793                    5.00 AVAILABLE       ONLINE
/u03/oradata/cdbdemo/users02.dbf                             10.00 AVAILABLE       ONLINE


SQL> ALTER DATABASE MOVE DATAFILE '/u03/oradata/cdbdemo/users02.dbf' TO '+DATA';

Database altered.


Enjoy....Abid Malik

Tuesday, May 13, 2014

How to install Grid Infrastructure for Oracle 12c

##################################################
How to install Grid Infrastructure for Oracle 12c
##################################################


=================================================
Step 1. Download Grid Infrastructure software
=================================================
[oracle@dbtrmrk tmp]$ ll
total 1906440
drwxr-xr-x  3 oracle oinstall       4096 Apr 30 05:39 CVU_12.1.0.1.0_oracle
drwxr-xr-x  2 oracle oinstall       4096 May  4 03:54 grid_1201
-rw-r--r--  1 oracle oinstall 1750478910 May 10  2014 linuxamd64_12c_grid_1of2.zip
-rw-r--r--  1 oracle oinstall  201673595 May 10  2014 linuxamd64_12c_grid_2of2.zip




=================================================
Step 2. Unzip Grid Infrastructure software
=================================================
[oracle@dbtrmrk tmp]$ unzip linuxamd64_12c_grid_1of2.zip -d /tmp/grid_1201/
[oracle@dbtrmrk tmp]$ unzip linuxamd64_12c_grid_2of2.zip -d /tmp/grid_1201/



=================================================
Step 3. Create Dir for Grid Infrastructure Home
=================================================
[root@dbtrmrk tmp]# mkdir /u10
[root@dbtrmrk tmp]# chown -R oracle:oinstall /u10
[root@dbtrmrk tmp]# su - oracle
[oracle@dbtrmrk ~]$ mkdir -p /u10/app/gridbase/product/grid/12gR1




===============================================================
Step 4. Set ORACLE_HOME and ORACLE_BASE for Grid Infrastructure
===============================================================
/u10/app/gridbase/product/grid/12gR1
[oracle@dbtrmrk 12gR1]$ export ORACLE_BASE=/u10/app/gridbase
[oracle@dbtrmrk 12gR1]$ export ORACLE_HOME=/u10/app/gridbase/product/grid/12gR1
[oracle@dbtrmrk 12gR1]$ cd /tmp/grid_1201/grid/response/




=====================================================
Step 5. Prepare Response File for Grid Infrastructure
=====================================================
[oracle@dbtrmrk response]$ cat grid.rsp

#------------------------------------------------------------------------------
# Do not change the following system generated value.
#------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_crsinstall_response_schema_v12.1.0
ORACLE_HOSTNAME=dbtrmrk.localdomain
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en
oracle.install.option=CRS_SWONLY
ORACLE_BASE=/u10/app/gridbase
ORACLE_HOME=/u10/app/gridbase/product/grid/12gR1
oracle.install.asm.OSDBA=dba
oracle.install.asm.OSOPER=oinstall
oracle.install.asm.OSASM=dba
oracle.install.crs.config.ClusterType=STANDARD
oracle.install.crs.config.gpnp.configureGNS=true
oracle.install.crs.config.autoConfigureClusterNodeVIP=true
oracle.install.crs.config.gpnp.gnsOption=CREATE_NEW_GNS
oracle.install.crs.managementdb.configure=true
oracle.install.crs.config.sharedFileSystemStorage.votingDiskLocations=
oracle.install.crs.config.sharedFileSystemStorage.votingDiskRedundancy=NORMAL
oracle.install.crs.config.sharedFileSystemStorage.ocrLocations=
oracle.install.crs.config.sharedFileSystemStorage.ocrRedundancy=NORMAL
oracle.install.crs.config.useIPMI=false
oracle.install.crs.config.ignoreDownNodes=false
oracle.installer.autoupdates.option=SKIP_UPDATES
PROXY_PORT=0




==============================================================
Step 7. Run Installer for Grid Infrastructure Software install
==============================================================
[oracle@dbtrmrk grid]$ ./runInstaller -silent -responseFile /tmp/grid_1201/grid/response/grid.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 12558 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3999 MB    Passed
You can find the log of this install session at:
 /u01/app/oraInventory/logs/installActions2014-05-04_10-30-56AM.log

The installation of Oracle Grid Infrastructure 12c was successful.

As a root user, execute the following script(s):
        1. /u10/app/gridbase/product/grid/12gR1/root.sh





=====================================================
Step 8. Run script as root for Grid Infrastructure
=====================================================
[root@dbtrmrk tmp]# /u10/app/gridbase/product/grid/12gR1/root.sh
Check /u10/app/gridbase/product/grid/12gR1/install/root_dbtrmrk.localdomain_2014-05-04_10-44-03.log for the output of root script

[root@dbtrmrk tmp]# cat /u10/app/gridbase/product/grid/12gR1/install/root_dbtrmrk.localdomain_2014-05-04_10-44-03.log
Performing root user operation for Oracle 12c

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u10/app/gridbase/product/grid/12gR1
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.

To configure Grid Infrastructure for a Stand-Alone Server run the following command as the root user:
/u10/app/gridbase/product/grid/12gR1/perl/bin/perl -I/u10/app/gridbase/product/grid/12gR1/perl/lib -I/u10/app/gridbase/product/grid/12gR1/crs/install /u10/app/gridbase/product/grid/12gR1/crs/install/roothas.pl


To configure Grid Infrastructure for a Cluster execute the following command as oracle user:
/u10/app/gridbase/product/grid/12gR1/crs/config/config.sh
This command launches the Grid Infrastructure Configuration Wizard. The wizard also supports silent operation, and the parameters can be passed through the response file that is available in the installation media.



=============================================================
Step 9. Run script as Oracle to confiture Grid Infrastructure
=============================================================
[root@dbtrmrk tmp]# /u10/app/gridbase/product/grid/12gR1/perl/bin/perl -I/u10/app/gridbase/product/grid/12gR1/perl/lib -I/u10/app/gridbase/product/grid/12gR1/crs/install /u10/app/gridbase/product/grid/12gR1/crs/install/roothas.pl
Using configuration parameter file: /u10/app/gridbase/product/grid/12gR1/crs/install/crsconfig_params
LOCAL ADD MODE
Creating OCR keys for user 'oracle', privgrp 'oinstall'..
Operation successful.
LOCAL ONLY MODE
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
CRS-4664: Node dbtrmrk successfully pinned.

2014/05/04 11:09:27 CLSRSC-327: Successfully configured Oracle Grid Infrastructure for a Standalone Server





===============================================================
Step 10. Verify Successfull installation of Grid Infrastructure
===============================================================
[root@dbtrmrk tmp]# //u10/app/gridbase/product/grid/12gR1/bin/crsctl check has
CRS-4638: Oracle High Availability Services is online


[oracle@dbtrmrk grid]$$ORACLE_HOME/bin/asmca

ASM Created and Started Successfully.
Disk Group DGDATA created successfully.



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

INSTANCE_NAME    HOST_NAME                                                        STATUS
---------------- ---------------------------------------------------------------- ------------
+ASM             dbtrmrk.localdomain                                              STARTED


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      4076     3944             1019            1462              0             N  DGDATA/

Note: I have created DGDATA with NORMAL REDUNDANCY



Enjoy.....Abid Malik

Saturday, May 10, 2014

How to stamp Disks for ASM using ASMLib Package

#########################################################
How to stamp Disks for ASM using ASMLib Package
#########################################################

Note: I have added 10 1GB SCSI disks in my database host, will stamp them as ASM DISKS:


===============================
Step 1. Add Hard Disk(s)
===============================
[root@dbtrmrk ~]# ls -ltr /dev/sd*
brw-rw---- 1 root disk 8, 128 May  4 01:09 /dev/sdi
brw-rw---- 1 root disk 8,  64 May  4 01:09 /dev/sde
brw-rw---- 1 root disk 8, 112 May  4 01:09 /dev/sdh
brw-rw---- 1 root disk 8,  96 May  4 01:09 /dev/sdg
brw-rw---- 1 root disk 8,  80 May  4 01:09 /dev/sdf
brw-rw---- 1 root disk 8,  32 May  4 01:09 /dev/sdc
brw-rw---- 1 root disk 8,  16 May  4 01:09 /dev/sdb
brw-rw---- 1 root disk 8, 144 May  4 01:09 /dev/sdj
brw-rw---- 1 root disk 8, 160 May  4 01:09 /dev/sdk
brw-rw---- 1 root disk 8,  48 May  4 01:09 /dev/sdd
brw-rw---- 1 root disk 8,   0 May  4 01:09 /dev/sda
brw-rw---- 1 root disk 8,   2 May  4 01:09 /dev/sda2
brw-rw---- 1 root disk 8,   1 May  4 01:09 /dev/sda1


Note: Hard Disks b-k has been added


===============================
Step 2. Format Hard Disk(s)
===============================
-----------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x88c10643.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

---------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xaa414d27.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3945f228.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7b431510.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6d543a55.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x10adb6d6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdh
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xafdbdc34.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdi
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe4a79ffc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdj
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x261ec39d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# fdisk /dev/sdk
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa5620de4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
[root@dbtrmrk ~]# ls -ltr /dev/sd*
brw-rw---- 1 root disk 8,   0 May  4 01:09 /dev/sda
brw-rw---- 1 root disk 8,   2 May  4 01:09 /dev/sda2
brw-rw---- 1 root disk 8,   1 May  4 01:09 /dev/sda1
brw-rw---- 1 root disk 8,  16 May  4 01:14 /dev/sdb
brw-rw---- 1 root disk 8,  17 May  4 01:14 /dev/sdb1
brw-rw---- 1 root disk 8,  32 May  4 01:15 /dev/sdc
brw-rw---- 1 root disk 8,  33 May  4 01:15 /dev/sdc1
brw-rw---- 1 root disk 8,  49 May  4 01:15 /dev/sdd1
brw-rw---- 1 root disk 8,  48 May  4 01:15 /dev/sdd
brw-rw---- 1 root disk 8,  65 May  4 01:16 /dev/sde1
brw-rw---- 1 root disk 8,  64 May  4 01:16 /dev/sde
brw-rw---- 1 root disk 8,  81 May  4 01:16 /dev/sdf1
brw-rw---- 1 root disk 8,  80 May  4 01:16 /dev/sdf
brw-rw---- 1 root disk 8,  97 May  4 01:16 /dev/sdg1
brw-rw---- 1 root disk 8,  96 May  4 01:16 /dev/sdg
brw-rw---- 1 root disk 8, 113 May  4 01:17 /dev/sdh1
brw-rw---- 1 root disk 8, 112 May  4 01:17 /dev/sdh
brw-rw---- 1 root disk 8, 129 May  4 01:17 /dev/sdi1
brw-rw---- 1 root disk 8, 128 May  4 01:17 /dev/sdi
brw-rw---- 1 root disk 8, 145 May  4 01:17 /dev/sdj1
brw-rw---- 1 root disk 8, 144 May  4 01:17 /dev/sdj
brw-rw---- 1 root disk 8, 161 May  4 01:17 /dev/sdk1
brw-rw---- 1 root disk 8, 160 May  4 01:17 /dev/sdk


=======================================================
Step 3. Verify ASM Module has been loaded into Kernerl
=======================================================
[root@dbtrmrk ~]# df -ha | grep oracleasm
oracleasmfs              0     0     0   -  /dev/oracleasm

[root@dbtrmrk ~]# /sbin/lsmod | grep oracleasm
oracleasm              53865  1




======================================
Step 4. Create ASM Disks
======================================
[root@dbtrmrk ~]# oracleasm listdisks

[root@dbtrmrk ~]# oracleasm createdisk ASM1 /dev/sdb1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM2 /dev/sdc1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM3 /dev/sdd1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM4 /dev/sde1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM5 /dev/sdf1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM6 /dev/sdg1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM7 /dev/sdh1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM8 /dev/sdi1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM9 /dev/sdj1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm createdisk ASM10 /dev/sdk1
Writing disk header: done
Instantiating disk: done

[root@dbtrmrk ~]# oracleasm listdisks
ASM1
ASM2
ASM3
ASM4
ASM5
ASM6
ASM7
ASM8
ASM9
ASM10



=========================================
Step 5. Verify ASM Disks
=========================================
[root@dbtrmrk ~]# oracleasm querydisk ASM1
Disk "ASM1" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM2
Disk "ASM2" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM3
Disk "ASM3" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM4
Disk "ASM4" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM5
Disk "ASM5" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM6
Disk "ASM6" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM7
Disk "ASM7" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM8
Disk "ASM8" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM9
Disk "ASM9" is a valid ASM disk

[root@dbtrmrk ~]#  oracleasm querydisk ASM10
Disk "ASM10" is a valid ASM disk


[root@dbtrmrk ~]# ls -ltr /dev/oracleasm/disks
total 0
brw-rw---- 1 oracle oinstall 8,  17 May  4 01:20 ASM1
brw-rw---- 1 oracle oinstall 8,  33 May  4 01:20 ASM2
brw-rw---- 1 oracle oinstall 8,  49 May  4 01:21 ASM3
brw-rw---- 1 oracle oinstall 8,  65 May  4 01:21 ASM4
brw-rw---- 1 oracle oinstall 8,  81 May  4 01:21 ASM5
brw-rw---- 1 oracle oinstall 8,  97 May  4 01:21 ASM6
brw-rw---- 1 oracle oinstall 8, 113 May  4 01:21 ASM7
brw-rw---- 1 oracle oinstall 8, 129 May  4 01:21 ASM8
brw-rw---- 1 oracle oinstall 8, 145 May  4 01:21 ASM9
brw-rw---- 1 oracle oinstall 8, 161 May  4 01:22 ASM10

Enjoy......Abid Malik

Friday, May 9, 2014

How to install ASMLib Package for Oracle 12c

##################################################################
How to install oracleasm (ASMLib) Package for Oracle Database 12c
##################################################################

======================================
Step 1 - Check Kernerl Driver Version
======================================
[root@dbtrmrk tmp]# uname -rm
2.6.39-400.209.1.el6uek.x86_64 x86_64

Note: It is Oracle Unbreakable Enterprise Kernal 2.6 (Linux 6) 64-bit OS



======================================
Step 2 - Download Oralce Public Yum
======================================
[root@dbtrmrk tmp]# cd /etc/yum.repos.d/
[root@dbtrmrk tmp]# wget https://public-yum.oracle.com/public-yum-ol6.repo

[root@dbtrmrk yum.repos.d]# ll
-rw-r--r-- 1 root root 1953 May  3 03:54 public-yum-ol6.repo


======================================
Step 3 - Enable repo in Public Yum ol6
======================================
[ol6_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=1


[ol6_UEK_latest]
name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/UEK/latest/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=1

[ol6_UEK_base]
name=Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/UEK/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=1



======================================
Step 4 - Install kmod-oracleasm
======================================
[root@dbtrmrk yum.repos.d]# yum install kmod-oracleasm
Loaded plugins: refresh-packagekit, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kmod-oracleasm.x86_64 0:2.0.6.rh1-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================
 Package                          Arch                     Version                           Repository                    Size
================================================================================================================================
Installing:
 kmod-oracleasm                   x86_64                   2.0.6.rh1-2.el6                   ol6_latest                    34 k

Transaction Summary
================================================================================================================================
Install       1 Package(s)

Total download size: 34 k
Installed size: 115 k
Is this ok [y/N]: y
Downloading Packages:
kmod-oracleasm-2.0.6.rh1-2.el6.x86_64.rpm                                                                |  34 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kmod-oracleasm-2.0.6.rh1-2.el6.x86_64                                                                        1/1
  Verifying  : kmod-oracleasm-2.0.6.rh1-2.el6.x86_64                                                                        1/1

Installed:
  kmod-oracleasm.x86_64 0:2.0.6.rh1-2.el6

Complete!




======================================
Step 5 - Install oracleasm-support
======================================
[root@dbtrmrk yum.repos.d]# yum install oracleasm-support
Loaded plugins: refresh-packagekit, security
Setting up Install Process
Package oracleasm-support-2.1.8-1.el6.x86_64 already installed and latest version
Nothing to do





======================================
Step 6 - Install oracleasmlib
======================================
[root@dbtrmrk yum.repos.d]# yum install oracleasmlib
Loaded plugins: refresh-packagekit, security
Setting up Install Process
No package oracleasmlib available.
Error: Nothing to do


Note: Somehow the public yum repo could not find this package, so I downloaded it manually.
Note: I put the .rpm in /tmp and installed manually:

[root@dbtrmrk yum.repos.d]# cd /tmp
[root@dbtrmrk tmp]# ll
-rw-r--r--  1 oracle oinstall 13300 May  9  2014 oracleasmlib-2.0.4-1.el6.x86_64.rpm

[root@dbtrmrk tmp]# rpm -Uvh oracleasmlib-2.0.4-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:oracleasmlib           ########################################### [100%]


[root@dbtrmrk yum.repos.d]# rpm -q -i oracleasmlib
Name        : oracleasmlib                 Relocations: (not relocatable)
Version     : 2.0.4                             Vendor: Oracle Corporation
Release     : 1.el6                         Build Date: Mon 26 Mar 2012 04:22:44 PM EDT
Install Date: Sat 03 May 2014 04:26:27 AM EDT      Build Host: ca-build44.us.oracle.com
Group       : System Environment/Kernel     Source RPM: oracleasmlib-2.0.4-1.el6.src.rpm
Size        : 27192                            License: Oracle Corporation
Signature   : RSA/8, Mon 26 Mar 2012 04:22:51 PM EDT, Key ID 72f97b74ec551f03
Packager    : Joel Becker <joel.becker@oracle.com>
URL         : http://oss.oracle.com/
Summary     : The Oracle Automatic Storage Management library userspace code.
Description :
The Oracle userspace library for Oracle Automatic Storage Management



======================================
Step 7 - Verify oracleasmlib
======================================
[root@dbtrmrk yum.repos.d]# rpm -qa | grep -i oracleasm
kmod-oracleasm-2.0.6.rh1-2.el6.x86_64
oracleasm-support-2.1.8-1.el6.x86_64
oracleasmlib-2.0.4-1.el6.x86_64




======================================
Step 8 - Configure ASMLib
======================================
[root@dbtrmrk yum.repos.d]# /usr/sbin/oracleasm configure -i
Configuring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM library
driver.  The following questions will determine whether the driver is
loaded on boot and what permissions it will have.  The current values
will be shown in brackets ('[]').  Hitting <ENTER> without typing an
answer will keep that current value.  Ctrl-C will abort.

Default user to own the driver interface [oracle]: oracle
Default group to own the driver interface [install]: oinstall
Start Oracle ASM library driver on boot (y/n) [y]: y
Scan for Oracle ASM disks on boot (y/n) [y]: y
Writing Oracle ASM library driver configuration: done



======================================
Step 9 - Initialize oracleasm
======================================
[root@dbtrmrk yum.repos.d]# /usr/sbin/oracleasm init




======================================
Step 10 - Verify oracleasm mount point
======================================
[root@dbtrmrk yum.repos.d]# df -h /dev/oracleasm/
Filesystem            Size  Used Avail Use% Mounted on
oracleasmfs              0     0     0   -  /dev/oracleasm



Enjoy.....Abid Malik

Thursday, May 8, 2014

How to Migrate a NON-CONTAINER-CDB to PDB using DBMS_PDB

########################################################
How to migrate a NON-CONTAINER-CDB to PDB using DBMS_PDB
########################################################


====================================
Before Migration to Pluggable DB
====================================
SQL> select name,cdb from v$database;

NAME      CDB
--------- ---
DBTRMRK   NO


SQL> select instance_name,host_name,version,status from gv$instance;

INSTANCE_NAME HOST_NAME                           VERSION    STATUS
------------- ----------------------------------- ---------- --------
dbtrmrk       dbtrmrk.localdomain                 12.1.0.1.0 OPEN



====================================
Migration Tasks
====================================

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> STARTUP OPEN READ ONLY;
ORACLE instance started.

Total System Global Area  801701888 bytes
Fixed Size                  2293496 bytes
Variable Size             327155976 bytes
Database Buffers          465567744 bytes
Redo Buffers                6684672 bytes
Database mounted.
Database opened.



====================================
DESCRIBE the NON-CONTAINER-CDB
====================================
SQL> BEGIN
  2      DBMS_PDB.DESCRIBE(
  3        pdb_descr_file => '/tmp/dbtrmrk.xml');
  4  END;
  5  /

PL/SQL procedure successfully completed.



====================================
SHUTDOWN NON-CONTAINER-CDB
====================================
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.



====================================
Analyze NON-CONTAINER-CDB XML File
====================================

[oracle@dbtrmrk ~]$ cat /tmp/dbtrmrk.xml
<?xml version="1.0" encoding="UTF-8"?>
<PDB>
  <pdbname>dbtrmrk</pdbname>
  <cid>0</cid>
  <byteorder>1</byteorder>
  <vsn>186646528</vsn>
  <dbid>863520319</dbid>
  <cdbid>863520319</cdbid>
  <guid>F7F3F5DD6A1E30D5E043C9A8A8C0C264</guid>
  <uscnbas>3396841</uscnbas>
  <uscnwrp>0</uscnwrp>
  <rdba>4303816</rdba>
  <tablespace>
    <name>SYSTEM</name>
    <type>0</type>
    <tsn>0</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/dbdata/dbtrmrk/system01.dbf</path>
      <afn>1</afn>
      <rfn>1</rfn>
      <createscnbas>7</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>117760</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>186646528</vsn>
      <fdbid>863520319</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3396840</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>995548</frlsb>
      <frlt>826799617</frlt>
    </file>
  </tablespace>
  <tablespace>
    <name>SYSAUX</name>
    <type>0</type>
    <tsn>1</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/dbdata/dbtrmrk/sysaux01.dbf</path>
      <afn>2</afn>
      <rfn>2</rfn>
      <createscnbas>2188</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>119040</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>186646528</vsn>
      <fdbid>863520319</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3396840</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>995548</frlsb>
      <frlt>826799617</frlt>
    </file>
  </tablespace>
  <tablespace>
    <name>TEMP</name>
    <type>1</type>
    <tsn>3</tsn>
    <status>1</status>
    <issft>0</issft>
    <bmunitsize>128</bmunitsize>
    <file>
      <path>/u01/app/oracle/dbdata/dbtrmrk/dbtrmrk/temp01.dbf</path>
      <afn>1</afn>
      <rfn>1</rfn>
      <createscnbas>995619</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>2560</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>186646528</vsn>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>80</incsize>
    </file>
  </tablespace>
  <tablespace>
    <name>USERS</name>
    <type>0</type>
    <tsn>4</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/dbdata/dbtrmrk/users01.dbf</path>
      <afn>4</afn>
      <rfn>4</rfn>
      <createscnbas>18919</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>640</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>186646528</vsn>
      <fdbid>863520319</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3396840</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>995548</frlsb>
      <frlt>826799617</frlt>
    </file>
  </tablespace>
  <optional>
    <csid>178</csid>
    <ncsid>2000</ncsid>
    <options>
      <option>APS=12.1.0.1.0</option>
      <option>CATALOG=12.1.0.1.0</option>
      <option>CATJAVA=12.1.0.1.0</option>
      <option>CATPROC=12.1.0.1.0</option>
      <option>CONTEXT=12.1.0.1.0</option>
      <option>JAVAVM=12.1.0.1.0</option>
      <option>ORDIM=12.1.0.1.0</option>
      <option>OWM=12.1.0.1.0</option>
      <option>SDO=12.1.0.1.0</option>
      <option>XDB=12.1.0.1.0</option>
      <option>XML=12.1.0.1.0</option>
      <option>XOQ=12.1.0.1.0</option>
    </options>
    <dv>0</dv>
    <ncdb2pdb>1</ncdb2pdb>
    <APEX>4.2.0.00.27:0</APEX>
    <parameters>
      <parameter>processes=300</parameter>
      <parameter>sessions=472</parameter>
      <parameter>sga_target=805306368</parameter>
      <parameter>db_block_size=8192</parameter>
      <parameter>compatible=11.2.0.0.0</parameter>
      <parameter>open_cursors=300</parameter>
      <parameter>pga_aggregate_target=268435456</parameter>
    </parameters>
    <tzvers>
      <tzver>primary version:18</tzver>
      <tzver>secondary version:0</tzver>
    </tzvers>
    <walletkey>0</walletkey>
  </optional>
</PDB>



====================================
LOGIN TO CONTAINER DATABASE
====================================
SQL> select name,cdb from v$database;

NAME      CDB
--------- ---
CDBDEMO   YES


SQL> select con_id,name from v$pdbs;

    CON_ID NAME
---------- ------------------------------
         2 PDB$SEED
         3 PDB1



====================================
Choose Destination PDB Location
====================================
SQL> select name from v$datafile;

NAME
----------------------------------------
/u03/oradata/cdbdemo/system01.dbf
/u03/oradata/cdbdemo/sysaux01.dbf
/u03/oradata/cdbdemo/undotbs01.dbf
/u03/oradata/cdbdemo/pdbseed/system01.dbf
/u03/oradata/cdbdemo/users01.dbf
/u03/oradata/cdbdemo/pdbseed/sysaux01.dbf
/u03/oradata/cdbdemo/pdb1/system01.dbf
/u03/oradata/cdbdemo/pdb1/sysaux01.dbf
/u03/oradata/cdbdemo/pdb1/pdb1_users01.dbf



====================================
Create PDB  
====================================
Note: In order to save time, I have already copied over the files so using NOCOPY option.

SQL>CREATE PLUGGABLE DATABASE PDBTRMRK USING '/tmp/dbtrmrk.xml'
SOURCE_FILE_NAME_CONVERT = ('/u01/app/oracle/dbdata/dbtrmrk/','/u03/oradata/cdbdemo/pdbtrmrk/')
NOCOPY TEMPFILE REUSE;

Pluggable database created.



SQL>  select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           MOUNTED
PDBTRMRK                       MOUNTED




====================================
Clean-Up New PDB 
====================================
SQL> ALTER SESSION SET CONTAINER=PDBTRMRK;

Session altered.

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
SQL> SET SERVEROUTPUT ON
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL>
SQL> WHENEVER SQLERROR EXIT;
SQL>
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC>   The following statement will cause an "ORA-01403: no data found"
DOC>   error if we're not in a PDB.
DOC>   This script is intended to be run right after plugin of a PDB,
DOC>   while inside the PDB.
DOC>#######################################################################
DOC>#######################################################################
DOC>#
SQL>
.
..
...

SQL> alter system flush shared_pool;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> alter session set container = "&pdbname";

Session altered.

SQL>
SQL> -- leave the PDB in the same state it was when we started
SQL> BEGIN
  2    execute immediate '&open_sql &restricted_state';
  3  EXCEPTION
  4    WHEN OTHERS THEN
  5    BEGIN
  6      IF (sqlcode <> -900) THEN
  7        RAISE;
  8      END IF;
  9    END;
 10  END;
 11  /

PL/SQL procedure successfully completed.

SQL>
SQL> WHENEVER SQLERROR CONTINUE;




====================================
OPEN PDB 
====================================
SQL> ALTER PLUGGABLE DATABASE "PDBTRMRK" OPEN;

Pluggable database altered.


SQL> select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           MOUNTED
PDBTRMRK                       READ WRITE


Enjoy.....Abid Malik


Tuesday, May 6, 2014

Creating Multitenant Oracle 12c Database manually via Database Creation Scripts

###############################################################################
Creating Multitenant Oracle 12c Database manually via Database Creation Scripts
###############################################################################

Note: DBUA gives us option to generate database creation script so we can run them manualy to create database.
Below are the scripts DBUA generated. We are only required to run shell script that is <dbname>.sh.


[oracle@dbtrmrk 12.1.0]$ ll
total 17624
drwxr-xr-x 69 oracle oinstall     4096 Apr 30 05:39 12cR1
-rwxr-xr-x  1 oracle oinstall      815 Apr 30 08:42 cdbdemo.sh
-rwxr-xr-x  1 oracle oinstall      649 Apr 30 08:42 cdbdemo.sql
-rw-r-----  1 oracle oinstall     1601 Apr 30 08:42 cloneDBCreation.sql
-rw-r-----  1 oracle oinstall      789 Apr 30 08:42 CloneRmanRestore.sql
-rw-r-----  1 oracle oinstall     1947 Apr 30 08:42 initcdbdemoTempOMF.ora
-rw-r-----  1 oracle oinstall     2047 Apr 30 08:42 initcdbdemoTemp.ora
-rw-r-----  1 oracle oinstall     1979 Apr 30 08:42 init.ora
-rw-r-----  1 oracle oinstall      535 Apr 30 08:42 lockAccount.sql
-rw-r-----  1 oracle oinstall       79 Apr 30 08:42 PDBCreation.sql
-rw-r-----  1 oracle oinstall      785 Apr 30 08:42 plug_pdb1.sql
-rw-r-----  1 oracle oinstall     2141 Apr 30 08:42 plug_PDBSeed.sql
-rw-r-----  1 oracle oinstall      969 Apr 30 08:42 postDBCreation.sql
-rw-r-----  1 oracle oinstall      163 Apr 30 08:42 postPDBCreation_pdb1.sql
-rw-r-----  1 oracle oinstall     1132 Apr 30 08:42 postScripts.sql
-rw-r-----  1 oracle oinstall       87 Apr 30 08:42 rmanPDBCleanUpDatafiles.sql
-rw-r-----  1 oracle oinstall      290 Apr 30 08:42 rmanPDBRestoreDatafiles.sql
-rw-r-----  1 oracle oinstall      517 Apr 30 08:42 rmanRestoreDatafiles.sql
-rw-r-----  1 oracle oinstall 17973248 Apr 30 08:42 tempControl.ctl


================================
Main Shell Script
================================
Note: As you can notice, this script set the env variables and then call other .sql scripts in sequence

[oracle@dbtrmrk 12.1.0]$ more cdbdemo.sh
#!/bin/sh

OLD_UMASK=`umask`
umask 0027
mkdir -p /u01/app/oracle/admin/cdbdemo/adump
mkdir -p /u01/app/oracle/admin/cdbdemo/dpdump
mkdir -p /u01/app/oracle/admin/cdbdemo/pfile
mkdir -p /u01/app/oracle/audit
mkdir -p /u01/app/oracle/cfgtoollogs/dbca/cdbdemo
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/fast_recovery_area/cdbdemo
mkdir -p /u03/app/oracle/12.1.0/12cR1/dbs
mkdir -p /u03/arch
mkdir -p /u03/oradata/cdbdemo
mkdir -p /u03/oradata/cdbdemo/pdbseed
umask ${OLD_UMASK}
PERL5LIB=$ORACLE_HOME/rdbms/admin:$PERL5LIB; export PERL5LIB
ORACLE_SID=cdbdemo; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
echo You should Add this entry in the /etc/oratab: cdbdemo:/u03/app/oracle/12.1.0/12cR1:Y
/u03/app/oracle/12.1.0/12cR1/bin/sqlplus /nolog @/u03/app/oracle/12.1.0/cdbdemo.sql
[oracle@dbtrmrk 12.1.0]$ more /u03/app/oracle/12.1.0/cdbdemo.sql
set verify off
ACCEPT sysPassword CHAR PROMPT 'Enter new password for SYS: ' HIDE
ACCEPT systemPassword CHAR PROMPT 'Enter new password for SYSTEM: ' HIDE
host /u03/app/oracle/12.1.0/12cR1/bin/orapwd file=/u03/app/oracle/12.1.0/12cR1/dbs/orapwcdbdemo force=y format=12
@/u03/app/oracle/12.1.0/CloneRmanRestore.sql
@/u03/app/oracle/12.1.0/cloneDBCreation.sql
@/u03/app/oracle/12.1.0/plug_PDBSeed.sql
@/u03/app/oracle/12.1.0/postScripts.sql
@/u03/app/oracle/12.1.0/lockAccount.sql
@/u03/app/oracle/12.1.0/postDBCreation.sql
@/u03/app/oracle/12.1.0/PDBCreation.sql
@/u03/app/oracle/12.1.0/plug_pdb1.sql
@/u03/app/oracle/12.1.0/postPDBCreation_pdb1.sql


====================================
Main <dbname>.sql script
====================================

[oracle@dbtrmrk 12.1.0]$ more cdbdemo.sql
set verify off
ACCEPT sysPassword CHAR PROMPT 'Enter new password for SYS: ' HIDE
ACCEPT systemPassword CHAR PROMPT 'Enter new password for SYSTEM: ' HIDE
host /u03/app/oracle/12.1.0/12cR1/bin/orapwd file=/u03/app/oracle/12.1.0/12cR1/dbs/orapwcdbdemo force=y format=12
@/u03/app/oracle/12.1.0/CloneRmanRestore.sql
@/u03/app/oracle/12.1.0/cloneDBCreation.sql
@/u03/app/oracle/12.1.0/plug_PDBSeed.sql
@/u03/app/oracle/12.1.0/postScripts.sql
@/u03/app/oracle/12.1.0/lockAccount.sql
@/u03/app/oracle/12.1.0/postDBCreation.sql
@/u03/app/oracle/12.1.0/PDBCreation.sql
@/u03/app/oracle/12.1.0/plug_pdb1.sql
@/u03/app/oracle/12.1.0/postPDBCreation_pdb1.sql
[oracle@dbtrmrk 12.1.0]$ more /u03/app/oracle/12.1.0/cloneDBCreation.sql
SET VERIFY OFF
connect "SYS"/"&&sysPassword" as SYSDBA
set echo on
spool /u03/app/oracle/12.1.0/cloneDBCreation.log append
shutdown abort;
startup nomount pfile="/u03/app/oracle/12.1.0/init.ora";
Create controlfile reuse set database "cdbdemo"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
Datafile
'&&file0',
'&&file1',
'&&file2',
'&&file3'
LOGFILE GROUP 1 ('/u03/oradata/cdbdemo/redo01.log') SIZE 50M,
GROUP 2 ('/u03/oradata/cdbdemo/redo02.log') SIZE 50M,
GROUP 3 ('/u03/oradata/cdbdemo/redo03.log') SIZE 50M RESETLOGS;
exec dbms_backup_restore.zerodbid(0);
shutdown immediate;
startup nomount pfile="/u03/app/oracle/12.1.0/initcdbdemoTemp.ora";
Create controlfile reuse set database "cdbdemo"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
Datafile
'&&file0',
'&&file1',
'&&file2',
'&&file3'
LOGFILE GROUP 1 ('/u03/oradata/cdbdemo/redo01.log') SIZE 50M,
GROUP 2 ('/u03/oradata/cdbdemo/redo02.log') SIZE 50M,
GROUP 3 ('/u03/oradata/cdbdemo/redo03.log') SIZE 50M RESETLOGS;
alter system enable restricted session;
alter database "cdbdemo" open resetlogs;
exec dbms_service.delete_service('seeddata');
exec dbms_service.delete_service('seeddataXDB');
alter database rename global_name to "cdbdemo";
ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oradata/cdbdemo/temp01.dbf' SIZE 61440K REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;
select tablespace_name from dba_tablespaces where tablespace_name='USERS';
alter user sys account unlock identified by "&&sysPassword";
alter user system account unlock identified by "&&systemPassword";


===============================================
Set ORACLE_HOME before you run .sh script
===============================================
Note: if we do not set the ORACLE_HOME, we will get the following error:

Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory


[oracle@dbtrmrk 12.1.0]$ export ORACLE_HOME=/u03/app/oracle/12.1.0/12cR1
[oracle@dbtrmrk 12.1.0]$ ./cdbdemo.sh
You should Add this entry in the /etc/oratab: cdbdemo:/u03/app/oracle/12.1.0/12cR1:Y

SQL*Plus: Release 12.1.0.1.0 Production on Wed Apr 30 09:59:18 2014

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

Enter new password for SYS:
Enter new password for SYSTEM:

Enter password for SYS:

Connected to an idle instance.
SQL> spool /u03/app/oracle/12.1.0/CloneRmanRestore.log append
SQL> startup mount pfile="/u03/app/oracle/12.1.0/initcdbdemoTempOMF.ora";
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
Database mounted.
SQL> execute dbms_backup_restore.resetCfileSection(dbms_backup_restore.RTYP_DFILE_COPY);

PL/SQL procedure successfully completed.

SQL> execute dbms_backup_restore.resetCfileSection(13);

PL/SQL procedure successfully completed.

SQL> host /u03/app/oracle/12.1.0/12cR1/bin/rman @/u03/app/oracle/12.1.0/rmanRestoreDatafiles.sql &&sysPassword;

Recovery Manager: Release 12.1.0.1.0 - Production on Wed Apr 30 09:59:58 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target *
2>
3> CATALOG START WITH   '/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//Seed_Database.dfb'  NOPROMPT  ;
4>
5> RUN {
6>
7> set newname for datafile 3 to  '/u03/oradata/cdbdemo/sysaux01.dbf' ;
8>
9> set newname for datafile 1 to  '/u03/oradata/cdbdemo/system01.dbf' ;
10>
11> set newname for datafile 6 to  '/u03/oradata/cdbdemo/users01.dbf' ;
12>
13> set newname for datafile 4 to  '/u03/oradata/cdbdemo/undotbs01.dbf' ;
14>
15> restore datafile 3;
16>
17> restore datafile 1;
18>
19> restore datafile 6;
20>
21> restore datafile 4; }
22>
connected to target database: SEEDDATA (DBID=4144941807, not open)

Starting implicit crosscheck backup at 30-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=123 device type=DISK
Finished implicit crosscheck backup at 30-APR-14

Starting implicit crosscheck copy at 30-APR-14
using channel ORA_DISK_1
Finished implicit crosscheck copy at 30-APR-14

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//Seed_Database.dfb

List of Files Unknown to the Database
=====================================
File Name: /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 30-APR-14
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u03/oradata/cdbdemo/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: piece handle=/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb tag=TAG20130524T133058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 30-APR-14

Starting restore at 30-APR-14
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u03/oradata/cdbdemo/system01.dbf
channel ORA_DISK_1: reading from backup piece /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: piece handle=/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb tag=TAG20130524T133058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 30-APR-14

Starting restore at 30-APR-14
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u03/oradata/cdbdemo/users01.dbf
channel ORA_DISK_1: reading from backup piece /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: piece handle=/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb tag=TAG20130524T133058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 30-APR-14

Starting restore at 30-APR-14
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u03/oradata/cdbdemo/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb
channel ORA_DISK_1: piece handle=/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates/Seed_Database.dfb tag=TAG20130524T133058
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 30-APR-14

Recovery Manager complete.

SQL> column file0 NEW_VALUE file0;
SQL> select NAME file0 FROM V$DATAFILE_COPY where file# = 1;

FILE0
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/system01.dbf

SQL> column file1 NEW_VALUE file1;
SQL> select NAME file1 FROM V$DATAFILE_COPY where file# = 3;

FILE1
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/sysaux01.dbf

SQL> column file2 NEW_VALUE file2;
SQL> select NAME file2 FROM V$DATAFILE_COPY where file# = 4;

FILE2
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/undotbs01.dbf

SQL> column file3 NEW_VALUE file3;
SQL> select NAME file3 FROM V$DATAFILE_COPY where file# = 6;

FILE3
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/users01.dbf

SQL> spool off
SQL> @/u03/app/oracle/12.1.0/cloneDBCreation.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/cloneDBCreation.log append
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup nomount pfile="/u03/app/oracle/12.1.0/init.ora";
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
SQL> Create controlfile reuse set database "cdbdemo"
  2  MAXINSTANCES 8
  3  MAXLOGHISTORY 1
  4  MAXLOGFILES 16
  5  MAXLOGMEMBERS 3
  6  MAXDATAFILES 1024
  7  Datafile
  8  '&&file0',
  9  '&&file1',
 10  '&&file2',
 11  '&&file3'
 12  LOGFILE GROUP 1 ('/u03/oradata/cdbdemo/redo01.log') SIZE 50M,
 13  GROUP 2 ('/u03/oradata/cdbdemo/redo02.log') SIZE 50M,
 14  GROUP 3 ('/u03/oradata/cdbdemo/redo03.log') SIZE 50M RESETLOGS;

Control file created.

SQL> exec dbms_backup_restore.zerodbid(0);

PL/SQL procedure successfully completed.

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile="/u03/app/oracle/12.1.0/initcdbdemoTemp.ora";
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
SQL> Create controlfile reuse set database "cdbdemo"
  2  MAXINSTANCES 8
  3  MAXLOGHISTORY 1
  4  MAXLOGFILES 16
  5  MAXLOGMEMBERS 3
  6  MAXDATAFILES 1024
  7  Datafile
  8  '&&file0',
  9  '&&file1',
 10  '&&file2',
 11  '&&file3'
 12  LOGFILE GROUP 1 ('/u03/oradata/cdbdemo/redo01.log') SIZE 50M,
 13  GROUP 2 ('/u03/oradata/cdbdemo/redo02.log') SIZE 50M,
 14  GROUP 3 ('/u03/oradata/cdbdemo/redo03.log') SIZE 50M RESETLOGS;

Control file created.

SQL> alter system enable restricted session;

System altered.

SQL> alter database "cdbdemo" open resetlogs;

Database altered.

SQL> exec dbms_service.delete_service('seeddata');

PL/SQL procedure successfully completed.

SQL> exec dbms_service.delete_service('seeddataXDB');

PL/SQL procedure successfully completed.

SQL> alter database rename global_name to "cdbdemo";

Database altered.

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oradata/cdbdemo/temp01.dbf' SIZE 61440K REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;

Tablespace altered.

SQL> select tablespace_name from dba_tablespaces where tablespace_name='USERS';

TABLESPACE_NAME
------------------------------
USERS

SQL> alter user sys account unlock identified by "&&sysPassword";

User altered.

SQL> alter user system account unlock identified by "&&systemPassword";

User altered.

SQL> @/u03/app/oracle/12.1.0/plug_PDBSeed.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/plugDatabase.log append
SQL> select     'database_running' from dual;

'DATABASE_RUNNIN
----------------
database_running

SQL> spool /u03/app/oracle/12.1.0/plugDatabase.log append
SQL> startup ;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u03/app/oracle/12.1.0/12cR1/dbs/initcdbdemo.ora'
SQL> host mkdir -p /u03/oradata/cdbdemo/pdbseed;

SQL> host /u03/app/oracle/12.1.0/12cR1/bin/rman @/u03/app/oracle/12.1.0/rmanPDBRestoreDatafiles.sql &&sysPassword;

Recovery Manager: Release 12.1.0.1.0 - Production on Wed Apr 30 10:02:48 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target *
2>
3> run
4> {
5> set command id  to 'PDB$SEED';
6> RESTORE FOREIGN DATAFILE  2 FORMAT '/u03/oradata/cdbdemo/pdbseed/system01.dbf',4 FORMAT '/u03/oradata/cdbdemo/pdbseed/sysaux01.dbf' FROM BACKUPSET  '/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//pdbseed.dfb' ;
7> }
8> exit;
connected to target database: CDBDEMO (DBID=3503257845)

executing command: SET COMMAND ID

Starting restore at 30-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=244 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring foreign file 00002
channel ORA_DISK_1: restoring foreign file 00004
channel ORA_DISK_1: reading from backup piece /u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//pdbseed.dfb
channel ORA_DISK_1: restoring foreign file 2 to /u03/oradata/cdbdemo/pdbseed/system01.dbf
channel ORA_DISK_1: restoring foreign file 4 to /u03/oradata/cdbdemo/pdbseed/sysaux01.dbf
channel ORA_DISK_1: foreign piece handle=/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//pdbseed.dfb
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 30-APR-14

Recovery Manager complete.

SQL> column pdbfile0 NEW_VALUE pdbfile0;
SQL> select dc.name pdbfile0 from v$datafile_copy dc, v$rman_status rs where dc.name is not null and dc.status = 'A' and file# = 2 and rs.recid = dc.rman_status_recid and rs.stamp =dc.rman_status_stamp and rs.command_id = 'PDB$SEED';

PDBFILE0
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/pdbseed/system01.dbf

SQL> column pdbfile1 NEW_VALUE pdbfile1;
SQL> select dc.name pdbfile1 from v$datafile_copy dc, v$rman_status rs where dc.name is not null and dc.status = 'A' and file# = 4 and rs.recid = dc.rman_status_recid and rs.stamp =dc.rman_status_stamp and rs.command_id = 'PDB$SEED';

PDBFILE1
--------------------------------------------------------------------------------
/u03/oradata/cdbdemo/pdbseed/sysaux01.dbf

SQL> host /u03/app/oracle/12.1.0/12cR1/bin/rman @/u03/app/oracle/12.1.0/rmanPDBCleanUpDatafiles.sql &&sysPassword;

Recovery Manager: Release 12.1.0.1.0 - Production on Wed Apr 30 10:03:38 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target *
2>
3> change datafilecopy '&&pdbfile0','&&pdbfile1' uncatalog
4> exit;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "exit": expecting one of: "device, ;"
RMAN-01007: at line 4 column 1 file: /u03/app/oracle/12.1.0/rmanPDBCleanUpDatafiles.sql

SQL> alter session set "_oracle_script"=TRUE;

Session altered.

SQL> create pluggable database PDB$SEED as clone  using '/u03/app/oracle/12.1.0/12cR1/assistants/dbca/templates//pdbseed.xml'  source_file_name_convert = ('/ade/b/3593327372/oracle/oradata/seeddata/pdbseed/temp01.dbf','/u03/oradata/cdbdemo/pdbseed/pdbseed_temp01.dbf',
  2  '/ade/b/3593327372/oracle/oradata/seeddata/pdbseed/system01.dbf','&&pdbfile0',
  3  '/ade/b/3593327372/oracle/oradata/seeddata/pdbseed/sysaux01.dbf','&&pdbfile1') NOCOPY;

Pluggable database created.

SQL> alter session set "_oracle_script"=true;

Session altered.

SQL> alter pluggable database PDB$SEED open restricted;

Pluggable database altered.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected to an idle instance.
SQL> startup restrict pfile="/u03/app/oracle/12.1.0/initcdbdemoTemp.ora";
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
Database mounted.
Database opened.
SQL> select sid, program, serial#, username from v$session;

       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
         1 oracle@dbtrmrk.localdomain (VKTM)                         1


         2 oracle@dbtrmrk.localdomain (DIAG)                         1


         3 oracle@dbtrmrk.localdomain (LGWR)                         1



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
         4 oracle@dbtrmrk.localdomain (SMON)                         1


         5 oracle@dbtrmrk.localdomain (MMNL)                         1


         6 oracle@dbtrmrk.localdomain (TT00)                         5



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       119 oracle@dbtrmrk.localdomain (GEN0)                         1


       120 oracle@dbtrmrk.localdomain (DBRM)                         1


       121 oracle@dbtrmrk.localdomain (CKPT)                         1



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       122 oracle@dbtrmrk.localdomain (RECO)                         1


       123 oracle@dbtrmrk.localdomain (SMCO)                         3


       237 oracle@dbtrmrk.localdomain (PMON)                         1



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       238 oracle@dbtrmrk.localdomain (MMAN)                         1


       239 oracle@dbtrmrk.localdomain (DIA0)                         1


       240 oracle@dbtrmrk.localdomain (LG00)                         1



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       241 oracle@dbtrmrk.localdomain (LREG)                         1


       242 oracle@dbtrmrk.localdomain (W000)                         1


       355 sqlplus@dbtrmrk.localdomain (TNS V1-V3)                   5
SYS


       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       356 oracle@dbtrmrk.localdomain (PSP0)                         1


       357 oracle@dbtrmrk.localdomain (TMON)                         5


       358 oracle@dbtrmrk.localdomain (DBW0)                         1



       SID PROGRAM                                             SERIAL#
---------- ------------------------------------------------ ----------
USERNAME
------------------------------
       359 oracle@dbtrmrk.localdomain (LG01)                         1


       360 oracle@dbtrmrk.localdomain (MMON)                         1


       363 oracle@dbtrmrk.localdomain (CJQ0)                         3



24 rows selected.

SQL> alter database character set INTERNAL_CONVERT WE8MSWIN1252;

Database altered.

SQL> alter database national character set INTERNAL_CONVERT AL16UTF16;

Database altered.

SQL> alter system disable restricted session;

System altered.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> alter session set "_oracle_script"=TRUE;

Session altered.

SQL> alter pluggable database PDB$SEED CLOSE IMMEDIATE;

Pluggable database altered.

SQL> alter pluggable database PDB$SEED OPEN;

Pluggable database altered.

SQL> @/u03/app/oracle/12.1.0/postScripts.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/postScripts.log append
SQL> UPDATE sys.USER$ set SPARE6=NULL;

121 rows updated.

SQL> host perl /u03/app/oracle/12.1.0/12cR1/rdbms/admin/catcon.pl -n 1 -l /u03/app/oracle/12.1.0 -b dbmssml /u03/app/oracle/12.1.0/12cR1/rdbms/admin/dbmssml.sql;

SQL> execute dbms_datapump_utl.replace_default_dir;

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> host perl /u03/app/oracle/12.1.0/12cR1/rdbms/admin/catcon.pl -n 1 -l /u03/app/oracle/12.1.0 -b ordlib /u03/app/oracle/12.1.0/12cR1/ord/im/admin/ordlib.sql;

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> create or replace directory XMLDIR as '/u03/app/oracle/12.1.0/12cR1/rdbms/xml';

Directory created.

SQL> create or replace directory XSDDIR as '/u03/app/oracle/12.1.0/12cR1/rdbms/xml/schema';

Directory created.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> execute ORACLE_OCM.MGMT_CONFIG_UTL.create_replace_dir_obj;

PL/SQL procedure successfully completed.

SQL> execute dbms_qopatch.replace_logscrpt_dirs;

PL/SQL procedure successfully completed.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/postDBCreation.log append
SQL> grant sysdg to sysdg;

Grant succeeded.

SQL> grant sysbackup to sysbackup;

Grant succeeded.

SQL> grant syskm to syskm;

Grant succeeded.

SQL> @/u03/app/oracle/12.1.0/lockAccount.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/lockAccount.log append
SQL> BEGIN
  2   FOR item IN ( SELECT USERNAME FROM DBA_USERS WHERE ACCOUNT_STATUS IN ('OPEN', 'LOCKED', 'EXPIRED') AND USERNAME NOT IN (
  3  'SYS','SYSTEM') )
  4   LOOP
  5    dbms_output.put_line('Locking and Expiring: ' || item.USERNAME);
  6    execute immediate 'alter user ' ||
  7           sys.dbms_assert.enquote_name(
  8           sys.dbms_assert.schema_name(
  9           item.USERNAME),false) || ' password expire account lock' ;
 10   END LOOP;
 11  END;
 12  /

PL/SQL procedure successfully completed.

SQL> spool off
SQL> @/u03/app/oracle/12.1.0/postDBCreation.sql
SQL> SET VERIFY OFF
SQL> spool /u03/app/oracle/12.1.0/postDBCreation.log append
SQL> host perl /u03/app/oracle/12.1.0/12cR1/rdbms/admin/catcon.pl -n 1 -l /u03/app/oracle/12.1.0 -b catbundle -a 1  /u03/app/oracle/12.1.0/12cR1/rdbms/admin/catbundle.sql 1psu 1apply;

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected to an idle instance.
SQL> startup mount pfile="/u03/app/oracle/12.1.0/init.ora";
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> create spfile='/u03/app/oracle/12.1.0/12cR1/dbs/spfilecdbdemo.ora' FROM pfile='/u03/app/oracle/12.1.0/init.ora';

File created.

SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> host perl /u03/app/oracle/12.1.0/12cR1/rdbms/admin/catcon.pl -n 1 -l /u03/app/oracle/12.1.0 -b utlrp /u03/app/oracle/12.1.0/12cR1/rdbms/admin/utlrp.sql;

SQL> select comp_id, status from dba_registry;

COMP_ID                        STATUS
------------------------------ -----------
DV                             VALID
APEX                           VALID
OLS                            VALID
SDO                            VALID
ORDIM                          VALID
CONTEXT                        VALID
OWM                            VALID
XDB                            VALID
CATALOG                        VALID
CATPROC                        VALID
JAVAVM                         VALID

COMP_ID                        STATUS
------------------------------ -----------
XML                            VALID
CATJAVA                        VALID
APS                            VALID
XOQ                            VALID
RAC                            OPTION OFF

16 rows selected.

SQL> execute dbms_swrf_internal.cleanup_database(cleanup_local => FALSE);

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected to an idle instance.
SQL> startup ;
ORACLE instance started.

Total System Global Area 1252663296 bytes
Fixed Size                  2287864 bytes
Variable Size             855639816 bytes
Database Buffers          385875968 bytes
Redo Buffers                8859648 bytes
Database mounted.
Database opened.
SQL> spool off
SQL> @/u03/app/oracle/12.1.0/PDBCreation.sql
SQL> SET VERIFY OFF
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/PDBCreation.log append
SQL> @/u03/app/oracle/12.1.0/plug_pdb1.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/plugDatabase.log append
SQL> select     'database_running' from dual;

'DATABASE_RUNNIN
----------------
database_running

SQL> spool /u03/app/oracle/12.1.0/plugDatabase.log append
SQL> startup ;
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> host mkdir -p /u03/oradata/cdbdemo/pdb1;

SQL> CREATE PLUGGABLE DATABASE pdb1 ADMIN USER PDBADMIN IDENTIFIED BY "redhat" ROLES=(CONNECT)  file_name_convert=('/u03/oradata/cdbdemo/pdbseed',
  2  '/u03/oradata/cdbdemo/pdb1');

Pluggable database created.

SQL> alter pluggable database pdb1 open;

Pluggable database altered.

SQL> alter system register;

System altered.

SQL> alter session set container =pdb1;

Session altered.

SQL> CREATE SMALLFILE TABLESPACE "USERS" LOGGING  DATAFILE '/u03/oradata/cdbdemo/pdb1/pdb1_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED  EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT       AUTO;

Tablespace created.

SQL> ALTER DATABASE DEFAULT TABLESPACE "USERS";

Database altered.

SQL> @/u03/app/oracle/12.1.0/postPDBCreation_pdb1.sql
SQL> SET VERIFY OFF
SQL> connect "SYS"/"&&sysPassword" as SYSDBA
Connected.
SQL> alter session set container=pdb1;

Session altered.

SQL> set echo on
SQL> spool /u03/app/oracle/12.1.0/postPDBCreation.log append
SQL> exit;
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


==========================================
Verification of Database Creation
==========================================
Note: We have created this Multitenant database with one pluggable database.
Every .sql script generated a .log file for us to view the operation.

[oracle@dbtrmrk 12.1.0]$ ps -ef | grep pmon
oracle   23063     1  0 10:08 ?        00:00:00 ora_pmon_cdbdemo

[oracle@dbtrmrk 12.1.0]$ ps -ef | grep tns
oracle   21937     1  0 08:42 ?        00:00:04 /u03/app/oracle/12.1.0/12cR1/bin/tnslsnr CDB_LISTENER -inherit

Note: As you can see we created cdbdemo database successfully, listener CDB_LISTENER is running from ORACLE_HOME.

Enjoy.......Abid Malik