oracle锁表查询,资源占用,连接会话,低效SQL等性能检查
查询oracle用户名,机器名,锁表对象
select l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
l.os_user_name,
s.machine,
s.terminal,
o.object_name,
s.logon_time
from v$locked_object l, all_objects o, v$session s
where l.object_id = o.object_id
and l.session_id = s.sid
order by sid, s.serial#;
查询导致锁表的SQL语句
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#;
select b.sql_text
from v$session a, v$sql b
where a.sid = 6 --session_id
and a.SQL_ADDRESS = b.ADDRESS(+);
锁表查询
select count(*) from v$locked_object;
select * from v$locked_object;
查询哪个表被锁
select b.owner, b.object_name, a.session_id, a.locked_mode
from v$locked_object a, dba_objects b
where b.object_id = a.object_id;
查询哪个session引起的锁表
select b.username, b.sid, b.serial#, b.logon_time
from v$locked_object a, v$session b
where a.session_id = b.sid
order by b.logon_time;
杀掉进程
--3028:SID,15898:SERIAL#
alter system kill session '3028,15898';
显示正在等待锁的所有会话
select * from dba_waiters;
查询表空间使用情况(最常用)
select upper(f.tablespace_name) "表空间名",
d.tot_grootte_mb "表空间大小(m)",
d.tot_grootte_mb - f.total_bytes "已使用空间(m)",
to_char(round((d.tot_grootte_mb - f.total_bytes) /d.tot_grootte_mb * 100,2),'990.99') || '%' "使用比",
f.total_bytes "空闲空间(m)",
f.max_bytes "最大块(m)"
from (select tablespace_name,
round(sum(bytes) / (1024 * 1024), 2) total_bytes,
round(max(bytes) / (1024 * 1024), 2) max_bytes
from sys.dba_free_space
group by tablespace_name) f,
(select dd.tablespace_name,
round(sum(dd.bytes) / (1024 * 1024), 2) tot_grootte_mb
from sys.dba_data_files dd
group by dd.tablespace_name) d
where d.tablespace_name = f.tablespace_name
order by 1;
查看空间占用多的表或索引
SELECT
segment_name 对象,
segment_type 对象类型,
bytes / 1024 / 1024 MB,
tablespace_name 表空间名称
FROM
user_segments
ORDER BY
bytes DESC;
注意:查看ins用户下的表的空间要使用ins用户登录数据库
表空间不足如何处理?
1、查看表在哪个表空间
select tablespace_name,table_name from user_tables where table_name='TB_BASE_USER';
2、获取用户的默认表空间
select username,default_tablespace from dba_users where username='SCOTT'
3、找出该表空间对应的数据文件及路径
select * from dba_data_files t where t.tablespace_name = 'USERS'
4、查看表空间使用情况
5、方案一:扩展表空间
alter database datafile 'D:\ORACLE\PRODUCT\11.2.0\DBHOME_1\DATABASE\TEST_SPACE.DBF' resize 500M
--自动增长
alter database datafile 'D:\ORACLE\PRODUCT\11.2.0\DBHOME_1\DATABASE\TEST_SPACE.DBF' autoextend onnext 50m maxsize 500m;
--增加数据文件
alter tablespace tablespace_name add datafile 'D:\ORACLE\PRODUCT\11.2.0\DBHOME_1\DATABASE\TEST_SPACE.DBF' size 500M
6、方案二:移动至其他表空间
alter table ins.app_iops_dev_daily_nj move tablespace TBS_OSSMOB_ANDROID;
alter index index_name rebuild tablespace tablespace_name;--如果有索引的话必须重建索引
表空间尽量让free百分比保持在10%以上,如果低于10%就增加datafile或者resize datafile,一般数据文件不要超过2G
查找使用CPU多的用户session
select a.sid,
spid,
status,
substr(a.program, 1, 40) prog,
a.terminal,
osuser,
value / 60 / 100 value
from v$session a, v$process b, v$sesstat c
where c.statistic# = 12
and c.sid = a.sid
and a.paddr = b.addr
order by value desc;
Oracle数据库查询效率低的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 > 1 --1表示执行次数超过一次
and buffer_gets > 0
and (buffer_gets - disk_reads) / buffer_gets < 0.8 -- disk_reads是读硬盘的数量
order by 4 desc;
检查执行时间7月1日以后超过30秒的语句
select *
from v$session_longops s
where s.start_time > to_date('2017-07-01','yyyy-mm-dd')
and s.LAST_UPDATE_TIME - s.START_TIME > 30/1440/60
order by start_time;
检查目前打开的游标情况
select sql_text, count(1) from v$open_cursor where user_name = 'X' group by sql_text order by count(1) desc
检查指定时间的语句情况
select * from v$sql s where first_load_time < '2017-07-01/00:00:00' order by s.EXECUTIONS desc;
监控当前数据库谁在运行什么SQL语句
select osuser, username, sql_text from v$session a, v$sqltext b where a.sql_address = b.address order by address, piece;
等待最多的sql
select a.program,
a.session_id,
a.user_id,
d.username,
s.sql_text,
sum(a.wait_time + a.time_waited) total_wait_time
from v$active_session_history a, v$sqlarea s, dba_users d
where a.sample_time between sysdate - 30 / 2880 and sysdate
and a.sql_id = s.sql_id
and a.user_id = d.user_id
group by a.program, a.session_id, a.user_id, s.sql_text, d.username;
查看消耗资源最多的sql
select hash_value, executions, buffer_gets, disk_reads, parse_calls
from v$sqlarea
where buffer_gets > 10000000
or disk_reads > 1000000
order by buffer_gets + 100 * disk_reads desc;
最占用资源的查询
select b.username username,
a.disk_reads reads,
a.executions exec,
a.disk_reads / 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.disk_reads > 100000
order by a.disk_reads desc;
查看某条sql语句的资源消耗
select hash_value, buffer_gets, disk_reads, executions, parse_calls
from v$sqlarea
where hash_value = 228801498
and address = hextoraw('cbd8e4b0');
查询会话执行的实际SQL
select a.sid, a.username, s.sql_text
from v$session a, v$sqltext s
where a.sql_address = s.address
and a.sql_hash_value = s.hash_value
and a.status = 'ACTIVE'
order by a.username, a.sid, s.piece;
占用最多内存的sql语句
select b.username username,
a.buffer_gets gets,
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
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;
Oracle数据库查询当前连接会话数
select s.value, s.sid, a.username
from v$sesstat s, v$statname n, v$session a
where n.statistic# = s.statistic#
and name = 'session pga memory'
and s.sid = a.sid
order by s.value;
SELECT
s.sid,
s.username,
sum(a.wait_time + a.time_waited) total_wait_time
FROM
v$active_session_history a,
v$session s
WHERE
a.sample_time BETWEEN sysdate - 30 / 2880
AND sysdate
GROUP BY
s.sid,
s.username
ORDER BY
total_wait_time DESC;
具有最高等待的对象
select o.owner,
o.object_name,
o.object_type,
a.event,
sum(a.wait_time + a.time_waited) total_wait_time
from v$active_session_history a, dba_objects o
where a.sample_time between sysdate - 30 / 2880 and sysdate
and a.current_obj# = o.object_id
group by o.owner, o.object_name, o.object_type, a.event
order by total_wait_time desc;
select a.session_id,
s.osuser,
s.machine,
s.program,
o.owner,
o.object_name,
o.object_type,
a.event,
sum(a.wait_time + a.time_waited) total_wait_time
from v$active_session_history a, dba_objects o, v$session s
where a.sample_time between sysdate - 30 / 2880 and sysdate
and a.current_obj# = o.object_id
and a.session_id = s.sid
group by o.owner,
o.object_name,
o.object_type,
a.event,
a.session_id,
s.program,
s.machine,
s.osuser
order by total_wait_time desc;
Oracle数据库查看各用户资源占用的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 #;
oracle锁表查询,资源占用,连接会话,低效SQL等性能检查的更多相关文章
- Oracle锁表查询和解锁方法
数据库操作语句的分类 DDL:数据库模式定义语言,关键字:create DML:数据操纵语言,关键字:Insert.delete.update DCL:数据库控制语言 ,关键字:grant.remov ...
- oracle锁表查询
ORACLE EBS操作某一个FORM界面,或者后台数据库操作某一个表时发现一直出于"假死"状态,可能是该表被某一用户锁定,导致其他用户无法继续操作 复制代码代码如下: --锁表查 ...
- Oracle锁表查询与解锁
锁表查询和解锁 --查询SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv ...
- ORACLE锁表查询及解锁方法
--查看锁表情况 select distinct a.sid, to_char(a.logon_time, 'YYYY-MM-DD HH24:mi:ss') loginTime, a.serial#, ...
- Oracle锁表查询以及解锁
一.查看锁表进程SQL语句 select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo ...
- oracle 锁表查询及解决、表字段查询
在进行批量对DML操作时程序竟然中断了,不再往下执行.查询一下某张表被锁住了,因此不再往下执行了 如果怀疑表被锁了,或者事务未被正常关闭,在Oracle数据库中我们可以通过以下语句进行查询获取相关信息 ...
- oracle 锁表查询与解锁
查询锁住的表 SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,s.terminal, ...
- oracle锁表问题解决方法
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp52 Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程 ...
- 查询Oracle锁表和解决方法
Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作,那么这些操作是怎么实现的呢?本文我们主要就介绍一下这部分内容.(1)锁表查询的代码有以下的形式:select count( ...
随机推荐
- 05 方法与数组笔记【JAVA】
---恢复内容开始--- 1:方法(掌握) (1)方法:就是完成特定功能的代码块. 注意:在很多语言里面有函数的定义,而在Java中,函数被称为方法. (2)格式: 修饰符 返回值类型 方法名(参数类 ...
- alpha冲刺随笔(一)
项目Alpha冲刺(团队) Alpha冲刺第一天 姓名 学号 博客链接 何守成 031602408 http://www.cnblogs.com/heshoucheng/ 黄锦峰 031602411 ...
- 如何区别英语前缀pri,pro,per,pre?
pri- 前缀pri-来源于拉丁语的这几个形容词“prim.us”, “prim.a”, “prim.um”,表示“第一的”的意思,和“pri.or”, “pri.or”, “pri.us”,是“优先 ...
- msyql: navicat 连接时msyql遇到的问题
1.使用 mysql的用户,密码连接 服务器上的MySQL时,连接不上,报 100xx的错误. 1)原因是,MySQL默认情况下,只允许本地连接[127.0.0.1,或localhost]来连接mys ...
- Spring之AOP实现原理
- java 23种设计模式 深入浅出
以下内容只作为对自己对知识进行总结,如有引用他人文章会在文段末尾表明出处: Java的23种设计模式 23种设计模式总共可以分为三大类,进行不定期更新总结,将逐步展开介绍自己对设计模式的理解,多多指教 ...
- Enum 枚举值 (一) 获取描述信息
封装了方法: public static class EnumOperate { public class BaseDescriptionAttribute : DescriptionAttribut ...
- 以 BZOJ 2002 为例学习有根树LCT(Link-Cut Tree)
以BZOJ 2002 弹飞绵羊为例学习有根树LCT(Link-Cut Tree) 注:本文非常简单,只涉及有根树LCT,对于无根树,LCT还有几个本文没有提到的操作,以后慢慢更新 =v= 知识储备 [ ...
- Problem A: Dreamweaver 解题报告
人生首道非传统题给了交互... 考试的时候花了半小时搞清楚了这东西是啥,然后打了10分的暴力...但并没有拿到分. 而且一直不会本地测试... 捣鼓捣鼓了好久,问了人才知道.. 我本地没装g++,下发 ...
- 关于程序设计中INF和MOD值的设定
在取模操作中,我们常把MOD设置为1000000007 模一个大数和模一个质数可以减少冲突 而1e9+7又有一个很好的特点,就是相加不会爆int,相乘不会爆long long 在设置无穷大值时中我们常 ...