Tuesday, July 16, 2019

Library cache pin lock resolution

Many a times some database objects get locked and even after killing the sessions or even fushing the shared_pool or restarting the instance the lock doesn't get released. Below are the steps to follow in such case.
ORA-4068 ORA-4065 ORA-06508 Errors Signalled For Valid Objects
How to Find the Blocker of the 'library cache pin' in a RAC environment?
Symptoms:
When loading certain PL/SQL packages the database continuously reports ORA-04068 errors.
Restarting database does not help.  Flushing shared pool does not help.
We can see timestamp discrepancies exist for valid objects.
set pagesize 10000
column d_name format a20
column p_name format a20
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;

Output would look like:
RADAR_SALES_ORDER_API                  11 VEHICLE_STOCK_API 08-JUN-2007 13:27:06 15-JUN-2007 19:03:05 *DIFFER*
SALES_SALES_OBJ_ITEMS_API              11 SALES_BUSINESS_DEALS_API    15-JUN-2007 18:45:09 15-JUN-2007 19:03:07 *DIFFER*

Also the problematic packages/procedures reported in the error exists and have status VALID in dba_objects view.
Cause:
The cause of this problem has been identified and verified in
Bug 6136074 - ORA-4068 ORA-4065 ORA-06508 ERRORS SIGNALED FOR VALID OBJECTS
Note: Recompilation of a view might lead to inconsistent timestamps for some of the view's PLSQL dependents.
If you see the above errors for packages/procedures which are in VALID state then you are hitting this bug.
Solution:
Workaround #1
1. Recompile the parent view.
2. Check the list of objects with timestamp mismatch using the SQL referred above.
3. Recompile those objects in point #2.
Workaround #2
Download and apply one-off Patch 6136074 or the 10.2.0.4 patchset to *prevent* this issue in the future.
For AIX 5L based system a Merge Label Request was created on top of 10.2.0.3 for bugs Unpublished Bug 5901891 and Bug 6136074.  Download and apply Merge Patch for unpublished Bug 6164148 which contains the fix for the Base Bug 6136074.
Note : Objects which has * timestamp mismatch * before applying the patch should be compiled manually.

  • select * From x$kglob where kglnaobj='XXFIN_PKG';
  • SELECT 'alter system kill session ''' || s.sid || ','  || s.serial# || ',@' || s.inst_id ||''||''' immediate;' FROM x$kglpn p, gv$session s WHERE p.kglpnuse=s.saddr AND  kglpnhdl in (select kglhdadr From x$kglob where kglnaobj='XXFIN_PKG');
  • ALTER SYSTEM KILL SESSION '3760,67,@1';
  • SELECT s.inst_id,s.sid, s.serial#, s.username, s.osuser, s.machine, s.status , kglpnmod "Mode", kglpnreq "Req" FROM x$kglpn p, gv$session s WHERE p.kglpnuse=s.saddr AND  kglpnhdl='0000000456E00898';

Reference: How to Find the Blocker of the 'library cache pin' in a RAC environment? (Doc ID 780514.1)
Reference:456338.1--->ORA-4068 ORA-4065 ORA-06508 Errors Signalled For Valid Objects