Translate

Friday, 10 February 2012

11i and Listener Passwords

A standard practice for any Oracle database should be to enable passwords on your listeners. EBS is no exception and recently Oracle published a metalink note: 386374.1 on how to do this for 11.5.x environments.

There are some pre-reqs, specifically:

3453499 (11i.ADX.F)
5225940 (Post ADX.F Fixes)
5107107 - AUTOCONFIG ENGINE & CONFIG TOOLS ROLLUP PATCH N or higher

The note has detailed steps on how to set the password at the application and database tiers.

In my opinion, just as important as setting a password, is to monitor for invalid attempts after. Otherwise whats the point? At best you will only slow down a determined intruder. Once you have set a password, any attempt to execute a command via lsnrctl (without setting your password first) will result in the following error showing up in your listener log:

TNS-01169: The listener has not recognized the password

Each DBA has his preferred language for scripts. Some prefer shell, others perl. Myself, I prefer perl. Below is a perl script I have used to monitor the listener log for the above error.



#!/usr/bin/perl -w

if ($#ARGV !=1) {
die "Usage: check_alert.pl ex. hostname /var/opt/oracle/listener.log.\n";
}
sleep 2;

$interval=60; # How many seconds before we check to see if data has been written to the logfile;
$email_threshold=5; # How many errors within the interval before an email gets sent;
$hostname=$ARGV[0];
$file=$ARGV[1];
open(filePtr, $file) or die "Can't find $file\n";


for (;;) {
@errors=("Subject: Listener Password Errors for $hostname\n");
$currTime = localtime(time);
push(@errors,"Here are some errors found at $currTime for $hostname.\n");

while () {
chop $_;
if (/TNS-01169/) {
push(@errors, "$_\n");
}
}

if ($#errors > $email_threshold) {
$rndExt = time;
$rndFile = "alert_errors_$rndExt";
open (TMPFILE, ">/tmp/$rndFile");

foreach $error (@errors) {
print TMPFILE $error;
}
close(TMPFILE);
system ("mail username\@mycompany.com < /tmp/$rndFile");
system ("rm /tmp/$rndFile");
}

sleep $interval;
seek filePtr, 0, 1;
}



The script takes two parameters:

A couple of key things you may want to customize in the above script are the $intervaland $email_threshold variables. As well, there is an email address towards the bottom where alerts will be sent.

R12: Sometimes cloning doesn’t remove all source references

I’m in the process of applying the latest round of security patches to our environment. While patching NITISH (I’ve already applied it to a sandbox and DEV environment), I hit the following error:

OPatch found the word "error" in stderr, please look into it.
You may have to run the make again.
Stderr Output (from /var/NITISH/apps/tech_st/10.1.2/.patch_storage/12828135/make_local.stderr):
/usr/bin/ld: cannot find –ljava
collect2: ld returned 1 exit status
make[1]: *** [/u01/NITISH/apps/tech_st/10.1.2/sysman/lib/libnmemso.so] Error 1
make: *** [libnmemso] Error 2

The issue was with the same file:

$ORACLE_HOME/sysman/lib/env_sysman.mk

The following line was still pointing to the source system:


JRE_LIB_DIR=/u01/PROD/apps/tech_st/10.1.2/jdk/jre/lib/i386

I changed it to NITISH, reran the patch and it completed successfully. Just a reminder that cloning doesn’t update all the necessary files.

Thursday, 9 February 2012

ORA-29283: invalid file operation

Error starting at line 1 in command:
BEGIN
DECLARE
file_name VARCHAR2(50);
file_handle utl_file.file_type;
BEGIN
file_name := 'table.txt';
file_handle := utl_file.fopen('SEND',file_name,'W');
FOR rec in(
SELECT column 1
||'~'||column 2
||'~'||column 3 out_line
FROM table1)LOOP
UTL_FILE.PUT_LINE(file_handle,rec.out_line);
UTL_FILE.FFLUSH(file_handle);
END LOOP;
UTL_FILE.FCLOSE(file_handle);
END;
end;

Error report:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 7
29283. 00000 - "invalid file operation"

Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.

Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.


We had migrated our servers from standalone to RAC and sometimes they worked sometimes not.

It was because we were not using the shared location for utl directory.

Once we put the files on shared location,it started working.

Sunday, 29 January 2012

Recovery from RMAN cold Backup

The RMAN documentation differentiates between "inconsistent" and "consistent" backups on the basis of whether the database is OPEN or not (respectively) during the Backup.
The nomenclature "inconsistent backup" makes me nervous. Why not call it the good old "HOT" Backup ?

To do a consistent" backup with RMAN, the database must be mounted as RMAN needs to access and update the controlfiles. With an OS scripted backup pre-RMAN, the database was truly "COLD" -- there would be no Oracle processes running.
RMAN does not backup the Online Redo Log files. With an OS scripted backup, you had the option -- you could choose to include these files in your backup if you were careful about how you planned to use Cold Backups for Roll-Forward recoveries with ArchiveLog.

Since RMAN does not backup the Online Redo Log files, you must, perforce, OPEN RESETLOGS on a Restore. With a scripted backup, if you also included your Online Redo Log files in your backup and restore (provided that you did not plan to apply any ArchiveLogs), you could simply STARTUP the database and continue LogSequenceNumbers again. (Of course, you might be duplicating LogSequenceNumbers if the database had been active in ArchiveLog mode since the backup, so you have to be careful to distinguish the two "streams" of ArchiveLogs).


Here below is the simplest "consistent" Backup and Restore using RMAN :



C:\>rman

Recovery Manager: Release 10.2.0.3.0 - Production on Thu May 8 22:20:17 2011

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

RMAN> connect target /

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area 536870912 bytes

Fixed Size 1291652 bytes
Variable Size 297798268 bytes
Database Buffers 234881024 bytes
Redo Buffers 2899968 bytes

RMAN> backup database;

Starting backup at 08-MAY-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=58 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=C:\NITISH10G\SYSTEM01.DBF
input datafile fno=00003 name=C:\NITISH10G\SYSAUX01.DBF
input datafile fno=00002 name=F:\NITISH10G\TEST_TBS_01.DBF
input datafile fno=00004 name=C:\NITISH10G\USERS01.DBF
input datafile fno=00005 name=C:\NITISH10G\EXAMPLE01.DBF
input datafile fno=00007 name=C:\NITISH10G\UNDO.DBF
channel ORA_DISK_1: starting piece 1 at 08-MAY-08
channel ORA_DISK_1: finished piece 1 at 08-MAY-08
piece handle=C:\NITISH10G_FLASH\NITISH10G\BACKUPSET\2011_05_08\O1_MF_NNNDF_TAG200
0508T222041_42631X6C_.BKP tag=TAG20110508T222041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:47
Finished backup at 08-MAY-08

Starting Control File and SPFILE Autobackup at 08-MAY-08
piece handle=C:\NITISH10G_FLASH\NITISH10G\AUTOBACKUP\2011_05_08\O1_MF_S_654214767
426358M1_.BKP comment=NONE
Finished Control File and SPFILE Autobackup at 08-MAY-08

RMAN>
RMAN> shutdown

database dismounted
Oracle instance shut down

RMAN>

******************* BACKUP COMPLETED *****************
******************************************************

========= database files deleted ====================
++++++++++++++++++++++++++++++++++++++++++++++++++++++
======================================================



C:\>rman target /

Recovery Manager: Release 10.2.0.3.0 - Production on Thu May 8 22:32:07 2011

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

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area 536870912 bytes

Fixed Size 1291652 bytes
Variable Size 301992572 bytes
Database Buffers 230686720 bytes
Redo Buffers 2899968 bytes

RMAN>
RMAN> restore controlfile from autobackup;

Starting restore at 08-MAY-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=57 devtype=DISK

recovery area destination: \NITISH10G_FLASH
database name (or database unique name) used for search: NITISH10G
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: C:\NITISH10G_FLASH\NITISH10G\AUTOBACKUP\2011
_05_08\O1_MF_S_654214767_426358M1_.BKP
channel ORA_DISK_1: control file restore from autobackup complete
output filename=C:\NITISH10G\CONTROL01.CTLa
output filename=C:\NITISH10G\CONTROL02.CTL
output filename=C:\NITISH10G\CONTROL03.CTL
Finished restore at 08-MAY-08

RMAN>
RMAN> restore database;

Starting restore at 08-MAY-08
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/08/2011 22:33:28
ORA-01507: database not mounted

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN>
RMAN> restore database;

Starting restore at 08-MAY-08
Starting implicit crosscheck backup at 08-MAY-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=57 devtype=DISK
Crosschecked 45 objects
Finished implicit crosscheck backup at 08-MAY-08

Starting implicit crosscheck copy at 08-MAY-08
using channel ORA_DISK_1
Finished implicit crosscheck copy at 08-MAY-08

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: C:\NITISH10G_FLASH\NITISH10G\AUTOBACKUP\2011_05_08\O1_MF_S_654214767_42
6358M1_.BKP

using channel ORA_DISK_1

skipping datafile 2; already restored to file F:\NITISH10G\TEST_TBS_01.DBF
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to C:\NITISH10G\SYSTEM01.DBF
restoring datafile 00003 to C:\NITISH10G\SYSAUX01.DBF
restoring datafile 00004 to C:\NITISH10G\USERS01.DBF
restoring datafile 00005 to C:\NITISH10G\EXAMPLE01.DBF
restoring datafile 00007 to C:\NITISH10G\UNDO.DBF
channel ORA_DISK_1: reading from backup piece C:\NITISH10G_FLASH\NITISH10G\BACKUPS
ET\2011_05_08\O1_MF_NNNDF_TAG20110508T222041_42631X6C_.BKP
channel ORA_DISK_1: restored backup piece 1
piece handle=C:\NITISH10G_FLASH\NITISH10G\BACKUPSET\2011_05_08\O1_MF_NNNDF_TAG2011
0508T222041_42631X6C_.BKP tag=TAG20110508T222041
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 08-MAY-08

RMAN>
RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 05/08/2011 22:36:48
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RMAN>
RMAN> alter database open resetlogs;

database opened

RMAN>

Friday, 27 January 2012

Upgrade Oracle to 11.1.0.7

My only 11G instance was running 11.1.0.6 and needed to be upgrade it to 11.1.0.7 to fix a couple of bugs. Apparently this patchkit also includes some new functionality. Before starting the upgrade I needed to do a bit of housekeeping. This instance is relatively small so I performed a full database backup as well as a full database export. I also created a pfile for good measure.

create pfile from spfile ;

I like to have a list of invalid objects to I can compare the before and after.

select object_name, owner, object_type
from all_objects where status like ‘INVALID’;

Next I checked the prerequisites for this upgrade. The time_zone check is a very important check that needs to be made.

select version from v$timezone_file;

