select count(*) from v$session;/n
select sid, serial#, username, event from v$session where event != ‘SQL*Net message from client’;
2. 故障诊断
使用以下语句,可以查看数据库的错误日志:
select to_char(log_date, ‘yyyy-mm-dd hh24:mi:ss’) log_time, user_name, message_text
from DBMS_LOGSTDBY.SKIP_ERROR_LOG$;
3. 性能优化
使用以下语句,可以查看SQL语句的执行计划:
expln plan for select * from table_name;
select * from table(dbms_xplan.display);
4. 容量规划
使用以下查询语句,可以查看表空间的使用情况:
select tablespace_name, round(sum(bytes)/1024/1024) size_MB, round(sum(bytes)/1024/1024) – round(free_space/1024/1024) used_MB, round(free_space/1024/1024) free_MB, trunc((1 – free_space/sum(bytes))*100) “% used”
from (select tablespace_name,bytes,decode(autoextensible,’YES’,maxbytes,bytes) maxbytes from dba_data_files union all select tablespace_name,bytes,bytes from dba_temp_files) a, (select tablespace_name,sum(bytes) free_space from dba_free_space group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
group by tablespace_name,free_space;
5. 应用分析
使用以下语句,可以查看应用程序交互数据量:
select to_char(begin_interval_time, ‘yyyy-mm-dd hh24:mi:ss’) begin_time, to_char(end_interval_time, ‘yyyy-mm-dd hh24:mi:ss’) end_time, round(value/1024/1024,2) MB
from dba_hist_sysmetric_summary
where metric_name = ‘Database bytes sent via SQL*Net to client’;