0、数据库参数属性col PROPERTY_NAME format a25col PROPERTY_VALUE format a30col DESCRIPTION format a100select * from database_properties;
select * from v$version;
1、求当前会话的SID,SERIAL#SELECT Sid, Serial# FROM V$sessionWHERE Audsid = Sys_Context('USERENV', 'SESSIONID');
2、查询session的OS进程IDSELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#,s.Osuser, s.MachineFROM V$process p, V$session s, V$bgprocess bWHERE p.Addr = s.PaddrAND p.Addr = b.Paddr And (s.sid=&1 or p.spid=&1)UNION ALLSELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid,s.Serial#, s.Osuser, s.MachineFROM V$process p, V$session sWHERE p.Addr = s.PaddrAnd (s.sid=&1 or p.spid=&1)AND s.Username IS NOT NULL;
3、根据sid查看对应连接正在运行的sql SELECT /*+ PUSH_SUBQ */ Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts,Version_Count, Loaded_Versions, Open_Versions, Users_Opening, Executions,Users_Executing, Loads, First_Load_Time, Invalidations, Parse_Calls,Disk_Reads, Buffer_Gets, Rows_Processed, SYSDATE Start_Time,SYSDATE Finish_Time, '>' || Address Sql_Address, 'N' StatusFROM V$sqlarea WHERE Address = (SELECT Sql_AddressFROM V$session WHERE Sid = &sid );
4、查找object为哪些进程所用SELECT p.Spid, s.Sid, s.Serial# Serial_Num, s.Username User_Name,a.TYPE Object_Type, s.Osuser Os_User_Name, a.Owner,a.OBJECT Object_Name,Decode(Sign(48 - Command), 1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,p.Program Oracle_Process, s.Terminal Terminal, s.Program Program,s.Status Session_StatusFROM V$session s, V$access a, V$process pWHERE s.Paddr = p.AddrAND s.TYPE = 'USER'AND a.Sid = s.SidAND a.OBJECT = '&obj'ORDER BY s.Username, s.Osuser
5、查看有哪些用户连接SELECT s.Osuser Os_User_Name,Decode(Sign(48 - Command),1,To_Char(Command),'Action Code #' || To_Char(Command)) Action,p.Program Oracle_Process, Status Session_Status, s.Terminal Terminal,s.Program Program, s.Username User_Name,s.Fixed_Table_Sequence Activity_Meter, '' Query, 0 Memory,0 Max_Memory, 0 Cpu_Usage, s.Sid, s.Serial# Serial_NumFROM V$session s, V$process pWHERE s.Paddr = p.AddrAND s.TYPE = 'USER'ORDER BY s.Username, s.Osuser
6、根据v.sid查看对应连接的资源占用等情况SELECT n.NAME, v.VALUE, n.CLASS, n.Statistic# FROM V$statname n, V$sesstat vWHERE v.Sid = &sidAND v.Statistic# = n.Statistic#ORDER BY n.CLASS, n.Statistic#
7、查询耗资源的进程(top session)SELECT s.Schemaname Schema_Name,Decode(Sign(48 - Command),1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,Status Session_Status, s.Osuser Os_User_Name, s.Sid, p.Spid,s.Serial# Serial_Num, Nvl(s.Username, '[Oracle process]') User_Name,s.Terminal Terminal, s.Program Program, St.VALUE Criteria_ValueFROM V$sesstat St, V$session s, V$process pWHERE St.Sid = s.SidAND St.Statistic# = To_Number('38')AND ('ALL' = 'ALL' OR s.Status = 'ALL')AND p.Addr = s.PaddrORDER BY St.VALUE DESC, p.Spid ASC, s.Username ASC, s.Osuser ASC
8、查看锁(lock)情况SELECT /*+ RULE */ Ls.Osuser Os_User_Name, Ls.Username User_Name,Decode(Ls.TYPE,'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock','TX', 'Transaction enqueue lock', 'UL', 'User supplied lock') Lock_Type,o.Object_Name OBJECT,Decode(Ls.Lmode,1, NULL, 2, 'Row Share', 3, 'Row Exclusive',4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive',NULL) Lock_Mode,o.Owner, Ls.Sid, Ls.Serial# Serial_Num, Ls.Id1, Ls.Id2 FROM Sys.Dba_Objects o, (SELECT s.Osuser, s.Username, l.TYPE, l.Lmode, s.Sid, s.Serial#, l.Id1,l.Id2 FROM V$session s, V$lock lWHERE s.Sid = l.Sid) LsWHERE o.Object_Id = Ls.Id1AND o.Owner <> 'SYS'ORDER BY o.Owner, o.Object_Name;
9、查看等待(wait)情况
SELECT Ws.CLASS, Ws.COUNT COUNT, SUM(Ss.VALUE) Sum_ValueFROM V$waitstat Ws, V$sysstat SsWHERE Ss.NAME IN ('db block gets', 'consistent gets')GROUP BY Ws.CLASS, Ws.COUNT;
10、求process/session的状态SELECT p.Pid, p.Spid, s.Program, s.Sid, s.Serial#FROM V$process p, V$session sWHERE s.Paddr = p.Addr;
11、求谁阻塞了某个session(10g)SELECT Sid, Username, Event, Blocking_Session, Seconds_In_Wait, Wait_TimeFROM V$sessionWHERE State IN ('WAITING')AND Wait_Class != 'Idle';
12、查会话的阻塞col user_name format a32SELECT /*+ rule */ Lpad(' ', Decode(l.Xidusn, 0, 3, 0)) || l.Oracle_Username User_Name,o.Owner, o.Object_Name, s.Sid, s.Serial#FROM V$locked_Object l, Dba_Objects o, V$session sWHERE l.Object_Id = o.Object_IdAND l.Session_Id = s.SidORDER BY o.Object_Id, Xidusn DESC;col username format a15col lock_level format a8col owner format a18col object_name format a32SELECT /*+ rule */ s.Username,Decode(l.TYPE, 'tm', 'table lock', 'tx', 'row lock', NULL) Lock_Level,o.Owner, o.Object_Name, s.Sid, s.Serial#FROM V$session s, V$lock l, Dba_Objects oWHERE l.Sid = s.SidAND l.Id1 = o.Object_Id(+)AND s.Username IS NOT NULL;
13、求等待的事件及会话信息/求会话的等待及会话信息SELECT Se.Sid, s.Username, Se.Event, Se.Total_Waits, Se.Time_Waited,Se.Average_WaitFROM V$session s, V$session_Event SeWHERE s.Username IS NOT NULLAND Se.Sid = s.SidAND s.Status = 'ACTIVE'AND Se.Event NOT LIKE '%SQL*Net%'ORDER BY s.Username;SELECT s.Sid, s.Username, Sw.Event, Sw.Wait_Time, Sw.State,Sw.Seconds_In_WaitFROM V$session s, V$session_Wait SwWHERE s.Username IS NOT NULLAND Sw.Sid = s.SidAND Sw.Event NOT LIKE '%SQL*Net%'ORDER BY s.Username;
14、求会话等待的file_id/block_idcol event format a24col p1text format a12col p2text format a12col p3text format a12SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3FROM V$session_WaitWHERE Event NOT LIKE '%SQL%'AND Event NOT LIKE '%rdbms%'AND Event NOT LIKE '%mon%'ORDER BY Event;SELECT NAME, Wait_TimeFROM V$latch lWHERE EXISTS (SELECT 1FROM (SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3FROM V$session_WaitWHERE Event NOT LIKE '%SQL%'AND Event NOT LIKE '%rdbms%'AND Event NOT LIKE '%mon%') xWHERE x.P1 = l.Latch#);
15、求会话等待的对象col owner format a18col segment_name format a32col segment_type format a32SELECT Owner, Segment_Name, Segment_TypeFROM Dba_ExtentsWHERE File_Id = &File_IdAND &Block_Id BETWEEN Block_Id AND Block_Id + Blocks - 1;
16、求出某个进程,并对它进行跟踪SELECT s.Sid, s.Serial#FROM V$session s, V$process pWHERE s.Paddr = p.AddrAND p.Spid = &1;Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, TRUE);Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, FALSE);
17、求当前session的跟踪文件SELECT P1.VALUE || '/' || P2.VALUE || '_ora_' || p.Spid || '.ora' FilenameFROM V$process p, V$session s, V$parameter P1, V$parameter P2WHERE P1.NAME = 'user_dump_dest'AND P2.NAME = 'instance_name'AND p.Addr = s.PaddrAND s.Audsid = Userenv('SESSIONID')AND p.Background IS NULLAND Instr(p.Program, 'CJQ') = 0;
18、求出锁定的对象SELECT Do.Object_Name, Session_Id, Process, Locked_ModeFROM V$locked_Object Lo, Dba_Objects DoWHERE Lo.Object_Id = Do.Object_Id;
19、DB_Cache建议SELECT size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_readsFROM V$DB_CACHE_ADVICEWHERE name = 'DEFAULT'AND block_size = (SELECT value FROM V$PARAMETER WHERE name = 'db_block_size')AND advice_status = 'ON';
20、查看各项SGA相关参数:SGA,SGASTATselect substr(name,1,10) name,substr(value,1,10) value from v$parameter where name = 'log_buffer';
select * from v$sgastat ;
select * from v$sga;
show parameters area_size #查看 各项区域内存参数, 其中sort_area为排序参数用; 各项视图建议参数值:V$DB_CACHE_ADVICE、V$SHARED_POOL_ADVICE),关于PGA也有相关视图V$PGA_TARGET_ADVICE 等。
21、内存使用锁定在物理内存:AIX 5L(AIX 4.3.3 以上)logon aix as rootcd /usr/samples/kernel./vmtune (信息如下) v_pingshm已经是1./vmtune -S 1然后oracle用户修改initSID.ora 中 lock_sga = true重新启动数据库
HP UNIXRoot身份登陆Create the file "/etc/privgroup": vi /etc/privgroupAdd line "dba MLOCK" to fileAs root, run the command "/etc/setprivgrp -f /etc/privgroup":$/etc/setprivgrp -f /etc/privgrouporacle用户修改initSID.ora中lock_sga=true重新启动数据库
SOLARIS (solaris2.6以上)8i版本以上数据库默认使用隐藏参数 use_ism = true ,自动锁定SGA于内存中,不用设置lock_sga, 如果设置 lock_sga =true 使用非 root 用户启动数据库将返回错误。
WINDOWS (作用不大)不能设置lock_sga=true,可以通过设置pre_page_sga=true,使得数据库启动的时候就把所有内存页装载,这样可能起到一定的作用。
22、内存参数调整数据缓冲区命中率select value from v$sysstat where name ='physical reads';
select value from v$sysstat where name ='physical reads direct';
select value from v$sysstat where name ='physical reads direct (lob)';
select value from v$sysstat where name ='consistent gets';
select value from v$sysstat where name = 'db block gets';
这里命中率的计算应该是令 x = physical reads direct + physical reads direct (lob)命中率 =100 - ( physical reads - x) / (consistent gets + db block gets - x)*100通常如果发现命中率低于90%,则应该调整应用可可以考虑是否增大数据缓冲区;
共享池的命中率select sum(pinhits)/sum(pins)*100 "hit radio" from v$librarycache;
假如共享池的命中率低于95%,就要考虑调整应用(通常是没使用bind var )或者增加内存;
关于排序部分select name,value from v$sysstat where name like '%sort%';
假如我们发现sorts (disk)/ (sorts (memory)+ sorts (disk))的比例过高,则通常意味着sort_area_size 部分内存较小,可考虑调整相应的参数。
关于log_bufferselect name,value from v$sysstatwhere name in('redo entries','redo buffer allocation retries');
假如 redo buffer allocation retries/ redo entries 的比例超过1%我们就可以考虑增大log_buffer