Oracle Technology Blog

OraTech Blog provides tips,tricks,scripts and how-to type answers for Oracle related technologies. I use these commands very often, so I thought it would be useful to share with everybody. Please feel free to include your comments/corrections/questions.

Friday, June 16, 2006

Oracle Memory Use

$ cat omemuse.sh*
#!/usr/bin/sh
#
# Copyright 2001 Oracle Corporation
#
# program: omemuse (Oracle MEMory USagE)
# by Richard Gulledge
#
# modification history:
# date by comments
# ---------- -------- ----------------
# 11/15/1999 rgulledg original program
# 04/16/2001 rgulledg minor usage check mods
#

usage()
{
echo "Usage: $0 [ SB ]"
echo "Usage: $0 [ P ]"
echo "Usage: $0 [ h ]"
echo " "
echo "specify 'S' for Oracle shadow processes"
echo "specify 'B' for Oracle background processes (includes shared memory SGA)"
echo "specify 'h' for help"
echo " "
}

echo " "

#
# check usage
#
if [ $# = "0" ];then
usage;exit 1
fi
Parm1=$1
if [ $Parm1 = "h" ];then
echo "This script uses the Sun Solaris pmap command to determine memory usage"
echo "for Oracle server [B]ackground processes and/or [S]hadow processes."
echo "An individual [P]rocess can also be specified."
echo " "
echo "Although the Oracle server background processes memory usage should"
echo "remain fairly constant, the memory used by any given shadow process"
echo "can vary greatly. This script shows only a snapshot of the current"
echo "memory usage for the processes specified."
echo " "
echo "The 'B' option shows the sum of memory usage for all Oracle server"
echo "background processes, including shared memory like the SGA."
echo " "
echo "The 'S' option shows the sum of private memory usage by all"
echo "shadow processes. It does not include any shared memory like the"
echo "SGA since these are part of the Oracle server background processes."
echo " "
echo "The 'P' option shows memory usage for a specified process, broken"
echo "into two categories, private and shared. If the same executable"
echo "for this process was invoked again, only the private memory"
echo "would be allocated, the rest is shared with the currently running"
echo "process."
echo " "
usage;exit 1
fi
echo $Parm1|grep '[SBP]' > /dev/null
ParmFound=$?
if [ $ParmFound != "0" ];then
usage;exit 1
fi
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
if [ $Parm1 != "P" ];then
usage;exit 1
fi
if [ "X$2" = "X" ];then
usage;exit 1
fi
Parm2=$2
echo $Parm2|grep '[^0-9]' > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
usage;exit 1
fi
PidOwner=`ps -ef | grep -v grep | grep $Parm2 | grep -v $0 | awk '{print $1}'`
CurOwner=`/usr/xpg4/bin/id -un`
if [ "X$PidOwner" != "X$CurOwner" ];then
echo "Not owner of pid $Parm2, or pid $Parm2 does not exist"
echo " "
usage;exit 1
fi
else
if [ "X${ORACLE_SID}" = "X" ];then
echo "You must set ORACLE_SID first"
usage;exit1
fi
fi

#
# initialize variables
#
Pmap="/usr/proc/bin/pmap"
SharUse="/tmp/omemuseS$$"
PrivUse="/tmp/omemuseP$$"
ShadUse="/tmp/omemuseD$$"
PidPUse="/tmp/omemusePP$$"
PidSUse="/tmp/omemusePS$$"
TotalShad=0
TotalShar=0
TotalPriv=0
PidPriv=0
PidShar=0

#
# shadow processes
#
echo $Parm1|grep S > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
ShadPrc="`ps -ef|grep -v grep|grep oracle$ORACLE_SID|awk '{print $2}'`"
echo "" > $ShadUse
for i in $ShadPrc;do
$Pmap $i | grep " rw" | grep -v " rwxs" | awk '{print $2}' | awk -FK '{print $1}' >> $ShadUse
done
for i in `cat $ShadUse`;do
TotalShad=`expr $TotalShad + $i`
done
TotalShad=`expr $TotalShad "*" 1024`
echo "Total Shadow (bytes) : $TotalShad"
/bin/rm $ShadUse
fi

#
# non-shared portion of background processes
#
echo $Parm1|grep B > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
OrclPrc="`ps -ef|grep -v grep|grep ora_|grep $ORACLE_SID|awk '{print $2}'`"
BkgdPrc="`echo $OrclPrc|awk '{print $1}'`"
echo "" > $PrivUse
for i in $OrclPrc;do
$Pmap $i | grep " rw" | grep -v " rwxs" | awk '{print $2}' | awk -FK '{print $1}' >> $PrivUse
done
for i in `cat $PrivUse`;do
TotalPriv=`expr $TotalPriv + $i`
done
TotalPriv=`expr $TotalPriv "*" 1024`
echo "Total Private (bytes) : $TotalPriv"

#
# shared portion of background processes
#
echo "" > $SharUse
$Pmap $BkgdPrc | grep " r-x" | awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
$Pmap $BkgdPrc | grep "rwxs" | awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
for i in `cat $SharUse`;do
TotalShar=`expr $TotalShar + $i`
done
TotalShar=`expr $TotalShar "*" 1024`
echo "Total Shared (bytes) : $TotalShar"
/bin/rm $SharUse $PrivUse
fi

#
# non-shared portion of pid
#
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
echo "" > $PidPUse
$Pmap $Parm2 | grep " rw" | grep -v " rwxs" | awk '{print $2}' | awk -FK '{print $1}' >> $PidPUse
for i in `cat $PidPUse`;do
PidPriv=`expr $PidPriv + $i`
done
PidPriv=`expr $PidPriv "*" 1024`
echo "Total Private (bytes) : $PidPriv"

#
# shared portion of pid
#
echo "" > $PidSUse
$Pmap $Parm2 | grep " r-x" | awk '{print $2}' | awk -FK '{print $1}' >> $PidSUse
$Pmap $Parm2 | grep " rwxs" | awk '{print $2}' | awk -FK '{print $1}' >> $PidSUse
for i in `cat $PidSUse`;do
PidShar=`expr $PidShar + $i`
done
PidShar=`expr $PidShar "*" 1024`
echo "Total Shared (bytes) : $PidShar"
/bin/rm $PidPUse $PidSUse
fi

#
# Display grand total
#
Gtotal="`expr $TotalShad + $TotalPriv + $TotalShar + $PidPriv + $PidShar`"
echo " -----"
echo "Grand Total (bytes) : $Gtotal"
echo " "

Resize redo log files

There is no direct way to resize the redo log files. Basically we have to drop and recreate with new size.

Here is an example. My existing redo size is 10 MB and want to increase to 100MB.
I have thread 1,2 and 3 because I have 3 nodes RAC clusters.

alter database drop logfile '/u01/oradata/$DBNAME/redo11.log';
alter database add logfile thread 1 group 1 '/u01/oradata/$DBNAME/redo11.log' size 100M resize;

alter database drop logfile '/u02/oradata/$DBNAME/redo12.log';
alter database add logfile thread 1 group 2 '/u02/oradata/$DBNAME/redo12.log' size 100M resize;

alter database drop logfile '/u03/oradata/$DBNAME/redo13.log';
alter database add logfile thread 1 group 3 '/u03/oradata/$DBNAME/redo13.log' size 100M resize;



alter database drop logfile '/u01/oradata/$DBNAME/redo21.log';
alter database add logfile thread 2 group 4 '/u01/oradata/$DBNAME/redo21.log' size 100M resize;

alter database drop logfile '/u02/oradata/$DBNAME/redo22.log';
alter database add logfile thread 2 group 5 '/u02/oradata/$DBNAME/redo22.log' size 100M resize;

alter database drop logfile '/u03/oradata/$DBNAME/redo23.log';
alter database add logfile thread 2 group 6 '/u03/oradata/$DBNAME/redo23.log' size 100M resize;



alter database drop logfile '/u01/oradata/$DBNAME/redo31.log';
alter database add logfile thread 3 group 7 '/u01/oradata/$DBNAME/redo31.log' size 100M resize;

alter database drop logfile '/u02/oradata/$DBNAME/redo32.log';
alter database add logfile thread 3 group 8 '/u02/oradata/$DBNAME/redo32.log' size 100M resize;

alter database drop logfile '/u03/oradata/$DBNAME/redo33.log';
alter database add logfile thread 3 group 9 '/u03/oradata/$DBNAME/redo33.log' size 100M resize;

Monday, June 12, 2006

Logminer Setup

Perform Initial Setup Activities

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
Database altered.

SQL> create tablespace logmnrts datafile '/u05/oradata/db_name/logmnrts.dbf' size 100M autoextend on maxsize 2048M;

Tablespace created.

SQL> EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');

PL/SQL procedure successfully completed.

Add Redo Logfiles

SQL> EXECUTE DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => '/u11/archive/uspibe2/0001S0000008035.ARC',OPTIONS => DBMS_LOGMNR.NEW);

