Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frequent error in Oracle ORA-04068: existing state of packages has been discarded

We're getting this error once a day on a script that runs every two hours, but at different times of the day.

ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "PACKAGE.NAME" has been
invalidated
ORA-06508: PL/SQL: could not find program unit being called:
"PACKAGE.NAME"
ORA-06512: at line 1

Could someone list what conditions can cause this error so that we could investigate?

Thanks.

UPDATE: Would executing 'ALTER SESSION CLOSE DATABASE LINK DBLINK' invalidate a state of the package?

like image 614
jonasespelita Avatar asked Nov 19 '09 07:11

jonasespelita


4 Answers

This one liner actually solved everything:

PRAGMA SERIALLY_REUSABLE;

Be sure that your global variables are stateless to avoid any issues.

like image 100
jonasespelita Avatar answered Nov 05 '22 07:11

jonasespelita


The package has public or private variables. (Right?) This variables form the state a the package. If you compile the package in 3rd session. The next access to this package will throw the ORA-04068.

The build timestamp of a package must be older than the package session state.

If the package state is not needed for script running, the call DBMS_SESSION.RESET_PACKAGE at the beginning of your script. This cleans all package states of your session.

like image 23
Christian13467 Avatar answered Nov 05 '22 07:11

Christian13467


You may also check dba_dependencies or user_dependencies.

select *
from dba_dependencies
where name = 'YOUR_PACKAGE'
and type = 'PACKAGE' --- or 'PACKAGE_BODY'
and owner = USER --- or USERNAME

This will give you the objects your package is dependent on. Check whats happening in there.

like image 5
Guru Avatar answered Nov 05 '22 07:11

Guru


We have had this issues for couple of times and for time being, we were compiling schema to resolve this issue temporarily. Over couple of days we were searching for the permanent resolution.

We found below query that showed timestamp difference in our synonym. we recompiled synonym and It worked !!! It's been almost a week and so far we have no issues. Here is the query that helped in our case.

**

select do.obj# d_obj,do.name d_name, do.type# d_type, po.obj# p_obj,po.name p_name,
to_char(p_timestamp,'DD-MON-YYYY HH24:MI:SS') "P_Timestamp",
to_char(po.stime ,'DD-MON-YYYY HH24:MI:SS') "STIME", 
decode(sign(po.stime-p_timestamp),0,'SAME','*DIFFER*') X 
from sys.obj$ do, sys.dependency$ d, sys.obj$ po
where P_OBJ#=po.obj#(+) and D_OBJ#=do.obj# 
and do.status=1 /*dependent is valid*/ 
and po.status=1 /*parent is valid*/ 
and po.stime!=p_timestamp /*parent timestamp not match*/ 
order by 2,1;

**

I hope this helps someone who may be having this issue.

like image 3
VRK Avatar answered Nov 05 '22 05:11

VRK