Tuesday, 14 July 2020

How to check running threads details in HANA Database with Command

We will see how to check running threads details with command 


We need to follow the below steps.


1: Login in HANA Studio with select permission and run below command. 
2: Run below command to get details 

SELECT top 200 HOST,SERVICE_NAME,APP_NAME,APP_SOURCE, APP_USER,THREAD_STATE,THREAD_TYPE, max(duration_ms) max_duration_ms, COUNT(*) NUM_SAMPLES,COUNT(*) / SUM(COUNT(*)) OVER (PARTITION BY BEGIN_TIME) * 100 PERCENT, COUNT(*) * SAMPLE_INTERVAL / TIME_SLICE_S AVG_ACT_THREADS FROM ( SELECT ADD_SECONDS(TO_TIMESTAMP('2014/01/01 00:00:00','YYYY/MM/DD HH24:MI:SS'), FLOOR(SECONDS_BETWEEN(TO_TIMESTAMP('2014/01/01 00:00:00','YYYY/MM/DD HH24:MI:SS'),T.SAMPLE_TIME) / BI.TIME_SLICE_S) * BI.TIME_SLICE_S) BEGIN_TIME,T.HOST HOST,S.SERVICE_NAME SERVICE_NAME, T.APP_NAME APP_NAME,T.APP_SOURCE APP_SOURCE,T.APP_USER APP_USER, T.THREAD_STATE THREAD_STATE,T.THREAD_TYP THREAD_TYPE,T.DURATION_MS DURATION_MS,BI.TIME_SLICE_S, I.SAMPLE_INTERVAL FROM ( SELECT TO_TIMESTAMP( '2018/08/01 13:00:00' ,'YYYY/MM/DD HH24:MI:SS') BEGIN_TIME, TO_TIMESTAMP('2020/08/01  15:00:00' ,'YYYY/MM/DD HH24:MI:SS') END_TIME, '%' HOST,'%' SERVICE_NAME,-1  THREAD_ID,'%' THREAD_TYPE,'%' THREAD_METHOD,'%' THREAD_STATE, '%' THREAD_DETAIL,'%' STATEMENT_HASH,'%' DB_USER,'%' APP_NAME,'%' APP_USER,'%' APP_SOURCE, -1  CLIENT_IP,-1  CLIENT_PID,-1  CONN_ID,3600 TIME_SLICE_S FROM DUMMY ) BI, ( SELECT HOST,PORT,TIMESTAMP SAMPLE_TIME,case left(THREAD_TYPE,6) when 'JobWrk' then 'JobWrk*' when 'Stats:' then 'Stats:*' else THREAD_TYPE end THREAD_TYP, THREAD_STATE,case when (duration > 999999 or duration < 0) then 0 else DURATION / 1000 end DURATION_MS,APPLICATION_NAME APP_NAME,APPLICATION_USER_NAME APP_USER, APPLICATION_SOURCE APP_SOURCE FROM M_SERVICE_THREAD_SAMPLES where THREAD_TYPE <> 'service thread sampler' ) T, ( SELECT HOST,PORT,SERVICE_NAME FROM M_SERVICES ) S, ( SELECT DISTINCT IFNULL(MAX(MAP(LAYER_NAME,'SYSTEM',VALUE,NULL)),MAX(MAP(LAYER_NAME,'DEFAULT',VALUE))) SAMPLE_INTERVAL FROM M_INIFILE_CONTENTS WHERE FILE_NAME = 'global.ini' AND SECTION = 'resource_tracking' AND KEY = 'service_thread_sampling_monitor_sample_interval' ) I WHERE S.SERVICE_NAME LIKE BI.SERVICE_NAME AND S.HOST LIKE BI.HOST AND T.HOST = S.HOST AND T.PORT = S.PORT AND T.SAMPLE_TIME BETWEEN BI.BEGIN_TIME AND BI.END_TIME AND T.THREAD_TYP LIKE BI.THREAD_TYPE AND T.THREAD_STATE LIKE BI.THREAD_STATE AND T.APP_NAME LIKE BI.APP_NAME AND T.APP_USER LIKE BI.APP_USER AND T.APP_SOURCE LIKE BI.APP_SOURCE ) GROUP BY BEGIN_TIME,HOST,SERVICE_NAME,APP_NAME,APP_SOURCE, APP_USER,THREAD_STATE,THREAD_TYPE,SAMPLE_INTERVAL,TIME_SLICE_S order by begin_time desc, NUM_SAMPLES desc


Note: Just need to change the start and end date