September 2010
M T W T F S S
« Jul    
 12345
6789101112
13141516171819
20212223242526
27282930  

SQL Plus Instant Client Basis

SQL Plus Instant Client 是一个具有SQL Plus 命令行所有功能的独立产品.它不需要安装Oracle客户端,可以直接连接远端的数据库.

1.SQL Plus Instant Client 安装
安装SQL Plus Instant Client, 你需要下面两个包.
可以在OTN下载,也可以从Oracle Client 的安装介质上拷贝相应的文件,拷贝的文件必须是同数据库版本的文件.

(1).SQL*Plus Instant Client package.
(2).Basic OCI Instant Client package, or the lightweight OCI Instant Client package.
Continue reading SQL Plus Instant Client Basis

生活成本在不断的增加

今天交房租给房东,房东说要收水费了(以前水费不收)。问为什么?答曰:你老婆来了,用水也多了。
oh,shit.我老婆来了也没多用多少水啊。
估计是看见我买了个洗衣机……
自从来杭州就一直租着这个房子,两年多了,经历了一次房租的涨价,这次又是水费。
看来要考虑换房子了。

How to Read PGA Memory Advisory Section in AWR and Statspack Reports

A doc from Metalink:

Preferred and easiest way of monitoring and setting pga_aggregate_target parameter (PGA) is section ‘PGA Memory Advisory’ in the AWR and Statspack reports.

PGA Memory Advisory

  • When using Auto Memory Mgmt, minimally choose a pga_aggregate_target value where Estd PGA Overalloc Count is 0
PGA Target Est (MB) Size Factr W/A MB Processed Estd Extra W/A MB Read/ Written to Disk Estd PGA Cache Hit % Estd PGA Overalloc Count
128 0.13 258,572.74 127,776.77 67.00 2,010
256 0.25 258,572.74 31,433.28 89.00 0
512 0.50 258,572.74 29,560.27 90.00 0
768 0.75 258,572.74 28,863.55 90.00 0
1,024 1.00 258,572.74 28,863.55 90.00 0
1,229 1.20 258,572.74 4,643.11 98.00 0
1,434 1.40 258,572.74 4,643.11 98.00 0
1,638 1.60 258,572.74 4,643.11 98.00 0
1,843 1.80 258,572.74 4,643.11 98.00 0
2,048 2.00 258,572.74 4,643.11 98.00 0
3,072 3.00 258,572.74 4,643.11 98.00 0
4,096 4.00 258,572.74 4,643.11 98.00 0
6,144 6.00 258,572.74 4,643.11 98.00 0
8,192 8.00 258,572.74 4,643.11 98.00 0

In this section, you first find the row where field ‘Size Factr’ is 1.00.  The field ‘PGA Target Est(MB)’ of this row will show your current PGA setting – figure 1024 in the above example. Other fields (columns) you will be interested in are: ‘Estd Extra W/A MB Read/ Written to Disk ‘ and ‘Estd PGA Overalloc Count’.

When you go down or up the advisory section from the row with ‘Size Factr’ = 1.00, you get estimations for Disk usage – column ‘Estd Extra W/A MB Read/ Written to Disk ‘ - for bigger or smaller settings of pga_aggregate_target. The less Disk usage figure in this column,  usually the better.

Your first goal is to have such a setting of pga_aggregate_target, that number in the column ‘Estd Extra W/A MB Read/ Written to Disk ‘ does not substantially reduce any more, see figure 28863.55 in the example AWR report.
In other words, further increases of pga_aggregate_target won’t give any more benefit.

Column ‘Estd PGA Overalloc Count’ shows estimations of how many times database would need to request from OS more PGA memory than the amount shown in the ‘PGA Target Est(MB)’ field of the respective row. Ideally this field  should be 0, and that is your equally important second goal.

In many cases  ‘Estd PGA Overalloc Count’ figures reach 0 before  the number in ‘Estd Extra W/A MB Read/ Written to Disk ‘ stabilizes

Question whether increase from the current actual size is possible  for a given database, should be always investigated.  The answer depends on how much of total memory (SGA+PGA) can be allocated for this database on this box, i.e. take into account memory needs of other databases, software and OS residing on the box.

Ref:DOC ID:786554.1

How to Tune log File Sync?

