暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片
一线运维 DBA 五年经验常用 SQL 大全(三).pdf
1052
35页
67次
2022-11-30
5墨值下载
一线运维 DBA 五年经验常 SQL 大全(三)
作者:JiekeXu
原文链接:https://mp.weixin.qq.com/s/YRTqgr9Nk-yx4BKTH9NVxQ
来源 | JiekeXu DBA 之路(ID: JiekeXu_IT)
转载请联系授权 | (微信 ID:JiekeXu_DBA)
SQL 大全一 https://www.modb.pro/doc/22598
SQL 大全二 https://www.modb.pro/db/45337
Oracle DBA 日常维护 SQL 脚本大全(收藏版)
https://www.modb.pro/db/44364
本文 SQL 均是在运维工作中总结整理而成的,对于运维 DBA 来说可提高很大工
作效率,当然如果你全部能够背下来那就牛逼了,如果不能,建议收藏下来慢慢
看,每条 SQL 的使用频率都很高,肯定能够帮助到你。
1、查询表的主外键关联
select a.CONSTRAINT_NAME,b.TABLE_NAME 引用表,b.COLUMN_NAME 引用
,c.TABLE_NAME 被引用表,c.COLUMN_NAME 被引用列 from
user_constraints a,
user_cons_columns b,
user_cons_columns c
where a.CONSTRAINT_NAME=b.CONSTRAINT_NAME
and a.R_CONSTRAINT_NAME=c.CONSTRAINT_NAME
and a.CONSTRAINT_TYPE='R'
and c.TABLE_NAME like 'T_BILL%';
2、查询一段时间内 sql 总等待时间
select event,a.sql_id,sql_text,sum(time_waited)
from v$active_session_history a,v$sql s
where a.SQL_ID=s.SQL_ID
and a.SAMPLE_TIME>to_date('20190124 12:00:00','yyyymmdd hh24:mi:ss')
and a.SAMPLE_TIME<to_date('20190124 12:30:00','yyyymmdd hh24:mi:ss')
group by event,a.sql_id,sql_text
order by 4 desc;
2、查询一段时间内 sql 单次执行时
select sql_id,s.SQL_TEXT,s.ELAPSED_TIME/s.EXECUTIONS
from v$sqlstats s
where s.LAST_ACTIVE_TIME>to_date('20190124 12:00:00','yyyymmdd
hh24:mi:ss')
and s.LAST_ACTIVE_TIME>to_date('20190124 12:00:00','yyyymmdd
hh24:mi:ss')
and s.EXECUTIONS>0
order by 3 desc;
3、查询历史会话阻塞等待情况
select
a.SAMPLE_TIME,a.SESSION_ID,a.SQL_ID,a.WAIT_TIME,a.BLOCKING_SESSION
from v$active_session_history a
where a.MACHINE='41cb3c835bb1'
and a.SAMPLE_TIME>to_date('20190125 15:50:00','yyyymmdd hh24:mi:ss')
and a.SAMPLE_TIME<to_date('20190125 16:10:00','yyyymmdd hh24:mi:ss')
group by event
order by 4 desc;
4、查询 undo 表空间使用较多的
select a.segment_name, count(*)
from dba_undo_extents a,
(SELECT n.name name
FROM V$session s, V$transaction t, V$rollstat r, v$rollname n
WHERE s.saddr = t.ses_addr
AND t.xidusn = r.usn
AND r.usn = n.usn) b
where a.segment_name = b.name
and a.status = 'ACTIVE'
group by a.segment_name
order by count(*);
5、查询导致 undo 使用量和使用率高的会话
select b.sid,
of 35
5墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