读书人

Oracle学习之路【4】DBA常用语句

发布时间: 2012-07-18 12:05:40 作者: rapoo

Oracle学习之路【四】DBA常用语句

========================================================================

--查看表锁 select * from sys.v_$sqlarea where disk_reads>100--监控事例的等待 select event,sum(decode(wait_Time,0,0,1)) "Prev", sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot" from v$session_Wait group by event order by 4 --回滚段的争用情况select name, waits, gets, waits/gets "Ratio" from v$rollstat a, v$rollname b where a.usn = b.usn--查看前台正在发出的SQL语句select user_name,sql_text   from v$open_cursor   where sid in (select sid from (select sid,serial#,username,program   from v$session   where status='ACTIVE'))--数据表占用空间大小情况select segment_name,tablespace_name,bytes,blocks from user_segments where segment_type='TABLE' ORDER BY bytes DESC ,blocks DESC--查看表空间碎片大小    select tablespace_name,round(sqrt(max(blocks)/sum(blocks))*           (100/sqrt(sqrt(count(blocks)))),2) FSFI    from dba_free_space    group by tablespace_name order by 1    --查看表空间占用磁盘情况     select              b.file_id                                 文件ID号,             b.tablespace_name                         表空间名,             b.bytes                                 字节数,             (b.bytes-sum(nvl(a.bytes,0)))                 已使用,             sum(nvl(a.bytes,0))                         剩余空间,             sum(nvl(a.bytes,0))/(b.bytes)*100         剩余百分比              from dba_free_space a,dba_data_files b              where a.file_id=b.file_id              group by b.tablespace_name,b.file_id,b.bytes              order by b.file_id--查看session使用回滚段SELECT  r.name 回滚段名,        s.sid,        s.serial#,        s.username 用户名,        t.status,        t.cr_get,        t.phy_io,        t.used_ublk,        t.noundo,        substr(s.program, 1, 78) 操作程序FROM   sys.v_$session s,sys.v_$transaction t,sys.v_$rollname rWHERE  t.addr = s.taddr and t.xidusn = r.usnORDER  BY t.cr_get,t.phy_io--查看SGA区剩余可用内存select name,      sgasize/1024/1024        "Allocated(M)",      bytes/1024            "自由空间(K)",      round(bytes/sgasize*100, 2)   "自由空间百分比(%)"   from   (select sum(bytes) sgasize from sys.v_$sgastat) s, sys.v_$sgastat f   where  f.name = 'free memory'--监控表空间I/O比例select df.tablespace_name name,df.file_name "file",f.phyrds pyr,        f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw from v$filestat f, dba_data_files df where f.file# = df.file_id order by df.tablespace_name--监控SGA命中率select a.value + b.value "logical_reads",        c.value "phys_reads",        round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) "BUFFER HIT RATIO" from v$sysstat a, v$sysstat b, v$sysstat c where a.statistic# = 38 and       b.statistic# = 39 and       c.statistic# = 40 --监控 SGA 中字典缓冲区的命中率select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 "miss ratio", (1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio" from v$rowcache where gets+getmisses <>0 group by parameter, gets, getmisses --监控 SGA 中共享缓存区的命中率,应该小于1%select sum(pins) "Total Pins", sum(reloads) "Total Reloads", sum(reloads)/sum(pins) *100 libcache from v$librarycache--监控 SGA 中重做日志缓存区的命中率,应该小于1%SELECT name, gets, misses, immediate_gets, immediate_misses, Decode(gets,0,0,misses/gets*100) ratio1, Decode(immediate_gets+immediate_misses,0,0, immediate_misses/(immediate_gets+immediate_misses)*100) ratio2 FROM v$latch WHERE name IN ('redo allocation', 'redo copy')--监控内存和硬盘的排序比率,最好使它小于 .10SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)') --监控字典缓冲区SELECT SUM(GETS) "DICTIONARY GETS",SUM(GETMISSES) "DICTIONARY CACHE GET MISSES" FROM V$ROWCACHE --非系统用户建在SYSTEM表空间中的表SELECT owner,table_name FROM DBA_TABLESWHERE tablespace_name in('SYSTEM','USER_DATA') AND       owner NOT IN('SYSTEM','SYS','OUTLN', 'ORDSYS','MDSYS','SCOTT', 'HOSTEAC')--性能最差的SQLSELECT * FROM ( SELECT PARSING_USER_ID EXECUTIONS,SORTS,COMMAND_TYPE,DISK_READS,sql_text                 FROM v$sqlarea                 ORDER BY disk_reads DESC) WHERE ROWNUM<100                             --读磁盘数超100次的sqlselect * from sys.v_$sqlarea where disk_reads>100--最频繁执行的sqlselect * from sys.v_$sqlarea where executions>100--查询使用CPU多的用户sessionselect a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 value from v$session a,v$process b,v$sesstat c where c.statistic#=12 and       c.sid=a.sid and       a.paddr=b.addr order by value desc--当前每个会话使用的对象数SELECT a.sid,s.terminal,s.program,count(a.sid) FROM V$ACCESS a,V$SESSION sWHERE a.owner <> 'SYS'AND s.sid = a.sid GROUP BY a.sid,s.terminal,s.programORDER BY count(a.sid)--表占用的空间select   a.segment_name,sum(bytes)/1024/1024   from   user_segments   a   where   segment_type= 'TABLE'   group   by   a.segment_name

?

========================================================================

读书人网 >其他数据库

热点推荐