Iandev Smarter Business - Logo Cor
Navegação no fórum
para criar postagens e tópicos.

Listar a query de uma determinada conexao no DB2 cmd

@echo off

rem --- Scrpit: listar sqls.
rem --- Objetivo: Listar a query de uma determinada conexao
rem ---
rem ---
rem ---
rem ---

rem --- Variaveis
set DB=teste
set P1=%1

rem --- Conexao com o banco de dados
db2 connect to %DB%

rem --- Inicio do CORE
db2 "select cast (apls.AGENT_ID as int) as ag_id, case APPL_STATUS when 1 then 'Conn Pend' when 2 then 'Connected' when 3 then 'UOW Exec' when 4 then 'UOW Wait' when 5 then 'Lock-Wait' when 6 then 'Commit' when 7 then 'Rollback' when 8 then 'Recompile' when 9 then 'Compile' when 18 then 'Restore' when 19 then 'Backup' when 20 then 'Load' when 21 then 'Unload' when 26 then 'Decoupled' else cast(APPL_STATUS as char(10)) end as status, substr(APPL_NAME,1,15) as appl_name, cast (POOL_DATA_L_READS + POOL_INDEX_L_READS as bigint) as lreads, cast (POOL_DATA_P_READS + POOL_INDEX_P_READS as bigint) as preads, cast (STMT_USR_CPU_TIME_S + STMT_SYS_CPU_TIME_S as smallint) as stmt_cpu, cast (LOCKS_HELD as int) as nr_locks, cast (LOCK_WAIT_TIME as int) as lkwait_time, length(stmt_text) as Text_size, substr(stmt_text,1,6000) as SQL_text from table(snapshot_appl_info(current server,-1)) as apinfo, table(snapshot_appl(current server,-1)) as apls, table(snapshot_statement(current server,-1)) as stmt where apinfo.AGENT_ID = apls.AGENT_ID and apinfo.AGENT_ID = stmt.AGENT_ID and apinfo.agent_id = %P1% order by stmt_cpu desc"

rem --- Fim do CORE

rem --- Desconexao com o banco de dados
db2 connect reset > nul
db2 terminate > nul