ORACLE下監(jiān)控SESSION、表空間性能數(shù)據(jù),需要以DBA身份,取得一些系統(tǒng)視圖的信息。
建立兩個表,
viva_session表,包含字段id(序列遞增),createdate(默認(rèn)系統(tǒng)時間sysdate),inactiveCount(不活躍會話數(shù)),activeCount(活躍會話數(shù))。
viva_tablespace表,包含字段字段id(序列遞增),createdatet(默認(rèn)系統(tǒng)時間sysdate),tablespace_name(表空間名稱),total_mb(總大小),used_mb(已使用的大小),used_pct(已使用的比例)。
1、SESSON數(shù)據(jù)的取得,代碼:
create or replace procedure viva_session_proc is
begin
DECLARE
inactiveCount NUMBER;
activeCount NUMBER;
begin
select count(*) into inactiveCount from v$session where status='INACTIVE';
select count(*) into activeCount from v$session where status='ACTIVE';
insert into pmsuser.viva_session(inactive,active)
values(inactiveCount,activeCount);
end;
end viva_session_proc;
2、表空間數(shù)據(jù)的取得,代碼:
create or replace procedure viva_tablespace_proc is
begin
insert into pmsuser.viva_tablespace(tablespace_name,total_mb,used_mb,used_pct)
select
total.tablespace_name,
round(total.MB, 2) as Total_MB,round(total.MB - free.MB, 2) as Used_MB,
round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct
from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_free_space
group by tablespace_name) free,
(select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name) total
where free.tablespace_name = total.tablespace_name;
end viva_tablespace_proc;