PL/SQL procedure successfully completed.

SQL> EXECUTE DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => '/u11/archive/uspibe2/0001S0000008036.ARC',OPTIONS => DBMS_LOGMNR.ADDFILE);

PL/SQL procedure successfully completed.

Start a LogMiner Session

To direct LogMiner to use the dictionary currently in use for the database, specify the online catalog as your dictionary source when you start LogMiner, as follows:

SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);

PL/SQL procedure successfully completed.

Query V$LOGMNR_CONTENTS

desc V$LOGMNR_CONTENTS

SELECT SQL_REDO, TIMESTAMP
FROM V$LOGMNR_CONTENTS
order by TIMESTAMP;

SELECT SEG_OWNER, SEG_NAME, COUNT(*) AS Hits
FROM V$LOGMNR_CONTENTS
WHERE SEG_NAME NOT LIKE '%$'
GROUP BYSEG_OWNER, SEG_NAME;

End a LogMiner Session

SQL> EXECUTE DBMS_LOGMNR.END_LOGMNR;

PL/SQL procedure successfully completed.

Tuesday, June 06, 2006

Oracle Instance Check Script

Purpose:

This script checks for oracle backgroud process and pages/emails if specified background is not present.

Step (1)
Prerequisite


create database list file ("/u11/misc/ActiveDBs.list") to loop through all the DB instances.


