知识大全 Oracle数据库维护常用SQL语句集合(3)

Posted

篇首语:看书和学习是思想的经常营养,是思想的无穷发展。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Oracle数据库维护常用SQL语句集合(3)相关的知识,希望对你有一定的参考价值。

Oracle数据库维护常用SQL语句集合(3)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  性能相关内容

   捕捉运行很久的SQL          column username format a         column opname format a         column progress format a         SELECT Username Sid Opname         Round(Sofar * / Totalwork ) || % AS Progress Time_Remaining         Sql_Text        FROM V$session_Longops V$sql        WHERE Time_Remaining <>         AND Sql_Address = Address        AND Sql_Hash_Value = Hash_Value;

   求DISK READ较多的SQL          SELECT St Sql_Text        FROM V$sql s V$sqltext St        WHERE s Address = St Address        AND s Hash_Value = St Hash_Value        AND s Disk_Reads > ;

   求DISK SORT严重的SQL          SELECT Sess Username SQL Sql_Text Sort Blocks        FROM V$session Sess V$sqlarea SQL V$sort_Usage Sort         WHERE Sess Serial# = Sort Session_Num        AND Sort Sqladdr = SQL Address        AND Sort Sqlhash = SQL Hash_Value        AND Sort Blocks > ;

   监控索引是否使用          alter index &index_name monitoring usage;        alter index &index_name nomonitoring usage;        select * from v$object_usage where index_name = &index_name;

   求数据文件的I/O分布          SELECT Df NAME Phyrds Phywrts Phyblkrd Phyblkwrt Singleblkrds Readtim         Writetim        FROM V$filestat Fs V$dbfile Df        WHERE Fs File# = Df File#        ORDER BY Df NAME;

   查看还没提交的事务          select * from v$locked_object;        select * from v$transaction;

   回滚段查看          SELECT Rownum Sys Dba_Rollback_Segs Segment_Name NAME         V$rollstat Extents Extents V$rollstat Rssize Size_In_Bytes         V$rollstat Xacts Xacts V$rollstat Gets Gets V$rollstat Waits Waits         V$rollstat Writes Writes Sys Dba_Rollback_Segs Status Status        FROM V$rollstat Sys Dba_Rollback_Segs V$rollname        WHERE V$rollname NAME(+) = Sys Dba_Rollback_Segs Segment_Name        AND V$rollstat Usn(+) = V$rollname Usn        ORDER BY Rownum

   查看系统请求情况          SELECT Decode(NAME summed dirty write queue length VALUE) /        Decode(NAME write requests VALUE) Write Request Length         FROM V$sysstat        WHERE NAME IN ( summed dirty queue length write requests )        AND VALUE > ;

   计算data buffer 命中率          SELECT a VALUE + b VALUE logical_reads c VALUE phys_reads         Round( * ((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# =         AND b Statistic# =         AND c Statistic# = ;        SELECT NAME         ( (Physical_Reads / (Db_Block_Gets + Consistent_Gets))) * h_Ratio        FROM V$buffer_Pool_Statistics;

   查看内存使用情况          SELECT Least(MAX(b VALUE) / ( * ) SUM(a Bytes) / ( * )) Shared_Pool_Used         MAX(b VALUE) / ( * ) Shared_Pool_Size         Greatest(MAX(b VALUE) / ( * ) SUM(a Bytes) / ( * ))         (SUM(a Bytes) / ( * )) Shared_Pool_Avail         ((SUM(a Bytes) / ( * )) / (MAX(b VALUE) / ( * ))) * Avail_Pool_Pct        FROM V$sgastat a V$parameter b        WHERE (a Pool = shared pool AND a NAME NOT IN ( free memory ))        AND b NAME = shared_pool_size ;

   查看用户使用内存情况

            SELECT Username SUM(Sharable_Mem) SUM(Persistent_Mem) SUM(Runtime_Mem)        FROM Sys v_$sqlarea a Dba_Users b        WHERE a Parsing_User_Id = b User_Id        GROUP BY Username;

   查看对象的缓存情况          SELECT Owner Namespace TYPE NAME Sharable_Mem Loads Executions Locks         Pins Kept        FROM V$db_Object_Cache        WHERE TYPE NOT IN        ( NOT LOADED NON EXISTENT VIEW TABLE SEQUENCE )        AND Executions >         AND Loads >         AND Kept = NO         ORDER BY Owner Namespace TYPE Executions DESC;        SELECT TYPE COUNT(*)        FROM V$db_Object_Cache        GROUP BY TYPE;

   查看库缓存命中率          SELECT Namespace Gets Gethitratio * Gethitratio Pins         Pinhitratio * Pinhitratio Reloads Invalidations        FROM V$librarycache

   查看某些用户的hash          SELECT a Username COUNT(b Hash_Value) Total_Hash         COUNT(b Hash_Value) COUNT(UNIQUE(b Hash_Value)) Same_Hash         (COUNT(UNIQUE(b Hash_Value)) / COUNT(b Hash_Value)) * u_Hash_Ratio        FROM Dba_Users a V$sqlarea b        WHERE a User_Id = b Parsing_User_Id        GROUP BY a Username;

   查看字典命中率          SELECT (SUM(Getmisses) / SUM(Gets)) Ratio        FROM V$rowcache;

   查看undo段的使用情况          SELECT d Segment_Name Extents Optsize Shrinks Aveshrink Aveactive         d Status        FROM V$rollname n V$rollstat s Dba_Rollback_Segs d        WHERE d Segment_Id = n Usn(+)        AND d Segment_Id = s Usn(+);

   求归档日志的切换频率(生产系统可能时间会很长)          SELECT Start_Recid Start_Time End_Recid End_Time Minutes        FROM (SELECT Test * Rownum AS Rn        FROM (SELECT b Recid Start_Recid         To_Char(b First_Time yyyy mm dd hh :mi:ss ) Start_Time         a Recid End_Recid         To_Char(a First_Time yyyy mm dd hh :mi:ss ) End_Time         Round(((a First_Time b First_Time) * ) * ) Minutes        FROM V$log_History a V$log_History b        WHERE a Recid = b Recid +         AND b First_Time > SYSDATE         ORDER BY a First_Time DESC) Test) y        WHERE y Rn <

   求回滚段正在处理的事务          SELECT a NAME b Xacts c Sid c Serial# d Sql_Text        FROM V$rollname a V$rollstat b V$session c V$sqltext d V$transaction e        WHERE a Usn = b Usn        AND b Usn = e Xidusn        AND c Taddr = e Addr        AND c Sql_Address = d Address        AND c Sql_Hash_Value = d Hash_Value        ORDER BY a NAME c Sid d Piece;

   求某个事务的重做信息(bytes)          SELECT s NAME m VALUE        FROM V$mystat m V$statname s        WHERE m Statistic# = s Statistic#        AND s NAME LIKE %redo size% ;

   求cache中缓存超过其 %的对象          SELECT o Owner o Object_Type o Object_Name COUNT(b Objd)        FROM V$bh b Dba_Objects o        WHERE b Objd = o Object_Id        GROUP BY o Owner o Object_Type o Object_Name        HAVING COUNT(b Objd) > (SELECT To_Number(VALUE) *         FROM V$parameter        WHERE NAME = db_block_buffers );

   求buffer cache中的块信息

            SELECT o Object_Type Substr(o Object_Name ) Objname b Objd b Status         COUNT(b Objd)        FROM V$bh b Dba_Objects o        WHERE b Objd = o Data_Object_Id        AND o Owner = &owner         GROUP BY o Object_Type o Object_Name b Objd b Status;

   求日志文件的空间使用          SELECT Le Leseq Current_Log_Sequence#         * Cp Cpodr_Bno / Le Lesiz Percentage_Full        FROM X$kcccp Cp X$kccle Le        WHERE Le Leseq = Cp Cpodr_Seq;

   求等待中的对象          SELECT /*+rule */        s Sid s Username w Event o Owner o Segment_Name o Segment_Type         o Partition_Name w Seconds_In_Wait Seconds w State        FROM V$session_Wait w V$session s Dba_Extents o        WHERE w Event IN (SELECT NAME        FROM V$event_Name        WHERE Parameter = file#         AND Parameter = block#         AND NAME NOT LIKE control% )        AND o Owner <> sys         AND w Sid = s Sid        AND w P = o File_Id        AND w P >= o Block_Id        AND w P < o Block_Id + o Blocks

   求当前事务的重做尺寸          SELECT V$statname NAME VALUE        FROM V$mystat V$statname        WHERE V$mystat Statistic# = V$statname Statistic#        AND V$statname NAME = redo size ;

   唤醒smon去清除临时段          column pid new_value Smon        set termout off        SELECT p Pid        FROM Sys v_$bgprocess b Sys v_$process p        WHERE b NAME = SMON         AND p Addr = b Paddr;        SET Termout ON Oradebug Wakeup &Smon Undefine Smon

   求回退率          SELECT b VALUE / (a VALUE + b VALUE) a VALUE b VALUE        FROM V$sysstat a V$sysstat b        WHERE a Statistic# =         AND b Statistic# = ;

   求free memory          SELECT *        FROM V$sgastat        WHERE NAME = free memory ;        SELECT a NAME SUM(b VALUE)        FROM V$statname a V$sesstat b        WHERE a Statistic# = b Statistic#        GROUP BY a NAME;

  查看一下谁在使用那个可以得回滚段 或者查看一下某个可以得用户在使用回滚段

  找出领回滚段不断增长的事务 再看看如何处理它 是否可以将它mit 再不行

  就看看能否kill它 等等 查看当前正在使用的回滚段的用户信息和回滚段信息:          set linesize         SELECT r NAME ROLLBACK SEGMENT NAME l Sid ORACLE PID         p Spid SYSTEM PID s Username ORACLE USERNAME         FROM V$lock l V$process p V$rollname r V$session s        WHERE l Sid = p Pid(+)        AND s Sid = l Sid        AND Trunc(l Id (+) / ) = r Usn        AND l TYPE(+) = TX         AND l Lmode(+) =         ORDER BY r NAME;

   查看用户的回滚段的信息          SELECT s Username Rn NAME        FROM V$session s V$transaction t V$rollstat r V$rollname Rn        WHERE s Saddr = t Ses_Addr        AND t Xidusn = r Usn        AND r Usn = Rn Usn

   查看内存中存的使用

  SELECT Decode(Greatest(CLASS )                 Decode(CLASS Data Sort Header To_Char(CLASS)) Rollback ) Class         SUM(Decode(Bitand(Flag ) )) Not Dirty         SUM(Decode(Bitand(Flag ) )) Dirty         SUM(Dirty_Queue) On Dirty COUNT(*) Total         FROM X$bh        GROUP BY Decode(Greatest(CLASS )                 Decode(CLASS Data Sort Header To_Char(CLASS)) Rollback );

cha138/Article/program/Oracle/201311/17840

相关参考

知识大全 Oracle维护常用SQL语句一

数据库手册:Oracle维护常用SQL语句一  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  查看

知识大全 Oracle维护常用SQL语句汇总

Oracle维护常用SQL语句汇总  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  如何远程判断O

知识大全 总结--常用的监控SQL语句集合

总结--常用的监控SQL语句集合  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  监控事例的等待:

知识大全 SQL Server 数据库管理常用的SQL和T-SQL语句[3]

SQLServer数据库管理常用的SQL和T-SQL语句[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来

知识大全 Oracle10G常用维护语句

Oracle10G常用维护语句  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  创建表空间    

知识大全 oracle与sql的区别(常用函数)

  许多软件公司都理解开发不依赖于特定数据库类型(例如OracleSQLServerDB)的应用程序的重要性它可以让客户们选择自己习惯的平台一般来说软件开发人员都能够识别出他们的负责数据库维护的客户和

知识大全 Oracle数据库SQL语句性能调整的基本原则

Oracle数据库SQL语句性能调整的基本原则  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  详

知识大全 SQL Server 数据库管理常用的SQL和T-SQL语句[2]

SQLServer数据库管理常用的SQL和T-SQL语句[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来

知识大全 SQL Server 数据库管理常用的SQL和T-SQL语句[1]

SQLServer数据库管理常用的SQL和T-SQL语句[1]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来

知识大全 ORACLE中常用的SQL语法和数据对象

ORACLE中常用的SQL语法和数据对象  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  一数据控