Monday, April 2, 2012

ORA 4021 - time-out occurred while waiting to lock object


Problem Description
-------------------

Trying to recreate a package, procedure or function (CREATE OR REPLACE ...) or dropping a the same (DROP PACKAGE ...) causes the application to hang (ie: SQL*Plus hangs after submitting the statement). Eventually ORA-4021 errors occur after the timeout (usually 5 minutes).

Solution Description

Verify that the package is not locked by another user by selecting from V$ACCESS view.  To do this, run:

SELECT * FROM v$access WHERE object = '';

Where is the package name (usually in all uppercase).  If there is a row returned, then the package is already locked and cannot be dropped until the lock is released.  Returned from  he query above will be the SID that has this locked. You can then use this to find out which session has obtained the lock.

In some cases, that session might have been killed and will not show up.  If this happens, the lock will not be release immediately.  Waiting for PMON to clean up the lock might take some time. The fastest way to clean up the lock is to recycle the database instance.

If an ORA-4021 error is not returned and the command continues to hang after issuing the CREATE OR REPLACE or DROP statment, you will need to do further analysis see where the hang is occuring. A starting point is to have a look in v$session_wait, see the referenced Note 61552.1 for how to analyze hang situations in general

Solution Explanation

Consider the following example:

Session 1:

create or replace procedure lockit(secs in number) as
shuttime date;
begin
shuttime := sysdate + secs/(24*60*60);
while sysdate <= shuttime loop
null;
end loop;
end;
/
show err

begin
-- wait 10 minutes
lockit(600);
end;
/

Session 2:

SQL> create or replace procedure ops$hnapel.lockit as
2  begin
3     null;
4  end;
5  /

Result: hang and eventually (the timeout is 5 minutes):

create or replace procedure ops$hnapel.lockit as
*
ERROR at line 1:
ORA-04021: timeout occurred while waiting to lock object OPS$HNAPEL.LOCKIT

Session 3:

SQL> connect  / as sysdba
Connected.
SQL> col owner for a10
SQL> col object for a15
SQL> select * from v$access where object = 'LOCKIT';

SID OWNER      OBJECT          TYPE
---------- ---------- --------------- ------------------------
9 OPS$HNAPEL LOCKIT          PROCEDURE

SQL> select sid, event from v$session_wait;

SID EVENT
---------- ----------------------------------------------------------------
9 null event
...
12 library cache pin

As you can see, the blocking sid 9 waits for nothing while session 2, the hanging session, is waiting for event library cache pin.

Source : Oracle Metalink

Wednesday, March 7, 2012

Database Links: Troubleshooting ORA-2085 "database link %s connects to %s"


  
To explain database link naming rules in an effort to avoid the error ORA-2085 "database link %s connects to %s"

When the source database initialization parameter GLOBAL_NAMES is set to true, the database link name must match the target database global name as it exists in the GLOBAL_NAME view in the data dictionary.

The GLOBAL_NAME can be determined by logging in to the database with system privileges and issuing the following command:

SQL>Select * from global_name;

Additionally, if you do not specify the domain portion of the dblink name in the create statement, Oracle automatically qualifies the link name with the domain of the SOURCE database global name view.

Check the contents of ALL_DB_LINKS for the fully qualified link name.

For example, if you defined a database link in PROD.ORACLE.COM to connect to target instance TEST.WORLD.COM in the following manner:

SQL>Create public database link TEST connect to userid identified by password using test;

SQL>select * from tablename@TEST;

This select would yield the following error:

ORA-2085 "database link TEST.ORACLE.COM connects to TEST.WORLD.COM"

The correct syntax for defining the link would be:

SQL>Create public database link TEST.WORLD.COM connect to userid identified by password using test;

SQL>select * from tablename@TEST.WORLD.COM;

Would yield desired result.

It is possible to alter the GLOBAL_NAME table so that the domain portion of both SOURCE and TARGET global names are identical. This would eliminate the need to include the domain in the create database link statement.

In the above example, we could alter the GLOBAL_NAME of TEST.WORLD.COM in the following manner:

Login to TEST with system privileges and issue:

SQL>alter database rename global_name to TEST.ORACLE.COM;

Now, the create database link statement could also be changed.

Login to PROD.

SQL>create public database link TEST connect to userid identified by password using test;

A database link would be defined in ALL_DB_LINKS as TEST.ORACLE.COM.

SQL>select * from tablename@TEST;

This would yield the desired result.


Sunday, February 5, 2012

PDF Printing slovenian characters problem


PDF Printing slovenian characters problem :

http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=11031

As I understand the limitation of reports 6i is due to the fact that Reports 6i has builtin support for an older PDF standard V1.1.

It's a documented limitation, see Metalink Note 222663.1.