Step (2)
$ cat .cronprofile

ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/9.2.0
ORACLE_SID=my_sid
NLS_LANG=AMERICAN_AMERICA.UTF8
PATH=./:${ORACLE_HOME}/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/openwin/bin:/usr/local/bin:${HOME}:/usr/ucb:/sbin:/usr/lib/vxvm/bin:/usr/lib/fs/vxfs:/opt/VRTSvxfs/sbin:/opt/VRTSvcs/bin:/opt/VRTSvcs/ops/bin:/opt/VRTSob/bin:/opt/VRTS/bin
MANPATH=$MANPATH:./:/usr/opt/SUNWmd/man
SERVER=`uname -n`
LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${ORACLE_HOME}/lib64:${ORACLE_HOME}/lib:${ORACLE_HOME}/jdbc/lib:/usr/openwin/lib:/usr/dt/lib:${ORACLE_HOME}/ctx/lib
#LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${ORACLE_HOME}/lib64:${ORACLE_HOME}/lib:${ORACLE_HOME}/jdbc/lib:/usr/openwin/lib:/usr/dt/lib:${ORACLE_HOME}/ctx/lib:/opt/ORCLcluster/lib

LD_LIBRARY_PATH_64=${ORACLE_HOME}/lib:$LD_LIBRARY_PATH
ORA_OEMAGENT_DIR=/opt/oracle/agent
TCL_LIBRARY=${ORACLE_HOME}/network/agent/tcl
export NLS_LANG ORACLE_BASE ORACLE_HOME PATH MANPATH SERVER LD_LIBRARY_PATH LD_LIBRARY_PATH_64 ORA_OEMAGENT_DIR TCL_LIBRARY