I am running version 4 so I am okay to upgrade. Check out MetaLink Note 568125.1 if you are running anything other than version 4. Next I ran the script utlu111i.sql in the $OH/rdbms/admin directory. It is designed to let you know if there are issues to address prior to the upgrade. Next I shutdown my Oracle instance and performed the upgrade through the GUI installer. All went well. Then it was time to upgrade my instance.

sqlplus /nolog
startup upgrade
spool upgrade.log
@?/rdbms/admin/catupgrd.sql
spool off

This process took about 90 minutes to run so plan enough time for your upgrade. The script was run without errors. The final step of the script shutdown the database. I started the database normally, then shut it down normally, then started it up again normally. I generally take these extra steps just to ensure everything looks okay. To check the post-upgrade status this script is helpful

@?/rdbms/admin/utlu111s.sql

Next I needed to fix some invalid object which I did with this script.

@?/rdbms/admin/utlrp.sql

The final step to the upgrade process is to take a full database backup. Now I am fully upgraded to the latest version of Oracle. To check my version I ran.

select * from v$version
And then
select comp_name,status,version from dba_registry;

Wednesday, 18 January 2012

How to Install Oracle Enterprise Management Agent using silent install

Operating System: Solaris 10 SPARC 64 bit
Agent Version: 11.1.0.1.0

Where to download software:

Go to http://www.oracle.com/technetwork/oem/grid-control/downloads/agentsoft-090381.html
Accept the License Agreement
Under “Agent Software 64-bit platform” click on the “+” before Sun SPARC Solaris
Download the 11.1.0.1.0 Management Agent software
Transfer the zip file to the remote server where you intend to perform the installation.
Create a directory /home/oracle/em_agent_install in the remote server
Move the agent software zip file to the /home/oracle/em_agent_install
Unzip the downloaded agent software zip file on remote server

Editing Response File:

Go to

cd /home/oracle/em_agent_install/solaris/response
Make a backup of the additional_agent.rsp file

cp additional_agent.rsp additional_agent_backup.rsp
Edit the the following fields in the response file. For OMS_HOST make sure to set appropriate hostname where you have installed the Oracle Management Service. If you have chosen secure agent connections then set the “AGENT_REGISTRATION_PASSWORD” parameter. Also make sure to change the OMS_PORT value if you changed it during the Oracle Management Service (OMS) installation.

The parameter ORACLE_AGENT_HOME_LOCATION defines the location for the agent installation. A directory agent11g gets created under the path defined in the ORACLE_AGENT_HOME_LOCATION. If you want to install it in a different location, change this parameter.

SECURITY_UPDATES_VIA_MYORACLESUPPORT=FALSE
DECLINE_SECURITY_UPDATES=TRUE
INSTALL_UPDATES_SELECTION="skip"
ORACLE_AGENT_HOME_LOCATION="/opt/app/oracle/"
b_silentInstall=true
OMS_HOST="YOUR_OMS_HOST.YOUR_DOMAIN.com"
OMS_PORT="4889"
AGENT_REGISTRATION_PASSWORD="YOUR_REGISTRATION_PASSWORD"
FROM_LOCATION="/home/oracle/em_agent_install/solaris/agent/stage/products.xml"

Leave the rest of the parameters as-it-is and Save the file and exit the editor.

Silent Installation:

Go to

cd /home/oracle/em_agent_install/solaris/agent

Run the following command:

./runInstaller -silent -responsefile /home/oracle/em_agent_install/solaris/response/additional_agent.rsp

How to Speed up ASM Disks Rebalancing Operation

How to Speed up ASM Disks Rebalancing Operation:

When I tried to drop two ASM disks (each ~ 100GB) from the ASM DISKGROUP I have noticed that the rebalance operation is taking more than an hour by querying the v$asm_operation.

SELECT group_number, operation, state, power, est_minutes FROM v$asm_operation;

Here is the ouput from the above command:

GROUP_NUMBER OPERA STAT POWER EST_MINUTES
------------ ----- ---- ---------- -----------
2 REBAL RUN 1 62

The total size of the diskgroup before dropping the two disks of interest is 500 GB of which 250 GB is free. So I decided to drop two ASM disks of each ~ 100 GB using ASMCA.

After doing little research, I altered the rebalance power for the diskgroup using the following command:

alter diskgroup DISKGROUP rebalance power 5;
The rebalance operation started again, this time the estimated time came down to about 15 minutes.

SELECT group_number, operation, state, power, est_minutes FROM v$asm_operation;

Here is the output from the above

GROUP_NUMBER OPERA STAT POWER EST_MINUTES
------------ ----- ---- ---------- -----------
2 REBAL RUN 5 15

Until the rebalance operation is finished, you shouldn’t touch the underlying physical disks.

How to Apply Patch 12827731 (Rolling Fashion) – 11.2.0.2.4 Grid Patch Set Update

How to Apply Patch 12827731 – 11.2.0.2.4 Grid Patch Set Update

12827731 Grid Infrastructure Patch Set Update is a combination of patch numbers 12827731 and 1282776. This patch can be applied in a rolling fashion.


In order to apply the patch, the opatch utility version must be 11.2.0.1.5 or later.

How to check and update the version of opatch utility?

Assuming that you have the appropriate version of the opatch utility

Download patch p12827731_112020_Linux-x86-64.zip from support.metalink.com
Transfer the zip file to the server where you intend to apply the patch [Note: I created a directory /oratemp01/11202/software and transferred the zip file to this location]
cd to the patch directory and unzip the patch file

cd /oratemp01/11202/software
unzip p12827731_112020_Linux-x86-64.zip
You will notice that the file extracts into two sub-directories 12827731 and 12827726

First set the appropriate environment.

export ORACLE_HOME=/u01/app/11.2.0.2/grid
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
I ran the prereq check using the following command to determine whether any currently installed one-off patches conflict with the current PSU patch

opatch prereq CheckconflictAgainstOHWithDetail -phBaseDir ./12827731


Generating OCM Response File:

During the Installation of the Patch you will be prompted to enter the path for the Oracle Configuration Manager (OCM) Response file. Here is how to generate it.

export ORACLE_HOME=/u01/app/11.2.0.2/grid
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH

cd $ORACLE_HOME/OPatch/ocm/bin
./emocmrsp
You will be prompted to enter you oracle support email address and password, if you wish to be informed about Oracle Securuity meastures enter them and hit enter, if not just hit enter. A response file gets created at /u01/app/11.2.0.2/grid/OPatch/ocm/bin/ocm.rsp

Procedure to Apply the Patch to Non-Shared Grid Infrastructure HOME and Non-Shared RDBMS HOME:

I am going to use opatch auto command to apply the patch first to a Non-shared Grid Infrastructure HOME and then to a Non-Shared Oracle RDBMS HOME

Shut down all the databases running under the to be patched 11.2.0.2.x Grid Home (Remeber ASM for 11gR2 runs under the Grid Infrastructure HOME)

Step-1: Apply the Patch to the Non-Shared Grid Infrastructure HOME

First Set the appropriate environment variables

export ORACLE_HOME=/u01/app/11.2.0.2/grid
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
Don’t shutdown the clusterware

Go to the patch directory

cd /oratemp01/11202/software
Issue the following command as root user or some one who has sudo privileges

sudo opatch auto -oh $ORACLE_HOME

[oracle@xyz software]$ sudo opatch auto -oh $ORACLE_HOME
Executing /usr/bin/perl /u01/app/11.2.0.2/grid/OPatch/crs/patch112.pl -patchdir /oratemp01/11202 -patchn software -oh /u01/app/11.2.0.2/grid -paramfile /u01/app/11.2.0.2/grid/crs/install/crsconfig_params
opatch auto log file location is /u01/app/11.2.0.2/grid/OPatch/crs/../../cfgtoollogs/opatchauto2011-11-16_14-33-59.log
Detected Oracle Clusterware install
Using configuration parameter file: /u01/app/11.2.0.2/grid/crs/install/crsconfig_params
OPatch is bundled with OCM, Enter the absolute OCM response file path:
/u01/app/11.2.0.2/grid/OPatch/ocm/bin/ocm.rsp
Successfully unlock /u01/app/11.2.0.2/grid
patch /oratemp01/11202/software/12827731 apply successful for home /u01/app/11.2.0.2/grid
patch /oratemp01/11202/software/12827726 apply successful for home /u01/app/11.2.0.2/grid
ACFS-9300: ADVM/ACFS distribution files found.
ACFS-9312: Existing ADVM/ACFS installation detected.
ACFS-9314: Removing previous ADVM/ACFS installation.
ACFS-9315: Previous ADVM/ACFS components successfully removed.
ACFS-9307: Installing requested ADVM/ACFS software.
ACFS-9308: Loading installed ADVM/ACFS drivers.
ACFS-9321: Creating udev for ADVM/ACFS.
ACFS-9323: Creating module dependencies - this may take some time.
ACFS-9327: Verifying ADVM/ACFS devices.
ACFS-9309: ADVM/ACFS installation correctness verified.
CRS-4123: Oracle High Availability Services has been started.

Do a opatch lsinventory to check if the patch has been applied to the 11.2.0.2.x GRID Infrastructure HOME

opatch lsinventory
Step-2: Apply the Patch to the 11.2.0.2.x Non-Shared RDBMS HOME

As mentioned earlier, in order to apply 12827731 patch the opatch utility version should be higher than 11.2.0.1.5.

How to check and update the version of opatch utility?

Shutdown all the databases associated with the 11.2.0.2.x Non-Shared RDBMS HOME

Set the appropriate environment variables

export ORACLE_HOME=/u01/app/oracle/product/11.2.0.2/db11202_r
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
Enter the following command as root user or someone with sudo privileges

sudo opatch auto -oh $ORACLE_HOME

When prompted enter the full path to the OCM (oracle configuration manager) response file generated in the Step-1

Here is the update from the above command:

[oracle@xyz software]$ sudo opatch auto -oh $ORACLE_HOME
[sudo] password for oracle:
Executing /usr/bin/perl /u01/app/oracle/product/11.2.0/db11202_r/OPatch/crs/patch112.pl -patchdir /oratemp01/11202 -patchn software -oh /u01/app/oracle/product/11.2.0/db11202_r -paramfile /u01/app/11.2.0.2/grid/crs/install/crsconfig_params
opatch auto log file location is /u01/app/oracle/product/11.2.0/db11202_r/OPatch/crs/../../cfgtoollogs/opatchauto2011-11-16_14-49-41.log
Detected Oracle Clusterware install
Using configuration parameter file: /u01/app/11.2.0.2/grid/crs/install/crsconfig_params
OPatch is bundled with OCM, Enter the absolute OCM response file path:
/u01/app/11.2.0.2/grid/OPatch/ocm/bin/ocm.rsp
patch /oratemp01/11202/software/12827731/custom/server/12827731 apply successful for home /u01/app/oracle/product/11.2.0/db11202_r
patch /oratemp01/11202/software/12827726 apply successful for home /u01/app/oracle/product/11.2.0/db11202_r

