<o:p></o:p>
SELECT event, total_waits, total_timeouts,time_waited, average_wait
FROM v$system_event
<o:p></o:p>
<o:p></o:p>
select sid, event, total_waits,average_wait
from v$session_event where sid=10;
<o:p></o:p>
SELECT sid, seq#, event, wait_time, state
FROM v$session_wait;
<o:p></o:p>
<o:p></o:p>
select * from v$sgastat;
<o:p></o:p>
<o:p></o:p>
select gethitratio
from v$librarycache
where namespace = 'SQL AREA';
select sql_text, users_executing,
executions, loads
from v$sqlarea;
<o:p></o:p>
select sum(pins) "Executions", sum(reloads) "Cache Misses",
sum(reloads)/sum(pins)
from v$librarycache;
<o:p></o:p>
select namespace,pins,reloads,invalidations
from v$librarycache;
<o:p></o:p>
<o:p></o:p>
select name, waits, gets, waits/gets "Ratio"
from v$rollstat a, v$rollname b
where a.usn = b.usn;
<o:p></o:p>
select df.tablespace_name name,df.file_name "file",f.phyrds pyr,
f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw
from v$filestat f, dba_data_files df
where f.file# = df.file_id
order by df.tablespace_name;
select substr(a.file#,1,2) "#", substr(a.name,1,30) "Name",
a.status, a.bytes, b.phyrds, b.phywrts
from v$datafile a, v$filestat b
where a.file# = b.file#;
<o:p></o:p>
select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name
from user_ind_columns, user_indexes
where user_ind_columns.index_name = user_indexes.index_name
and user_ind_columns.table_name = user_indexes.table_name
order by user_indexes.table_type, user_indexes.table_name,
user_indexes.index_name, column_position;
<o:p></o:p>
select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 "miss ratio",
(1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio"
from v$rowcache
where gets+getmisses <>0
group by parameter, gets, getmisses;
<o:p></o:p>
select sum(pins) "Total Pins", sum(reloads) "Total Reloads",
sum(reloads)/sum(pins) *100 libcache
from v$librarycache;
<o:p></o:p>
select sum(pinhits-reloads)/sum(pins) "hit radio",sum(reloads)/sum(pins) "reload percent"
from v$librarycache;
<o:p></o:p>
select count(name) num_instances ,type ,sum(source_size) source_size ,
sum(parsed_size) parsed_size ,sum(code_size) code_size ,sum(error_size) error_size,
sum(source_size) +sum(parsed_size) +sum(code_size) +sum(error_size) size_required
from dba_object_size
group by type order by 2;
<o:p></o:p>
select name, gets, misses, immediate_gets, immediate_misses,
Decode(gets,0,0,misses/gets*100) ratio1,
Decode(immediate_gets+immediate_misses,0,0,
immediate_misses/(immediate_gets+immediate_misses)*100) ratio2
FROM v$latch WHERE name IN ('redo allocation', 'redo copy');
<o:p></o:p>
SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');
<o:p></o:p>
select (sum(pins - reloads)) / sum(pins) "lib cache" from v$librarycache;
select (sum(gets - getmisses - usage - fixed)) / sum(gets) "row cache" from v$rowcache;
select sum(pins) "executions", sum(reloads) "cache misses while executing" from v$librarycache;
后者除以前者 , 此比率小于 1%, 接近 0% 为好
select sum(gets) "dictionary gets",sum(getmisses) "dictionary cache get misses"
from v$rowcache
<o:p></o:p>
select * from sys.props$ where name='NLS_CHARACTERSET';
<o:p></o:p>
select busy/(busy+idle) "shared servers busy" from v$dispatcher;
此值大于 0.5 时,参数需加大
select sum(wait)/sum(totalq) "dispatcher waits" from v$queue where type='dispatcher';
select count(*) from v$dispatcher;
select servers_highwater from v$mts;
<o:p></o:p>
servers_highwater 接近 mts_max_servers 时,参数需加大
<o:p></o:p>
select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name
having count(tablespace_name)>10;
<o:p></o:p>
alter tablespace name coalesce;
alter table name deallocate unused;
<o:p></o:p>
create or replace view ts_blocks_v as
select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space
union all
select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;
<o:p></o:p>
select * from ts_blocks_v;
<o:p></o:p>
select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space
group by tablespace_name;
<o:p></o:p>
查看碎片程度高的表
<o:p></o:p>
SELECT segment_name table_name , COUNT(*) extents
FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name
HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);
<o:p></o:p>
17. 表、索引的存储情况检查
<o:p></o:p>
select segment_name,sum(bytes),count(*) ext_quan from dba_extents where
tablespace_name='&tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name;
<o:p></o:p>
select segment_name,count(*) from dba_extents where segment_type='INDEX' and owner='&owner'
group by segment_name;
<o:p></o:p>
18 、找使用 CPU 多的用户 session
<o:p></o:p>
12 是 cpu used by this session
<o:p></o:p>
select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 value
from v$session a,v$process b,v$sesstat c
where c.statistic#=12 and c.sid=a.sid and a.paddr=b.addr order by value desc;
<o:p></o:p>
SQL> col tablespace format a20 -- 在显示中指明列的输出格式
SQL> select b.file_id -- 文件 ID,
b.tablespace_name -- 表空间 ,
b.file_name -- 物理文件名 ,
b.bytes -- 总字节数 ,
(b.bytes-sum(nvl(a.bytes,0))) -- 已使用 ,
sum(nvl(a.bytes,0)) -- 剩余 ,
sum(nvl(a.bytes,0))/(b.bytes)*100 -- 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space -- 表空间剩余空间状况
dba_data_files -- 数据文件空间占用情况
<o:p></o:p>
select segment_name,owner,tablespace_name,segment_id,file_id,status from dba_rollback_segs;
<o:p></o:p>
select tablespace_name,count(*),sum(blocks),sum(bytes)/1024/1024
from dba_data_files
group by tablespace_name;
<o:p></o:p>
select df.tablespace_name " 表空间名 ",totalspace " 总空间 M",freespace " 剩余空间 M",round((1-freespace/totalspace)*100,2) " 使用率 %"
from (select tablespace_name,round(sum(bytes)/1024/1024) totalspace
from dba_data_files
group by tablespace_name) df,
(select tablespace_name,round(sum(bytes)/1024/1024) freespace
from dba_free_space
group by tablespace_name) fs
where df.tablespace_name=fs.tablespace_name;
<o:p></o:p>
select t.name,d.name from v$tablespace t,v$datafile d where t.name='DATA_HOST_A' and t.ts#=d.ts#;alter tablespace DATA_HOST_A offline;
drop tablespace DATA_HOST_A including contents;
select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;
<o:p></o:p>
alter tablespace 表空间名 add datafile '/u1/oradata/userdata_002.ora' size 50m; --Unix
alter tablespace 表空间名 add datafile 'c:\oradata\userdata_002.ora' size 50m; --Windows NT
<o:p></o:p>
alter database datafile '/u1/oradata/userdata_001.ora' resize 50M; --Unix
alter database datafile 'c:\oradata\userdata_002.ora' resize 50M; --Windows NT
<o:p></o:p>
select substr(vses.username,1,12) "ORA_USER", substr(osuser,1,12) "OS_USER",
substR(sql_text,1,50) "SQL_STMT"
from
V$sqlarea vsql, V$session vses, V$sort_usage vsort
where
vsort.tablespace = 'TEMP' and vsort.sqladdr=vses.sql_address and vsql.address=vsort.sqladdr
<o:p></o:p>
select tablespace_name, extent_size, total_extents, used_extents, free_extents, max_used_size
from v$sort_segment;
<o:p></o:p>
select segment_name,exten from dba_extents -- 确定盘区的内容
desc dba_segments -- 确定段的内容
<o:p></o:p>
-- 返回了结果表明碎片的严重
select segment_name ,tablespace_name,extents,segment_type from dba_segments where extents>4
<o:p></o:p>
-- 空间碎片严重程度
select tablespace_name ,count(tablespace_name) from dba_free_space group by tablespace_name
having count(tablespace_name) >10
set transaction use rollback segment rollback_segment_name -- 指定回滚段
<o:p></o:p>
-- 光标的使用
declare @name char(30)
declare @homebase char(40)
declare @style char(20)
declare @arttist_id int
create artist_cursor cursor
for select * from dim_age
open artist_cursor
fetch artist_cursor into @arttist_id,@homebase,@style
while (@@sqlstatus=0)
begin
print @homebase
print @style
print @arttist_id
end
close artist_cursor
deallocate cursor artist_cursor
go
<o:p></o:p>
-- 数据导出导入 <o:p></o:p>
exp dss/dss@oralce query=\"where day_id > 12\" tables=(customer) file= d:\sample.dmp log=
rows=n
full=y tables=() owner= -- 三种导出方式
<o:p></o:p>
imp userid/pwd@oracle_sid fromuser =( dss,dwh) touser =(dss,dwh) dwh file=sample.dmp
<o:p></o:p>
-- 分区表的到导出 user1.table_name:px 分区 px<o:p></o:p>
exp user_id/pwd@oracle_sid tables=(user1.table_name:px) file=sample.dmp
<o:p></o:p>
1. 打开 ini.ora 文件
2. 修改文件内容
log_archive_start = true