umask 022

# Set up the terminal:
# TERM=vt220; export TERM
TERM=vt100; export TERM
stty erase "^H" kill "^U" intr "^C" eof "^D"
stty hupcl ixon ixoff
tabs
# Set up the shell environment:
set -u
trap "echo 'logout'" 0

# Set up the shell variables:
EDITOR=vi
export EDITOR
stty erase ^?

export SCRIPT_DIR=/opt/oracle/scripts/dba/monitoring
export PAGETO="1234567890@vtext.com"
export MAILTO="first_name.last_name@your_company.com"
export TEMP_DIR=/tmp
export LOG_DIR=/opt/oracle/scripts/dba/monitoring/logs
export LOGTO=${LOG_DIR}/alertlog_check.log


Step (3)
$ cat /opt/oracle/scripts/dba/monitoring/oracheck.sh

#!/bin/ksh
. /opt/oracle/scripts/dba/monitoring/.cronprofile
set -x

TIME=`date +'%a %b %d %Y %R'`



for SID in $(cat /u11/misc/ActiveDBs.list)
do
#MUSTRUN contains the ORACLE background processes
MUSTRUN="ora_smon_${SID} ora_dbw0_${SID} ora_pmon_${SID} ora_lgwr_${SID}"

ps -ef|grep -i $SID |grep -v grep > /tmp/${SID}.ps_out 2>&1
# for i in $MUSTRUN
# do
if ! grep "ora_" /tmp/${SID}.ps_out >/dev/null 2>&1
then
MESG="$TIME: $SID is no longer running on `uname -n` "
#Send a page
#sendpage DBA "$MESG"
#Send an e-mail
echo $MESG | mailx -s "$MESG" $PAGETO
fi
# done
done

Oracle Alert log Monitoring Script

Purpose:

This script can be used to check any Oracle error ("ORA-") in alertlog files.
This script can be configures as cronjob, so that it will scan the alert log at particular interval. When the script runs, it remembers the line number of each alertlog, this way when it runs next time it starts from where it left off.


Step (1)
Prerequisite


#
#
mkdir -p /opt/oracle/scripts/dba/monitoring/logs


# To remember the line number of the last scan,
# each alertlog will have a separate registry file under loglines directory
mkdir -p /opt/oracle/scripts/dba/monitoring/loglines

create database list file ("/u11/misc/ActiveDBs.list") to loop through all the DB instances.


(i)Copy the following .cronprofile and alert_check.sh into /opt/oracle/scripts/dba/monitoring directory.
(ii) Change environment variables, Pager (PAGE_TO) and email (EMAIL_TO) address.

Step (2)
$ cat .cronprofile

ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/9.2.0
ORACLE_SID=my_sid
NLS_LANG=AMERICAN_AMERICA.UTF8
PATH=./:${ORACLE_HOME}/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/openwin/bin:/usr/local/bin:${HOME}:/usr/ucb:/sbin:/usr/lib/vxvm/bin:/usr/lib/fs/vxfs:/opt/VRTSvxfs/sbin:/opt/VRTSvcs/bin:/opt/VRTSvcs/ops/bin:/opt/VRTSob/bin:/opt/VRTS/bin
MANPATH=$MANPATH:./:/usr/opt/SUNWmd/man
SERVER=`uname -n`
LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${ORACLE_HOME}/lib64:${ORACLE_HOME}/lib:${ORACLE_HOME}/jdbc/lib:/usr/openwin/lib:/usr/dt/lib:${ORACLE_HOME}/ctx/lib
#LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${ORACLE_HOME}/lib64:${ORACLE_HOME}/lib:${ORACLE_HOME}/jdbc/lib:/usr/openwin/lib:/usr/dt/lib:${ORACLE_HOME}/ctx/lib:/opt/ORCLcluster/lib

