Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Expose session serial# via sys_context

William RobertsonJan 5 2016 — edited Apr 24 2018

When logging messages, it makes sense to capture the session SID and SERIAL#. We can easily capture SID using sys_context('userenv', 'SID') and set this as a package constant, but there is no userenv entry for SERIAL#.

The recommended approach is to query v$session, but that is not accessible from stored PL/SQL by default and so requires an additional grant by SYS (not trivial to justify in a security-audited environment such as a bank), and even with that in place we cannot define it as a package constant or column default but need to write additional code to populate a variable (or write a function etc).

An alternative is to abandon SERIAL# and instead use AUDSID which can be populated with sys_context('userenv','sessionid'); however this is not the recommended use of AUDSID for various reasons (issues around background and distributed sessions), and in any case does not link to Oracle monitoring views such as v$active_session_history which use the standard sid, serial# combination to identify sessions.

Please can we have the value of the current session's SERIAL# made available through the default SYS_CONTEXT USERENV namespace as is already the case with SID.

Comments

Post Details

Added on Jan 5 2016
7 comments
5,787 views