Categorias
iiiiii
Administracion DBA
Descripcion
Script Comunes para administrar base de datos
Plsql
/*ver que esta en ejecucion en la base de datos*/
SELECT /*+rule*/
a.sid,serial#, a.username, b.INST_ID, trunc(plsql_exec_time/60) plsql_exec_time,
a.program, a.osuser, a.last_call_et, status,
TRUNC(a.last_call_et/60) || ' mins, ' ||MOD(a.last_call_et,60) || ' secs' running,
--b.*,
b.sql_text
FROM gv$sql b, gv$session a
where a.sql_address=b.address
---and a.status IN ( 'ACTIVE') --and RAWTOHEa.sql_address) <> '00'
and a.username is not null
--and sql_text like '%DECR%'
/*and username in ( 'N_DIANA', 'NAYIBE', 'FIN', 'SCHICUASUQUE' , 'JEIRAMIREZ' , 'AUXFAC2','REPORTES' , 'USUARIOWx',
'INTRAUSERx' , 'MCASTILLO' , 'P_EDINSONx', upper('msesquile') , 'LUZGARCI1', 'DAVALERO' , 'AUXFAC3' , 'AUXFAC2' , 'ADROJAS' , 'DORTIZ', 'ANDRESRODRIGUE1', 'REP' ,
a.username )*/ -- a.username
and username in ( 'JULGOMEZ', 'NAYIBE' , 'N_DIANA' ) -- a.username
and username NOT in ('SYS')
and a.inst_id = b.inst_id
--and a.last_call_et > 20
-- AND A.SID = 45
--order by a.username , a.last_call_et desc, 3;
order by a.last_call_et desc, 3;
/*Elimiar session bae de datos**************************************************************************************************/
create or replace procedure FIN.kill_session( p_sid in varchar2,
p_serial# in varchar2)
is
cursor_name pls_integer default dbms_sql.open_cursor;
ignore pls_integer;
BEGIN
select count(*)
into ignore
from V$session
where --username = USER
sid = p_sid
and serial# = p_serial# ;
if ( ignore = 1 ) then
dbms_sql.parse(cursor_name,'alter system kill session '''||p_sid||','||p_serial#||'''',dbms_sql.native);
ignore := dbms_sql.execute(cursor_name);
else
raise_application_error( -20001,'You do not own session ''' ||p_sid || ',' || p_serial# ||'''' );
end if;
END;
/
DECLARE
CURSOR CU_USU IS
--//Mira las sesiones activas Y CON USUARIO
with vs as (select rownum rnum,
inst_id,
sid,
serial#,
status,
username,
last_call_et,
command,
machine,
osuser,
module,
action,
resource_consumer_group,
client_info,
client_identifier,
type,
terminal,
sql_id,
sql_child_number
from gv$session)
select vs.inst_id, vs.sid ,serial# serial, vs.sql_id, vs.sql_child_number,
vs.username "Username",
case when vs.status = 'ACTIVE'
then last_call_et
else null end "Seconds in Wait",
(select command_name from v$sqlcommand where command_type = vs.command ) "Command",
vs.machine "Machine",
vs.osuser "OS User",
lower(vs.status) "Status",
vs.module "Module",
vs.action "Action",
vs.resource_consumer_group,
vs.client_info,
vs.client_identifier
from vs
where vs.USERNAME is not null
and nvl(vs.osuser,'x') <> 'SYSTEM'
and vs.type <> 'BACKGROUND'
and vs.status = 'ACTIVE'
and vs.username = 'JULGOMEZ' ---EL USUARIO QUE QUIERE MATAR SESIONES
order by 1,2,3;
BEGIN
FOR R_CU_USU IN CU_USU LOOP
BEGIN
FIN.kill_session(R_CU_USU.SID, R_CU_USU.SERIAL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;