LD_LIBRARY_PATH_64=${ORACLE_HOME}/lib:$LD_LIBRARY_PATH
ORA_OEMAGENT_DIR=/opt/oracle/agent
TCL_LIBRARY=${ORACLE_HOME}/network/agent/tcl
export NLS_LANG ORACLE_BASE ORACLE_HOME PATH MANPATH SERVER LD_LIBRARY_PATH LD_LIBRARY_PATH_64 ORA_OEMAGENT_DIR TCL_LIBRARY

umask 022

export SCRIPT_DIR=/opt/oracle/scripts/dba/monitoring
export PAGETO="1234567890@vtext.com"
export MAILTO="first_name.last_name@your_company.com"
export TEMP_DIR=/tmp
export LOG_DIR=/opt/oracle/scripts/dba/monitoring/logs
export LOGTO=${LOG_DIR}/alertlog_check.log


Step (3)
$ cat alert_check.sh

#!/usr/bin/ksh -x
. /opt/oracle/scripts/dba/monitoring/.cronprofile
for SID in $(cat /u11/misc/ActiveDBs.list)
do
#
# In RAC environment, ORACLE_SID=DB_NAME+INSTANCE_NUMBER.
# Here 1 indicates the instance number. For 2nd node it will be 2 and so on.
#
export ORACLE_SID=$SID'1'
export OSID=$ORACLE_SID
export ALERT_DIR=/opt/oracle/admin/${SID}/bdump
export ALERTFILE=${ALERT_DIR}/alert_${ORACLE_SID}.log
ADMIN2=""
PAGEFREQ=5
COUNT=0
cat $ALERTFILE >/tmp/alertlog_${OSID}.out
LOGFILE="/tmp/alertlog_${OSID}.out"
touch ${SCRIPT_DIR}/loglines/loglines.${ORACLE_SID}
LINECOUNT=`cat ${SCRIPT_DIR}/loglines/loglines.${ORACLE_SID}`
LINECOUNT=`expr $LINECOUNT + 1`
tail +$LINECOUNT $LOGFILE > ${SCRIPT_DIR}/tailfile
wc -l $LOGFILE | tr -s ' ' ' ' | cut -d' ' -f2 >${SCRIPT_DIR}/loglines/loglines.${ORACLE_SID}
GROUP=UNIX
ADMIN=$PAGETO

NUM=`date +'%S'`

SERVER=`uname -n`
ALERT=`egrep -i 'ORA-' ${SCRIPT_DIR}/tailfile`
if test -n "$ALERT"
then
egrep 'ORA-' ${SCRIPT_DIR}/tailfile | uniq >${SCRIPT_DIR}/mailfile
MFILE=${SCRIPT_DIR}/mailfile
if [[ -s ${SCRIPT_DIR}/alertlog_check.cnt ]]
then
COUNT=`cat ${SCRIPT_DIR}/alertlog_check.cnt`
COUNT=`expr $COUNT + 1`
MODVAL=`expr $COUNT % $PAGEFREQ`
if [ $MODVAL -eq 0 -o $COUNT -eq 2 -o $COUNT -eq 3 ]
then
MESG="Oracle alert on ${SERVER}:$OSID at `date +'%a
%m/%d %H:%M'`"
echo $MESG >> $LOGTO
# echo "MSG:" >${SCRIPT_DIR}/pagemsg.$NUM
# echo "TO: $GROUP" >>${SCRIPT_DIR}/pagemsg.$NUM
# echo "CONTENTS: ${SERVER}:$OSID `date +'%a %m/%d %H:%M'` $MESG" >>${SCRIPT_DIR}/pagemsg.$NUM
fi
echo $COUNT >${SCRIPT_DIR}/alertlog_check.cnt
else
COUNT=1
echo $COUNT >${SCRIPT_DIR}/alertlog_check.cnt
MESG="Oracle alert on ${SERVER}:$OSID at `date +'%a %m/%d %H:%M'`"
echo $MESG >> $LOGTO
# echo "MSG:" >${SCRIPT_DIR}/pagemsg.$NUM
# echo "TO: $GROUP" >>${SCRIPT_DIR}/pagemsg.$NUM
# echo "CONTENTS: ${SERVER}:$OSID `date +'%a %m/%d %H:%M'` $MESG" >>${SCRIPT_DIR}/pagemsg.$NUM
mailx -s "$MESG" $ADMIN <$MFILE
fi
else
if [[ -s ${SCRIPT_DIR}/alertlog_check.cnt ]]
then
rm ${SCRIPT_DIR}/alertlog_check.cnt
#/bin/rm pagemsg.*
fi
echo ""
fi
done

