数据库

img llmmysun

查找产生等待事件原因

发表于2004/10/27 15:20:00  1110人阅读

--最主要的等待视图
select * from v$session_wait;
select * from v$session_event;
select * from v$system_event;
select * from v$waitstat  where count>0;

--相关视图
select * from v$session_wait  
 
select * from v$filestat

select * from dba_data_files

select * from dba_extents  where OWNER='WANG'

SELECT * FROM SYS.UET$

SELECT * FROM V$LATCH

select * from v$filestat  where file# in(select p1 from v$session_wait   )

 

--基于等待事件的性能优化方法

--常见等待事件
select * from  V$system_event 
where event  in('buffer busy waits','free buffer waits','db file sequential read',
'db file scattered read','enqueue','latch free','log file parallel write','log file sync')


--查看对上面显示有贡献的等待事件

select B.USERNAME,B.PROGRAM,B.STATUS ,A.EVENT,A.TOTAL_WAITS,A.TOTAL_TIMEOUTS,A.TIME_WAITED,A.AVERAGE_WAIT
from V$SESSION_EVENT A , V$SESSION B WHERE B.USERNAME is not null and  A.SID=B.SID
AND A.EVENT NOT LIKE 'SQL*Net%'
and b.status='ACTIVE'

--为了找到与连接的会话有关的当前等待事件,使用下面的查询.这些信息是动态的,为了查看一个会话的等待最多的事件是什么,需要多次执行此查询

select sw.sid,s.Username,sw.Event,sw.wait_time,
sw.state,sw.seconds_in_wait SEC_IN_WAIT
from V$SESSION s,V$SESSION_WAIT sw
where s.Username is not null 
and s.sid=sw.sid 
and sw.event  NOT LIKE 'SQL*Net%'
order by sw.wait_time desc;

--查询显示了有关试验的等待事件的其他信息

select sid ,event,p1text,p1,p2text,p2,p3text,p3
from v$session_wait
where event not like '%SQL%'
AND  EVENT NOT LIKE '%rdbms%'


--利用 p1 和 p2 的信息很容易发现这个段是什么段

select owner,segment_name, segment_type,tablespace_name  from dba_extents
where file_id=&fileid_in
and &blockid_in  between  block_id and block_id + blocks-1

--访问表ITEM_MASTER

--GETSQLTXT.SQL

CREATE OR REPLACE function GetSQLTxt(HashAddr_in  in V$SQLTEXT.Hash_Value%Type , Addr_in  in V$SQLTEXT.Address%Type) return varchar2
is
  Temp_SQLTxt varchar2(32767);
  cursor  SQLPiece_Cur
  is
     select Piece,SQL_text 
     from v$sqltext
     where Hash_value=HashAddr_in
     and Address=Addr_in
     order by Piece;
begin
  for  SQLPiece_Rec   IN    SQLPiece_Cur
  loop
      Temp_SQLTxt:=Temp_SQLTxt||SQLPiece_Rec.Sql_Text;
  end loop    
   
  return Temp_SQLTxt;
end GetSQLTxt;
/

--看数据库启动以来 发生多少全表扫描!
select * from v$sysstat  where name like '%table scan%'

--监视全表扫描

select sid,serial#,opname,to_char(start_time,'HH:MI:SS') "START TIME", SOFAR/TOTALWORK "% COMPLETE"

from  v$session_longops

********************************************************************************************************************
--全表扫描时间长 解决过程

当前oracle系统性能 
查询 MUSICSONG 表  ,全表查询用了  400秒 
查询 使用  ____多少资源

最基本的时间花费
1.数据库读取,把某个表装入内存
2.计算部分(整个cpu),处理这些表
3.数据库写回

--确定oracle系统瓶颈

select  * from v$system_event  where total_timeouts>0  order  by   total_timeouts  desc

drop  table begin_sys_event ;
drop  table end_sys_event;

/*create table begin_sys_event at time T1 */
create table begin_sys_event  as
select * from v$system_event

/*wait n seconds or n minutes */

/*create table end_sys_event at time T2 */
create table end_sys_event  as
select * from v$system_event


select t1.event,(T2.total_waits-T1.total_waits) "Delta waits",
(T2.total_timeouts-T1.total_timeouts) "Delta timeouts",
(T2.time_waited-T1.time_waited) "Delta time waited",
(T2.Average_wait-t2.Average_wait) "Delta   Average  Wait"
from begin_sys_event  t1, end_sys_event  t2 
where t1.event=t2.event and t2.total_waits!=0;

select * From v$event_name;

select * from v$system_event  where  event  not in '%pmon timer%'
and event not like '%rdbms ipc message%'


--指定 LRU 闩锁集数量的上限。只有在 V$LATCH 中的失败率超过 3% 的情况下,才需要增大该值。
select * From V$LATCH;

--如何标识内部latch的冲突

Server manager monitor是一个相当有用的来监视latch等待、请求和冲突的工具。
也可查询相关的数据字典表:
v$latch, v$latchholder, v$latchname。


