select count(*) from v$session;
SELECT substr(v$lock.sid,1,4) "SID",
substr(username,1,12) "UserName",osuser,machine,
substr(object_name,1,25) "ObjectName",
v$lock.type "LockType",
decode(rtrim(substr(lmode,1,4)),
'2','Row-S (SS)','3','Row-X (SX)',
'4','Share', '5','S/Row-X (SSX)',
'6','Exclusive', 'Other' ) "LockMode",
substr(v$session.program,1,25) "ProgramName"
FROM V$LOCK,SYS.DBA_OBJECTS,V$SESSION
WHERE (OBJECT_ID = v$lock.id1
AND v$lock.sid = v$session.sid
AND username IS NOT NULL
AND username NOT IN ('SYS','SYSTEM')
AND SERIAL# != 1);
语句 execute DBMS_UTILITY.ANALYZE_DATABASE('COMPUTE',10000,NULL,'');
select table_name,num_rows,blocks,empty_blocks,avg_space,chain_cnt,avg_row_len,last_analyzed from all_tables where owner='RMS'
分析单表 analyze table rms.user_port compute statistics
select index_name,blevel,leaf_blocks,distinct_keys,avg_leaf_blocks_per_key,avg_data_blocks_per_key,clustering_factor,last_analyzed from all_indexes where owner='RMS';
select 'analyze table rms.'||segment_name||' compute statistics ;'segment_name,sum(bytes)/1024/1024 MB from user_segments,all_tables
where all_tables.owner='RMS' and all_tables.table_name= segment_name GROUP BY segment_name
语句 select table_name,chain_cnt from user_tables order by chain_cnt desc
select table_name,chain_cnt from all_tables where owner='RMS' order by chain_cnt desc
语句 "select 1-(phy.value/(cur.value+con.value)) from v$sysstat cur,v$sysstat con,v$sysstat phy
where cur.name='db block gets' and con.name='consistent gets'
and phy.name='physical reads'"
db block gets 4709479237
consistent gets 22146942
physical reads 8931785
命中率 0.998112322 1-physical reads/(db block gets+consistent gets)
建议 达到0.90或以上认为是好的
" column c0 heading 'Owner' format a15
column c1 heading 'Object|Name' format a30
column c2 heading 'Number|of|Buffers' format 999,999
column c3 heading 'Percentage|ofData|Buffer' format 999,999,999
select
owner c0,
object_name c1,
count(1) c2,
(count(1)/(select count(*) from v$bh)) *100 c3
from
dba_objects o,
v$bh bh
where
o.object_id = bh.objd
and
o.owner not in ('SYS','SYSTEM')
group by
owner,
object_name
order by
count(1) desc
;"
语句 SELECT SUM(pins-reloads)/SUM(pins) from v$librarycache
建议 低于0.99需要试着改善它,可以增加共享池的规模来改善它,如果有很多可用空间那就得从改善我们的程序
查看当前未使用的共享池 "select to_number(v$parameter.value) value, v$sgastat.BYTES,
(v$sgastat.bytes/v$parameter.value)*100 ""percent free""
from v$sgastat, v$parameter
where v$sgastat.name= 'free memory'
and v$parameter.name = 'shared_pool_size'
and v$sgastat.pool='shared pool'"
ALTER SYSTEM FLUSH SHARED_POOL;
语句 select sum(gets-getmisses-usage-fixed)/sum(gets) from v$rowcache
建议 达到0.85或以上认为是可以接受的
语句 select sum(gets),sum(waits),sum(waits)/sum(gets) from v$rollstat
建议 大于1%需要处理,可以通过更多回滚段来降低争用
查看回滚段的使用情况,哪个用户正在使用回滚段的资源,如果有用户最好更换时间(特别是生产环境)。
"
select s.username, u.name from v$transaction t,v$rollstat r,
v$rollname u,v$session s where s.taddr=t.addr and
t.xidusn=r.usn and r.usn=u.usn order by s.username;
"
"SELECT a.name , b.xacts ""活动事务个数"", b.writes ""写入的字节数"", b.extents as ""区个数""
FROM v$rollname a, v$rollstat b
WHERE a.usn=b.usn;"
语句 select name,shrinks from v$rollstat,v$rollname where V$rollstat.usn=v$rollname.usn
select name,value from v$sysstat where name ='redo buffer allocation retries'
select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||CONSTRAINT_NAME||';' from all_constraints where owner='RMS' AND CONSTRAINT_TYPE<>'P'
发现表链接行
select table_name,chain_cnt from user_tables order by chain_cnt desc;
"SELECT UPPER(F.TABLESPACE_NAME) ""表空间名"",
D.TOT_GROOTTE_MB ""表空间大小(M)"",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES ""已使用空间(M)"",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
2),
'990.99') ""使用比"",
F.TOTAL_BYTES ""空闲空间(M)"",
F.MAX_BYTES ""最大块(M)""
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC"
alter tablespace trmsdata coalesce;
"select segment_name,sum(bytes)/1024/1024 MB from user_segments,all_tables
where all_tables.owner='RMS' and all_tables.table_name= segment_name GROUP BY segment_name"
"select segment_name,sum(bytes)/1024/1024 MB from user_segments, all_indexes
where all_indexes.owner='RMS' and all_indexes.index_name= segment_name GROUP BY segment_name
"
swapinfo -atm HP UNIX内核参数 bufpages 61992 缓冲页 dbc_max_pct 10 动态缓存占内存最大百分比 dbc_min_pct 10 动态缓存占内存最小百分比
select c.sid,c.OSUSER,c.MACHINE,name,value from v$statname n,v$sesstat s,v$session c
"SELECT ses.sid
, DECODE(ses.action,NULL,'online','batch') ""User""
, MAX(DECODE(sta.statistic#,9,sta.value,0))
/greatest(3600*24*(sysdate-ses.logon_time),1) ""Log IO/s""
, MAX(DECODE(sta.statistic#,40,sta.value,0))
/greatest(3600*24*(sysdate-ses.logon_time),1) ""Phy IO/s""
, 60*24*(sysdate-ses.logon_time) ""Minutes""
FROM V$SESSION ses
, V$SESSTAT sta
WHERE ses.status = 'ACTIVE'
AND sta.sid = ses.sid
AND sta.statistic# IN (9,40)
GROUP BY ses.sid, ses.action, ses.logon_time
ORDER BY
SUM( DECODE(sta.statistic#,40,100*sta.value,sta.value) )
/ greatest(3600*24*(sysdate-ses.logon_time),1) DESC;"
"SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS,
COMMAND_TYPE,DISK_READS,sql_text.address FROM v$sqlarea
order BY disk_reads DESC )where ROWNUM<10 ;"
"select lpad(' ', 2*(level-1))||operation ""Operation"",
options ""Options"",
decode(to_char(id), '0', 'Cost='||nvl(to_char(position), 'n/a'), object_name) ""Object Name"",
substr(optimizer, 1, 6) ""Optimizer""
from v$sql_plan a
start with address = 'C0000000FCCDEDA0'
and id = 0
connect by prior id = a.parent_id
and prior a.address = a.address
and prior a.hash_value = a.hash_value;"
select * from V$PROCESS spid为系统进程ID
"SELECT a.username,a.machine,a.program,a.sid,a.serial#,
a.status,c.piece,c.sql_text from v$session a,v$process b,
v$sqltext c WHERE b.spid='ORCL' AND b.addr=a.paddr AND
a.sql_address=c.address(+)order BY c.piece"
"SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,
se.terminal,se.program,se.MODULE,se.sql_address,st.event,st.
p1text,si.physical_reads,
si.block_changes FROM v$session se,v$session_wait st,
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st.
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>8 AND st.
wait_time=0 AND st.event NOT LIKE '%SQL%' ORDER BY physical_reads DESC"
select sql_text,piece
from v$sqltext
where (address,hash_value) in ( select decode(sql_hash_value,0,prev_sql_addr,sql_address) ,
decode(sql_hash_value,0,prev_hash_value,sql_hash_value)
from v$session
where sid =&sid)
order by piece
alter system set events = 'immediate trace name flush_cache';
导记录
insert into tablename
select * from username.tablename