度量快速开发平台-专业、快速的软件定制快开平台
标题: oracle常用运维sql语句 [打印本页]
作者: fteair 时间: 2020-5-26 17:53
标题: oracle常用运维sql语句
查询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;
作者: fteair 时间: 2020-5-26 17:54
查询数据库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';
作者: fteair 时间: 2020-5-26 17:55
查询表空间使用率和数据文件碎片
普通表空间:
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(+);
作者: fteair 时间: 2020-5-26 17:56
查询数据库死锁
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;
作者: caixuqad 时间: 2020-5-26 23:22
作者: caixuqad 时间: 2020-5-26 23:23
作者: 张兴康 时间: 2020-5-27 14:18
作者: fteair 时间: 2020-5-27 15:38
作者: fteair 时间: 2020-5-27 15:38
作者: fteair 时间: 2020-5-27 15:44
闪回查询
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');
作者: fteair 时间: 2020-5-27 15:44
查询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;
作者: fteair 时间: 2020-5-27 15:45
查询DBA角色包含哪些权限
col grantee for a10
col privilege for a40
set pagesize 100
select * from dba_sys_privs where grantee='DBA';
作者: fteair 时间: 2020-5-27 15:46
查询隐含参数
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, ' _', ' ');
作者: caixuqad 时间: 2020-5-27 18:02
作者: fteair 时间: 2020-5-28 14:08
查询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;
作者: fteair 时间: 2020-5-28 14:09
查询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;
作者: fteair 时间: 2020-5-28 14:10
查询大事务以及对应的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;
作者: fteair 时间: 2020-5-28 14:10
查询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;
作者: 张兴康 时间: 2020-5-28 17:34
作者: caixuqad 时间: 2020-5-28 18:15
作者: fteair 时间: 2020-5-29 14:56
作者: fteair 时间: 2020-5-29 14:58
作者: 张兴康 时间: 2020-5-30 14:50
作者: fteair 时间: 2020-5-30 15:16
作者: 张兴康 时间: 2020-6-3 16:25
作者: fteair 时间: 2020-6-4 09:08
作者: caixuqad 时间: 2020-6-4 18:13
作者: 张兴康 时间: 2020-6-11 17:59
作者: fteair 时间: 2020-6-12 14:23
作者: fteair 时间: 2020-6-12 14:23
作者: 张兴康 时间: 2020-6-13 15:02
作者: caixuqad 时间: 2020-6-13 17:59
作者: fteair 时间: 2020-6-17 09:08
作者: 张兴康 时间: 2020-6-17 14:48
大耳朵,大舌头,大嘴巴
作者: fteair 时间: 2020-6-18 08:58
作者: 张兴康 时间: 2020-6-18 14:07
啊呀,头上有个补疤,嘴巴还是歪的
作者: fteair 时间: 2020-6-18 14:10
作者: 张兴康 时间: 2020-6-18 14:14
你早上不是回了帖么,怎么还在呢
作者: fteair 时间: 2020-6-18 14:16
ZUOTIANDE
欢迎光临 度量快速开发平台-专业、快速的软件定制快开平台 (http://plat.delit.cn/) |
Powered by Discuz! X3.2 |