Do a opatch lsinventory to check if the patch has been applied to the 11.2.0.2.x RDBMS HOME

opatch lsinventory

Perform similar steps on the remaining nodes one after another (rolling fashion)

Startup all the databases, associated with the patched RDBMS HOME

For each database set ORACLE_SID variable and load modified sql files into the database. Perform these steps only from one node.

export ORACLE_HOME=/u01/app/oracle/product/11.2.0.2/db11202_r
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba
At the sql prompt enter the following commands:

@?/rdbms/admin/catbundle.sql psu apply
QUIT

Saturday, 14 January 2012

Block Developers from Different TOOLS

CONNECT / AS SYSDBA;

CREATE OR REPLACE TRIGGER block_tools_from_prod
AFTER LOGON ON DATABASE
DECLARE
v_prog sys.v_$session.program%TYPE;
BEGIN
SELECT program INTO v_prog
FROM sys.v_$session
WHERE audsid = USERENV('SESSIONID')
AND audsid != 0 -- Don't Check SYS Connections
AND ROWNUM = 1; -- Parallel processes will have the same AUDSID's

IF UPPER(v_prog) LIKE '%TOAD%' OR UPPER(v_prog) LIKE '%T.O.A.D%' OR -- Toad
UPPER(v_prog) LIKE '%SQLNAV%' OR -- SQL Navigator
UPPER(v_prog) LIKE '%PLSQLDEV%' OR -- PLSQL Developer
UPPER(v_prog) LIKE '%BUSOBJ%' OR -- Business Objects
UPPER(v_prog) LIKE '%EXCEL%' -- MS-Excel plug-in
THEN
RAISE_APPLICATION_ERROR(-20000, 'Development tools are not allowed here.');
END IF;
END;
/
SHOW ERRORS

ORA-06553: PLS-801: internal error [56319]

Few things to do

1) Running utlirp.sql (this is going to invalidate most (for me around 80,000 objects) and then recompiles them again) Took a helluva time.. but got it sorted out. in the end.

2) Had to run utlirp.sql when database is in migration mode. (remember I ported the db from 32 bit to 64 bit).

I am sure that this "IS A" solutions as now, I am getting the same error with 32bit version of oracle software. However with 64 bit I am fine. now. before this the error was with 64 bit and 32 bit was clean.
-------------- Other Scenario---------------------------------------------------------
Worked great, I had to restore a 32 bit database on a 64 bit system. After restore/recover operations with RMAN I did the following.

1) startup upgrade;
2) @?/rdbms/admin/utlirp.sql
3) shutdown immediate;
4) startup;

------------Other Scenario-----------------------------------------------------

Received the "ORA-06553: PLS-801: internal error [56319]" error after cloning a db, while trying to drop a user.

SQL> drop user QCSITEADMIN_DB0 cascade;
drop user QCSITEADMIN_DB0 cascade
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-06553: PLS-801: internal error [56319]

and it got resolved after executing "utlirp.sql".

---------------------------------------------------My scenario -----------------

SYS @ avco >>conn volume/trace

ERROR:

ORA-06553: PLS-801: internal error [56327]

Error accessing package DBMS_APPLICATION_INFO

Connected.

VOLUME @ avco >>

VOLUME @ avco >>@utlirp.sql

VOLUME @ avco >>WHENEVER SQLERROR EXIT;

VOLUME @ avco >>DOC

DOC>#######################################################################

DOC>#######################################################################

DOC> The following statement will cause an "ORA-01722: invalid number"

DOC> error if there the database was not opened in UPGRADE mode

DOC>

DOC> If you encounter this error, execute "SHUTDOWN", "STARTUP UPGRADE" and

DOC> re-execute utlirp.sql

DOC>#######################################################################

DOC>#######################################################################

DOC>#

VOLUME @ avco >>SELECT TO_NUMBER('MUST_BE_OPEN_UPGRADE') FROM v$instance

2 WHERE status != 'OPEN MIGRATE';

SELECT TO_NUMBER('MUST_BE_OPEN_UPGRADE') FROM v$instance

*

ERROR at line 1:

ORA-00942: table or view does not exist



Disconnected from Oracle Database 11g Release 11.2.0.1.0 - Production

With the Automatic Storage Management option

[oracle@VOL-ORATEST admin]$ s

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 24 12:35:48 2011

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

Connected to:

Oracle Database 11g Release 11.2.0.1.0 - Production

With the Automatic Storage Management option

SYS @ avco >>shutdown

Database closed.

Database dismounted.

ORACLE instance shut down.

SYS @ avco >>startup upgrade

ORACLE instance started.



Total System Global Area 246910976 bytes

Fixed Size 1335752 bytes

Variable Size 192941624 bytes

Database Buffers 50331648 bytes

Redo Buffers 2301952 bytes

Database mounted.

Database opened.

SYS @ avco >>@utlirp.sql

......................

.........................

............................

PL/SQL procedure successfully completed.



SYS @ avco >>

SYS @ avco >>DOC

DOC>#######################################################################

DOC>#######################################################################

DOC> utlirp.sql completed successfully. All PL/SQL objects in the

DOC> database have been invalidated.

DOC>

DOC> Shut down and restart the database in normal mode and run utlrp.sql to

DOC> recompile invalid objects.

DOC>#######################################################################

DOC>#######################################################################

DOC>#

SYS @ avco >>

SYS @ avco >>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SYS @ avco >>startup

ORACLE instance started.



Total System Global Area 246910976 bytes

Fixed Size 1335752 bytes

Variable Size 192941624 bytes

Database Buffers 50331648 bytes

Redo Buffers 2301952 bytes

Database mounted.

Database opened.

SYS @ avco >>

SYS @ avco >>connect volumexx/xxxxx

Connected.

VOLUME @ avco >>

Monday, 2 January 2012

OCRCHECK utility

Have a Very Happy New Year 2012 to everyone.

OCRCHECK utility is used to verify the OCR integrity. The OCRCHECK utility displays the version of the OCR's block format, total space available and used space, OCRID, and the OCR locations that you have configured. OCRCHECK performs a block-by-block checksum operation for all of the blocks in all of the OCRs that you have configured. It also returns an individual status for each file as well as result for the overall OCR integrity check. The following is a sample of the OCRCHECK output:
Status of Oracle Cluster Registry is as follows :

Version : 2 Total space (kbytes) : 262144 Used space (kbytes) : 16256 Available space (kbytes) : 245888 ID : 1918913332 Device/File Name : /dev/raw/raw1 Device/File integrity check succeeded Device/File Name : /oradata/mirror.ocr Device/File integrity check succeeded Cluster registry integrity check succeeded

OCRCHECK creates a log file in the directory CRS_Home/log/hostname/client. To change amount of logging, edit the file CRS_Home/srvm/admin/ocrlog.ini

To remove an OCR location from your Oracle RAC environment:

Use the OCRCHECK utility to ensure that at least one OCR other than the OCR that you are removing is online.
> ocrcheck

Do not perform this OCR removal procedure unless there is at least one active OCR online.
Run the following comman on any node in the cluster to remove one copy of the OCR:
ocrconfig -replace ocr

This command updates the OCR configuration on all the nodes on which Oracle Clusterware is running.
Recovering the OCR

The first method uses automatically generated OCR file copies and the second method uses manually created OCR export files.

In event of a failure, before you attempt to restore the OCR, ensure that the OCR is unavailable. Run the following command to check the status of the OCR:

> ocrcheck

Thursday, 29 December 2011

ORA-19809: limit exceeded for recovery files – db_recovery_file_dest_size and archiver error

ORA-19815: WARNING: db_recovery_file_dest_size of 42949672960 bytes is 100.00% used, and has 0 remaining bytes available.
************************************************************************
You have following choices to free up space from flash recovery area:
1. Consider changing RMAN RETENTION POLICY. If you are using Data Guard,
then consider changing RMAN ARCHIVELOG DELETION POLICY.
2. Back up files to tertiary device such as tape using RMAN
BACKUP RECOVERY AREA command.
3. Add disk space and increase db_recovery_file_dest_size parameter to
reflect the new space.
4. Delete unnecessary files using RMAN DELETE command. If an operating
system command was used to delete files, then use RMAN CROSSCHECK and
DELETE EXPIRED commands.
************************************************************************
Errors in file /u00/app/oracle/diag/rdbms/sid/SID/trace/SID_ora_20214.trc:
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 1063256064 bytes disk space from 42949672960 limit
ARCH: Error 19809 Creating archive log file to ‘+FRA’

Monday, 26 December 2011

Finding the 10 largest objects in an Oracle database

col owner format a15
col segment_name format a30
col segment_type format a15
col mb format 999,999,999
select owner
, segment_name
, segment_type
, mb
from (
select owner
, segment_name
, segment_type
, bytes / 1024 / 1024 "MB"
from dba_segments
order by bytes desc
)
where rownum < 11
/

HOME ABOUT ORACLE SITES RSS Backing up your CRONTAB

If you are running a lot of scripts through CRON you may want to have a current backup. Since your CRON is simply a text schedule I prefer a daily email backup. It’s simple and does what I need. I add this line to my CRON:

00 0 * * * crontab -l > crontablist.txt;
mail -s "DW CRON - Quality Control" nitish@domain.com < crontablist.txt


Everyday at midnight I get an email with the contents of my CRON.

Dynamically Delete Old Partitions

Are you looking to delete older partitions in an Oracle database? Here is a basic SQL query that will give you what you need.
select ‘ALTER TABLE ‘||table_owner||’.'||table_name
||’ DROP PARTITION ‘
||partition_name||’ UPDATE INDEXES;’
from dba_tab_partitions
where table_owner = ‘AVCO’
and table_name = ‘LOAN_DETAIL’
order by PARTITION_POSITION;
Modify to your specific needs.

Change a table’s default tablespace

Do you need to change a table’s default tablespace? It’s pretty simple:
ALTER TABLE {OWNER}.{TABLE NAME}
MODIFY DEFAULT ATTRIBUTES TABLESPACE {NEW TABLESPACE NAME};
This does not move the table it only changes the attribute for the default tablespace. This is helpful if you are adding partitions, but not specifying the tablespace.

Remove non-ASCII characters from a column

