#精确计算表空间大小,消耗系统资源,慎用
SELECT F.TABLESPACE_NAME,
A.ALL_TOTAL "总空间" ,
A.ALL_USED "总使用空间" ,
A.ALL_TOTAL - A.ALL_USED "总剩余空间" ,
(A.ALL_TOTAL - A.ALL_USED) / A.ALL_TOTAL * 100 "总剩余比例" ,
A.TOTAL "当前大小" ,
U.USED "当前使用空间" ,
F. FREE "当前剩余空间" ,
(U.USED / A.TOTAL) * 100 "当前使用比例" ,
(F. FREE / A.TOTAL) * 100 "当前剩余比例"
FROM ( SELECT TABLESPACE_NAME,
SUM (BYTES / (1024 * 1024 * 1024)) TOTAL,
SUM (DECODE(AUTOEXTENSIBLE, 'YES' , MAXBYTES, BYTES) /
(1024 * 1024 * 1024)) ALL_TOTAL,
SUM (USER_BYTES) / (1024 * 1024 * 1024) ALL_USED
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) A,
( SELECT TABLESPACE_NAME, SUM (BYTES / (1024 * 1024 * 1024)) USED
FROM DBA_EXTENTS
GROUP BY TABLESPACE_NAME) U,
( SELECT TABLESPACE_NAME, SUM (BYTES / (1024 * 1024 * 1024)) FREE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE A.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
AND A.TABLESPACE_NAME = U.TABLESPACE_NAME(+)
ORDER BY (A.ALL_TOTAL - A.ALL_USED) / A.ALL_TOTAL,F. FREE / A.TOTAL ASC ;
# 检查系统中排行前10的等待事件 ,包括空闲等待事件
select * from (select sid,event,p1,p2,p3,p1text,WAIT_TIME,SECONDS_IN_WAIT from v$session_wait where
event not like 'SQL%' and event not like 'rdbms%' order by wait_time desc) where rownum <=10;
TOP SQL
# 逻辑读 TOP 10
select *
from (select sqt.logicr logical_Reads,
sqt.exec Executions,
decode(sqt.exec, 0, to_number(null), (sqt.logicr / sqt.exec)) Reads_per_Exec ,
(100 * sqt.logicr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =7634
AND E.SNAP_ID =7637
AND B.DBID = 3629726729
AND E.DBID = 3629726729
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'session logical reads'
and b.stat_name = 'session logical reads') Total_rate,
nvl((sqt.cput / 1000000), to_number(null)) CPU_Time_s,
nvl((sqt.elap / 1000000), to_number(null)) Elapsed_Time_s,
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module) SQL_Module,
nvl(st.sql_text, to_clob('** SQL Text Not Available **')) SQL_Text
from (select sql_id,
max(module) module,
sum(buffer_gets_delta) logicr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = 3629726729
and instance_number = 1
and 7634 < snap_id
and snap_id <= 7637
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 3629726729
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =7634
AND E.SNAP_ID =7637
AND B.DBID = 3629726729
AND E.DBID = 3629726729
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'session logical reads'
and b.stat_name = 'session logical reads') > 0
order by nvl(sqt.logicr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or Total_rate > 1);
# 物理读 TOP 10
select *
from (select sqt.dskr Physical_Reads,
sqt.exec Executions,
decode(sqt.exec, 0, to_number(null), (sqt.dskr / sqt.exec)) Reads_per_Exec ,
(100 * sqt.dskr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = $P{p_beg_snap}
AND E.SNAP_ID = $P{p_end_snap}
AND B.DBID = 1273705906
AND E.DBID = 1273705906
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') Total_rate,
nvl((sqt.cput / 1000000), to_number(null)) CPU_Time_s,
nvl((sqt.elap / 1000000), to_number(null)) Elapsed_Time_s,
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module) SQL_Module,
nvl(st.sql_text, to_clob('** SQL Text Not Available **')) SQL_Text
from (select sql_id,
max(module) module,
sum(disk_reads_delta) dskr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = 1273705906
and instance_number = 1
and $P{p_beg_snap} < snap_id
and snap_id <= $P{p_end_snap}
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 1273705906
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = $P{p_beg_snap}
AND E.SNAP_ID = $P{p_end_snap}
AND B.DBID = 1273705906
AND E.DBID = 1273705906
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') > 0
order by nvl(sqt.dskr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or Total_rate > 1);
# 消耗CPU TOP 10
select *
from (select nvl((sqt.elap / 1000000), to_number(null)) Elapsed_Time_s,
nvl((sqt.cput / 1000000), to_number(null)) CPU_Time_s,
sqt.exec Executions,
decode(sqt.exec,
0,
to_number(null),
(sqt.elap / sqt.exec / 1000000)) Elap_per_Exec_s,
(100 *
(sqt.elap / (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = 7396
AND E.SNAP_ID = 7399
AND B.DBID = 1273705906
AND E.DBID = 1273705906
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'DB time'
and b.stat_name = 'DB time')))/1000 Total_DB_Time_rate,
sqt.sql_id,
to_clob(decode(sqt.module,
null,
null,
'Module: ' || sqt.module)) SQL_Module,
nvl(st.sql_text, to_clob(' ** SQL Text Not Available ** ')) SQL_Text
from (select sql_id,
max(module) module,
sum(elapsed_time_delta) elap,
sum(cpu_time_delta) cput,
sum(executions_delta) exec
from dba_hist_sqlstat
where dbid = 65972167
and instance_number = 1
and 7396 < snap_id
and snap_id <= 7399
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 1273705906
order by nvl(sqt.cput, -1) desc, sqt.sql_id)
where rownum < 65
and (rownum <= 10 or Total_DB_Time_rate > 1);
# 执行时间 TOP 10
select *
from (select nvl((sqt.elap / 1000000), to_number(null)) Elapsed_Time_s,
nvl((sqt.cput / 1000000), to_number(null)) CPU_Time_s,
sqt.exec Executions,
decode(sqt.exec,
0,
to_number(null),
(sqt.elap / sqt.exec / 1000000)) Elap_per_Exec_s,
(100 *
(sqt.elap / (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = $P{p_beg_snap}
AND E.SNAP_ID = $P{p_end_snap}
AND B.DBID = 1273705906
AND E.DBID = 1273705906
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'DB time'
and b.stat_name = 'DB time')))/1000 Total_DB_Time_rate,
sqt.sql_id,
to_clob(decode(sqt.module,
null,
null,
'Module: ' || sqt.module)) SQL_Module,
nvl(st.sql_text, to_clob(' ** SQL Text Not Available ** ')) SQL_Text
from (select sql_id,
max(module) module,
sum(elapsed_time_delta) elap,
sum(cpu_time_delta) cput,
sum(executions_delta) exec
from dba_hist_sqlstat
where dbid = 1273705906
and instance_number = 1
and $P{p_beg_snap} < snap_id
and snap_id <= $P{p_end_snap}
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 1273705906
order by nvl(sqt.elap, -1) desc, sqt.sql_id)
where rownum < 65
and (rownum <= 10 or Total_DB_Time_rate > 1);
#查看等待事件的详细情况
create or replace procedure WaitHistogram(pFilter varchar2)
is
vTotalWaitCount integer;
cursor rec_cur is
select rpad(substr(event,1,40),42) event,
lpad(to_char(wait_time_MILLI,999999999.99),13) wtm,
lpad(to_char(wait_count,9999999999.99),13) wct,
100*(sum(wait_count) over(order by event,wait_time_milli)) pct_rt
from v$event_histogram where event=pFilter
order by 1,2;
c_event varchar2(100);
c_wtm varchar2(100);
c_wct varchar2(100);
c_pct_rt number(20,2);
begin
select sum(wait_count) into vTotalWaitCount from v$event_histogram where event=pFilter;
dbms_output.enable(800000);
dbms_output.put_line(rpad('event',45)||'Wait time Wait count Pct_rt');
open rec_cur;
fetch rec_cur into c_event,c_wtm,c_wct,c_pct_rt;
while rec_cur%found loop
dbms_output.put_line(c_event||' '||c_wtm||' '||c_wct||' '||to_char((c_pct_rt/vTotalWaitCount),0999.99));
fetch rec_cur into c_event,c_wtm,c_wct,c_pct_rt;
end loop;
close rec_cur;
end ;
/
exec WaitHistogram(pfilter=>'gc buffer busy');
感谢$无为公子、萧雨、惜分飞的帮助
参考至:http://mlxia.iteye.com/blog/741227
http://blog.csdn.net/soulcq/article/details/5418085
http://www.dbtan.com/2010/05/latch-free.html
http://www.2cto.com/database/201107/96826.html
http://blog.csdn.net/robinson1988/article/details/4793962
http://blog.csdn.net/tianlesoftware/article/details/5263238
http://www.laoxiong.net/dbms_stats_and_analyze_and_global_statistics.html
http://www.laoxiong.net/wp-content/uploads/2008/12/sosi.sql
http://www.cnblogs.com/caizhimin816/archive/2012/12/21/2827375.html
http://oracledoug.com/px.pdf
http://www.linuxeden.com/html/database/20111127/117134.html
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=1019722.6
http://docs.oracle.com/cd/E11882_01/server.112/e25523/parallel006.htm#VLDBG1513
本文原创,转载请注明出处,作者
如有错误,欢迎指正
邮箱:czmcj@163.com
相关推荐
### 如何查看、启动或关闭Oracle数据库的归档模式 #### 归档模式概述 在Oracle数据库中,归档模式(Archivelog Mode)是一种重要的数据保护机制,它允许数据库在发生故障时进行完整的恢复。当数据库处于归档模式时...
根据给定的文件信息,以下是对“oracle维护常用SQL”中的关键知识点的详细解析: ### 1. 查询表空间大小 SQL语句:`select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size from dba_tablespaces t, ...
ORACLE数据库调整归档日志空间...ORACLE数据库的归档日志是一种重要的灾难恢复机制,需要正确地配置和维护。通过调整归档日志空间大小和删除不必要的归档日志文件,可以解决归档日志满的问题,确保数据库的稳定运行。
Oracle RAC 集群开启归档日志是指在 Oracle RAC 集群环境中启用归档日志功能,以便提高数据库的可靠性和可维护性。为了实现这一功能,需要修改集群参数文件,重启数据库。 在开启归档日志之前,需要查看当前的归档...
Oracle 通过归档日志功能支持基于时间点的恢复,而 SQL Server 则通过事务日志备份机制实现这一目标。这两种方法都能够有效地帮助用户恢复数据至特定的时间点,确保数据的完整性和可用性。 #### 系统元数据 系统元...
以上这些查询是Oracle DBA日常工作中常见的SQL命令,它们涵盖了数据库监控、性能分析、存储管理等多个方面,对于优化数据库性能和维护数据库健康状态具有重要意义。掌握这些查询技巧,能让你更有效地管理和操作...
Oracle有归档模式和非归档模式,归档模式下可以进行更复杂的恢复操作,如时间点恢复。而SQL Server的恢复模型包括简单恢复、完整恢复和大容量日志恢复,其中完整恢复模型可以配合事务日志备份实现时间点恢复。 在...
这些脚本通常包含一系列SQL命令和操作系统级别的指令,旨在安全地删除不再需要的归档日志,以释放存储空间,并保持数据库的健康运行状态。归档日志管理对于保持数据库性能至关重要,因为过多的归档日志会占用大量...
- 了解和熟悉Oracle数据库的备份和恢复策略对于维护系统的稳定性和数据安全性至关重要。 通过以上步骤,可以在Oracle 9i和10g版本中成功地设置归档日志,为数据库提供更高级别的保护和恢复能力。
根据给定的文件信息,以下是对“Oracle维护常用SQL语句”的详细解析,涉及的知识点主要包括Oracle数据库的系统视图、表空间管理、回滚段、控制文件、日志文件、自由空间、对象状态、版本信息、数据库模式、长期运行...
在Oracle数据库管理中,归档日志的管理和清理是一项重要的维护任务。归档日志是数据库系统为了实现数据恢复而产生的日志文件,当数据库处于归档模式时,每一次完整的数据库备份后都会生成归档日志。随着时间的推移,...
### Oracle数据库归档模式详解与配置 ...通过以上步骤和配置,可以有效地管理和维护Oracle数据库的归档模式,从而确保数据的安全性。这对于任何使用Oracle数据库的企业来说都是非常关键的操作之一。
Oracle数据库归档日志挖掘是数据库管理中一项重要的任务,特别是在数据恢复、审计或问题排查时。本操作手册提供了一套详细...通过理解并遵循这些步骤,用户可以有效地挖掘和分析归档日志,从而更好地管理和维护数据库。
### Oracle维护常用SQL语句汇总 #### 一、概述 在Oracle数据库的日常维护工作中,熟练掌握常用的SQL语句对于提高工作效率、确保数据库稳定运行至关重要。本文将对一系列Oracle维护中常用的SQL语句进行总结,并详细...
13. **备份与恢复**:Oracle 9i提供了全面的备份和恢复策略,包括在线备份、归档日志模式、数据泵导出导入等,确保数据安全无损。 Oracle 9i SQL说明文档详细阐述了以上知识点,是学习和使用Oracle 9i SQL的宝贵...
正确管理和定期清理归档日志对于维护Oracle数据库的高效运行至关重要。通过上述步骤,不仅可以释放宝贵的磁盘空间,还能确保数据库的稳定性和数据的一致性。在实际操作过程中,一定要谨慎行事,特别是在删除日志文件...