HANA - Session

Management

Kill

ALTER SYSTEM CANCEL SESSION '<M_CONNECTIONS.LOGICAL_CONNECTION_ID>';

Example of procedure to implement a simple timeout

DROP PROCEDURE cancel_session_above_timeout;
CREATE PROCEDURE cancel_session_above_timeout (p_timeout INTEGER) LANGUAGE SQLSCRIPT 
AS 
BEGIN  
	
	DECLARE CURSOR c_cursor1 (l_timeout INTEGER) FOR
		select 
			logical_connection_id,
			seconds_between(start_time,now()) seconds_since_start_time
		from 
			M_CONNECTIONS
		where
			client_host = 'applicationHost' 
			and connection_status = 'RUNNING'
			and seconds_between(start_time,now()) > :l_timeout;
	
	FOR cur_row AS c_cursor1(p_timeout) 
	DO
		EXEC 'ALTER SYSTEM CANCEL SESSION ''' || cur_row.logical_connection_id || '''';
                EXEC 'INSERT INTO message_box VALUES (''The running time (' || cur_row.seconds_since_start_time || ') of the connection (' || cur_row.logical_connection_id || ') was above the timeout limit of (' || p_timeout || ' sec) and was canceled'', CURRENT_TIMESTAMP)';
        END FOR;
	
END;

Context

Session Context

SET SESSION 'APPLICATION' = 'Nico';
SET SESSION 'APPLICATIONUSER'= 'Nico';
SET SESSION 'APPLICATIONVERSION' = '10.8';
SET SESSION 'APPLICATIONACTION' = 'myAction';
SET SESSION 'APPLICATIONSOURCE' = 'mySource';
SELECT * FROM M_SESSION_CONTEXT WHERE connection_id=current_connection;
  • application name = name of the application
  • application user name = name of the application user (usually the user logged into the application)

Example:

select 
	connection_id,
	max(case when key = 'APPLICATION' then value end) as application,
	max(case when key = 'APPLICATIONUSER' then value end ) as applicationuser,
	max(case when key = 'APPLICATIONCOMPONENT' then value end) as applicationcomponent,
	max(case when key = 'APPLICATIONCOMPONENTTYPE' then value end) as applicationcomponenttype,
	max(case when key = 'APPLICATIONCOMPONENTVERSION' then value end) as applicationcomponentversion,
	max(case when key = 'APPLICATIONSOURCE' then value end) as applicationsource,
	max(case when key = 'CLIENT' then value end) as client
from M_SESSION_CONTEXT 
group by connection_id

Documentation / Reference


Powered by ComboStrap