Do you need to remove special (non-ASCII) characters from a VarChar2 column in Oracle? Create this function:
CREATE OR REPLACE FUNCTION O1DW.RECTIFY_NON_ASCII(INPUT_STR IN VARCHAR2)
RETURN VARCHAR2
IS
str VARCHAR2(2000);
act number :=0;
cnt number :=0;
askey number :=0;
OUTPUT_STR VARCHAR2(2000);
begin
str:=’^'||TO_CHAR(INPUT_STR)||’^';
cnt:=length(str);
for i in 1 .. cnt loop
askey :=0;
select ascii(substr(str,i,1)) into askey
from dual;
if askey < 32 or askey >=127 then
str :=’^'||REPLACE(str, CHR(askey),”);
end if;
end loop;
OUTPUT_STR := trim(ltrim(rtrim(trim(str),’^'),’^'));
RETURN (OUTPUT_STR);
end;
/

Move and partitioned index to a new tablespace

To dynamically move a partitioned index to a new tablespace run the following SQL

select ‘Alter index ‘||INDEX_OWNER||’.'||INDEX_NAME||’
rebuild partition ‘||PARTITION_NAME||’ tablespace ABC_DETAIL_INDEX1;’
from dba_ind_partitions where TABLESPACE_NAME = ‘DW_ABC_DETAIL’;

Wednesday, 21 December 2011

How to resolve “Unable to create Patch Object” error?

FTU % opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir ./12419278

Invoking OPatch 11.1.0.6.0
Oracle Interim Patch Installer version 11.1.0.6.0 Copyright (c) 2007, Oracle Corporation. All rights reserved.

PREREQ session
Oracle Home : /u02/app/oracle/product/11.2.0.1/FTU
Central Inventory : /u01/app/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.0
OUI version : 11.2.0.1.0
OUI location : /u02/app/oracle/product/11.2.0.1/FTU/oui Log file location : /u02/app/oracle/product/11.2.0.1/FTU/cfgtoollogs/opatch/opatch2011-11-05_01-50-34AM.log

Invoking prereq “checkconflictagainstohwithdetail”
The location “./12419278/README.html” is not a directory or a valid patch zip file.
Prereq “checkConflictAgainstOHWithDetail” not executed
PrereqSession failed: Unable to create Patch Object.
Exception occured : Patch ID is null.

OPatch failed with error code 73

We have two solutions for this problem

SOLUTION # 1
——————-

Move the text files like readme.html, readme.txt etc from the patch directory to some other location and try checking conflicts and it will be successful

But the problem is, this is not a permanent solution and just a workaround

SOLUTION # 2
——————–

This is the permanent solution for this problem. Cause for this error is we don’t have latest opatch version. As you can see in the output above my database version is 11.2.0.1, but my opatch version is 11.1.0.6. So, download latest opatch version from My Oracle Support with the help of patch # 6880880 and install it

Steps to install new opatch
1. copy the downloaded zip file for patch # 6880880 to $ORACLE_HOME
2. change location to ORACLE_HOME and rename the old OPatch directory
example : FTU% cd $ORACLE_HOME
FTU% mv OPatch OPatch.old
3. unzip the zip file which will create new OPatch directory
4. run below command to check if version is changed
FTU% $ORACLE_HOME/OPatch/opatch version

The above steps are also available in README file of the patch

how to define RMAN retention policy time?

Many a times, I heard DBA’s complaining about RMAN retention policy through which they face some problems during restore or recovery.

For example a friend posted that his retention policy is set to recovery window of 90 days, but when tried to restore the database to 30 days back date, RMAN saying recovery till that time is not possible. he wondered why this cannot be done if he has retention of 90 days.

Here is the answer for the same….

we all know that RMAN will store backup metadata in control file’s reusable location if recovery catalog is not configured. Generally this information will be stored for 7 days and can be changed by modifying CONTROLFILE_RECORD_KEEP_TIME parameter.

whenever we define retention policy of RMAN either to recovery window or redundancy to some X value, we need to remember that RMAN still follow the value defined for CONTROLFILE_RECOD_KEEP_TIME. That means, if recovery window is set to 30 days, but the above parameter is set to 7 days (default), you cannot recover beyond 7 days… which is very unfortunate…

Right ! so lets see what can be done for this?

we need to define CONTROLFILE_RECORD_KEEP_TIME always a higher value than what we set for retention policy. As per the formula, it should be

CONTROLFILE_RECORD_KEEP_TIME=retention policy value+ level 0 backup interval+ 1

let me throw some example for easy understanding…

If suppose your retention time is set to recovery window of 90 days and a weekly full level 0 backup is scheduled, then CONTROLFILE_RECORD_KEEP_TIME = 90 (retention policy) + 7 (level 0 backup interval) + 1 = 98

Note: In worst case, atleast you should set that same (equal to) as retention policy value

What happens if I don’t set to higher value?

In such case, RMAN will overwrite the content of backup metadata prior to obsolete them by RMAN and even though physically backup pieces are existing, you cannot use them

Tuesday, 20 December 2011

Important Changes to Oracle Database Patch Sets Starting With 11.2.0.2

Applies to:
Oracle Server - Enterprise Edition - Version: 11.2.0.2 and later [Release: 11.2 and later ]
Oracle Server - Standard Edition - Version: 11.2.0.2 and later [Release: 11.2 and later]
Oracle Server - Personal Edition - Version: 11.2.0.2 and later [Release: 11.2 and later]
Information in this document applies to any platform.
What is being announced?
Important Changes to Oracle Database Patch Sets Starting With 11.2.0.2
What has changed?

Packaging: Starting with the first patch set for Oracle Database 11g Release 2 (11.2.0.2), Oracle Database patch sets are full installations of the Oracle Database software. In past releases, Oracle Database patch sets consisted of a set of files that replaced files in an existing Oracle home. Beginning with Oracle Database 11g Release 2, patch sets are full installations that replace existing installations.

Because Oracle Database 11g Release 2 and later patch sets are a full installation, Oracle patch sets are now released as several installation bundles, just as are the base releases:
Oracle Database Server
Oracle Grid Infrastructure
Oracle Database Client
Companion/examples
Oracle Gateways

Simplified new installation: Because the release 11.2.0.2 patch set is a full installation package, if you are installing Oracle Database on a system without an existing Oracle Database installation, then you can simply install the release 11.2.0.2 patch set. You are no longer required to install the base release, and then apply the patch set.

Upgrade process: Beginning with the release 11.2.0.2 patch set, you have two ways to apply a patch set:

Out-of-place upgrade – This is Oracle's recommended way to apply a patch set. You install the patch set into a new, separate Oracle home location. After you install the patch upgrade, you then migrate the Oracle Database from the older Oracle home. The patch set upgrade is now the same process to upgrade from one version to another. Oracle recommends that you perform an out-of-place patch set upgrade, because this patch set application option requires much less downtime, and is safer because it does not require patching an ORACLE_HOME that is already being used in production. However, you must ensure that you have sufficient free disk space to accommodate two Oracle home directories at the same time.
In-place upgrade – You install the patch set into an existing Oracle home location. Oracle recommends that you select this option only if you do not have sufficient free disk space to perform an out-of-place upgrade, as the upgrade removes the existing Oracle installation. This patch option requires less disk space, but requires more time, and is riskier, because if you encounter an installation failure, then you must recover the entire existing Oracle home from a backup. If you choose this more risky option, then before you begin the patch installation, complete the following tasks:
Make a complete backup of your existing Oracle home
Read through the entire Upgrade Guide section dealing with in-place upgrades


Note: All Oracle Grid Infrastructure patch set upgrades must be out-of-place upgrades, in which you install the patch set into a new Grid home. In-place patch set upgrades are not supported.


Direct upgrade from previous releases: You can upgrade from a previous Oracle Database release directly to the latest patch set, without having to install the base release. For example, if you want to upgrade from Oracle Database 10g Release 2, or Oracle Database 11g Release 1, then you can upgrade directly to Oracle Database 11g Release 2, patch set 2 (11.2.0.2) using an out-of-place upgrade. Oracle now supports direct upgrades to the release 11.2.0.2 patch set from any release where direct upgrade to the base release (11.2.0.1) is supported, as well as direct upgrades from 11.2.0.1 to 11.2.0.2.

New Features Available in Patch Sets

In addition to the usual set of fixes, the release 11.2.0.2 patch set contains a small number of features that complete the Database 11g Release 2 feature set. The new features fall into the following five categories:
General improvements
Oracle Automatic Storage Management Cluster File System (ACFS) improvements
Quality of Service Management
Database Replay
Management
How to Obtain the Patch Set
As with all previous patch sets, the release 11.2.0.2 patch set is available for download from the Patches tab on My Oracle Support.
Important Changes to Note:
Disk space requirement: Because the out-of-place upgrade requires the installation of a new Oracle home, you must have enough free disk space to accommodate the new Oracle home, as well as disk space needed for temporary files during installation.
ORACLE_HOME location change: When using the out-of-place upgrade path, the location of your Oracle home is different after you complete the upgrade. You must change any direct references to the old location of your Oracle home (such as in /etc/oratab or in tnsnames.ora) to the new location, and update user environment variables for the Oracle home.
In-place upgrade process differs from previous patch set installation processes: Even though it seems similar, the in-place upgrade process for the release 11.2.0.2 patch set differs from previous patch set installation procedures. It is very important to read the entire in-place upgrade process before you begin to install the release 11.2.0.2 patch set, because the preinstallation steps are different.
Frequently Asked Questions
Q. Is this really a patch set?

A. Yes – This patch set still consists primarily of incremental bug fixes to the base release (11.2.0.1) but with different packaging. While new features are included in 11.2.0.2, the number of new features is very small, and is included to complete the 11.2 feature set.

Q. Why did Oracle make this change?

A. In response to customer feedback, Oracle is making this change for several reasons:
Out-of-place upgrade has been a best practice of many customers for patch set application for years. Out-of-place upgrades reduce downtime, because you can complete the initial installation and configuration of the upgrade before you take down the existing installation. Out-of-place patch upgrades are easier, safer, and provide faster fallback if needed: If you encounter issues with the new installation, then simply point clients back to the original Oracle Database installation Oracle home, and restart the database.
Out-of-place upgrades allow customers running multiple instances out of one Oracle home to upgrade each instance individually rather than having to upgrade all instances sharing an Oracle home at the same time (and incur downtime on them all simultaneously).
Full installations provide a better customer experience during the upgrade. By creating a full installation package that uses the same installation process as a base release (as opposed to a differential install of the changes objects), Oracle is able to use the same tools to build and test the patch set installation as Oracle uses with the base release. Improved testing enables a smoother, more trouble-free upgrade process that uses significantly less down time.
Full installations provide an easier upgrade for customers moving to release 11.2.0.2 from releases earlier than Oracle Database 11g release 2. Instead of having to install the base release, and then applying a patch release, you can now upgrade to the latest release in one step.
Q. Is this new packaging unique to the 11.2.0.2 patch set, or will Oracle follow this model for future patch sets?

A. This will be the new model going forward. Oracle will release patch set release 11.2.0.3 and later patch sets as full installation packages. Direct out-of-place upgrade is the Oracle best practices recommendation for patch set upgrades.

Q. There are many new features in 11.2.0.2. Are patch sets not just for bug fixes?

A. Oracle intends to maintain the focus of patch sets as a fix delivery vehicle. Oracle has included a very small number of new features in past patch sets. In this case, after the release of Oracle Database 11g release 2 (11.2.0.1), Oracle completed development of a small number of features that are closely related to the 11.2 release, and Oracle is including these features so that you can use them now, rather than wait for their inclusion in next major release.

Reference Note: Important Changes to Oracle Database Patch Sets Starting With 11.2.0.2 [ID 1189783.1]

Step By Step Manual Database Upgrade to 11.2.0.2

Compatibility Matrix

Minimum Version of the database that can be directly upgraded to Oracle 11g Release 2

Source Database Target Database
9.2.0.8 or higher 11.2.x
10.1.0.5 or higher 11.2.x
10.2.0.2 or higher 11.2.x
11.1.0.6 or higher 11.2.x

The following database version will require an indirect upgrade path.

Source Database ---> Upgrade Path for Target Database--->Target Database
7.3.3 (or lower)-----> 7.3.4 ---> 9.2.0.8 ---->11.2.x
8.0.5 (or lower)----> 8.0.6 ---> 9.2.0.8 ---->11.2.x
8.1.7 (or lower)----> 8.1.7.4---> 10.2.0.4---->11.2.x
9.0.1.3 (or lower)----> 9.0.1.4-- ->10.2.0.4---->11.2.x
9.2.0.7(or lower)---->9.2.0.8---->11.2.x
Here I am upgrading my Oracle 10.2.0.4 database to Oracle 11.2.0.2
1. Copy Pre upgrade Information gathering Script:
Log in to the system as the owner of the Oracle Database 11g Release 2 (11.2) Oracle home directory.
Copy the Pre-Upgrade Information Tool (utlu112i.sql) and utltzuv2.sql from the Oracle Database 11g Release 2 (11.2) ORACLE_HOME/rdbms/admin directory to a directory outside of the Oracle home, such as the temporary directory on your system.

$ORACLE_HOME/rdbms/admin/utlu112i.sql

2. Execute Pre Upgrade Script:
Should be change to the directory where utlu112i.sql had been copied in the previous step.
Start SQL*Plus and connect to the database instance as a user with SYSDBA privileges. Then run and spool the utlu112i.sql file. Please note that the database should be started using the Source Oracle Home.
$ sqlplus '/ as sysdba'
SQL> spool upgrade_info.log
SQL> @utlu112i.sql
SQL> spool off
SQL>

Check the spool file and examine the output of the upgrade information tool.

3. Check for the integrity of the source database:

Check for the integrity of the source database prior to starting the upgrade by downloading and running dbupgdiag.sql script from below My Oracle Support article
Note 556610.1 Script to Collect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql) (Avoid this step if don’t have support access)

