转贴BEA 常用DBA SQL

常用DBA SQL

查询最耗时的SQL
select t1.username,
t1.sid,
t1.opname,
t1.TARGET,
t2.sql_text,
t1.START_TIME,
t1.LAST_UPDATE_TIME
from v$session_longops t1, v$sql t2
where t1.sql_address = t2.address
and t1.sql_hash_value = t2.hash_value
order by t1.START_TIME

查找最占用资源的查询(基于V$SQL视图)
select * from (
select sql_text,
rank() over(order by buffer_gets desc) as rank_bufgets,
to_char(100 * ratio_to_report(buffer_gets) over(), '999.99') pct_bufgets
from v$sql ) where rank_bufgets <11


查找最占用资源的查询(基于V$SQLAREA 视图)
select b.username,
a.DISK_READS reads,
a.EXECUTIONS exec,
a.DISK_READS / decode(a.EXECUTIONS, 0, 1, a.EXECUTIONS) rds_exec_ratio,
a.sql_text
from v$sqlarea a, dba_users b
where a.PARSING_USER_ID = b.user_id
and a.DISK_READS > 100000
order by a.DISK_READS desc


按OS进程ID查询数据库联系信息
select v2.* from v$process v1,v$session v2 where v1.ADDR=v2.PADDR and v1.SPID=16860

按OS进程ID查询数据库当前的SQL
SELECT b.sid,b.serail#,a.sql_text FROM
v$sqltext a,
v$session b,
v$process c
WHERE
a.hash_value = b.sql_hash_value and
b.ADDR=c.PADDR and
AND c.SID='&sid'
ORDER BY piece ASC

如何查看各个表空间占用磁盘情况?
select a.tb_name,
b.tb_size/1024/1024 tb_size_M,
(b.tb_size - a.tb_free)/1024/1024 tb_used_M,
a.tb_free/1024/1024 tb_free_M,
((b.tb_size - a.tb_free)/b.tb_size)*100 tb_used_rate
from (select t.tablespace_name tb_name, sum(t.bytes) tb_free
from sys.dba_free_space t
group by t.tablespace_name) a,
(select b.tablespace_name tb_name, sum(b.bytes) tb_size
from dba_data_files b
group by b.tablespace_name) b
where a.tb_name = b.tb_name
order by tb_used_rate desc

查看表空间中Table类型和Index类型对象占用的空间大小
select segment_name , sum(bytes) as total, count(*) ext_quan
from dba_extents
where tablespace_name = '&tablespace_name'
and segment_type = 'TABLE' or segment_type = 'INDEX'
group by tablespace_name, segment_name
order by total desc

杀Session
alter system kill session 'sid,serial#'


分析索引的B树Level

execute Dbms_Stats.gather_index_stats('MSTORE','MSG_SEND_IDX1');

select blevel,index_name from user_indexes where index_name='MSG_SEND_IDX1';

一般情况下如果删除了20~25%的记录,需要重建索引降低 B树Level(应该在5以下)

查看当前Scheme下的索引类型

select * from user_indexes t

查看各个表空间的磁盘IO情况

select b.NAME, a.PHYRDS, a.PHYWRTS, a.READTIM, a.WRITETIM
from v$filestat a, v$dbfile b
where a.FILE# = b.FILE#
order by a.READTIM desc


查看各个表空间的extents的数量(一般情况下应小于1024)
select t.tablespace_name,sum(t.extents) from dba_segments t group by t.tablespace_name

查询当前当前Scheme的中最占空间的segment,对应占用空间比较大的Object应该增加其extents的大小(可以设置tablespace 为 的extents 为 uniform 格式,或者设置 objects 的 stoage 参数),以保证extents的数量不至于太多
select t.segment_name,
t.segment_type,
t.bytes,
t.blocks,
t.extents,
t.bytes / (1024 * 1024) as bytes_M
from user_segments t
order by t.bytes desc

查看数据缓存(db_cache)的命中率,至少应该在95%以上(从90%提高到98%会提高500%的性能)
select physical_reads,
db_block_gets,
consistent_gets,
(1 - physical_reads / (db_block_gets + consistent_gets)) * 100 hitratio
from (select sum(decode(name, 'physical reads', value, 0)) physical_reads,
sum(decode(name, 'db block gets', value, 0)) db_block_gets,
sum(decode(name, 'consistent gets', value, 0)) consistent_gets
from v$sysstat t)

查看
'sga_max_size','pga_aggregate_target','db_cache_size','shared_pool_size'
这个的参数的配置值

select t.name,t.VALUE/1024/1024 M from v$parameter t
where t.name in ('sga_max_size','pga_aggregate_target','db_cache_size','shared_pool_size'
)

查看数据字典缓存的命中率,至少应该在95%以上。如果低于95%增大SHARED_POOL_SIZE参数的值
select (1 - (sum(GETMISSES) / (sum(gets) + sum(GETMISSES)))) * 100 hit_Rate
from v$rowcache t
where t.GETS + t.GETMISSES <> 0;

使用单独的行参数缓存来查看共享池的使用情况(重点分析丢失率在10%的项目,tag 为×)
select t.PARAMETER,
t.GETS,
t.GETMISSES,
t.MODIFICATIONS,
t.FLUSHES,
(getmisses / decode(gets, 0, 1, gets)) "getmiss_ratio%",
(case
when (getmisses / decode(gets, 0, 1, gets)) > 0.1 then
'*'
else
''
end) tag
from v$rowcache t
where t.GETS + t.GETMISSES <> 0
order by "getmiss_ratio%" desc

查看库缓存(LibCache)的重载率(为0)和命中率(接近1) 【否则增大SHARED_POOL_SIZE】
select sum(pins) Hits,
sum(reloads) Misses,
((sum(reloads) / sum(pins)) * 100) "Reload%",
sum(pins) / (sum(pins) + sum(reloads)) * 100 "Hit Ratio%"
from v$librarycache
查看库缓存分项(LibCache)的重载率(低于15%)和命中率(接近1)【否则增大SHARED_POOL_SIZE】
select t.NAMESPACE,
t.PINS,
t.PINHITS,
t.PINHITRATIO "PinHitRatio%",
t.RELOADS / decode(t.PINS, 0, 1, t.PINS) "PinReLoadRatio%"
from v$librarycache t

使用可以内存来判断SHARED_POOL_SIZE是否设置正确(如果运行的时间足够长,且还有大量可用内存则无需增加SHARED_POOL_SIZE)
select to_number(b.VALUE) "Shared Pool Size",
a.BYTES / 1024 / 1024 "Free MB",
(a.BYTES / b.VALUE) * 100 "Percent Free%"
from v$sgastat a, v$parameter b
where a.NAME = 'free memory'
and b.NAME = 'shared_pool_size'
and a.POOL = 'shared pool';

原文地址:http://dev2dev.bea.com.cn/blog/QiuHj/200710/23_524.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值