"PDF output is only supported for latin 1 code pages (US7ASCII, WE8ISO8859P1 and WE8MSWIN1252). "

Tuesday, January 10, 2012

ORA-12154 ORA-12162 calling SQL*Loader / SQL*Plus


Problem Description 

Running SQL*Loader as: 

sqlload userid=... control=... data=... log=... 

HOSTSTR logical has been set to same value as your connection string but without domain name. 

When you have specified connect string (ie. SCOTT/TIGER@DATABASE) but no domain you receive these errors: 

SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0] 
ORA-12154: TNS:could not resolve service name 

When you have not specified connect string (ie. SCOTT/TIGER) you receive these errors: 

SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0] 
ORA-12162: TNS:service name is incorrectly specified 

Your sqlnet.ora has: 

names.default_domain entry = world 

The syntax in your tnsnames.ora entry is correct. 

Your entry in tnsnames.ora does not include the .WORLD extension (default domain from sqlnet.ora). 

Solution Description 

Specify the .WORLD in your tnsnames.ora and also in your connect string. This will remove the error. 

Also, ensure you are not hitting [BUG:893290].   

Source : Oracle Metalink Note:116852.1

Tuesday, December 20, 2011

ORA-00439 When Trying To Create Materialized View With Enable Query Rewrite


ORA-00439 When Trying To Create Materialized View With Enable Query Rewrite

1. When trying to create a materialized view in SQL*Plus an error is returned:

  CREATE MATERIALIZED VIEW store_sales_mv
  PCTFREE 0 TABLESPACE mviews
  STORAGE (INITIAL 16k NEXT 16k PCTINCREASE 0)
  PARALLEL
  BUILD DEFERRED
  REFRESH COMPLETE
  ENABLE QUERY REWRITE
  AS
  SELECT
   s.store_name,
   SUM(dollar_sales) AS sum_dollar_sales
   FROM store s, fact
   WHERE f.store_key = s.store_key
   GROUP BY s.store_name;

  ORA-00439: feature not enabled: %s
     Cause: The specified feature is not enabled.
     Action: Do not attempt to use this feature.

3. The ENABLE QUERY REWRITE option is removed from the above statement and the error goes away and the statement processes successfully.

Solution Description:

The proper options must be installed to use some features of the materialized views. The query 'select * from V$option' will show what options are installed. The options needed to use enable query rewrite and refresh capabilities are:

Parameter                                              Value
Materialized view rewrite                        TRUE     -> For ENABLE QUERY REWRITE
Materialized view warehouse refresh     TRUE     -> For REFRESH

In addition, the following initialization parameters must also be set:

QUERY_REWRITE_ENABLED = default is set to FALSE, can change to TRUE
QUERY_REWRITE_INTEGRITY = ENFORCED, STALE_TOLERATED, TRUSTED

Source : Oracle Metalink 

Wednesday, November 9, 2011

ORA-29540: class oracle/plsql/net/TCPConnection does not exist


Problem Description

When attempting to run the packages UTL_SMTP, and UTL_TCP, an error is returned indicating that the class oracle/plsql/net/TCPConnection does not exist.  This class, along with others that support SQLJ functionality, should normally be loaded when the "initjvm.sql" script is run. 
However, that script has already been run successfully, to completion.

ORA-29540: class oracle/plsql/net/TCPConnection does not exist

Solution Description

The initjvm.sql script (located in the ORACLE_HOME/javavm/install directory) is run automatically during normal installation of the database, except during custom installation.  In any event, thescript can be run manually (as SYS) at a later time. When this script is run, approximately 8000+ java classes are loaded into the database. 

Unfortunately, there is another script, initplsj.sql (located in ORACLE_HOME/rdbms/admin) which is supposed to be called by the initjvm.sql script. This does not occur. To fix the problem, runthe initplsj.sql script (as SYS).  You will note that 200+ classes get loaded into the database as a result of this script. 

This should then allow you to use the UTL_SMTP and UTL_TCP packages.

This script also needs to be run:

$ORACLE_HOME/javavm/install/init_security.sql

Source: Oracle Metalink

Monday, October 3, 2011

Oracle Reports background engine stopping


In Forms 6i when a report is run, a background process called Reports Background Engine is created. Sometimes we want  this process to be terminated automatically when a report is completed and we exit from report.

Here is the PL/SQL code for this:

DECLARE
  pl_id ParamList;
BEGIN
  pl_id := Create_Parameter_List('dummy');
  Add_Parameter(pl_id,'ORACLE_SHUTDOWN',TEXT_PARAMETER,'Yes');
  Add_Parameter(pl_id,'PARAMFORM',TEXT_PARAMETER,'NO');
  Run_product(REPORTS,'<>',SYNCHRONOUS,     RUNTIME,FILESYSTEM,pl_id,NULL);
END;