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语句的更多相关文章

  1. Oracle 常用运维命令整理

    点击上方"开源Linux",选择"设为星标" 回复"学习"获取独家整理的学习资料! 一.oracle建库与删库命令 (1)oracle11g ...

  2. Oracle 常用性能监控SQL语句

    1.  --查看表锁     SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; 2.  --监控事例的等待     SELECT EVEN ...

  3. postgres常用运维sql

    1.查看数据库大小 select pg_database_size('log_analysis'); postgres=# select pg_database_size('postExpress') ...

  4. SQLServer常用运维SQL整理

    今天线上SQLServer数据库的CPU被打爆了,紧急情况下,分析了数据库阻塞.连接分布.最耗CPU的TOP10 SQL.查询SQL并行度配置.查询SQL 重编译的原因等等 整理了一些常用的SQL 1 ...

  5. SQLServer常用运维SQL整理(转)

    转载地址:https://www.cnblogs.com/tianqing/p/11152799.html 今天线上SQLServer数据库的CPU被打爆了,紧急情况下,分析了数据库阻塞.连接分布.最 ...

  6. sqlserver常用运维sql

    1. sqlserver 检测sql SELECT top 10 (total_elapsed_time / execution_count)/1000 N'平均时间ms' ,total_elapse ...

  7. Oracle常用函数(SQL语句)

    使用sql函数,您可以在一个select语句的查询当中,直接计算数据库资料的平均值.总数.最小值.最大值.总和.标准差.变异数等统计.使用recordset对象时,也可使用这些sql函数. sql函数 ...

  8. Oracle 常用修改字段SQL语句

    1. 更新字段名称 alter table table_name rename column column_old to column_new; 2. 添加字段 ); 3. 删除字段 alter ta ...

  9. Oracle种常用性能监控SQL语句

    --Oracle常用性能监控SQL语句 --1 SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; --2 监控事例的等待 SELECT E ...

随机推荐

  1. FTP原理与配置

    FTP(file transfer protocol)文件传输协议(基于tcp协议).是用来传送文件的协议,使用FTP实现文件传输的同时,还可以保证数据传输的可靠性和高效性.通过学习我们需要掌握以下两 ...

  2. maven POM总结

    可继承的字段 version property 其他占坑: parent import scope   Dependency_Management中的scope是可以被继承的,http://maven ...

  3. aspnetcore的中间件

    Run会终止中间件继续传递 app.Run(new RequestDelegate(async context => { await Task.Run(() => { context.Re ...

  4. datagrid 里面的formatter方法

    A.{field:'station_staus',title:'工位状态',width:250,align:'center',formatter: function(value,row,index){ ...

  5. 5 - 参考函数-API

    5.1 鼠标管理 a). MouseClick 点击鼠标 MouseClick ( "button" [, x, y [, clicks = 1 [, speed = 10]]] ...

  6. SSRF总结

    ssrf漏洞,全称为服务端请求伪造漏洞,由于有的web应用需要实现从其它服务器上获取资源的功能,但是没有对url进行限制,导致可以构造非本意的url对内网或者其它服务器发起恶意请求.ssrf漏洞的危害 ...

  7. Java基础重点指南

    Java基础重点指南 每个人都有自己的学习方法,下面是我学完Java后总结的一些要点: 一:(了解)Java诞生于1995年,由Sun公司开发.它把源代码编译成“中间码”,然后通过“Java虚拟机”把 ...

  8. WPF根据数据项获取条目控件的方法-ItemContainerGenerator

    一.方法: ContainerFromIndex:返回 ItemCollection 中指定索引处的项的容器. ContainerFromItem:返回与制定的项对应的容器(ComboxItem等条目 ...

  9. 巧用前端神器,fakerjs生成json文件

    安装 cnpm install faker json-serve --save-dev 在目录下创建一个模板文件 示例 makeJson.js var faker = require('faker') ...

  10. wow.js+animate.css——有趣的页面滚动动画

    今天偶然间发现了一个使用特别简单的页面动画效果,还挺不错的,玩了一个上午,现在介绍一下这个滚动动画: 一.使用方法: 1.下载animate.css 2.下载wow.js 3.引用文件,像这样: &l ...