If the dbupgdiag.sql script reports any invalid objects, run $ORACLE_HOME/rdbms/admin/utlrp.sql (multiple times) to validate the invalid objects in the database, until there is no change in the number of invalid objects.
$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus "/ as sysdba"
SQL> @utlrp.sql

After validating the invalid objects, re-run dbupgdiag.sql in the database once again and make sure that everything is fine.
4. Check that National Characterset:
Check that National Characterset (NLS_NCHAR_CHARACTERSET) is UTF8 and AL16UTF16.

select value from NLS_DATABASE_PARAMETERS where parameter = 'NLS_NCHAR_CHARACTERSET';

If this is UTF8 or AL16UTF16 then no action is needed.
If is not UTF8 or AL16UTF16 then refer the following article
Note 276914.1 The National Character Set in Oracle 9i and 10g.

5. Optimizer Statistics:
When upgrading to Oracle Database 11g Release 2 (11.2), optimizer statistics are collected for dictionary tables that lack statistics. This statistics collection can be time consuming for databases with a large number of dictionary tables, but statistics gathering only occurs for those tables that lack statistics or are significantly changed during the upgrade

$ sqlplus "/as sysdba"

SQL> EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;

6. Ensure that no files need media recovery:
Sql> SELECT * FROM v$recover_file;

7. Stop the listener for the database:

Make pfile from spfile;

$ lsnrctl stop

8. Suhtdown the Database:

Shutdown the database.

$ sqlplus "/as sysdba"
SQL> shutdown immediate;

9. Back Up the Database:

1- Perform Cold Backup
(or)
2- Take a backup using RMAN

Connect to RMAN:

rman "target / nocatalog"

RUN
{
ALLOCATE CHANNEL chan_name TYPE DISK;
BACKUP DATABASE FORMAT '%U' TAG before_upgrade;
BACKUP CURRENT CONTROLFILE TO '';
}

10 Backup and change pfile:

Make a backup of the init.ora file.
Comment out obsolete parameters

* The DIAGNOSTIC_DEST initialization parameter replaces the USER_DUMP_DEST, BACKGROUND_DUMP_DEST.

Note: Once the Parameter file is modified as per your requirement, copy the file to $ORACLE_HOME/dbs (11g Oracle Home )

11 Set Environment Variables:

If your operating system is UNIX then complete this step, else skip to next Step.

1. Make sure the following environment variables point to the Oracle 11g Release directories:

- ORACLE_BASE
- ORACLE_HOME
- PATH
$ export ORACLE_HOME=
$ export PATH=$ORACLE_HOME/bin:$PATH
$ export ORACLE_BASE=
Note : If ORACLE_BASE is not known, after setting Path towards 11g Oracle Home, execute 'orabase', which will point the location of base.
$ orabase
/uo1/app/oracle

2. Update the oratab entry, to set the new ORACLE_HOME pointing towards ORCL and disable automatic startup

Sample /etc/oratab

#orcl:/opt/oracle/product/10.2/db_1:N
orcl:/opt/oracle/product/11.2/db_1:N

Note : After /etc/oratab is updated to have sid and Oracle Home (11.2), you can execute oraenv (/usr/local/bin/oraenv) and set the environment. The input has to be the sid which is entered in /etc/oratab against 11g home.
for Instance,

[oracle@localhost ~]$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for ORACLE_HOME=/opt/oracle/product/11.2/db_1 is /u01/app/oracle
[oracle@localhost ~]$

12 Upgrade Database:

At the operating system prompt, change to the $ORACLE_HOME/rdbms/admin directory of 11gR2 Oracle Home.

$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus "/ as sysdba"
SQL> startup UPGRADE

Set the system to spool results to a log file for later verification after the upgrade is completed and start the upgrade script.

SQL> set echo on
SQL> SPOOL upgrade.log
SQL> @catupgrd.sql
SQL> spool off

These measures are an important final step to ensure the integrity and consistency of the newly upgraded Oracle Database software. Also, if you encountered a message listing obsolete initialization parameters when you started the database for upgrade, then remove the obsolete initialization parameters from the parameter file before restarting. If necessary, convert the SPFILE to a PFILE so you can edit the file to delete parameters.

Post Upgrade Steps

13 Post Upgrade:
Start the database and run the Post-Upgrade Status Tool $ORACLE_HOME/rdbms/admin/utlu112s.sql which provides a summary of the upgrade at the end of the spool log. It displays the status of the database components in the upgraded database and the time required to complete each component upgrade. Any errors that occur during the upgrade are listed with each component and must be addressed
$ sqlplus "/as sysdba"
SQL> STARTUP
SQL> @utlu112s.sql

14 Recompile Invalid Objects:
This script can be run concurrently with utlrp.sql. Run utlrp.sql to recompile any remaining stored PL/SQL and Java code in another session.
SQL> @utlrp.sql

15 Check for the integrity of the source database:

Check for the integrity of the upgraded database by running dbupgdiag.sql script from below Metalink article
Note 556610.1 Script to Collect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql)
If the dbupgdiag.sql script reports any invalid objects, run $ORACLE_HOME/rdbms/admin/utlrp.sql (multiple times) to validate the invalid objects in the database, until there is no change in the number of invalid objects.

After validating the invalid objects, re-run dbupgdiag.sql in the upgraded database once again and make sure that everything is fine.
16 Configure & Start Listener.ora :

Modify the listener.ora file:

For the upgraded instance(s) modify the ORACLE_HOME parameter to point to the new ORACLE_HOME. Start the listener :

lsnrctl start

17 Crosscheck Environment Variables:

Set Environment Variables

1. Make sure the following environment variables point to the Oracle 11g Release directories:

- ORACLE_BASE
- ORACLE_HOME
- PATH

Also check that your oratab file and any client scripts that set the value of ORACLE_HOME point to the Oracle Database 11g Release 2 (11.2) home.

Note : If you are upgrading a cluster database, then perform these checks on all nodes in which this cluster database has instances configured.

2. Modify /etc/oratab entry to use automatic startup
SID:ORACLE_HOME:Y

For Instance,
orcl:/opt/oracle/product/11.2/db_1:Y

18 Spfile from Pfile:
Edit init.ora:

- If you changed the CLUSTER_DATABASE parameter prior the upgrade set it back to TRUE
- Migrate your initialization parameter file to a server parameter file.

Create a server parameter file with a initialization parameter file
SQL> create spfile from pfile;

This will create a spfile as a copy of the init.ora file located in $ORACLE_HOME/dbs (UNIX) & %ORACLE_HOME%\database (Windows).
19 Start the Database with spfile:
Shutdown the database:
Sql> shutdown immediate
Now start the database it will user spfile
Sql> startup
Check the Alert log file for any Error.
Database is ready to use now.

How to see free space on unix system.