当会话等待redo log buffer 中的信息被写到磁盘的时候就会发生Log file sync waits 等待事件。
通常这是由LGWR的磁盘写入速度慢或者用户的频繁递交引起的。
下面是一些常用的减少log file sync waits 等待时间的方法:
1)调整LGWR以获得更好的磁盘写入吞吐量。
2)如果在短时间段内有很多事务,看有没有可能把这些事务分批处理以减少commit操作。
每个递交动作oracle都会首先去确认相关的redo log 信息以及被写到了磁盘。
3)看是不是有可能使用COMMIT NOWAIT 选项。在Oracle 10g R2中,Oracle增强了COMMIT命令,
增加了WRITE语句来控制redo log文件写入磁盘的方式以提高性能。这个新特性应该只是被用在以下情况:
(1)大事务量导致的redo log 写。
(2)在实例崩溃的时候,可以接受数据的丢失。
(3)处理的事务会引起严重的redo log writes 等待。

COMMIT语句的一些可用选项:
COMMIT;
COMMIT WRITE WAIT;      –> The commit command is synchronous. It doesn’t return until the relevant redo information is written to the online redo log.
COMMIT WRITE NOWAIT;    –> The commit command is asynchronous. It can return before the relevant redo information is written to the online redo log.
COMMIT WRITE BATCH;     –> The commit command is synchronous. It doesn’t return until the relevant redo information is written to the online redo log.
COMMIT WRITE IMMEDIATE; –> The commit “prods” the LGWR process by sending a message, so that the redo is written immediately to the redo logs.

Default COMMIT behavior New option
IMMEDIATE The redo information is written to disk immediately (forcing a disk I/O for each commit). BATCH Oracle buffers the redo information. The log writer will write this redo information to disk, but in its own time. Thus, several I/Os can be “batched”.
WAIT Oracle does not return from the commit until the commit has completed successfully. NOWAIT Oracle doesn’t wait for the commit to complete, but returns right away.

为了避免代码的修改,可以修改COMMIT_WRITE参数文件,参数可以在会话级别或者系统级别设置。
例如:
SQL> ALTER [SYSTEM | SESSION] SET COMMIT_WRITE=’IMMEDIATE,NOWAIT’;

你也可以创建一个触发器在运行程序的用户级别设置COMMIT 方式:
SQL> CREATE OR REPLACE TRIGGER sys.global_commit_session_settings AFTER LOGON ON <your application_username>.SCHEMA
BEGIN
execute immediate ‘alter session set COMMIT_WRITE =”IMMEDIATE,NOWAIT”’;
END;
/

4)看看是否可以使用NOLOGGING/UNRECOVERYABLE选项处理事务,以减少redo log 的生成。

Reference:
DOC ID:857576.1

What do OS stats section of AWR report really tell us?

NUM_LCPUS Probably 0 because LPARs not set up
NUM_VCPUS Same thing
AVG_BUSY_TIME BUSY_TIME/NUM_CPUS
AVG_IDLE_TIME IDLE_TIME/NUM_CPUS
AVG_IOWAIT_TIME IOWAIT_TIME/NUM_CPUS
AVG_SYS_TIME SYS_TIME/NUM_CPUS
AVG_USER_TIME USER_TIME/NUM_CPUS
BUSY_TIME Time equiv of %usr+%sys in sar output
IDLE_TIME Time equiv of %idle in sar
IOWAIT_TIME Time equiv of %wio in sar
SYS_TIME Time equiv of %sys in sar
USER_TIME Time equiv of %usr in sar
LOAD  
OS_CPU_WAIT_TIME Supposedly time waiting on run queues
RSRC_MGR_CPU_WAIT_TIME Time waited coz of resource manager
PHYSICAL_MEMORY_BYTES Total memory in use supposedly
NUM_CPUS Number of CPUs reported by OS
NUM_CPU_CORES Number of CPU sockets on motherboard

 

If you want to convert the times (expressed in seconds) back into percentages, then total elapsed time is
e = BUSY_TIME + IDLE_TIME + IOWAIT TIME or
e = SYS_TIME + USER_TIME + IDLE_TIME + IOWAIT_TIME since BUSY_TIME = (SYS_TIME+USER_TIME)

e should also be roughly close to elapsed time of report (59.78 min * 60 seconds/min * 8 (NUM_CPUS))

but the report itself takes time to run (actually the snapshots take time as well) and neither the snapshot,

the V$ tables the snapshot is taken from, nor the report itself are AS OF a single consistent point in time.

Anyway at this point you can see, (BUSY_TIME / e) = %busy.
Finally,

CPU used by this session                    234,148           65.3         112.4

This is CPU time Oracle reports it used (though we don’t include time spent in SQL*Net code and maybe not all background

processes may be reporting the CPU time they used). It is expressed in centiseconds rather than seconds so

234,148 / (e * 100) will tell you what percent of the total CPU resources on the machine Oracle was keeping busy.

Actually it’s probably easier to look at DB CPU stat since that is already in seconds.

BUSY_TIME – “DB CPU” is the amount of CPU usage that seems to be because of things mostly happening outside the database.