首页 > 数据库 >oracle 会话查询

oracle 会话查询

时间:2022-11-16 14:45:46浏览次数:50  
标签:1024 name -- 查询 会话 session oracle where select

需要管理员用户下执行(sys/sysdba)


--先查锁
select * from v$lock where lmode > 0 and type in ('TM','TX');
--查用户名
select * from v$session where username = 'PROD_JCJ'
-- 查编号方便下一步 kill
select sid,serial#,username from v$session where sid = '13313';
 
--kill 锁死的会话
alter system kill session '15489,47476';
alter system kill session '16215,2972';
alter system kill session '2545,51671';
alter system kill session '609,63963';
alter system kill session '6415,45951';
alter system kill session '2306,64117';
 
 
--查看被锁的表       
select * from v$locked_object a, dba_objects b where b.object_id = a.object_id  

-- 执行以下语句子,获得被锁表的Session ID
select b.owner,b.object_name,a.session_id,a.locked_mode
from dba_objects b, v$locked_object a
where b.object_id = a.object_id
and b.object_name='PER_ALL_ASSIGNMENTS_F';



-- 1.查询oracle的最大连接数:
select * from v$parameter where name='processes';


select count(*) from v$process; --当前的连接数


select value from v$parameter where name = 'processes' --数据库允许的最大连接数


-- 日志文件位置
select * from V$diag_Info;


--查看表锁的原因
select l.session_id sid,
       s.serial#,
       l.locked_mode,
       l.oracle_username,
       s.user#,
       l.os_user_name,
       s.machine,
       s.terminal,
       a.sql_text,
       a.action from v$sqlarea a, v$session s, v$locked_object l
       where l.session_id = s.sid and s.prev_sql_addr = a.address
       order by sid,s.serial#;


--查询低效的SQL
SELECT EXECUTIONS, DISK_READS, BUFFER_GETS,
   ROUND ((BUFFER_GETS-DISK_READS)/BUFFER_GETS, 2) Hit_radio,
   ROUND (DISK_READS/EXECUTIONS, 2) Reads_per_run,
   SQL_TEXT
FROM   V$SQLAREA
WHERE  EXECUTIONS>0
AND     BUFFER_GETS > 0 
AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS < 0.8 
ORDER BY 4 DESC




-- 查看表空间大小及使用情况
SELECT a.tablespace_name "表空间名", 
total "表空间大小", 
free "表空间剩余大小", 
(total - free) "表空间使用大小", 
total / (1024 * 1024 * 1024) "表空间大小(G)", 
free / (1024 * 1024 * 1024) "表空间剩余大小(G)", 
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)", 
round((total - free) / total, 4) * 100 "使用率 %" 
FROM (SELECT tablespace_name, SUM(bytes) free 
FROM dba_free_space 
GROUP BY tablespace_name) a, 
(SELECT tablespace_name, SUM(bytes) total 
FROM dba_data_files 
GROUP BY tablespace_name) b 
WHERE a.tablespace_name = b.tablespace_name




--查看各用户的各种资源占用,可以运行下面的SQL
select se.SID, ses.username, ses.osuser, n.NAME, se.VALUE
  from v$statname n, v$sesstat se, v$session ses
  where n.statistic# = se.statistic# and
        se.sid = ses.sid and
        ses.username is not null and
        n.name in ('CPU used by this session',
                   'db block gets',
                   'consistent gets',
                   'physical reads',
                   'free buffer requested',
                   'table scans (long tables)',
                   'table scan rows gotten',
                   'sorts (memory)',
                   'sorts (disk)',
                   'sorts (rows)', 
                   'session uga memory max' ,
                   'session pga memory max')
  order by sid, n.statistic#;
	
	
	--从V$SQLAREA中查询最占用资源的查询
select b.username username,a.buffer_gets reads,
    a.executions exec,a.buffer_gets/decode(a.executions,0,1,a.executions) rds_exec_ratio,
    a.sql_text Statement
