资源描述:
《oracle数据库维护常用的sql代码示例》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1、求当前会话的SID,SERIAL#1.SELECT Sid, Serial# 2.FROM V$session 3.WHERE Audsid = Sys_Context('USERENV', 'SESSIONID'); 2、查询session的OS进程ID1.SELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#, 2.s.Osuser, s.Machine 3.FROM V$process p, V
2、$session s, V$bgprocess b 4.WHERE p.Addr = s.Paddr 5.AND p.Addr = b.Paddr 6.And (s.sid=&1 or p.spid=&1) 7.UNION ALL 8.SELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid, 9.s.Serial#, s.Osuser, s.Machine 10.FROM V$process p, V$session
3、s 11.WHERE p.Addr = s.Paddr 12.And (s.sid=&1 or p.spid=&1) 13.AND s.Username IS NOT NULL; 3、根据sid查看对应连接正在运行的sql1.SELECT /*+ PUSH_SUBQ */ 2.Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts, 3.Version_Count, Loaded_Versions, Open
4、_Versions, Users_Opening, Executions, 4.Users_Executing, Loads, First_Load_Time, Invalidations, Parse_Calls, 5.Disk_Reads, Buffer_Gets, Rows_Processed, SYSDATE Start_Time, 6.SYSDATE Finish_Time, '>'
5、
6、 Address Sql_Address, 'N' Status 7.FROM V$sqlarea
7、8.WHERE Address = (SELECT Sql_Address 9.FROM V$session 10.WHERE Sid = &sid ); 4、查找object为哪些进程所用1.SELECT p.Spid, s.Sid, s.Serial# Serial_Num, s.Username User_Name, 2.a.TYPE Object_Type, s.Osuser Os_User_Name, a.Owner, 3.a.OBJECT Object_Name, 4.Decode(S
8、ign(48 - Command), 1, To_Char(Command), 'Action Code #'
9、
10、 To_Char(Command)) Action, 5.p.Program Oracle_Process, s.Terminal Terminal, s.Program Program, 6.s.Status Session_Status 7.FROM V$session s, V$access a, V$process p 8.WHERE s.Paddr = p.Addr 9.A
11、ND s.TYPE = 'USER' 1.AND a.Sid = s.Sid 2.AND a.OBJECT = '&obj' 3.ORDER BY s.Username, s.Osuser 5、查看有哪些用户连接1.SELECT s.Osuser Os_User_Name, 2.Decode(Sign(48 - Command),1,To_Char(Command), 3.'Action Code #'
12、
13、 To_Char(Command)) Action, 4.p.Program Oracle
14、_Process, Status Session_Status, s.Terminal Terminal, 5.s.Program Program, s.Username User_Name, 6.s.Fixed_Table_Sequence Activity_Meter, '' Query, 0 Memory, 7.0 Max_Memory, 0 Cpu_Usage, s.Sid, s.Serial# Serial_Num 8.FROM V$session s, V$proces