Friday 20 November 2015

Installing Oracle Multimedia Component on 11g


Installing Oracle Multimedia, which is required for Spatial and/or Locator is quite simple.
All of the following must be carried out while logged in as a SYSDBA user.

1.Pre-Requisite to install Oracle Multimedia component.

Decide which tablespace to use for the Oracle Multimedia users, and which tablespace to use for the Oracle

Spatial/Oracle Multimedia Location Services user. Oracle recommends using the SYSAUX tablespace for all

of these users.

2.Create the users and grant the appropriate privileges, as follows:

Call the script ordinst.sql, with two parameters for the Oracle Multimedia tablespace and the Oracle

Spatial/Oracle Multimedia Location Services tablespace:

On Linux and UNIX:

SQL> @<ORACLE_HOME>/ord/admin/ordinst.sql SYSAUX SYSAUX

On Windows:

SQL> @<ORACLE_HOME>\ord\admin\ordinst.sql SYSAUX SYSAUX

3.Install the Oracle Multimedia types and packages, as follows:

Call the script catim.sql, while you are connected as SYSDBA:

On Linux and UNIX:

SQL> @<ORACLE_HOME>/ord/im/admin/catim.sql

On Windows:

SQL> @<ORACLE_HOME>\ord\im\admin\catim.sql


Now Oracle Multimedia is ready for use.

4.Verifying an Installed Version of Oracle Multimedia

set lines 140
col COMP_NAME format a40
select comp_name, version, status from dba_registry;


COMP_NAME VERSION STATUS
---------------------------------------- ------------------------------ -----------
Oracle Database Vault 12.1.0.2.0 VALID
Oracle Application Express 4.2.5.00.08 VALID
Oracle Label Security 12.1.0.2.0 VALID
Spatial 12.1.0.2.0 VALID
Oracle Multimedia 12.1.0.2.0 VALID
Oracle Text 12.1.0.2.0 VALID
Oracle Workspace Manager 12.1.0.2.0 VALID
Oracle XML Database 12.1.0.2.0 VALID
Oracle Database Catalog Views 12.1.0.2.0 VALID
Oracle Database Packages and Types 12.1.0.2.0 VALID
JServer JAVA Virtual Machine 12.1.0.2.0 VALID
Oracle XDK 12.1.0.2.0 VALID
Oracle Database Java Packages 12.1.0.2.0 VALID
OLAP Analytic Workspace 12.1.0.2.0 VALID
Oracle OLAP API 12.1.0.2.0 VALID
Oracle Real Application Clusters 12.1.0.2.0 OPTION OFF

16 rows selected.





I hope this article helped you. Y
our suggestions/feedback are most welcome.

Keep learning... Have a great day!!!



Friday 23 October 2015

How to find the last RMAN backup’s log?

set pagesize 2000
set linesize 2000
select
output
from
GV$RMAN_OUTPUT
where
session_recid =
(
select
session_recid
from
V$RMAN_BACKUP_JOB_DETAILS
where
session_key=(select max(session_key) from v$RMAN_BACKUP_JOB_DETAILS)
);


OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
connected to target database: TEST (DBID=3221280546)
connected to recovery catalog database


allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=2817 devtype=DISK
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1243_891780004.arc recid=2465 stamp=893720321
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1243_891780004.arc recid=2466 stamp=893720321
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1244_891780004.arc recid=2467 stamp=893720321
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1244_891780004.arc recid=2468 stamp=893720321
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1245_891780004.arc recid=2469 stamp=893720326
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1245_891780004.arc recid=2470 stamp=893720326
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1246_891780004.arc recid=2471 stamp=893720326
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1246_891780004.arc recid=2472 stamp=893720326
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1247_891780004.arc recid=2475 stamp=893720329
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1247_891780004.arc recid=2476 stamp=893720329
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1248_891780004.arc recid=2473 stamp=893720329
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1248_891780004.arc recid=2474 stamp=893720329
archive log filename=/backup/data/TEST/arch/TEST1_1251_891780004.arc recid=2482 stamp=893722157
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1252_891780004.arc recid=2483 stamp=893723957
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1252_891780004.arc recid=2484 stamp=893723957
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1253_891780004.arc recid=2485 stamp=893725758
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1253_891780004.arc recid=2486 stamp=893725758
validation succeeded for archived log
archive log filename=/data/TEST/arch/TEST1_1254_891780004.arc recid=2487 stamp=893727558
validation succeeded for archived log
archive log filename=/backup/data/TEST/arch/TEST1_1254_891780004.arc recid=2488 stamp=893727558
.
.
.
input archive log thread=1 sequence=1305 recid=2589 stamp=893806765
channel CH1: starting piece 1 at 22-OCT-15
channel CH1: finished piece 1 at 22-OCT-15
piece handle=/backup/data/TEST/rman_backup/arch/FULL_TEST_1_5nqkcq6k_1_1 tag=TAG20151022T234001 comment=NONE
channel CH1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-OCT-15
released channel: CH1
released channel: CH2
released channel: CH3



