经常忘记,记录这里,以便备查:
PGA的内存命中:
SELECT name profile,cnt,decode( total, 0, 0, round( cnt * 100 / total)) percentage
FROM ( SELECT name, value cnt, ( SUM( value ) OVER()) total
FROM v$sysstat
WHERE name LIKE 'workarea exec%');
-- 数据缓冲区高速缓存
SELECT physical_reads, db_block_gets, consistent_gets, NAME,
100 * ( 1 - ( physical_reads / (consistent_gets + db_block_gets - physical_reads))) "Data Buffer Hit Ratio"
FROM v$buffer_pool_statistics;
-- 重做日至缓冲区
SELECT a.VALUE redo_entries, b.VALUE redo_buffer_allocation_retries,
ROUND ((1 - b.VALUE / a.VALUE) * 100, 4) log_buffer_ratio
FROM v$sysstat a, v$sysstat b
WHERE a.NAME = 'redo entries' AND b.NAME = 'redo buffer allocation retries';
-- 数据字典高速缓存
SELECT SUM (pinhits) / SUM (pins) * 100 "hit radio"
FROM v$librarycache;
-- 库高速缓存
SELECT TO_CHAR (ROUND ((1 - SUM (getmisses) / SUM (gets)) * 100, 1)) || '%' "Dictionary Cache Hit Ratio"
FROM v$rowcache;
-- 排序
SELECT a.VALUE disk_sort, b.VALUE memory_sort, ROUND ((1 - a.VALUE / (a.VALUE + b.VALUE)) * 100, 4) sort_ratio
FROM v$sysstat a, v$sysstat b
WHERE a.NAME = 'sorts (disk)' AND b.NAME = 'sorts (memory)';
--找出相关的sql根据系统pid
select se.username,se.machine,sq.cpu_time,sq.sql_text from
v$process p,v$session se,v$sqlarea sq
where p.addr=se.paddr and se.sql_hash_value=sq.hash_value and p.addr='&pid';
列出cpu_time top 10
select cpu_time,sql_text
from (select sql_text,cpu_time,
rank() over (order by cpu_time desc) exec_rank
from v$sql
)
where exec_rank <=10;
执行次数最多的top 10
select sql_text,executions
from (select sql_text,executions,
rank() over
(order by executions desc) exec_rank
from v$sql)
where exec_rank <=10;
今天看到个帖子,关于索引中是否包含ROWID,做个DUMP跟踪下看,以下为详细的跟踪记录:
SQL> create table test as select rownum a ,'c' c from dual connect by level<101;
Table created
SQL> create index u_test on test(a);
Index created
SQL> select extent_id,file_id,block_id from dba_extents where segment_name='U_TEST';
EXTENT_ID FILE_ID BLOCK_ID
---------- ---------- ----------
0 6 121
SQL> alter system dump datafile 6 block 121; --assm 自动段管理位图占3个块,跳3个块
System altered
SQL> alter system dump datafile 6 block 124;
System altered
以下部分跟踪记录:
row#0[8024] flag: ------, lock: 0, len=12
col 0; len 2; (2): c1 02 ----------------索引键值
col 1; len 6; (6): 01 80 00 74 00 00 -----------------------rowid
row#1[8012] flag: ------, lock: 0, len=12
col 0; len 2; (2): c1 03
col 1; len 6; (6): 01 80 00 74 00 01
row#2[8000] flag: ------, lock: 0, len=12
col 0; len 2; (2): c1 04
col 1; len 6; (6): 01 80 00 74 00 02
SQL> create unique index u_test on test(a);
Index created
SQL> select extent_id,file_id,block_id from dba_extents where segment_name='U_TEST';
EXTENT_ID FILE_ID BLOCK_ID
---------- ---------- ----------
0 6 121
SQL> alter system dump datafile 6 block 124;
以下部分跟踪记录:
row#0[8025] flag: ------, lock: 0, len=11, data:(6): 01 80 00 74 00 00
col 0; len 2; (2): c1 02
row#1[8014] flag: ------, lock: 0, len=11, data:(6): 01 80 00 74 00 01
col 0; len 2; (2): c1 03
row#2[8003] flag: ------, lock: 0, len=11, data:(6): 01 80 00 74 00 02
col 0; len 2; (2): c1 04
row#3[7992] flag: ------, lock: 0, len=11, data:(6): 01 80 00 74 00 03
如上所示:唯一索引不包含ROWID,普通索引包含rowid.
Oracle常用dump命令,记录一下备查。 一.Memory Dumps 1).Global Area ALTER SESSION SET EVENTS 'immediate trace name global_area level n'; 1 包含PGA 2).Library Cache ALTER SESSION SET EVENTS 'immediate trace name library_cache level n'; 1 library cache统计信息 3).Row Cache ALTER SESSION SET EVENTS 'immediate trace name row_cache level n'; 1 row cache统计信息 4).Buffers ALTER SESSION SET EVENTS 'immediate trace name buffers level n'; 1 buffer header 5).Buffer ALTER SESSION SET EVENTS 'immediate trace name buffer level n'; n为某个指定block的rdba,该命令可以转储某个block在buffer中的所有版本。 6).Heap ALTER SESSION SET EVENTS 'immediate trace name heapdump level level'; 1 PGA摘要 7).Sub Heap Oracle 9.0.1版本之前 ALTER SESSION SET EVENTS 'immediate trace name heapdump_addr level n'; 若n为subheap的地址,转储的是subheap的摘要信息 Oracle 9.2.0版本之后 ALTER SESSION SET EVENTS 'immediate trace name heapdump_addr level n, addr m'; 其中m为subheap的地址 n为1转储subheap的摘要,n为2转储subheap的内容 8).Process State ALTER SESSION SET EVENTS 'immediate trace name processstate level n'; 9).System State ALTER SESSION SET EVENTS 'immediate trace name systemstate level n'; 10).Error State ALTER SESSION SET EVENTS 'immediate trace name errorstack level n'; 0 Error stack 11).Hang Analysis ALTER SESSION SET EVENTS 'immediate trace name hanganalyze level n'; 12).Work Area ALTER SESSION SET EVENTS 'immediate trace name workareatab_dump level n'; 1 SGA信息 13).Latches ALTER SESSION SET EVENTS 'immediate trace name latches level n'; 1 latch信息 14).Events ALTER SESSION SET EVENTS 'immediate trace name events level n'; 1 session 15).Locks ALTER SESSION SET EVENTS 'immediate trace name locks level n'; 16).Shared Server Process ALTER SESSION SET EVENTS 'immediate trace name shared_server_state level n'; n取值为1~14 17).Background Messages ALTER SESSION SET EVENTS 'immediate trace name bg_messages level n'; n为pid+1 二.File Dumps 1).Block Oracle 7之前 ALTER SESSION SET EVENTS 'immediate trace name blockdump level n'; n为block的rdba Oracle8以后 ALTER SYSTEM DUMP DATAFILE file# BLOCK block#; ALTER SYSTEM DUMP DATAFILE file# 2).Tree Dump ALTER SESSION SET EVENTS 'immediate trace name treedump level n'; n为object_id 3).Undo Segment Header ALTER SYSTEM DUMP UNDO_HEADER 'segment_name'; 4).Undo for a Transaction ALTER SYSTEM DUMP UNDO BLOCK 'segment_name' XID xidusn xidslot xidsqn; 5).File Header ALTER SESSION SET EVENTS 'immediate trace name file_hdrs level n'; 1 控制文件中的文件头信息 6).Control file ALTER SESSION SET EVENTS 'immediate trace name controlf level n'; 1 文件头信息 7).Redo log Header ALTER SESSION SET EVENTS 'immediate trace name redohdr level n'; 1 控制文件中的redo log信息 8).Redo log ALTER SYSTEM DUMP LOGFILE 'FileName'; ALTER SYSTEM DUMP LOGFILE 'FileName' 其中time = (((((yyyy - 1988)) * 12 + mm - 1) * 31 + dd - 1) * 24 + hh) * 60 + mi) * 60 + ss; 9).Loghist ALTER SESSION SET EVENTS 'immediate trace name loghist level n'; 1 dump控制文件中最早和最迟的日志历史项
2 包含SGA
4 包含UGA
8 包含indrect memory
2 包含hash table histogram
3 包含object handle
4 包含object结构(Heap 0)
2 包含hash table histogram
8 包含object结构
2 level 1 + block header
3 level 2 + block contents
4 level 1 + hash chain
5 level 2 + hash chain
6 level 3 + hash chain
8 level 4 + users/waiters
9 level 5 + users/waiters
10 level 6 + users/waiters
2 SGA摘要
4 UGA摘要
8 Current call(CGA)摘要
16 User call(CGA)摘要
32 Large call(LGA)摘要
1025 PGA内容
2050 SGA内容
4100 UGA内容
8200 Current call内容
16400 User call内容
32800 Large call内容
若n为subheap的地址+1,转储的则是subheap的内容
1 level 0 + function call stack
2 level 1 + process state
3 level 2 + context area
2 Workarea Table摘要信息
3 Workarea Table详细信息
2 统计信息
2 process
3 system
BLOCK MIN minimum_block#
BLOCK MAX maximum_block#;
2 level 1 + 文件头信息
3 level 2 + 数据文件头信息
10 level 3
2 level 1 + 数据库信息 + 检查点信息
3 level 2 + 可重用节信息
10 level 3
2 level 1 + 文件头信息
3 level 2 + 日志文件头信息
10 level 3
SCN MIN MinimumSCN
SCN MAX MaximumSCN
TIME MIN MinimumTime
TIME MAX MaximumTime
LAYER Layer
OPCODE Opcode
DBA MIN FileNumber . BlockNumber
DBA MAX FileNumber . BlockNumber
RBA MIN LogFileSequenceNumber . BlockNumber
RBA MAX LogFileSequenceNumber . BlockNumber;
>1 dump 2^n个日志历史项
由于需要,需缩小一数据库的SGA,并重新分配:
alter system set sga_max_size=500m scope=spfile;
alter system set sga_target=500m scope=spfile;
shutdown immediate;
startup;
alter system system set shared_poll_size=300m scope=both;
记录下.
昨天在给应用系统做升级的时候,脚本老是执行到一半,就出现,已断开数据库连接,跟踪后发现,执行到中间回出现,ora-03113错误(通信通道的文件结束),接着就是ora-03114(失去oracle连接).
1.怀疑脚本问题,语句有问题,仔细研究下,没问题.
2.网络问题.换台机器还是一样.
3.换了个库试下,还是一样.
4.查了下 失效对象,有一些失效对象,compile之,结果得以解决.
总结: 一些失效的对象也会引起ora-03113 ora-3114错误