oracle常用运维sql语句
1.查询dblink语句
col owner for a20
col db_link for a30
col username for a20
col host for a30
set linesize 120
set pages 60
select * from dba_db_links order by owner;
2.查询数据库job语句
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
col owner for a20
col job_name for a30
col LAST_START_DATE for a20
col NEXT_RUN_DATE for a20
col job_action for a40
col what for a40
col status for a10
set linesize 200
set pages 100
select * from (with a as
(select log_Date, job_name, status
from ALL_SCHEDULER_JOB_LOG l
where owner not in ('SYS','SYSTEM','SYSMAN')),
b as
(select job_name, max(log_date) m_date
from ALL_SCHEDULER_JOB_LOG l
where owner not in ('SYS','SYSTEM','SYSMAN')
group by job_name),
c as
(select j.owner,
j.job_name,
j.last_start_date,
j.next_run_date,
j.JOB_ACTION
from all_scheduler_jobs j
where j.owner not in ('SYS','SYSTEM','SYSMAN'))
select c.owner,
a.job_name,
to_char(c.LAST_START_DATE, 'yyyy-mm-dd hh24:mi:ss') LAST_START_DATE,
to_char(c.NEXT_RUN_DATE, 'yyyy-mm-dd hh24:mi:ss') NEXT_RUN_DATE,
c.job_action,
a.status,
sysdate "search_date"
from a, b, c
where a.job_name = b.job_name
and a.job_name = c.job_name
and a.log_date = b.m_date)
union all
select schema_user,
to_char(job) "job_name",
to_char(last_date, 'yyyy-mm-dd hh24:mi:ss') "LAST_DATE",
to_char(next_date, 'yyyy-mm-dd hh24:mi:ss') "NEXT_DATE",
what,
case
when failures = 0 then
'SUCCEEDED'
else
'FAILED'
end case,
sysdate
from dba_jobs
where schema_user not in ('SYS','SYSTEM','SYSMAN') and broken = 'N';
3.查询表空间使用率和数据文件碎片
普通表空间:
col total_mb for 999999
col free_mb for 99999
col free_rate for a15
col used_rate for a15
select d.tablespace_name,
d.mb total_mb,
f.mb free_mb,
round((f.mb / d.mb), 4) * 100 || '%' free_rate,
round((d.mb - f.mb) / d.mb, 4) * 100 || '%' used_rate
from (select tablespace_name, bytes / 1024 / 1024 mb from dba_data_files) d,
(select tablespace_name, sum(bytes) / 1024 / 1024 mb
from dba_free_space
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name(+)
order by (d.mb - f.mb) / d.mb desc;
临时表空间:
SELECT A.tablespace_name tablespace,
D.mb_total,
SUM(A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total - SUM(A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment@ncslave.com A,
(SELECT B.name, C.block_size, SUM(C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace@ncslave.com B, v$tempfile@ncslave.com C
WHERE B.ts# = C.ts#
GROUP BY B.name, C.block_size) D
WHERE A.tablespace_name = D.name GROUP by A.tablespace_name, D.mb_total;
数据文件碎片:
select file_name,
ceil((nvl(hwm, 1) * 8192) / 1024 / 1024 / 1024) smallest,
ceil(blocks * 8192 / 1024 / 1024 / 1024) currsize,
ceil(blocks * 8192 / 1024 / 1024 / 1024) -
ceil((nvl(hwm, 1) * 8192) / 1024 / 1024 / 1024) savings
from dba_data_files a,
(select file_id, max(block_id + blocks - 1) hwm
from dba_extents
group by file_id) b
where a.file_id = b.file_id(+);
4.查询数据库死锁
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
col oracle_username for a15
col os_user_name for a15
col object_name for a30
col machine for a20
set linesize 150
set pages 100
SELECT l.session_id sid, s.serial#,l.oracle_username,l.os_user_name,s.machine,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 and s.status<>'ACTIVE' ORDER BY sid, s.serial#;
杀掉僵死会话:
alter system kill session 'sid,serial#' immediate;
5.闪回查询
SELECT * FROM
(SELECT * FROM comp_rs_ins_comp as of timestamp (to_date('2014-12-2 15:50:00','yyyy-mm-dd hh24:mi:ss')) )
WHERE comp_rs_ins_id in ('5030933252');
6.查询asm磁盘组空间使用率
set feedback off
set linesize 120
col grp_name for a10
col grp_num for a10
col used_rate for a10
select 'grp'||group_number grp_num,name grp_name,type,round(total_mb/1024,2) total_gb,round(free_mb/1024,2) free_gb,round(REQUIRED_MIRROR_FREE_MB/1024,2) req_mir_free_gb,round(USABLE_FILE_MB/1024,2) usable_gb,round((total_mb-free_mb)/total_mb*100,2)||'%' used_rate from v$asm_diskgroup_stat;
7.查询DBA角色包含哪些权限
col grantee for a10
col privilege for a40
set pagesize 100
select * from dba_sys_privs where grantee='DBA';
8.查询隐含参数
select x.ksppinm name,
y.ksppstvl value,
y.ksppstdf isdefault,
decode(bitand(y.ksppstvf, 7),
1,
'MODIFIED',
4,
'SYSTEM_MOD',
'FALSE') ismod,
decode(bitand(y.ksppstvf, 2), 2, 'TRUE', 'FALSE') isadj
from sys.x$ksppi x, sys.x$ksppcv y
where x.inst_id = userenv('Instance')
and y.inst_id = userenv('Instance')
and x.indx = y.indx
and x.ksppinm like '%_optimizer_cbqt_no_size_restriction%'
order by translate(x.ksppinm, ' _', ' ');
9.查询latch情况
col name for a30
col gets for 9999999999999999
col misses for 9999999999999999
col immediate_gets for 999999999999999
select * from (select name,gets,misses,immediate_gets,immediate_misses,sleeps from v$latch order by misses desc) where rownum<10;
10.查询ash
select sql_id,event,count(*) from v$active_session_history where sql_id is not null and event is not null and sample_time between to_date('20161125150000','yyyy-mm-dd hh24:mi:ss') and to_date('20161125160000','yyyy-mm-dd hh24:mi:ss') group by sql_id,event order by count(*) desc;
11.查询大事务以及对应的sql
col xid for a20
col schemaname for a20
col sql_text for a40
set linesize 150
set pagesize 100
select s.sid,s.serial#,s.status,t.start_time, t.xidusn||'.'||t.xidslot||'.'||t.xidsqn xid,
s.username,decode(s.sql_id,null,s.prev_sql_id,s.sql_id) sqlid
from v$transaction t, v$session s
where s.saddr = t.ses_addr
order by t.start_time;
select s.sid,s.serial#,s.status,t.start_time, t.xidusn||'.'||t.xidslot||'.'||t.xidsqn xid,
s.username,decode(s.sql_id,null,s.prev_sql_id,s.sql_id) sqlid,l.sql_text
from v$transaction t, v$session s,v$sql l
where s.saddr = t.ses_addr and l.sql_id=s.sql_id
order by t.start_time;
12.查询pga和uga使用量
select a.name,b.value from v$statname a,v$sesstat b where a.statistic#=b.statistic# and b.sid=(select sid from v$mystat where rownum=1) and (a.name like '%ga %' or a.name like '%direct temp%')
union all
select 'total: '||a.name,sum(b.value) from v$statname a,v$sesstat b,v$session c where a.statistic#=b.statistic# and (a.name like '%ga %' or a.name like '%direct temp%') and b.sid=c.sid and c.username is not null group by 'total: '||a.name;
oracle常用运维sql语句的更多相关文章
- Oracle 常用运维命令整理
点击上方"开源Linux",选择"设为星标" 回复"学习"获取独家整理的学习资料! 一.oracle建库与删库命令 (1)oracle11g ...
- Oracle 常用性能监控SQL语句
1. --查看表锁 SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; 2. --监控事例的等待 SELECT EVEN ...
- postgres常用运维sql
1.查看数据库大小 select pg_database_size('log_analysis'); postgres=# select pg_database_size('postExpress') ...
- SQLServer常用运维SQL整理
今天线上SQLServer数据库的CPU被打爆了,紧急情况下,分析了数据库阻塞.连接分布.最耗CPU的TOP10 SQL.查询SQL并行度配置.查询SQL 重编译的原因等等 整理了一些常用的SQL 1 ...
- SQLServer常用运维SQL整理(转)
转载地址:https://www.cnblogs.com/tianqing/p/11152799.html 今天线上SQLServer数据库的CPU被打爆了,紧急情况下,分析了数据库阻塞.连接分布.最 ...
- sqlserver常用运维sql
1. sqlserver 检测sql SELECT top 10 (total_elapsed_time / execution_count)/1000 N'平均时间ms' ,total_elapse ...
- Oracle常用函数(SQL语句)
使用sql函数,您可以在一个select语句的查询当中,直接计算数据库资料的平均值.总数.最小值.最大值.总和.标准差.变异数等统计.使用recordset对象时,也可使用这些sql函数. sql函数 ...
- Oracle 常用修改字段SQL语句
1. 更新字段名称 alter table table_name rename column column_old to column_new; 2. 添加字段 ); 3. 删除字段 alter ta ...
- Oracle种常用性能监控SQL语句
--Oracle常用性能监控SQL语句 --1 SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; --2 监控事例的等待 SELECT E ...
随机推荐
- 1101 Quick Sort(25 分
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- LeetCode 088 Merge Sorted Array 合并两个有序数组
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You ...
- Spark Mllib里的如何对单个数据集用斯皮尔曼计算相关系数
不多说,直接上干货! import org.apache.spark.mllib.stat.Statistics 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mlli ...
- 操作手册_MyEclipse
前言 假 如 你 的 人 生 有 理 想,那 么 就 一 定 要 去 追,不 管 你 现 在 的 理 想 在 别 人 看 来是 多 么 的 可 笑 , 你 也 不 用 在 乎 , 人 生 蹉 跎 几 ...
- Python 面向对象程序设计
类的设计 方法优先的原则, 在__init__方法中创建出需要的属性, 对于基类来说, 只进行默认值得初始化, 0, None等, 对于真正需要使用的子类, __init__方法则是进行我们需要的初始 ...
- Ajax跨域设置Access-Control-Allow-Origin
传统的跨域请求没有好的解决方案,无非就是jsonp和iframe,随着跨域请求的应用越来越多,W3C提供了跨域请求的标准方案(Cross-Origin Resource Sharing).IE8.Fi ...
- chroot 的应用
http://www.williamlong.info/archives/3864.html http://my.oschina.net/u/1590519/blog/342576
- node安装启动服务
一.下载安装包: node下载地址:https://nodejs.org/en/download/,根据自己电脑的配置下载相应的windows64位安装包,下载完成后,进行安装.下面我用的8.9.0版 ...
- 捷宇高拍仪XY530 网页集成总结
应甲方要求,需要把高拍仪集成到B/S系统中来,在集成过程中遇到的几点问题做为总结,以备查找. 1.甲方送来的高拍仪是淘宝上买来的,型号是XY530,功能非常简单,成像效果也很一般.如果没有其它要求,可 ...
- nvm安装nodejs(安装在非系统盘内)
在使用nodejs时有时需要不同的版本之间进行切换,所以就用到了版本管理工具nvm,在windows系统下用的是nvm-windows,这里选择的是nvm-noinstall.zip免安装版本(需要配 ...