DBMS_APPLICATION_INFO.SET_CLIENT_INFO 不起作用

2021-12-30 00:00:00 oracle11g oracle

我需要设置 client_info 值以区分不同的客户端.

I need to set the client_info value to differentiate between different clients.

这些是我正在运行以测试的脚本.

These are the scripts that I am running to test.

第 1 步:系统架构

ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SYSTEM FLUSH BUFFER_CACHE;

第 2 步:人力资源架构

Step 2:HR SCHEMA

EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO(UTL_INADDR.GET_HOST_NAME );
EXEC DBMS_APPLICATION_INFO.SET_MODULE( 'CHECK','select' );

select                                      
    a.FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME
from                                        
    HR.EMPLOYEES a                                      
where                                       
    a.DEPARTMENT_ID = '40'
;

第 3 步:系统架构

select
    *
from
    (
        select
           a.SQL_ID
          ,a.SQL_FULLTEXT
          ,to_char( a.LAST_ACTIVE_TIME,'DD-MON-YYYY HH24:MI:SS' )                                                                                as LAST_ACTIVE_TIME
          ,a.SERVICE
          ,b.SCHEMANAME
          ,b.CLIENT_INFO
          ,a.MODULE
          ,a.ACTION
        from
            GV$SQL a
        left outer join GV$SESSION b
        on
            (
                b.SQL_ID = a.SQL_ID
            )
        where
            a.EXECUTIONS != 0
    )
    c
where
    c.MODULE like '%CHECK%'
order by
    c.LAST_ACTIVE_TIME desc ;

MODULE 和 ACTION 列正在获取值,但 CLIENT_INFO 没有显示任何内容.

The MODULE and ACTION columns are getting the values but the CLIENT_INFO is not showing anything.

有什么我遗漏的吗?

更新:我也试过没有运气

EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO( SYS_CONTEXT('userenv','ip_address') );
EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO( '10.10.10.10' );

推荐答案

SET_CLIENT_INFO 与会话相关,而不是与单个 SQL 语句相关.

SET_CLIENT_INFO is related to a Session, not to a single SQL Statement.

这样做

第 1 步:系统架构

ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SYSTEM FLUSH BUFFER_CACHE;

第 2 步:人力资源架构

Step 2:HR SCHEMA

EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO(UTL_INADDR.GET_HOST_NAME );
EXEC DBMS_APPLICATION_INFO.SET_MODULE( 'CHECK','select' );

第 3 步:系统架构

SELECT
    a.SQL_ID
   ,a.CLIENT_INFO
   ,a.MODULE
   ,a.ACTION
   ,a.SCHEMANAME
   ,a.USERNAME
FROM
   V$SESSION a
WHERE
    a.MODULE = 'CHECK';

相关文章