【问题标题】:oracle 12c cursor_sharing alter multple sessionsoracle 12c cursor_sharing 更改多个会话
【发布时间】:2017-09-11 15:14:18
【问题描述】:

问题: 是否有等效于 dbms_system.set_int_param_in_session 的方法适用于值是字符串而不是整数或布尔值的 init 参数?

背景故事: 我遇到了一个 3rd 方应用程序的问题,它的 api 不使用绑定变量。这会导致高 CPU 和低性能,因为应用程序一遍又一遍地发出相同的 sql。 (硬解析)我发现将 cursor_sharing 参数设置为 FORCE 可以提高性能,但是这样做存在安全问题。第 3 方应用程序维护许多会话 (~30-50) 所以我目前的方法是在第 3 方应用程序执行其操作时将 cursor_sharing 设置为强制,然后在完成时将 cursor_sharing 设置回精确。克鲁吉?是的,非常。我们做了一些研究,发现 dbms_system.set_int_param_in_session 过程似乎是一个合适的解决方案,除了它只适用于数据类型为整数的初始化参数。具有数据类型字符串值的参数是否有等价物?

【问题讨论】:

    标签: oracle12c


    【解决方案1】:

    虽然我不熟悉使用 dbms_system,但基于可用于dbms_system 包的info,我尝试在会话级别使用add_parameter_value,结果出现以下错误:

    SQL> set serveroutput on
    DECLARE
     sid_value VARCHAR2(10);
    BEGIN
      dbms_system.get_env('ORACLE_SID', sid_value);
      dbms_output.put_line(sid_value);
      dbms_system.add_parameter_value('cursor_sharing', 'EXACT', 'MEMORY', sid_value, 4);
    END;
    /
    show errorsSQL>   2    3    4    5    6    7    8  mydb
    DECLARE
    *
    ERROR at line 1:
    ORA-20004: cursor_sharing is not a list parameter
    
    
    SQL> 
    

    因此,尝试了以下基于触发器的方法,该方法仅针对用户 SCOTTcursor_sharing 设置为 force,您可以根据需要进行更改。

    SQL> create or replace trigger csf
    after logon
    on database
    begin
       if user='SCOTT' then
          execute immediate 'alter session set cursor_sharing=force';
       else
          execute immediate 'alter session set cursor_sharing=exact';
       end if;
    end;
    /  2    3    4    5    6    7    8    9   10   11  
    
    Trigger created.
    
    SQL> 
    SQL> 
    SQL> conn scott/tiger
    Connected.
    SQL> show parameter cursor_sharing
    
    NAME                  TYPE      VALUE
    --------------------- --------- ---------------
    cursor_sharing        string    FORCE
    SQL> 
    SQL> conn system/manager
    Connected.
    SQL> show parameter cursor_sharing
    
    NAME                  TYPE      VALUE
    --------------------- --------- ---------------
    cursor_sharing        string    EXACT
    SQL> 
    

    希望这可以帮助您避免将值设置回原始值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      相关资源
      最近更新 更多