[oracle@itc-799 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 100G 72G 24G 76% /
/dev/sda2 341G 205G 119G 64% /data
/dev/sda1 92M 12M 76M 14% /boot
tmpfs 2.0G 0 2.0G 0% /dev/shm

df -h is command to check space usage on unix system, type this command on unix prompt and the out will be like above detail. In the above example, we have two mount points “/” and “/data” which we can use. In local environment usually we have two or one mount point.

Let’s talk about these mount points one by one.
/dev/sda3 100G 72G 24G 76% /

This mount point is known as root mount point and has total 100G of space out of which 72G is used and 24G is available.

/dev/sda2 341G 205G 119G 64% /data

This mount point is known as data mount point as given name and have 341G of space out of which 205G is used and 119G is free and the used percentage is 64%.

Some systems may have more mount points like

Filesystem Size Used Avail Use% Mounted on
/dev/sda3 100G 72G 24G 76% /
/dev/sda2 341G 205G 119G 64% /data
/dev/sda4 341G 205G 119G 64% /data1
/dev/sda1 92M 12M 76M 14% /boot
tmpfs 2.0G 0 2.0G 0% /dev/shm

This system has there mount points “/” , “/data” and “/data1”.

Moving between two Oracle Homes

I have two Oracle versions installed on my system. Oracle 11.2.0.1 and Oracle 11.2.0.2.

Here are the steps how to switch between them.

Make Oracle 11.2.0.1 as Oracle Home

oracle@suse32:~> cd /opt/oracle/product/11.2/db_1/bin/
oracle@suse32:/opt/oracle/product/11.2/db_1/bin> export ORACLE_HOME=/opt/oracle/product/11.2/db_1 product/11.2/db_1
oracle@suse32:/opt/oracle/product/11.2/db_1/bin> ./sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 7 23:47:37 2011

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

SQL> exit;

oracle@suse32:/opt/oracle/product> ls
11.2 11.2.0.2

Make Oracle 11.2.0.2 as Oracle Home

oracle@suse32:/opt/oracle/product> cd 11.2.0.2/
oracle@suse32:/opt/oracle/product/11.2.0.2> cd db_1/bin/
oracle@suse32:/opt/oracle/product/11.2.0.2/db_1/bin> export ORACLE_HOME=/opt/oracle/product/11.2.0.2/db_1
oracle@suse32:/opt/oracle/product/11.2.0.2/db_1/bin> ./sqlplus /nolog

SQL*Plus: Release 11.2.0.2.0 Production on Mon Nov 7 23:58:40 2011

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

SQL>

Saturday, 26 November 2011

10046 trace file content

The 10046 trace file contents differ greatly between different versions of Oracle.


Indeed, format of trace files changes sometimes between Oracle versions but definitely not greatly.

Somewhere near 9.2.0.2 STAT lines changed a bit (row source execution statistics was added).
Instead of just:
STAT #2 id=1 cnt=1 pid=0 pos=1 obj=17 op='TABLE ACCESS FULL FILE$'
they started look like this:
STAT #2 id=1 cnt=1 pid=0 pos=1 obj=17 op='TABLE ACCESS FULL FILE$ (cr=4 pr=0 pw=0 time=91 us)'

And in 10.2 format of WAIT lines and BINDS sections changed significantly.

BINDS sections can not be processed by tkprof in any versions of Oracle so I just skip them.

As for WAIT lines, here's the pre-10.2 WAIT line:
WAIT #4: nam='SQL*Net message from client' ela= 2794957 p1=1111838976 p2=1 p3=0 p3=62
Compare it with 10.2:
WAIT #4: nam='SQL*Net message from client' ela= 2794957 driver id=1111838976 #bytes=1 p3=0 obj#=62 tim=42601199281

Wait events parameters (p1,p2,p3) got a meaningful name (as a side note: but sometimes not a meaningful value -- #bytes in 'SQL*Net messages' still always equal to 1) and every WAIT line now have tim-stamp.

The funny thing is that tkprof from Oracle 9.2 correctly process trace files from 10.2! Looks like tkprof parses WAIT line by splitting line on '=' character and just gets the first three values.

In summary, I beleive that when tkprof from old version can correctly process trace files from the new one then it's more natural to say that 'trace files contents does not differ greatly between different versions of Oracle'.

Thursday, 24 November 2011

How to Configure OEM 10g Database Control after Clone

After cloning an EBS environment I had tried to start the OEM 10g Database Control (DBConsole) and I got this message:

[oratest@testsrv1 ~]$ emctl start dbconsole
TZ set to Israel
OC4J Configuration issue.
/oracle/test/db/testdb/10.2/ oc4j/j2ee/OC4J_DBConsole_testsrv1.domain_TEST not found.

However, it was an acceptable message since DB Console wasn't configured to this instance yet.

Using emca I've tried to recreate the DB Control configuration files as follow:

[oratest@testsrv1 ~]$ emca -config dbcontrol db

...
INFO: Database Control started successfully
...
INFO: >>>>>>>>>>> The Database Control URL is http://testsrv1.domain:5500/em <<<<<<<<<<<
Enterprise Manager configuration completed successfully

Well, I thought it looks fine, but when I opened the DB Console I saw this message at the top of the page:

error:
java.lang.Exception: Exception in sending Request :: null



After some research, logs digging and Metalink searches, I found that the Agent component should be relinked manually.
But before there are two issues in env_sysman.mk file that should be fixed before executing the relink command.

I will show my actions step by step:

Stop DB Console:
emctl stop dbconsole

cd $ORACLE_HOME/sysman/lib

Edit env_sysman.mk and look for "JRE_LIB_DIR"
In my instance JRE_LIB_DIR was populated with the old environment name..
I changed it from:
JRE_LIB_DIR=/oracle/prod/db/proddb/10.2/jdk/jre/lib/i386
To:
JRE_LIB_DIR=/oracle/test/db/testdb/10.2/jdk/jre/lib/i386

One more issue for env_sysman.mk, look for "$(LIBNMEM) $(LIBNMER)"
And change from:
$(LIBNMEM) $(LIBNMER) \
To:
$(LIBNMEM) $(LIBNMER) $(LIBNMO) \

Now relink the Agent component by issuing this command:
make -f ins_sysman.mk agent

Recreate the DB Control configuration files (Again, even if you did it before)
emca -config dbcontrol db
Following this procedure will make the DBConsole configured and work for the new cloned instance.

ADPATCH with "options=prereq" - what really happens there?

With adpatch utility we have a possibility to ask for a prerequisite check prior to running patch driver files.
Actually, some patches must apply with prerequisite check before applying them.

The adpatch command should look like: adpatch option=prereq
This flag indicate to adpatch to check prerequisite before applying patch.

adpatch checks the prerequisite based on information from patch files and current snapshot on APPL_TOP.

When running adpatch with "prereq" flag, we might get an error message like:
Analyzing prerequisite patch information...
AutoPatch error: This patch has some prerequisites specified, but a "snapshot" of this APPL-TOP's file-system has never been taken, thereby rendering it impossible to check for the prerequisites.
Please take a "snapshot" of this APPL-TOP using "AD Administration" first.

This error message will show up if a snapshot on current APPL_TOP doesn't exists.

To create such snapshot on APPL_TOP:
1) run adadmin
2) Select "Maintain Applications Files menu"
3) Select "Update current view snapshot"
4) Rerun adpatch

**It might take couple of hours depends on your hardware and APPL_TOP size.


So how adpatch check the prerequisites?

1) Check if a snapshot on current APPL_TOP exist.
using sql script - adbkflsn.sql (if not, will terminate with above error message.....)

2) adpatch uploads a ldt file with FNDLOAD utility into system (bug-fixes).
ldt file name is: b[PATCH_NUMER].ldt - comes from patch root directory.

3) Execute the UMS analysis engine based on the snapshot and bug-fixes to check if all prerequisites exists.

How to check conflicts while applying CPU patch?

Please use below command to check the conflicts aganist the oracle_home and avoid to land in problems

step 1: unzip your patch zip file
step 2: run below command
$ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir

Example:

$ unzip p9655017_10204_linux.zip
$ $ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir 9655017
The other day, when I am doing patching on a RAC database, after executing the above conflict command, got below error

Following patches have conflicts. Please contact Oracle Support and get the merged patch of the patches :
6600051, 8836683
Whenever you get this type of error message, plz contact oracle support by raising a service request(SR)

In my case, Oracle support suggested to apply a merge patch 9347333 before applying Jul CPU 2011. Once done with applying merge patch, without any further issues I successfully applied CPU patch

Sometimes apart from above message you may see below warning messages which you can ignore

Summary of Conflict Analysis:

Patches that can be applied now without any conflicts are :
10013975, 10014009, 10014012, 10014015, 10325878, 10325885, 11787762, 11787763, 11787765, 11787766, 12419249, 12566121, 12566124, 12566126, 12566129, 12566131, 12566134, 12566136, 12566137, 12566139, 12566141, 12566142, 12566143, 7155248, 7155249, 7155250, 7155251, 7155252, 7155253, 7155254, 7197583, 7375611, 7375613, 7375617, 7609057, 8309592, 8309632, 8568395, 8568397, 8568398, 8568402, 8568404, 8836667, 8836671, 8836675, 8836677, 8836678, 8836683, 8836684, 8836686, 9173244, 9173253, 9442328, 9442331, 9442339, 9678690, 9678695, 9678697

Following patches are not required, as they are subset of the patches in Oracle Home or subset of the patches in the given list :
10249540, 8836681, 8568405

Following patches will be rolled back from Oracle Home on application of the patches in the given list :
10013975, 10014009, 10014012, 10014015, 10325878, 10249540, 8836681, 8568405, 7155248, 7155249, 7155250, 7155251, 7155252, 7197583, 7375611, 7375613, 7375617, 7609057, 8309592, 8309632, 8568395, 8568397, 8568398, 8568402, 8568404, 8836667, 8836671, 8836675, 8836677, 8836678, 8836683, 8836684, 8836686, 9173244, 9173253, 9442328, 9442331, 9442339, 9678690, 9678695

How to resolve ORA-00490 error?

Root Cause:

This error will occur when there is no free space available in swap area of System for spawning new process of Oracle. Due to this reason Process SPwaner process PSP0 (with ORA-00490 error code of Oracle) terminated because it doesn’t able to manage or create Oracle processes. Result is Oracle instance crashed by PMON process with errorstack 490 (which is pointing out ORA-00490). If lack of system resource found then also same situation can be occurring.

Solution :

There are 2 solutions for this problem which are mentioned below

1. Check your swap space and increase swap area in system. Because due to lack of space in swap are Oracle unable to create new process and PSP0 Process SPwaner is unable to manage Oracle process.

2. Check “ulimit” setting for Oracle. “ulimit” is for user shell limitation. If maximum shell limit is reached then also PSP0 process becomes unstable to manage other Oracle processes.Increase the “ulimit” setting for Oracle user.

Purge old files on Linux/Unix using “find” command

I've noticed that one of our interface directories has a lot of old files, some of them were more than a year old. I checked it with our implementers and it turns out that we can delete all files that are older than 60 days.

I decided to write a (tiny) shell script to purge all files older than 60 days and schedule it with crontab, this way I won't deal with it manually. I wrote a find command to identify and delete those files. I started with the following command:

find /interfaces/inbound -mtime +60 -type f -maxdepth 1 -exec rm {} \;

It finds and deletes all files in directory /interface/inbound that are older than 60 days.
"-maxdepth 1" -> find files in current directory only. Don't look for files in sub directories.

After packing it in a shell script I got a request to delete "csv" files only. No problem... I added the "-name" to the find command:

find /interfaces/inbound -name "*.csv" -mtime +60 -type f -maxdepth 1 -exec rm {} \;

All csv files in /interface/inbound that are older than 60 days will be deleted.

But then, the request had changed, and I was asked to delete "*.xls" files further to "*.csv" files.

I tried several things, like add another "-name" to the find command:

find /interfaces/inbound -name "*.csv" -name "*.xls" -mtime +60 -type f -maxdepth 1 -exec rm {} \;

But no file was deleted. Couple of moments later I understood that I'm trying to find csv files which is also xls files... (logically incorrect of course).

After struggling a liitle with the find command, I managed to make it works:

find /interfaces/inbound \( -name "*.csv" -o -name "*.xls" \) -mtime +60 -type f -maxdepth 1 -exec rm {} \;

