oracle锁表查询,资源占用,连接会话,低效SQL等性能检查

时间:2022-11-05 16:37:10

查询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等性能检查的更多相关文章

  1. Oracle锁表查询和解锁方法

    数据库操作语句的分类 DDL:数据库模式定义语言,关键字:create DML:数据操纵语言,关键字:Insert.delete.update DCL:数据库控制语言 ,关键字:grant.remov ...

  2. oracle锁表查询

    ORACLE EBS操作某一个FORM界面,或者后台数据库操作某一个表时发现一直出于"假死"状态,可能是该表被某一用户锁定,导致其他用户无法继续操作 复制代码代码如下: --锁表查 ...

  3. Oracle锁表查询与解锁

    锁表查询和解锁 --查询SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv ...

  4. ORACLE锁表查询及解锁方法

    --查看锁表情况 select distinct a.sid, to_char(a.logon_time, 'YYYY-MM-DD HH24:mi:ss') loginTime, a.serial#, ...

  5. Oracle锁表查询以及解锁

    一.查看锁表进程SQL语句 select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo ...

  6. oracle 锁表查询及解决、表字段查询

    在进行批量对DML操作时程序竟然中断了,不再往下执行.查询一下某张表被锁住了,因此不再往下执行了 如果怀疑表被锁了,或者事务未被正常关闭,在Oracle数据库中我们可以通过以下语句进行查询获取相关信息 ...

  7. oracle 锁表查询与解锁

    查询锁住的表 SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,s.terminal, ...

  8. oracle锁表问题解决方法

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp52 Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程 ...

  9. 查询Oracle锁表和解决方法

    Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作,那么这些操作是怎么实现的呢?本文我们主要就介绍一下这部分内容.(1)锁表查询的代码有以下的形式:select count( ...

随机推荐

  1. Maven学习笔记

    1.Maven安装 Maven和ant同为apache出版的构建工具,与gradle是一类东西,与C语言中的make是同一类产品.从apache官网上下载maven的zip安装包,解压即可使用,需要把 ...

  2. Macbook 的 print screen 是什么

  3. linux环境中使用转义字符使命令行字符颜色高亮

    而通过转义序列设置终端显示属性的格式为: \033[Param {;Param;...}m 其中转义序列以 \033[ 为开头,m 为设置属性结束,中间部分的 Param 为属性值,{} 表示可以设置 ...

  4. Fragment的startActivityForResult和Activity的startActivityForResult的区别

    2016-08-30 18:22:33 前提:我们的APP要兼容Api level 11以前的,所以必须用FragmentActivity 1.对于Fragment的,我们很多时候都会在Activit ...

  5. sql server和mysql中分别实现分页功能

    MySQL 在MySQL中,可以用 Limit 来查询第 m 列到第 n 列的记录, 例如: select * from tablename limit m, n sql="select * ...

  6. 【BZOJ 4269】再见Xor

    zky学长提供的线性基求法: for(int i=1;i<=n;i++) for(int j=64;j>=1;j--) { if(a[i]>>(j-1)&1) { if ...

  7. hdu 1023 卡特兰数&plus;高精度

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU1565&plus;状态压缩dp

    简单的压缩状态 dp /* 状态压缩dp 同hdu2167 利用滚动数组!! */ #include<stdio.h> #include<string.h> #include& ...

  9. Flask 开发&vert; Flaskr 开发内容总结

    Flaskr 开发说明 官方文档 http://flask.pocoo.org/docs/0.12/tutorial/ 演示网站 http://flaskr.it592.com/ 涉及到的内容: 连接 ...

  10. apach ab 安装时的错误

    1.cmd进入bin下:执行httpd -k install 需要管理员 登陆安装 我们打开conf文件夹,找到httpd.conf,修改如下内容,让serverroot指向你的安装位置: Defin ...