--latch有40余种,但作为DBA关心的主要应有以下几种:

Cache buffers chains latch: 当用户进程搜索SGA寻找database cache buffers时需要使用此latch。

Cache buffers LRU chain latch: 当用户进程要搜索buffer cache中包括所有 dirty blocks的LRU (least recently used) 链时使用该种latch。

Redo log buffer latch: 这种latch控制redo log buffer中每条redo entries的空间分配。

Row cache objects latch: 当用户进程访问缓存的数据字典数值时,将使用Row cache objects latch

Redo Copy Latch只应用于多CPU的系统。在多CPU的instance中,如果一个redo entry太大,超过了LOG_SMALL_ENTRY_MAX_SIZE定义值,则不能进行“在redo allocation latch上的拷贝”, 此时用户进程必须获取redo copy latch。一个instance中可以有多个redo copy latch,其数目由初始参数LOG_SIMULTANEOUS_COPIES决定,缺省值为CPU数目。

在单CPU情况下,不存在redo copy latch,所有的redo entry无论大小, 都进行“在redo allocation latch上的拷贝”。

对redo log buffer的过多访问将导致redo log buffer latch的冲突,latch冲突将降低系统性能,我们可通过如下查询来检测这种latch冲突:

col name for a40

SELECT ln.name,gets,misses,immediate_gets,immediate_misses

FROM v$latch l,v$latchname ln

WHERE ln.name IN('redo allocation','redo copy') AND ln.latch#=l.latch#

/

若misses与gets的比例超过1%或immediate_misses与(immediate_gets+immediate_misses)比例超过1%时,应考虑采取措施减少latch的冲突。

************************************************************************************************************************
Here is a page I downloaded before, I forget where it come from. Share with you all. I think this is a very good document for you.

Performance Tuning WebWizard
Oracle RDBMS Tuning for AIX

Use this WebWizard to tuning your Oracle RDBMS running on an IBM pSeries with AIX. This WebWizard assumes you are a Database Administrator (DBA). 
Note these are the AIX specific tuning tips. See also the UNIX general tuning tips. 

We take no credit for this information as its taken from the Oracle Manuals. 


Tip 1 - Use Asynchronous I/O
In the init.ora configuration file set: use_async_io=true 
Then set the minservers and maxservers using SMIT->Devices->Asynchronous I/O->Change/Show Characteristics of Asynchronous I/O (or just type smit aio) to: 

MaxServers = 10 * number of disks 
MinServers = MaxServers /2 
This is likely to increase performance by 6 - 8%. 
Tip 2 - Use Parallel Recovery
In the init.ora configuration file set: recovery_parallelism=[number of CPUs but not less than 2] 
This is likely to increase recovery processing by 0 - 50%. 

Tip 3 - Use Logical Volume Manager
To spread out the data across disks you could use Oracle files or the AIX LVM. It is strongly recommended that the LVM is used. Striping data across disks is very effective as it makes full use of the disks in usage terms, makes excellent use of read ahead for sequential I/O and spreads I/O evenly (better perforamnce). For striping use the following: 
Stripe unit size 64KB 
max_coalesce 64KB 
minpgahead 2 
maxpgahead 16 
Note: the striped LV size must be a multiple number of the drives used. 
Note: striped data and log must be on different sets of dicks. 
Note: AIX LVM does not currently allow striping and mirroring at the same time. 
This is likely to increase performance by 0 - 500%. 

Tip 4 - Use readv()
In the init.ora configuration file set: use_readv=TRUE 
This effectively ask the AIX Kernel not to buffer reads (particularly JFS files) and should increase performance. 

Note this can make performance worse so test this firsts. 

Tip 5 - Use db_file_multiblock_read_count
In the init.ora configuration file set: db_file_multiblock_read_count=[8 or 16] 
This should be set to db_block_size*db_file_multiblock_read_count is greater than the LVM stripe size. 

Tip 6 - Use JFS or Raw Partitions
This is a well worn subject with agruments on both sided. 
JFS - If your database is not I/O bound i.e. you do lots of computation on data retrieved the JFS will be nice because its simpler to administer and backup/recover. 
Raw partitions/raw disks/raw logical volume - otherwise use these for performance. 
Moving to Raw Disks is likely to increase performance by 0 - 50%. 

Tip 7 - Direct I/O
Not implemented on AIX. 
Tip 8 - Use Write Behind
Disable the AIX feature by setting the AIX parameter using: vmtune -c 0 
Note to set the AIX parameter back to normal: vmtune -c 8 

This might not be suitable unless the machine is solely a database server. 

Tip 9 - Tune Sequential Read Ahead
The Virtual Memory Manager spots sequential reading of files by watching the access pattern. After a number of reads in order are noticed, it will attempt to read upto maxphahead blocks of the file in adavance. By default these are: 
minpgahead 2 
maxpgahead 8 
These can be increased to increase sequential reading of data using: vmtune -r 512 -R 1024 
Keep the numbers powers of 2. 