ORA-00821 Specified value of sga_target is too small....

Resized your SGA_TARGET too small and found you can’t now start your database.

If you are using a PFILE then just edit it and set the SGA_TARGET to a larger value. But what if you’re using an SPFILE. One possibility is to create the pfile from the spfile edit the pfile, and then either start the database using the pfile and remove the spfile and start the database as normal and the new pfile will be picked up.

The problem arises when the spfile is in an ASM, creating the pfile from this can be a problem. One solution is to create a pfile which calls the spfile in the ASM but after the call to the spfile add an extra line which alters the SGA_TARGET as follows

SPFILE='+DATA1/PROD1/spfilePROD1.ora'
SGA_TARGET=1024M

This pfile can be places in $OH/dbs thus, the next time you start the database this pfile will be run. Alternatively, you could explicitly use the ‘pfile=’ parameter when starting the database thus

Startup pfile=$OH/dbs/initPROD1.ora

Wednesday, 23 November 2011

Oracle Applications Schema Password Change Utility - (FNDCPASS)

Changing passwords periodically helps ensure database security. Oracle Applications provides a command line utility, FNDCPASS, to set Oracle Applications schema passwords. In addition to changing the schema password in the database, this utility changes the password registered in Oracle Applications tables (FND Tables). This utility can also change Applications End User passwords.


FNDCPASS changes

Oracle Applications Database System Users (APPS, APPLSYS)
Oracle Applications Product Schema Passwords (GL, AR, AP, etc,)
Oracle Applications End User Account Passwords (SYSADMIN, OPERATIONS etc)

Note: the utility, FNDCPASS, cannot be used for changing the database SYSTEM and SYS users. Only users that are registered in FND meta data tables need to be changed using FNDCPASS. Normally, the APPS database user password and APPLSYS password need to be the same. When changing the APPLSYS password using FNDCPASS, the APPS password is also changed.

Syntax of FNDCPASS command:

FNDCPASS logon 0 Y system/password mode username new_password

Where logon is username/password[@connect]

System/password is password of the system account of that database
Mode is SYSTEM/USER/ORACLE
Username is the username where you want to change its password
new_password is the new password in unencrypted format

Example:

$ FNDCPASS apps/apps 0 Y system/manager SYSTEM APPLSYS WELCOME

$ FNDCPASS apps/apps 0 Y system/manager ORACLE GL GL1

$ FNDCPASS apps/apps 0 Y system/manager USER VISION WELCOME

