设为首页收藏本站

80后

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 8930|回复: 0

oracle常用运维sql语句

[复制链接]

16

主题

23

帖子

66

积分

注册会员

Rank: 2

积分
66
发表于 2017-7-25 13:37:48 | 显示全部楼层 |阅读模式
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;


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|www.333cm.com ( 京ICP备16037542号  

GMT+8, 2020-8-5 01:51 , Processed in 0.328521 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表