1. Test Setup
-- code from Blog: "library cache: mutex X" and Application Context
-- (http://ksun-oracle.blogspot.com/2016/11/library-cache-mutex-x-and-application.html)
create or replace context test_ctx using test_ctx_pkg;
--create or replace context test_ctx using test_ctx_pkg accessed globally;
create or replace package test_ctx_pkg is
procedure set_val (attr varchar2, val varchar2);
end;
/
create or replace package body test_ctx_pkg is
procedure set_val (attr varchar2, val varchar2) as
begin
--dbms_session.clear_all_context('TEST_CTX');
dbms_session.set_context('TEST_CTX', attr, val);
end;
end;
/
create or replace procedure ctx_set(p_cnt number, attr_pre varchar2, val_pre varchar2) as
begin
for i in 1..p_cnt loop
test_ctx_pkg.set_val(attr_pre||i, val_pre||i); -- 'library cache: mutex X' on TEST_CTX
end loop;
end;
/
create or replace procedure test_ORA_28268 (p_cnt number) as
l_attr_pre varchar2(32000);
l_val_pre varchar2(32000);
l_val varchar2(32000);
begin
--dbms_session.clear_all_context('TEST_CTX');
ctx_set(p_cnt, 'ATTR_', 'VAL_');
select sys_context('TEST_CTX', 'ATTR_'||1) into l_val from dual;
dbms_output.put_line('l_attr='||'ATTR_'||1||', VAL='||l_val);
select sys_context('TEST_CTX', 'ATTR_'||p_cnt) into l_val from dual;
dbms_output.put_line('l_attr='||'ATTR_'||p_cnt||', VAL='||l_val);
end;
/
create or replace procedure list_context as
l_tab dbms_session.appctxtabtyp;
l_size number;
begin
dbms_session.list_context(l_tab, l_size);
dbms_output.put_line('l_tab.count: '||l_tab.count||', l_size:'||l_size);
for i in 1..l_tab.count loop
dbms_output.put_line('namespace: '||l_tab(i).namespace||', attribute: '||l_tab(i).attribute||', value: '||l_tab(i).value);
end loop;
end;
/
2. Test Run
SQL > exec test_ORA_28268(10000-300);
l_attr=ATTR_1, VAL=VAL_1
l_attr=ATTR_9700, VAL=VAL_9700
SQL > exec test_ORA_28268(10000+300);
BEGIN test_ORA_28268(10000+300); END;
ERROR at line 1:
ORA-28268: Exceeded the maximum allowed size for Context information in a session
ORA-06512: at "SYS.DBMS_SESSION", line 141
ORA-06512: at "K.TEST_CTX_PKG", line 5
ORA-06512: at "K.CTX_SET", line 4
ORA-06512: at "K.TEST_ORA_28268", line 7
ORA-06512: at line 1
3. ORA-28268
Oracle document:
28268, 0000, "Exceeded the maximum allowed size for Context information in a session"
// *Cause: The maximum size specified by the _session_context_size
// init.ora parameter was exceeded.
// *Action: Please change the value for _session_context_size in the
//
ORA-28268 is raised when the number of session local context entries exceeded limit (session local context array)
which is defined by "_session_context_size" (default 10,000).It is only applied to local context (dba_context.type = 'ACCESSED LOCALLY')
(for global context, ORA-04031 when too many global context entries, check v$sgastat.name = 'Global Context').
It's value can be modified by:
alter system set "_session_context_size"=10000 scope=spfile;
One cause of ORA-28268 is probably session local context leak.The name "_session_context_size" seems misleading, mabybe renamed as "_session_context_entry_limit".