Monday, June 05, 2006

10g New fatures - Tip of the Day

What is the replacement for fromuser/touser in impdp?

Z:\OraDocs\10g\Work>impdp sami/sami remap_schema=scott:sami dumpfile=sami2.dmp logfile=sami2_imp.log

Import: Release 10.1.0.2.0 - Production on Sunday, 07 August, 2005 16:00

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
tion
With the Partitioning, OLAP and Data Mining options
Master table "SAMI"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SAMI"."SYS_IMPORT_FULL_01": sami/******** remap_schema=scott:sami dum
pfile=sami2.dmp logfile=sami2_imp.log
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SAMI" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/SE_PRE_SCHEMA_PROCOBJACT/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SAMI"."SYS_EXPORT_TABLE_01" 54.91 KB 337 rows
. . imported "SAMI"."DEPT" 5.656 KB 4 rows
. . imported "SAMI"."EMP" 7.820 KB 14 rows
. . imported "SAMI"."SALGRADE" 5.585 KB 5 rows
. . imported "SAMI"."BONUS" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/SE_POST_SCHEMA_PROCOBJACT/PROCOBJ
.
.
.
Job "SAMI"."SYS_EXPORT_SCHEMA_01" successfully completed at 16:33


The user SAMI should have all the privileges to create objects residing in SCOTT schema.


For example, user ARASI dose not have privilege to create_program as show below.


Z:\OraDocs\10g\Work>impdp sami/sami remap_schema=scott:arasi dumpfile=sami2.dmp
logfile=arasi_imp.log

Import: Release 10.1.0.2.0 - Production on Sunday, 07 August, 2005 16:01

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
tion
With the Partitioning, OLAP and Data Mining options
Master table "SAMI"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SAMI"."SYS_IMPORT_FULL_01": sami/******** remap_schema=scott:arasi dumpfile=sami2.dmp logfile=arasi_imp.log
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/SE_PRE_SCHEMA_PROCOBJACT/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "ARASI"."SYS_EXPORT_TABLE_01" 54.91 KB 337 rows
. . imported "ARASI"."DEPT" 5.656 KB 4 rows
. . imported "ARASI"."EMP" 7.820 KB 14 rows
. . imported "ARASI"."SALGRADE" 5.585 KB 5 rows
. . imported "ARASI"."BONUS" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/SE_POST_SCHEMA_PROCOBJACT/PROCOBJ
ORA-39083: Object type PROCOBJ failed to create with error:
ORA-27486: insufficient privileges
Failing sql is:
BEGIN
dbms_scheduler.create_program('"CHECK_ALERT_LOG_ERRORS"','EXECUTABLE',
'C:\oracle\product\10.1.0\WorkArea\check_alert.bat'
,0, TRUE,
'Email DBA if errors in the alert file'
);COMMIT; END;


Job "SAMI"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 16:01

Sunday, June 04, 2006

10g New Features- Tip of the Day

How to avoid or fix the famous ORA-01555 or "snapshot too old error"?

In 10g, use the RETENTION GUARANTEE (to avoid snapshot too old error ) clause when creating the undo tablespace (CREATE UNDO TABLESPACE or CREATE DATABASE) or later using the ALTER TABLESPACE statement.

SQL> alter tablespace undotbs1 retention guarantee;
Tablespace altered.