Note: The FNDCPASS has a new mode, "ALLORACLE", in which all Oracle Application schema passwords can be changed in one call. Apply the patch (Patch No# 4745998) to have this option, if not available currently with your Apps.

Syntax:

FNDCPASS 0 Y ALLORACLE

Example:

$ FNDCPASS apps/apps 0 Y system/manager ALLORACLE WELCOME

To change APPS/APPLSYS password, we need to give mode as SYSTEM
To change product schema passwords, i.e., GL, AP, AR, etc., we need to give mode as ORACLE
To change end user passwords, i.e., SYSADMIN, OPERATIONS etc., we need give mode as USER

Note: Till 11.5.9 there is bug in FNDCPASS, which allows FNDCPASS to change APPS&APPLSYS passwords. Doing so will corrupt the data in FND meta data tables and cause to the application unusable. Because of that it is recommend taking backup of the tables FND_USER and FND_ORACLE_USERID before changing the passwords.

After changing the APPS/APPLSYS or APPLSYSPUB user, following extra manual steps needs to be done.

If you changed the APPS (and APPLSYS) password, update the password in these files:

iAS_TOP/Apache/modplsql/cfg/wdbsvr.app
ORACLE_HOME/reports60/server/CGIcmd.dat
If you changed the APPLSYSPUB password, update the password in these files:

FND_TOP/resource/appsweb.cfg
OA_HTML/bin/appsweb.cfg
FND_TOP/secure/HOSTNAME_DBNAME.dbc

Note: I would you suggest you to first try changing the passwords using FNDCPASS on your test Apps Instances, once you are done with this without any errors or issues then you can move this to production, and also request you to search in metalink for more information about FNDCPASS utility and it's usage.

DB Link to Oracle 11g

As you know in Oracle 11g passwords are case sensitive by default. This applies to connecting via SQL*Plus or other client tools. And it also applies to database links between databases. So when you link from Oracle 10g to Oracle 11g create database link like this:

CREATE DATABASE LINK my_link
CONNECT TO remote_user IDENTIFIED BY "CaSe_SeNsItIvE_PaSsWoRd"
USING 'TNS_ID_11G';


Do not forget to enclose password by double-quote marks!

When you do not set password this way, you will be getting:

ORA-01017: invalid username/password; logon denied.

Hope this small tip will be useful for someone.

Tuesday, 15 November 2011

ORA-28576: lost RPC connection to external procedure agent

Cause: of this error is abnormal termination of the invoked "C" routine. If this is not the case, check for network problems. Correct the problem if you find it. If all components appear to be normal but the problem persists, the problem could be an internal logic error in the RPC transfer code. Contact your customer support representative.
Action: First check the 3GL code you are invoking; the most likely

ORA-04031: unable to allocate string bytes of shared memory ("string","string","string","string")

Cause: More shared memory is needed than was allocated in the shared pool.
Action: If the shared pool is out of memory, either use the dbms_shared_pool package to pin large packages, reduce your use of shared memory, or increase the amount of available shared memory by increasing the value of the INIT.ORA parameters "shared_pool_reserved_size" and "shared_pool_size". If the large pool is out of memory, increase the INIT.ORA parameter "large_pool_size".

Monday, 14 November 2011

How to know which columns are in the overflow segment?

Remember that the INCLUDE_COLUMN of the USER_INDEXES view gives you the last column included in the index and so in the top segment, so joining this view with the USER_TAB_COLUMNS you can separate the columns that are in the top segment from those that are in the overflow one as with the following statement:
SQL> SELECT c.table_name, c.column_name,
2 CASE WHEN c.column_id <= i.include_column THEN 'TOP' ELSE 'OVERFLOW' END segment
3 FROM user_tab_columns c, user_indexes i
4 WHERE i.table_name = c.table_name
5 ORDER by table_name, column_id;

TABLE_NAME COLUMN_NAME SEGMENT
------------------------------ ------------------------------ --------
MY_IOT ID TOP
MY_IOT VALUE TOP
MY_IOT COMMENTS OVERFLOW

How to move an IOT into another tablespace?

SQL> SELECT segment_name, segment_type, tablespace_name FROM user_segments ORDER BY 1;

SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME
------------------------------ ------------------ ------------------------------
SYS_IOT_OVER_71142 TABLE TS_D01
SYS_IOT_TOP_71142 INDEX TS_D01
Let's assume you want to move all the segments from their current tablespace to another tablespace. You'll quickly discover that you cannot use the standard commands:
SQL> ALTER TABLE sys_iot_over_71142 MOVE TABLESPACE ts_i01;

ALTER TABLE sys_iot_over_71142 MOVE TABLESPACE ts_i01
*
ERROR at line 1:
ORA-25191: cannot reference overflow table of an index-organized table

SQL> ALTER INDEX sys_iot_top_71142 REBUILD TABLESPACE ts_i01;

ALTER INDEX sys_iot_top_71142 REBUILD TABLESPACE ts_i01
*
ERROR at line 1:
ORA-28650: Primary index on an IOT cannot be rebuilt
You have to first find the name of the associated IOT table:
SQL> SELECT iot_name FROM user_tables WHERE table_name = 'SYS_IOT_OVER_71142';

IOT_NAME
------------------------------
MY_IOT

SQL> SELECT table_name FROM user_indexes WHERE index_name = 'SYS_IOT_TOP_71142';

TABLE_NAME
------------------------------
MY_IOT

Then you can move the segments:
SQL> ALTER TABLE my_iot MOVE TABLESPACE ts_i01;

Table altered.

SQL> ALTER TABLE my_iot MOVE OVERFLOW TABLESPACE ts_i01;

Table altered.

SQL> SELECT segment_name, segment_type, tablespace_name FROM user_segments ORDER BY 1;

SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME
------------------------------ ------------------ ------------------------------
SYS_IOT_OVER_71142 TABLE TS_I01
SYS_IOT_TOP_71142 INDEX TS_I01
The first statement moves the top segment and the second one the overflow segment. This can be done in one statement using:
SQL> ALTER TABLE my_iot MOVE TABLESPACE ts_d01 OVERFLOW TABLESPACE ts_d01;

Table altered.

What is Oracle Exadata ???

Oracle recently announced a wide array of products and solutions spanning database, middleware, applications and hardware in the Indian market. Among all these products and solution - Exadata, drew our attention.

According to the company, Oracle "Exadata Database Machine" provides extreme performance for both data warehousing and online transaction processing (OLTP) applications, making it the ideal platform for consolidating onto grids or private clouds. A complete package of servers, storage, networking, and software, the product is scalable, secure, and redundant.

Till now more than 1000 Exadata machines have been installed in 67 countries and across 23 industries. With more than 60 per cent market share, the company aims to leverage its existing customer base, which consists of more than 7000 Indian organizations to drive sales for Exadata.

Currently, Sun Pharmaceuticals, Tech Mahindra, Religare, Reliance Consumer Finance and Stock Holding Corporation and Stock Holding Corporation of India have adopted Exadata for their datawarhousing , database and OLTP requirement.

Placed among the top five vendors worldwide, Oracle believes that Exadata has made a strong contribution to Oracle’s growth in Q4 FY10, IT PRO India explores the product with Sheshagiri Anegondi, Vice President – Technology, Oracle India.

Bringing in technical innovation

"Exadata brings forward key technical innovations like Intelligent Storage, Smart Flash Cache and Hybrid Columnar Compression. With these innovations, Exadata provides extreme performance while ensuring maximum ROI," says Sheshagiri Anegondi, Vice President – Technology, Oracle India.

He further adds, "the smart storage software in Exadata offloads data-intensive query processing from Oracle Database 11g servers to Exadata’s storage layer for parallel data processing. Because there’s less data moving through the higher-bandwidth connections, you get dramatically improved performance as well as concurrency for simple and complex data warehousing queries.”

Exadata packs in some impressive features. It performs 1.5 million I/O operations in 1 second, speeding database performance by 10x. It also reduces electricity consumption by 87.5 percent and floor space by 75 percent – thereby shrinking datacenter from an entire building to a single room.

Playing pivotal role in security issues

Exadata will also play a pivotal role in data security. "As organizations consolidate their data, more and more sensitive information ranging from email addresses to credit card numbers now resides in a single database, giving organizations the ability to secure and monitor that data more efficiently than ever before," according to Anegondi.

As a matter of fact Exadata, can utilize Oracle’s industry leading database security solutions to block threats and detect unauthorized activities like misuse of privileged user credentials, insider threats, and SQL injection.

For further security Oracle is offering Oracle's Advanced Security for Exadata. This would include Oracle Database Vault that protects against misuse of stolen login credentials, application bypass, and unauthorized changes to applications, including attempts to make copies of application tables, Oracle Audit Vault that provides auditors and internal security personnel an efficient means of reviewing of activity inside the Oracle Exadata Database Machine and Oracle Database Firewall to monitor in-bound SQL traffic over Oracle SQL Net and the TCP/IP protocol."

Oracle RAC Background processes

RAC Background Processes:

1. Lock Monitor Processes ( LMON)
2. Lock Monitor Services (LMS)
3. Lock Monitor Daemon Process ( LMD)
4. LCKn ( Lock Process)
5. DIAG (Diagnostic Daemon)

1. Lock Monitor Processes ( LMON)

It Maintains GCS memory structures.
Handles the abnormal termination of processes and instances.
Reconfiguration of locks & resources when an instance joins or leaves the cluster are handled by LMON ( During reconfiguration LMON generate the trace files)
It responsible for executing dynamic lock remastering every 10 mins ( Only in 10g R2 & later versions).
LMON Processes manages the global locks & resources.
It monitors all instances in cluster, primary for dictionary cache locks,library cache locks & deadlocks on deadlock sensitive on enqueue & resources.
LMON also provides cluster group services.
Also called Global enqueue service monitor.

2. Lock Monitor Services (LMS)

LMS is most very active background processes.
Consuming significant amount of CPU time. ( 10g R2 - ensure that LMS process does not encounter the CPU starvation).
Its primary job is to transport blocks across the nodes for cache-fusion requests.
If there is a consistent-read request, the LMS process rolls back the block, makes a Consistent-Read image of the block and then ship this block across the HSI (High Speed Interconnect) to the process requesting from a remote node.
LMS must also check constantly with the LMD background process (or our GES process) to get the lock requests placed by the LMD process.
Each node have 2 or more LMS processes.

GCS_SERVER_PROCESSES --> no of LMS processes specified in init. ora parameter.
Above parameter value set based on number of cpu's ( MIN(CPU_COUNT/2,2))
10gR2, single CPU instance,only one LMS processes started.
Increasing the parameter value,if global cache activity is very high.
Also called the GCS (Global Cache Services) processes.

Internal View: X$KJMSDP

3. Lock Monitor Daemon Process ( LMDn)

LMD process performs global lock deadlock detection.
Also monitors for lock conversion timeouts.
Also sometimes referred to as the GES (Global Enqueue Service) daemon since its job is to manage the global enqueue and global resource access.
LMD process also handles deadlock detection and remote enqueue requests.
Remote resource requests are the requests originating from another instance.
Internal View: X$KJMDDP
4. LCKn ( Lock Process)
Manages instance resource requests & cross instance calls for shared resources.
During instance recovery,it builds a list of invalid lock elements and validates lock elements.
5. DIAG (Diagnostic Daemon)
Oracle 10g - this one new background processes ( New enhanced diagnosability framework).
Regularly monitors the health of the instance.
Also checks instance hangs & deadlocks.
It captures the vital diagnostics data for instance & process failures.

What's blocking my lock?

Create a blocking lock

To begin, create a situation where one user is actively blocking another. Open two sessions. Issue the following commands in Session 1 to build the test table:

SQL> create table tstlock (foo varchar2(1), bar varchar2(1));

Table created.

SQL> insert into tstlock values (1,'a');

1 row created.

SQL> insert into tstlock values (2, 'b');

1 row created.

SQL> select * from tstlock ;

FOO BAR
--- ---
1 a
2 b

2 rows selected.

SQL> commit ;

Commit complete.
Now grab a lock on the whole table, still in Session 1:

SQL> select * from tstlock for update ;

And in Session 2, try to update a row:

SQL> update tstlock set bar=
2 'a' where bar='a' ;
This statement will hang, blocked by the lock that Session 1 is holding on the entire table.

Identify the blocking session

Oracle provides a view, DBA_BLOCKERS, which lists the SIDs of all blocking sessions. But this view is often, in my experience, a good bit slower than simply querying V$LOCK, and it doesn't offer any information beyond the SIDs of any sessions that are blocking other sessions. The V$LOCK view is faster to query, makes it easy to identify the blocking session, and has a lot more information.

SQL> select * from v$lock ;

ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
AF9E2C4C AF9E2C60 479 TX 131078 16739 0 6 685 0
ADDF7EC8 ADDF7EE0 422 TM 88519 0 3 0 697 0
ADDF7F74 ADDF7F8C 479 TM 88519 0 3 0 685 0
ADEBEA20 ADEBEB3C 422 TX 131078 16739 6 0 697 1
.... .... ... ... .... .... .... .... .... ....
Note the BLOCK column. If a session holds a lock that's blocking another session, BLOCK=1. Further, you can tell which session is being blocked by comparing the values in ID1 and ID2. The blocked session will have the same values in ID1 and ID2 as the blocking session, and, since it is requesting a lock it's unable to get, it will have REQUEST > 0.

In the query above, we can see that SID 422 is blocking SID 479. SID 422 corresponds to Session 1 in our example, and SID 479 is our blocked Session 2.

To avoid having to stare at the table and cross-compare ID1's and ID2's, put this in a query:

SQL> select l1.sid, ' IS BLOCKING ', l2.sid
2 from v$lock l1, v$lock l2
3 where l1.block =1 and l2.request > 0
4 and l1.id1=l2.id1
5 and l1.id2=l2.id2
SQL> /

SID 'ISBLOCKING' SID
---------- ------------- ----------
422 IS BLOCKING 479

1 row selected.
Even better, if we throw a little v$session into the mix, the results are highly readable:

SQL> select s1.username || '@' || s1.machine
2 || ' ( SID=' || s1.sid || ' ) is blocking '
3 || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
4 from v$lock l1, v$session s1, v$lock l2, v$session s2
5 where s1.sid=l1.sid and s2.sid=l2.sid
6 and l1.BLOCK=1 and l2.request > 0
7 and l1.id1 = l2.id1
8 and l2.id2 = l2.id2 ;


BLOCKING_STATUS
----------------------------------------------------------------------------------------------------
BULKLOAD@yttrium ( SID=422 ) is blocking BULKLOAD@yttrium ( SID=479 )

1 row selected.
There's still more information in the v$lock table, but in order to read that information, we need to understand a bit more about lock types and the cryptically-named ID1 and ID2 columns.

Lock type and the ID1 / ID2 columns

In this case, we already know that the blocking lock is an exclusive DML lock, since we're the ones who issued the locking statement. But most of the time, you won't be so lucky. Fortunately, you can read this information from the v$lock table with little effort.

The first place to look is the TYPE column. There are dozens of lock types, but the vast majority are system types. System locks are normally only held for a very brief amount of time, and it's not generally helpful to try to tune your library cache, undo logs, etc. by looking in v$lock! (See the V$LOCK chapter in the Oracle Database Reference for a list of system lock types.)

There are only three types of user locks, TX, TM and UL. UL is a user-defined lock -- a lock defined with the DBMS_LOCK package. The TX lock is a row transaction lock; it's acquired once for every transaction that changes data, no matter how many objects you change in that transaction. The ID1 and ID2 columns point to the rollback segment and transaction table entries for that transaction.

The TM lock is a DML lock. It's acquired once for each object that's being changed. The ID1 column identifies the object being modified.

Lock Modes

You can see more information on TM and TX locks just by looking at the lock modes. The LMODE and REQUEST columns both use the same numbering for lock modes, in order of increasing exclusivity: from 0 for no lock, to 6 for exclusive lock. A session must obtain an exclusive TX lock in order to change data; LMODE will be 6. If it can't obtain an exclusive lock because some of the rows it wants to change are locked by another session, then it will request a TX in exclusive mode; LMODE will be 0 since it does not have the lock, and REQUEST will be 6. You can see this interaction in the rows we selected earlier from v$lock:

ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
AF9E2C4C AF9E2C60 479 TX 131078 16739 0 6 685 0
ADEBEA20 ADEBEB3C 422 TX 131078 16739 6 0 697 1
Note that ID1 and ID2 in Session 2, which is requesting the TX lock (LMODE=0, REQUEST=6), point back to the rollback and transaction entries for Session 1. That's what lets us determine the blocking session for Session 2.

You may also see TX locks in mode 4, Shared mode. If a block containing rows to be changed doesn't have any interested transaction list (ITL) entries left, then the session acquires a TX lock in mode 4 while waiting for an ITL entry. If you see contention for TX-4 locks on an object, you probably need to increase INITRANS for the object.

TM locks are generally requested and acquired in modes 3, aka Shared-Row Exclusive, and 6. DDL requires a TM Exclusive lock. (Note that CREATE TABLE doesn't require a TM lock -- it doesn't need to lock any objects, because the object in question doesn't exist yet!) DML requires a Shared-Row Exclusive lock. So, in the rows we selected earlier from v$lock, you can see from the TM locking levels that these are DML locks:

ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
ADDF7EC8 ADDF7EE0 422 TM 88519 0 3 0 697 0
ADDF7F74 ADDF7F8C 479 TM 88519 0 3 0 685 0
Identifying the locked object
Now that we know that each TM row points to a locked object, we can use ID1 to identify the object.

SQL> select object_name from dba_objects where object_id=88519 ;

OBJECT_NAME
--------------
TSTLOCK
Sometimes just knowing the object is enough information; but we can dig even deeper. We can identify not just the object, but the block and even the row in the block that Session 2 is waiting on.

Identifying the locked row

We can get this information from v$session by looking at the v$session entry for the blocked session:

SQL> select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#
2* from v$session where sid=479 ;

ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW#
------------- -------------- --------------- -------------
88519 16 171309 0
This gives us the object ID, the relative file number, the block in the datafile, and the row in the block that the session is waiting on. If that list of data sounds familiar, it's because those are the four components of an extended ROWID. We can build the row's actual extended ROWID from these components using the DBMS_ROWID package. The ROWID_CREATE function takes these arguments and returns the ROWID:

SQL> select do.object_name,
2 row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
3 dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
4 from v$session s, dba_objects do
5 where sid=543
6 and s.ROW_WAIT_OBJ# = do.OBJECT_ID ;

OBJECT_NAME ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# DBMS_ROWID.ROWID_C
--------------- ------------- -------------- --------------- ------------- ------------------
TSTLOCK 88519 16 171309 0 AAAVnHAAQAAAp0tAAA
And, of course, this lets us inspect the row directly.

SQL> select * from tstlock where rowid='AAAVnHAAQAAAp0tAAA' ;

FOO BAR
--- ---
1 a

Conclusion

We've seen how to identify a blocking session, and how to inspect the very row that the waiting session is waiting for. And, I hope, learned a bit about v$lock in the process.