from  v$sqlarea a,dba_users b
where a.parsing_user_id=b.user_id
 and a.buffer_gets > 100000
order by a.buffer_gets desc;



--列出使用频率最高的5个查询:
select sql_text,executions
from (select sql_text,executions,
   rank() over
    (order by executions desc) exec_rank
   from v$sql)
where exec_rank <=5;




--消耗磁盘读取最多的sql top5:
select disk_reads,sql_text
from (select sql_text,disk_reads,
   dense_rank() over
     (order by disk_reads desc) disk_reads_rank
   from v$sql)
where disk_reads_rank <=5;




--找出需要大量缓冲读取(逻辑读)操作的查询:
select buffer_gets,sql_text
from (select sql_text,buffer_gets,
   dense_rank() over
     (order by buffer_gets desc) buffer_gets_rank
   from v$sql)
where buffer_gets_rank<=5;


--查询日志文件位置
select * from V$diag_Info;


-- 查询v$session_wait获取各进程等待事件
select sid,event,p1,p1text from v$session_wait;

select event,count(*)  from v$session_event group by event order by count(*) desc ;



https://www.cnblogs.com/hziwei/p/15588249.html

标签:1024,name,--,查询,会话,session,oracle,where,select
From: https://www.cnblogs.com/redarmy/p/16895848.html

相关文章

  • SQL查询
    selectid_stocpf,operat_nscomp,datemodif,SUBSTRING(heuremodif,1,6)ASTIMEfrom(selectid_stocpffromt_stocpfwhereet_refcmp='655392800C'anddatemodifbetw......
  • mysql巧妙化解递归查询树形数据 | 纯sql
    前言开发中树形结构应该是很常见的一种数据结构了。而在数据库方面往往也都伴随相应的树形设计。在​​mysql​​中通过​​parent_id​​来绑定其上游,从而达到树形结构......
  • 限制用户只能在特定时间段登录 oracle
    需求:只允许一些用户在特定时间内登录实现方式:通过触发器去实现(对具有dba权限的用户不适用),触发器代码如下CREATEORREPLACETRIGGERlimit_connectionAFTERLO......
  • 小程序云开发模糊查询实现
    constcloud=require('wx-server-sdk');cloud.init({env:cloud.DYNAMIC_CURRENT_ENV});constdb=cloud.database();const_=db.command;const$=db.com......
  • CentOS7_Oracle12C 安装非容器数据库
    Oracle12C安装非容器数据库1.安装环境准备1.1条件准备Oracle安装包:linuxx64_12201_database.zipSSH远程工具:MobaxVMware虚拟机:centos7.6(内存:2G,Swap:3G磁......
  • ArrayList为什么比LinkedList查询速度快
    知乎:https://www.zhihu.com/question/61920401举个简单的例子:假如有很多人,排成长队,这个时候要找5号的人就非常简单,问都不用问,直接定位。假如不排成长队,只是随机站在很大......
  • 批量创建xshell会话
    importreimportostmp_file=r"C:\Users\yc\Documents\NetSarangComputer\7\Xshell\Sessions\192.168.2.253.xsh"withopen(tmp_file,"r+",encoding="utf-16......
  • [Oracle] 11gR2 GI Node May not Join the Cluster After Private Network is Functio
    11gR2GINodeMaynotJointheClusterAfterPrivateNetworkisFunctionalAfterEvictionduetoPrivateNetworkProblem(文档ID1479380.1)InthisDocument......
  • 连接查询
    连接查询有表t1和表t2:mysql>SELECT*FROMt1;m1n11a2b3cmysql>SELECT*FROMt2;m2n22b3c4d连接的本质就是把各个连......
  • 记录一个gorm发生全局查询条件的问题
       正常情况下在使用gorm做修改操作时,会使用omit过滤一些字段,比如上图中修改的时候就不应该修改创建时间和创建人字段的值。关键点在于上图如果omit中没有增加id字......