toad分析oracle日志,toad for oracle如何分析sql

1dd8a6fb3added25a33f41816de125f0.png

应该关心的内容有:

表空间共有多少个;

总共有多少自由空间;

最大的自由空间是什么;

表空间的碎片有多少。

1。查询数据文件及自由表空间情况

下面例子是一个经常使用的脚本,可以查出数据文件和表空间的可用情况。

clear buffer

clear columns

clear breaks

column a1 heading 'Tablespace' format a15

column a2 heading 'data File' format a45

column a3 heading 'Total|Space' format 999,999.99

column a4 heading 'Free|Space' format 999,999.99

column a5 heading 'Free|perc' format 999,999.99

break on a1 on report

compute sum of a3 on a1

compute sum of a4 on a1

compute sum of a3 on report

compute sum of a4 on report

set linesize 120

select a.tablespace_name a1, a.file_name a2, a.avail a3, nvl(b.free,0) a4,

nvl(round(((free/avail)*100),2),0) a5

from (select tablespace_name, substr(file_name,1,45) file_name,

file_id, round(sum(bytes/(1024*1024)),3) avail

from   sys.dba_data_files

group by  tablespace_name, substr(file_name,1,45),

file_id) a,

(select tablespace_name, file_id,

round(sum(bytes/(1024*1024)),3) free

from   sys.dba_free_space

group by tablespace_name, file_id) b

where a.file_id = b.file_id (+)

order by 1, 2

/

2。查询是否存在表的扩展超出表空间可用大小

表空间的连续块被多次的修改与删除等操作后出现了许多的不连续的块(叫碎片)。这样就有可能出现表的扩展所需要的连续块不能满足的情况。

脚本:

Col segment_name for a20

Select  segment_name, segment_type, owner, a.tablespace_name tablespace,

Initial_extent, next_extent, pct_increase,b.bytes max_bytes

From  dba_segments a,

( select tablespace_name, max(bytes) bytes from dba_free_space

group  by tablespace_name ) b

where a.tablespace_name=b.tablespace_name  and   next_extent > b.bytes ;

3。查询表空间自由、最大及碎片

下面脚本可以查询出所有表空间的自由空间、总空间数、已用空间、自由百分比及最大块的字节数。

set pau off

col free heading 'Free(Mb)' format 99999.9

col total heading 'Total(Mb)' format 999999.9

col used heading 'Used(Mb)' format 99999.9

col pct_free heading 'Pct|Free' format 99999.9

col largest heading 'Largest(Mb)' format 99999.9

compute sum of total on report

compute sum of free on report

compute sum of used on report

break on report

select substr(a.tablespace_name,1,13) tablespace,

round(sum(a.total1)/1024/1024, 1) Total,

round(sum(a.total1)/1024/1024, 1)-round(sum(a.sum1)/1024/1024, 1) used,

round(sum(a.sum1)/1024/1024, 1) free,

round(sum(a.sum1)/1024/1024, 1)*100/round(sum(a.total1)/1024/1024, 1) pct_free,

round(sum(a.maxb)/1024/1024, 1) largest,

max(a.cnt) fragment

from

(select tablespace_name, 0 total1, sum(bytes) sum1,

max(bytes) MAXB,

count(bytes) cnt

from dba_free_space

group by tablespace_name

union

select tablespace_name, sum(bytes) total1, 0, 0, 0 from dba_data_files

group by tablespace_name) a

group by a.tablespace_name

/

4。自动合并表空间碎片

当系统出现过多的碎片后,就影响系统的运行效率。下面脚本可以对相临的碎片进行合并。

set verify off;

set termout off;

set head off;

spool c:\temp\coalesce.log

select 'alter tablespace '||TABLESPACE_NAME||' coalesce ;'

from  DBA_FREE_SPACE_COALESCED where PERCENT_EXTENTS_COALESCED <100

or PERCENT_BLOCKS_COALESCED<100 ;

spool off;

@ c:\temp\coalesce.log

set head on;

set termout on;

set verify on;

prompt Tablespaces are coalesced successfully

5。 查询临时表空间和段的信息

整个系统的临时段信息:desc DBA_TEMP_FILES

查询系统临时段信息:select  file_name,tablespace_name, bytes, status  from  dba_temp_files;

不用这么麻烦,用oracle自己带的管理控制台最方便了

到开始菜单中启动Enterprise Manager Console

选择独立启动

双击你关注的数据库,登陆后到“存储”子项目,下面就有表空间,表空间文件等等了,点一下表空间,右边就会出现这个数据库的所有表空间的使用百分比(图形的),双击图形可以查看详细情况,可以更改表空间文件等等

其他的工具比如toad什么的也可以查看,不过没有oracle自带的管理控制台方便,哈哈

ps:你的oralce用户必须是dba或者具有OEM_MONITOR角色权限,否则管理控制台是打不开的

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值