967 rows selected.




I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!

Wednesday 14 October 2015

oracle script to check the database growth

SET LINESIZE 200
SET PAGESIZE 200
COL "Database Size" FORMAT a13
COL "Used Space" FORMAT a11
COL "Used in %" FORMAT a11
COL "Free in %" FORMAT a11
COL "Database Name" FORMAT a13
COL "Free Space" FORMAT a12
COL "Growth DAY" FORMAT a11
COL "Growth WEEK" FORMAT a12
COL "Growth DAY in %" FORMAT a16
COL "Growth WEEK in %" FORMAT a16
SELECT
(select min(creation_time) from v$datafile) "Create Time",
(select name from v$database) "Database Name",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2) || ' MB' "Database Size",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 ),2) || ' MB' "Used Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 )) / ROUND(SUM(USED.BYTES) / 1024 / 1024 ,2)*100,2) || '% MB' "Used in %",
ROUND((FREE.P / 1024 / 1024 ),2) || ' MB' "Free Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - ((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 )))/ROUND(SUM(USED.BYTES) / 1024 / 1024,2 )*100,2) || '% MB' "Free in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile),2) || ' MB' "Growth DAY",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100,3) || '% MB' "Growth DAY in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)*7,2) || ' MB' "Growth WEEK",
ROUND((((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100)*7,3) || '% MB' "Growth WEEK in %"
FROM    (SELECT BYTES FROM V$DATAFILE
UNION ALL
SELECT BYTES FROM V$TEMPFILE
UNION ALL
SELECT BYTES FROM V$LOG) USED,
(SELECT SUM(BYTES) AS P FROM DBA_FREE_SPACE) FREE
GROUP BY FREE.P;

Output:



Sunday 4 October 2015

SHUTDOWN: waiting for active calls to complete.

Issue:

Active call for process 1993 user ‘oraprod’ program ‘oracleprod@prod
Active call for process 18672 user ‘oraprod’ program ‘oracleprod@prod’
Active call for process 19304 user ‘oraprod’ program ‘oracleprod@prod’
SHUTDOWN: waiting for active calls to complete.
Problem: When SHUTDOWN IMMEDIATE HUNG with above message means PMON process is unable to clear any uncommitted transaction and oracle hung for long time.
Solution:
1. Connect to SYS user with new terminal window
SQL> conn / sysdba
Connected to idle instance.
2. Shutdown database with ABORT option
SQL> shutdown abort;
ORACLE instance shut down.
3. Open database for normal shutdown with RESTRICT option
SQL> startup restrict
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 788496 bytes
Variable Size 149682160 bytes
Database Buffers 16777216 bytes
Redo Buffers 524288 bytes

Database mounted.
Database opened.
4. Now shutdown database with NORMAL option
SQL> shutdown normal;
Database closed.
Database dismounted.
ORACLE instance shut down.







I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!


Wednesday 30 September 2015

Move a datafile with RMAN

Using RMAN is the best way before 12c to relocate a datafile with a minimum downtime. The only downtime is for switching from the old datafile to the new one and recover it. That means that the datafile size as no impact on the downtime.

Check schmea report before moving datafile.


Here is the situation before moving the datafile

RMAN> report schema
2> ;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name XE

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 360 SYSTEM *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF
2 650 SYSAUX *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\UNDOTBS1.DBF
3 25 UNDOTBS1 *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSAUX.DBF
4 100 USERS *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF


List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 C:\ORACLEXE\APP\ORACLE\ORADATA\XE\TEMP.DBF


1.Create a copy of datafile to new destination.

The first step is to create a copy of your datafile in the new destination. Here, we will copy the USERS datafile to
C:\ORACLEXE\APP\ORACLE\ORADATA2\XE:


RMAN> copy datafile 4 to 'C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF';

Starting backup at 14-01-27
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF
output file name=C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF tag=TAG20140127T132133 RECID=1 STAMP=837955296
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 14-01-27

2.Take tablespace offline.

Now I hae a copy of my datafile in the new destination, I have to switch from the old datafile to the new one. Of course this operation cannot be done online, I’ll have to put my tablespace offline, this is the begining of the downtime.

RMAN> SQL 'ALTER TABLESPACE USERS OFFLINE';

sql statement: ALTER TABLESPACE USERS OFFLINE

3.Switch old datafile to new datafile.

Now I can switch from the old datafile to the new one:

RMAN> SWITCH DATAFILE 4 TO COPY;

datafile 4 switched to datafile copy "C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF"

4.Recover the datafile.

Now we have to recover the datafile:

RMAN> RECOVER DATAFILE 4;

Starting recover at 14-01-27
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 14-01-27

5.Put tablespace back to online.

And we put back the tablespace USERS online:

RMAN> SQL 'ALTER TABLESPACE USERS ONLINE';

sql statement: ALTER TABLESPACE USERS ONLINE

6. Check status now.

Here is the new situation:

Report of database schema for database with db_unique_name XE

RMAN> report schema

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 360 SYSTEM *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF
2 650 SYSAUX *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\UNDOTBS1.DBF
3 25 UNDOTBS1 *** C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSAUX.DBF
4 100 USERS *** C:\ORACLEXE\APP\ORACLE\ORADATA2\XE\USERS.DBF

List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 C:\ORACLEXE\APP\ORACLE\ORADATA\XE\TEMP.DBF

The old datafile is kept as copy:

7.Check old datafile copy.

RMAN> list copy of datafile 4;

List of Datafile Copies
=======================

Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
2 4 A 14-01-27 379024 14-01-27
Name: C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF

Check 8.Remove old copy if do not need

We can remove it as we no longer need it:

RMAN> DELETE DATAFILECOPY 2;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
List of Datafile Copies
=======================

Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
2 4 A 14-01-27 379024 14-01-27
Name: C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF

Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy file name=C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF RECID=2 STAMP=837955601

Deleted 1 objects


And its done :)




I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!



Monday 28 September 2015

ora-01244: unnamed datafile(s) added to control file by media recovery

Cause: Media recovery with a backup control file or a control file that was rebuilt, encountered the creation of a datafile that was not in the control file. An entry has been added to the control file for the new datafiles, but with the file name UNNAMEDnnnn, where nnnn is the file number. Attached errors describe the file names that were originally used to create the files.


Action: Rename the files to valid file names and resume recovery. If necessary the command ALTER DATABASE CREATE DATAFILE may be used to create a file suitable for recovery and do the rename. If the file is not going to be recovered then take it offline with the FOR DROP option.
You'll encouter below error in alert log:
Errors in file /u01/app/11.2.0.3/diag/rdbms/odsprod/odsprod/trace/odsprod_pr00_16095.trc:
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to control file by media recovery
ORA-01110: data file 684: '/OSP/Data45/osp/data/tblspc_osp_686.dbf'
Slave exiting with ORA-283 exception

And your database recovery will abort
Now there can be a couple of scenarios, where in you may encounter this error, and their respective solutions .

1.You restored a full database and are recovering it through archives from source

Here, you are recovering after a full restore and hence the error says that the required data file doesn't exist.
To over come this issue, you simply have to execute below SQL:
alter database create datafile file#_from_error as '/new/path/to/data/file.dbf';
So, in our case that would be:
SQL> alter database create datafile 684 as '/bkp_loc/OSP/data/tblspc_osp_686.dbf';
The path is where you want the data file to be created. This can be similar to the one reported in error (if you have same path as source) or could be different, as in this case.
Also, if you are using ASM or to create Oracle managed datafile name
SQL> alter database create datafile 684 as new;
Now, you can continue with your recovery.

2.You lost a control file and restored it from a backup after which you had added data files to the database

Here, the data files already exist, (but they didn't at the time you backed up control file) but just that the restored control file is from time before the data files were added and hence not aware of them.
So, in this case, we can just rename the file to its existing file:

SQL> alter database rename file '/u01/app/product/11.2.0/dbhome_1/dbs/UNNAMED00684' to '/OSP/Data45/osp/data/tblspc_osp_686.dbf';

While renaming or recreating, just ensure that the target file being created doesn't already exist or if renaming, you aren't renaming it to other existing data files.
In any case if you know that you dont need that file, you can mark the same offline




I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!