SQL> alter tablespace undotbs1 retention noguarantee;
Tablespace altered.

10g New Features - Tip of the Day

The COMPATIBLE parameter in Oracle 10g is irreversible; once you set it, you cannot change its value to one that is less than a previous value. To lower the value, you need to perform a point-in-time recovery of the database.



AWR collects the following types of data:

a)Time model statistics that show the amount of time spent by each activity

b)Object statistics that determine access and usage of database segments (database feature usage)

c)Selected statistics from V$SYSSTAT and V$SESSTAT (wait classes)

d)SQL statements that are producing high load on the system

e)ASH, which represents the history of recent sessions activity sampled from
V$SESSION every second

f)Operating system statistics

10g DATAPUMP

23)The Data Pump has the following advantages over the traditional expand imp tools:

Data access methods are decided automatically. For circumstances where direct path cannot be used, the external method is used.
Can perform export in parallel. It can also write to multiple files on different disks. (Specify parameters PARALLEL=2 and the two directory names with file specification DUMPFILE=DDIR1:/file1.dmp,DDIR2:/file2.dmp.)

Has the ability to attach and detach from a job gives the DBA opportunity to monitor job progress remotely and make adjustments to the job as needed.

Has the ability to restart a failed job from where it failed.

Has more options to filter metadata objects. The INCLUDE and EXCLUDE options of the expdp and impdp utilities—which are described in the following section—make it possible to extract metadata with several possible combinations.

Has the option to filter data rows during import.

The ESTIMATE_ONLY option can be used to estimate disk space requirements before actually performing the job.

Data can be exported from a remote database and imported to a remote database using a database link.

Its job status can be queried from the database directly or by using the Enterprise Manager.

Jobs can be allocated resources dynamically based on the workload.

Explicit database version can be specified, so only supported object types are exported.

Its operations can be performed from one database to another without writing to a dump file, using the network method.

During import, you can change target file names, schema, and tablespaces.


Data pump performance can be improved by using the PARALLEL parameter. This should be used in conjunction with the "%U" wildcard in the DUMPFILE parameter to allow multiple dumpfiles to be created or read:

What happens when we don't use wildcard character in conjunction with PARALLEL.

No let us look at how to use ORACLE_DATAPUMP driver to LOAD and UNLOAD data into external table.

LOAD
====
drop table employees;

CREATE TABLE employees (
ename VARCHAR2 (10),
title VARCHAR2 (10),
salary NUMBER (8))
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER <<<<<<==========*************
DEFAULT DIRECTORY WORK_DIR
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE FIELDS (
ename CHAR(10),
title CHAR(10),
salary CHAR(8)))
LOCATION ('employee.dat'));


UNLOAD
======
Oracle have incorporated support for data pump technology into external tables. The ORACLE_DATAPUMP access driver can be used to unload data to data pump export files and subsequently reload it. The unload of data occurs when the external table is created using the "AS" clause:

CREATE TABLE emp_xt
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP <<<<<<==========*************
DEFAULT DIRECTORY test_dir
LOCATION ('emp_xt.dmp')
)
AS SELECT * FROM emp;

boolean return type from function

How to get boolean return type from function?

CREATE OR REPLACE FUNCTION F_Is_Even(i_number IN NUMBER)
RETURN BOOLEAN
AS
/*
DECLARE
b1 BOOLEAN;
v1 VARCHAR2(10);
BEGIN
b1 :=F_Is_Even(10);
IF (b1) THEN
v1 :='TRUE';
ELSE
v1 :='FALSE';
END IF;
dbms_output.put_line(v1);
END;


*/
v1 VARCHAR2(10);
v2 BOOLEAN;
BEGIN
SELECT DECODE(MOD(i_number,2),0,'TRUE',1,'FALSE','FALSE') INTO v1 FROM dual;
IF v1='TRUE' THEN
v2 :=TRUE;
ELSE
v2 :=FALSE;
END IF;
RETURN v2;
END;
/

Friday, June 02, 2006