| 導購 | 订阅 | 在线投稿
分享
 
 
當前位置: 王朝網路 >> oracle >> Oracle數據庫維護常用SQL語句集合
 

Oracle數據庫維護常用SQL語句集合

2008-07-02 07:24:11  編輯來源:互聯網  简体版  手機版  評論  字體: ||
 
 
  進程相關:

  1、 求當前會話的SID,SERIAL#

  SELECT Sid, Serial#

  FROM V$session

  WHERE Audsid = Sys_Context('USERENV', 'SESSIONID');

  2、 查詢session的OS進程ID

  SELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#,

  s.Osuser, s.Machine

  FROM V$process p, V$session s, V$bgprocess b

  WHERE p.Addr = s.Paddr

  AND p.Addr = b.Paddr

  And (s.sid=&1 or p.spid=&1)

  UNION ALL

  SELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid,

  s.Serial#, s.Osuser, s.Machine

  FROM V$process p, V$session s

  WHERE p.Addr = s.Paddr

  And (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' Status

  FROM V$sqlarea

  WHERE Address = (SELECT Sql_Address

  FROM 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_Status

  FROM V$session s, V$access a, V$process p

  WHERE s.Paddr = p.Addr

  AND s.TYPE = 'USER'

  AND a.Sid = s.Sid

  AND 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_Num

  FROM V$session s, V$process p

  WHERE s.Paddr = p.Addr

  AND 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 v

  WHERE v.Sid = &sid

  AND 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_Value

  FROM V$sesstat St, V$session s, V$process p

  WHERE St.Sid = s.Sid

  AND St.Statistic# = To_Number('38')

  AND ('ALL' = 'ALL' OR s.Status = 'ALL')

  AND p.Addr = s.Paddr

  ORDER 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 l

  WHERE s.Sid = l.Sid) Ls

  WHERE o.Object_Id = Ls.Id1

  AND o.Owner <> 'SYS'

  ORDER BY o.Owner, o.Object_Name

  9、查看等待(wait)情況

  SELECT Ws.CLASS, Ws.COUNT COUNT, SUM(Ss.VALUE) Sum_Value

  FROM V$waitstat Ws, V$sysstat Ss

  WHERE 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 s

  WHERE s.Paddr = p.Addr;

  11、求誰阻塞了某個session(10g)

  SELECT Sid, Username, Event, Blocking_Session, Seconds_In_Wait, Wait_Time

  FROM V$session

  WHERE State IN ('WAITING')

  AND Wait_Class != 'Idle';

  12、查會話的阻塞

  col user_name format a32

  SELECT /*+ 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 s

  WHERE l.Object_Id = o.Object_Id

  AND l.Session_Id = s.Sid

  ORDER BY o.Object_Id, Xidusn DESC;

  col username format a15

  col lock_level format a8

  col owner format a18

  col object_name format a32

  SELECT /*+ 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 o

  WHERE l.Sid = s.Sid

  AND 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_Wait

  FROM V$session s, V$session_Event Se

  WHERE s.Username IS NOT NULL

  AND Se.Sid = s.Sid

  AND 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_Wait

  FROM V$session s, V$session_Wait Sw

  WHERE s.Username IS NOT NULL

  AND Sw.Sid = s.Sid

  AND Sw.Event NOT LIKE '%SQL*Net%'

  ORDER BY s.Username;

  14、求會話等待的file_id/block_id

  col event format a24

  col p1text format a12

  col p2text format a12

  col p3text format a12

  SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3

  FROM V$session_Wait

  WHERE Event NOT LIKE '%SQL%'

  AND Event NOT LIKE '%rdbms%'

  AND Event NOT LIKE '%mon%'

  ORDER BY Event;

  SELECT NAME, Wait_Time

  FROM V$latch l

  WHERE EXISTS (SELECT 1

  FROM (SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3

  FROM V$session_Wait

  WHERE Event NOT LIKE '%SQL%'

  AND Event NOT LIKE '%rdbms%'

  AND Event NOT LIKE '%mon%') x

  WHERE x.P1 = l.Latch#);

  15、求會話等待的對象

  col owner format a18

  col segment_name format a32

  col segment_type format a32

  SELECT Owner, Segment_Name, Segment_Type

  FROM Dba_Extents

  WHERE File_Id = &File_Id

  AND &Block_Id BETWEEN Block_Id AND Block_Id + Blocks - 1;

  16、求出某個進程,並對它進行跟蹤

  SELECT s.Sid, s.Serial#

  FROM V$session s, V$process p

  WHERE s.Paddr = p.Addr

  AND 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' Filename

  FROM V$process p, V$session s, V$parameter P1, V$parameter P2

  WHERE P1.NAME = 'user_dump_dest'

  AND P2.NAME = 'instance_name'

  AND p.Addr = s.Paddr

  AND s.Audsid = Userenv('SESSIONID')

  AND p.Background IS NULL

  AND Instr(p.Program, 'CJQ') = 0;

  18、求出鎖定的對象

  SELECT Do.Object_Name, Session_Id, Process, Locked_Mode

  FROM V$locked_Object Lo, Dba_Objects Do

  WHERE Lo.Object_Id = Do.Object_Id;
 
 
 
上一篇《解決Oracle 10g library內存分配告警問題》
下一篇《oracle裏long類型的總結(1)》
 
 
 
日版寵物情人插曲《Winding Road》歌詞

日版寵物情人2017的插曲,很帶節奏感,日語的,女生唱的。 最後聽見是在第8集的時候女主手割傷了,然後男主用嘴幫她吸了一下,插曲就出來了。 歌手:Def...

兄弟共妻,我成了他們夜裏的美食

老鍾家的兩個兒子很特別,就是跟其他的人不太一樣,魔一般的執著。兄弟倆都到了要結婚的年齡了,不管自家老爹怎麽磨破嘴皮子,兄弟倆說不娶就不娶,老父母爲兄弟兩操碎了心...

如何磨出破洞牛仔褲?牛仔褲怎麽剪破洞?

把牛仔褲磨出有線的破洞 1、具體工具就是磨腳石,下面墊一個硬物,然後用磨腳石一直磨一直磨,到把那塊磨薄了,用手撕開就好了。出來的洞啊很自然的。需要貓須的話調幾...

我就是掃描下圖得到了敬業福和愛國福

先來看下敬業福和愛國福 今年春節,支付寶再次推出了“五福紅包”活動,表示要“把欠大家的敬業福都還給大家”。 今天該活動正式啓動,和去年一樣,需要收集“五福”...

冰箱異味産生的原因和臭味去除的方法

有時候我們打開冰箱就會聞到一股異味,冰箱裏的這種異味是因爲一些物質發出的氣味的混合體,聞起來讓人惡心。 産生這些異味的主要原因有以下幾點。 1、很多人有這種習...

《極品家丁》1-31集大結局分集劇情介紹

簡介 《極品家丁》講述了現代白領林晚榮無意回到古代金陵,並追隨蕭二小姐化名“林三”進入蕭府,不料卻陰差陽錯上演了一出低級家丁拼搏上位的“林三升職記”。...

李溪芮《極品家丁》片尾曲《你就是我最愛的寶寶》歌詞

你就是我最愛的寶寶 - 李溪芮 (電視劇《極品家丁》片尾曲) 作詞:常馨內 作曲:常馨內 你的眉 又鬼馬的挑 你的嘴 又壞壞的笑 上一秒吵鬧 下...

烏梅的功效與作用以及烏梅的食用禁忌有哪些?

烏梅,又稱春梅,中醫認爲,烏梅味酸,性溫,無毒,具有安心、除熱、下氣、祛痰、止渴調中、殺蟲的功效,治肢體痛、肺痨病。烏梅泡水喝能治傷寒煩熱、止吐瀉,與幹姜一起制...

什麽是脂肪粒?如何消除臉部脂肪粒?

什麽是脂肪粒 在我們的臉上總會長一個個像脂肪的小顆粒,弄也弄不掉,而且顔色還是白白的。它既不是粉刺也不是其他的任何痘痘,它就是脂肪粒。 脂肪粒雖然也是由油脂...

網絡安全治理:國家安全保障的主要方向是打擊犯罪,而不是處置和懲罰受害者

來源:中國青年報 新的攻擊方法不斷湧現,黑客幾乎永遠占據網絡攻擊的上風,我們不可能通過技術手段杜絕網絡攻擊。國家安全保障的主要方向是打擊犯罪,而不是處置和懲罰...

 
 
 
進程相關: 1、 求當前會話的SID,SERIAL# SELECT Sid, Serial# FROM V$session WHERE Audsid = Sys_Context('USERENV', 'SESSIONID'); 2、 查詢session的OS進程ID SELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#, s.Osuser, s.Machine FROM V$process p, V$session s, V$bgprocess b WHERE p.Addr = s.Paddr AND p.Addr = b.Paddr And (s.sid=&1 or p.spid=&1) UNION ALL SELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid, s.Serial#, s.Osuser, s.Machine FROM V$process p, V$session s WHERE p.Addr = s.Paddr And (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' Status FROM V$sqlarea WHERE Address = (SELECT Sql_Address FROM 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_Status FROM V$session s, V$access a, V$process p WHERE s.Paddr = p.Addr AND s.TYPE = 'USER' AND a.Sid = s.Sid AND 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_Num FROM V$session s, V$process p WHERE s.Paddr = p.Addr AND 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 v WHERE v.Sid = &sid AND 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_Value FROM V$sesstat St, V$session s, V$process p WHERE St.Sid = s.Sid AND St.Statistic# = To_Number('38') AND ('ALL' = 'ALL' OR s.Status = 'ALL') AND p.Addr = s.Paddr ORDER 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 l WHERE s.Sid = l.Sid) Ls WHERE o.Object_Id = Ls.Id1 AND o.Owner <> 'SYS' ORDER BY o.Owner, o.Object_Name 9、查看等待(wait)情況 SELECT Ws.CLASS, Ws.COUNT COUNT, SUM(Ss.VALUE) Sum_Value FROM V$waitstat Ws, V$sysstat Ss WHERE 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 s WHERE s.Paddr = p.Addr; 11、求誰阻塞了某個session(10g) SELECT Sid, Username, Event, Blocking_Session, Seconds_In_Wait, Wait_Time FROM V$session WHERE State IN ('WAITING') AND Wait_Class != 'Idle'; 12、查會話的阻塞 col user_name format a32 SELECT /*+ 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 s WHERE l.Object_Id = o.Object_Id AND l.Session_Id = s.Sid ORDER BY o.Object_Id, Xidusn DESC; col username format a15 col lock_level format a8 col owner format a18 col object_name format a32 SELECT /*+ 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 o WHERE l.Sid = s.Sid AND 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_Wait FROM V$session s, V$session_Event Se WHERE s.Username IS NOT NULL AND Se.Sid = s.Sid AND 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_Wait FROM V$session s, V$session_Wait Sw WHERE s.Username IS NOT NULL AND Sw.Sid = s.Sid AND Sw.Event NOT LIKE '%SQL*Net%' ORDER BY s.Username; 14、求會話等待的file_id/block_id col event format a24 col p1text format a12 col p2text format a12 col p3text format a12 SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3 FROM V$session_Wait WHERE Event NOT LIKE '%SQL%' AND Event NOT LIKE '%rdbms%' AND Event NOT LIKE '%mon%' ORDER BY Event; SELECT NAME, Wait_Time FROM V$latch l WHERE EXISTS (SELECT 1 FROM (SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3 FROM V$session_Wait WHERE Event NOT LIKE '%SQL%' AND Event NOT LIKE '%rdbms%' AND Event NOT LIKE '%mon%') x WHERE x.P1 = l.Latch#); 15、求會話等待的對象 col owner format a18 col segment_name format a32 col segment_type format a32 SELECT Owner, Segment_Name, Segment_Type FROM Dba_Extents WHERE File_Id = &File_Id AND &Block_Id BETWEEN Block_Id AND Block_Id + Blocks - 1; 16、求出某個進程,並對它進行跟蹤 SELECT s.Sid, s.Serial# FROM V$session s, V$process p WHERE s.Paddr = p.Addr AND 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' Filename FROM V$process p, V$session s, V$parameter P1, V$parameter P2 WHERE P1.NAME = 'user_dump_dest' AND P2.NAME = 'instance_name' AND p.Addr = s.Paddr AND s.Audsid = Userenv('SESSIONID') AND p.Background IS NULL AND Instr(p.Program, 'CJQ') = 0; 18、求出鎖定的對象 SELECT Do.Object_Name, Session_Id, Process, Locked_Mode FROM V$locked_Object Lo, Dba_Objects Do WHERE Lo.Object_Id = Do.Object_Id;
󰈣󰈤
 
 
 
  免責聲明:本文僅代表作者個人觀點,與王朝網路無關。王朝網路登載此文出於傳遞更多信息之目的,並不意味著贊同其觀點或證實其描述,其原創性以及文中陳述文字和內容未經本站證實,對本文以及其中全部或者部分內容、文字的真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,並請自行核實相關內容。
 
 
Afternoon Girl
精致的外景拍攝
零點一公分的距離
俏麗迷人 視覺享受
北海老城隨拍(二)
夢中的郭河
Gassin(法國最美麗小鎮之一) part
瑤池夕照
 
>>返回首頁<<
 
 熱帖排行
 
 
 
 
© 2005- 王朝網路 版權所有