SQL> create or replace PROCEDURE pining此时Calling对于Pining的引用将会在Pining的Body上获得共享Pin,此时在另外一个Session执行重建Procedure的操作:
2 IS
3 BEGIN
4 NULL;
5 END;
6 / Procedure created.SQL>
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';Session altered.SQL> create or replace procedure calling
2 is
3 begin
4 pining;
5 dbms_lock.sleep(60);
6 end;
7 /Procedure created.SQL>
SQL> col object_name for a30
SQL> select object_name,last_ddl_time from dba_objects where object_name in ('PINING','CALLING');OBJECT_NAME LAST_DDL_TIME
------------------------------ -------------------
CALLING 2007-04-02 09:12:57
PINING 2007-04-02 09:12:57SQL>
SQL> exec calling;
SQL> create or replace PROCEDURE pining这个操作将一直挂起,直到第一个session的操作完成,此时在第三个session可以观察到Library Cache Pin的竞争:
2 IS
3 BEGIN
4 NULL;
5 END;
6 /
SQL> select sid,event from v$session where username='EYGLE'当第一个session执行完成之后,第二个session的操作随之完成,我们可以看到LAST_DDL_TIME并未改变:
2 / SID EVENT
---------- ----------------------------------------------------------------
137 library cache pin
139 PL/SQL lock timer
157 SQL*Net message to client
SQL> exec calling; PL/SQL procedure sUCcessfully completed.SQL>实际上session 2执行了一次无谓的Library Cache Pin,理想的方式应该是,Oracle能够判定之前的Library Cache Pin的模式,假如是共享模式,则可以跳过Pin请求,假如是排他模式,则必须等待,目前的处理并不能从实质上改变竞争。不过并非全无益处,我们发现,对于另一类DDL操作,Oracle完全可以跳过Library Cache Pin的请求,这类操作是Grant,在以前版本中的行为可以参考:
SQL> select object_name,last_ddl_time from dba_objects where object_name in ('PINING','CALLING');OBJECT_NAME LAST_DDL_TIME
------------------------------ -------------------
CALLING 2007-04-02 09:12:57
PINING 2007-04-02 09:12:57
09:40:18 SQL> drop procedure calling; Procedure dropped.在Session 2执行授权:
09:40:18 SQL>
09:40:18 SQL> drop procedure pining;Procedure dropped.09:40:18 SQL>
09:40:18 SQL> create or replace PROCEDURE pining
09:40:18 2 IS
09:40:18 3 BEGIN
09:40:18 4 NULL;
09:40:18 5 END;
09:40:18 6 /Procedure created.09:40:18 SQL>
09:40:18 SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';Session altered.09:40:18 SQL> create or replace procedure calling
09:40:18 2 is
09:40:18 3 begin
09:40:18 4 pining;
09:40:18 5 dbms_lock.sleep(60);
09:40:18 6 end;
09:40:18 7 /Procedure created.09:40:18 SQL>
09:40:18 SQL> col object_name for a30
09:40:18 SQL> select object_name,last_ddl_time from dba_objects where object_name in ('PINING','CALLING');OBJECT_NAME LAST_DDL_TIME
------------------------------ -------------------
CALLING 2007-04-02 09:40:18
PINING 2007-04-02 09:40:1809:40:18 SQL>
09:40:18 SQL> exec calling;
SQL> set time on我们看到Session 2的授权顺利通过,再转到Session 1:
09:40:22 SQL> grant execute on pining to sys; Grant succeeded.09:40:22 SQL>
09:40:18 SQL> exec calling; PL/SQL procedure successfully completed.09:41:18 SQL>我们看到对象PINING的LAST_DDL_TIME已经变化。
09:41:18 SQL> select object_name,last_ddl_time from dba_objects where object_name in ('PINING','CALLING');OBJECT_NAME LAST_DDL_TIME
------------------------------ -------------------
CALLING 2007-04-02 09:40:18
PINING 2007-04-02 09:40:22
新闻热点
疑难解答