Tip 10 - Tune Disk I/O Pacing
Disk I/O pacing is an AIX feature that stops disk I/O intension applications flooding the CPU. This is done with low and high water marks via: smit->System Environment->Change/Show Characteristics of OS. 
Be careful as this can hurt performance if not set correctly. 

Tip 11 - Using RAID
Raid can improve read performance but is slow in write. For performance never use RAID as random I/O is typically 4 times slower. 
Tip 12 - Disk Geometry Considerations
On AIX you can place data of particular parts of the disk. The middle part of the disk being the fastest as it reduces seek times. 
This may increase performance by 10% 

Tip 13 - Use Processor Binding on SMP
Certain processes can be locked to run on a particular CPU. This increases level 1 cache hits but the process cannot then float to unused CPU's if its CPU is busy. Use the bindprocessor command. 
Note: do not use bind processor on AIX 3 

You can use this feature to bind the main Oracle processes to different CPUs with good effect. Also, if the SQL*Net listener is bound its forked off servers for use connection are also bound. 

This may increase performance by 15% 

Tip 14 - Spin Count on SMP
This can reduce Oracle internal latch contention. In the init.ora configuration file the default is: spin_count=2000 
Increasing this means the process will spin longer waiting for the process on other CPUs to free the latch so it can continue. Setting this to 0 can help on single CPU machines or when CPU usage is very high. 

Tip 15 - Process Priority
Warning: getting this wrong may crash your machine. 
Only the root user can set this using the setpri() system call. 

Increasing the priority (reducing the number) can improve performance if there are lots of runnable processes on the machine. Oracle provide a setorapri command to do this: setorapri 39 

This may increase perforamnce by 15% 

Tip 16 - Buffer Cache Paging
For JFS database there can be a copy of the SGA block in the Buffer Cahce too. This can effect performance and cause I/O bottlenecks. There are four AIX buffer cache tuning parameters: 
minfree - below this page stealing starts trying to reclaim memory pages 
maxfree - above this page stealing stops 
minperm - minimum number of pages allocated to File I/O 
maxperm - maximum number of pages allocated to File I/O 
Increase minfree and maxfree so that read ahead pages do not reduce free pages to zero and there is alway free memory. 
Tip 17 - File Buffer cache
You can adjust the minperm and maxperm (see tip 16) to effect the size of the buffer cache resources. 
This depend so much on the workload and I/O characterists of your database that its difficult to recommend particular values. Try: vmtune -p 30 -P 60 

The defaults are 20 and 80. 

Tip 18 - Paging Space
Never run out of paging space. Two to three time RAM is typical. Use: lsps -a to determine the size and use of paging. 
Tip 19 - Block Size
db_blcok_size=4096 for small, JFS and OLTP/mixed workload databases 
db_block_size=8192 for raw lare DSS workload 
Tip 20 - Redo Buffer Latch
Set the following init.ora file parameters: 
log_small_entry_max_size= 0 
log_simultaneous_copies=[2 times the number of CPUs] 
Tip 21 - Archiver Buffers
The log_archive_buffer_size effects the perforamcne of the archiver which is used to copy log files to other resources so they can be reused later. Set the init.ora file parameter: 
log_archive_buffer_size=[upto 128] 
log_archive_buffer=[default of 4] 
Over doing this can degrade performance but may give 20% better performance. 

Tip 22 - SGA Size
The SGA must not be paged or swapped out. The amount of memory that can be allocated to the SGA depends on: 
high numbers of users need more SGA 
actual RAM available 
if the machine is a DB server or stand alone 
Set the init.ora parameters: 
db_block_buffers 
shared_pool_size 
For example as a rough guide: 

System type  Stand alone  Server only  
OLTP  30% of RAM  40% to 60% of RAM  
DSS  40% to 70% of RAM  50% to 80% of RAM  


Tip 23 - SQL*Loader I/O Buffers
While loading data with SQL*Loader it ends up waiting for the I/O to complete. Increasing the BUFFERS parameter will improve load performance. 
Tip 24 - Out-of-bound breacks with SQL*Net TCPIP
This is the communications use between client and server and by default is switched on (orasrv does this). 
This may increase perfromance by 20% 

Tip 25 - Post-Wait Kernel Extension
This reduces the overhead of semaphore operations. 
Make sure the correct version is installed. 
This may increase performance by 20% 

Tip 26 - TCPIP
SQL*Net V2 uses 2KB packet sizes. The underlying packet size is 1KB for most installations. 
This can be changed with SQL*Net connection string parameters. 
It is not recommended to change this as it can degrade perforamnce. 

Tip 27 - Compliling Pro*C
Use the right optimisation level 
-O3 
Compile for the right chipset: 

-qarch=COM for the common mode (i.e. runs on everything) 
-qarch=PWR for POWER only machines 
-qarch=PWRX for POWER2 only machines 
-qarch=PPC for POWERPC only machines
***********************************************************************************************************************

 


 

阅读全文
0 0

相关文章推荐

img
取 消
img