標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 爬蟲 (1) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) Fedora (1) FI (57) File Transfer (1) Firefox (3) FM (2) fourjs (1) Genero (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (4) JavaScript (22) jQuery (6) JSON (1) K3b (1) ldd (1) LED (3) Linux (117) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) OpenSSL (1) Oracle (126) Outlook (3) PDF (6) Perl (60) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (5) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium (3) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) sqlplus (1) SQuirreL SQL Client (1) SSH (2) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (24) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (37) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) VirtualBox (1) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) Xvfb (2) youtube (1) yum (2)

2015年12月20日 星期日

隨身硬碟裡頭的資料夾全部消失不見,但容量依然佔用著,怎麼回事?


http://forum.gamer.com.tw/Co.php?bsn=60030&sn=1466369

1.開始->執行->cmd
2.切換到自己的隨身碟代碼,假如我的隨身碟在(E:)的話,就直接打 E:然後按下 Enter 鍵
3.然後用複製的或輸入以下指令:
attrib -h -s *.* /s /d

大概跑個幾分鐘就可以了。

-h(代表解除隱藏的檔案或資料夾)
-s(代表解除檔案或資料夾的系統屬性)
/s(處理資料夾及子資料夾)
/d(一併處理資料夾)

2015年11月18日 星期三

Perl and Oracle BLOB

#!/usr/bin/perl

use DBI;

require "$ENV{HOME}/perl/setEnv.pl";

my $dbh = DBI->connect( "dbi:Oracle:$topprod", "$echoUser", "$echoPass" )
    || die( $DBI::errstr . "\n" );
$dbh->{LongReadLen} = 50000000;  # Make sure buffer is big enough for BLOB
my $sth = $dbh->prepare(q{
select regexp_substr(gca01,'ASO[789]-.*') oea01,
       gcb07,gcb09
  from gca_file,gcb_file
 where gca07 = gcb01
   and gca01 in (
                 select 'oea01='||oga16 gca01
                   from echo01.oga_file
                  where oga913 = to_date('20151001','yyyymmdd')
                    and regexp_like(oga01,'^ASH[789]-')
                )
}) || die "\nPrepare error: $DBI::err .... $DBI::errstr\n";;
$sth->execute() || die "\nExecute error: $DBI::err .... $DBI::errstr\n";

&blobSelect();

sub blobSelect()
{
   while (@data = $sth->fetchrow_array())
   {
      open FILE, "> $data[0]_$data[1]";
      print FILE $data[2];
      close FILE;
   }
   $sth->finish();
}

2015年11月15日 星期日

PHP install OCI (RHEL / CentOS / Fedora)

http://antoine.hordez.fr/2012/09/30/howto-install-oracle-oci8-on-rhel-centos-fedora/

1.
yum install php.x86_64 ()
yum php-mysql.x86_64 (不確定)
yum install
php-pear
yum install php-devel

2.
pear download pecl/oci8
tar vzf oci8-x.x.x.tar
cd oci8-x.x.x/
phpize
(確認整個OS只有一個php/phpize/ph-config/pecl/pear/peardev/的版本,
我在這裡吃了大苦頭。由於有兩個版本,compile一直用到舊版本。
如果有舊版本,通常會在/usr/loca/bin裡面,可以用find / -name php...找。
但是使用yum install php... 安裝的通常在/usr/bin,而$PATH的/usr/local/bin通常又先於/usr/bin,所以一直抓到舊版
)

3.
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/xxx/client64/lib/ (xxx是Oracle 版本)4.
make
make install

5.
setsebool -P httpd_execmem 1 (如果有啟動SEinux)

6.
vi /etc/php.ini
[OCI8]
extension=oci8.so
or
cd /etc/php.d
vim oci8.ini
extension=oci8.so
以下為原文

HOWTO install Oracle OCI8 on RHEL / CentOS / Fedora

How to install OCI8 (PHP extension to access Oracle Databases) on a RHEL / Fedora Linux system.
Download from http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html :
EDIT 2013/09/24 : http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
  • RPM Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
  • RPM Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
Install both RPM packages :
rpm -ivh instantclient-basic-linux.XXX.rpm
rpm -ivh instantclient-sdk-linux.XXX.rpm
Install some prerequisite
yum install php-pear
yum install php-devel
Download the OCI8 extension
pear download pecl/oci8
tar xvzf oci8-1.4.7.tgz
cd oci8-1.4.7/
phpize
Configure the extension with your Oracle client library path (change the path …/11.2/… with your own version) :
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib/
Compil and install
make
make install
Configure SELinux : allows httpd to execute programs that require memory addresses that are both executable and writeable
setsebool -P httpd_execmem 1
Add the folowing configuration at the end of php.ini
vi /etc/php.ini
[OCI8]
extension=oci8.so
Restart Apache
service httpd restart
That’s all folks.

2015年11月10日 星期二

PHPMail 寄 html

#!/usr/bin/php

<?php
    $cnt = 0;
    $text;
    function getData() {
        require "/root/php/setEnv.php";

        //EIP Connect
        $con = new mysqli("$hostEIP","$usernameEIP","$passwordEIP","$databaseEIP");
        if ($con->connect_errno)
          {
            die('Could not connect: ' . $con->connect_error());
          }
        mysqli_set_charset($con,"utf8");

        $stmt = $con->prepare("
SELECT account_lastname, vfs_directory, vfs_name,
       concat( 'http://xxx.xxx.xxx.xxx/eipplus/index.php?menuaction=filemanager.uifilemanager.index&path_id=', vfs_file_id ) link
  FROM hplus_vfs, hplus_accounts
 WHERE vfs_directory LIKE '%共用文件區%'
   AND vfs_mime_type LIKE 'application%'
   AND vfs_createdby_id = account_id
   AND vfs_created >= sysdate( ) - 144000
");
        $stmt->bind_result($name,$dir,$file,$link);
        $stmt->execute();

        $GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>\n";
        $GLOBALS['text'] .= " <table style=' border: 1px solid #aaa; border-collapse: collapse; '> \n";
        $GLOBALS['text'] .= " <tr> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳人員 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳目錄 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 檔案名稱 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> EIP連結 </th> </tr> \n";
        while($stmt->fetch())
        {
          $GLOBALS['text'] .= " <tr> <td style='border: 1px solid #c3c3c3;'> $name </td> <td style='border: 1px solid #c3c3c3;'> $dir </td> <td style='border: 1px solid #c3c3c3;'> $file </td> <td style='border: 1px solid #c3c3c3;'> $link </td> </tr>\n";
          $GLOBALS['cnt'] += 1;
        }
        $GLOBALS['text'] .= " </table> \n";

        #$GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>";
        #while($stmt->fetch()) {
        #   $GLOBALS['text'] .= "上傳人員 : $name<br>上傳目錄 : $dir<br>檔案名稱 : $file<br>EIP連結 : $link<br> <br>";
        #   $GLOBALS['cnt'] += 1;
        #}

        #echo $text;
        #echo $cnt;
        #echo $GLOBALS['cnt'];

        $stmt->close();
        $con->close();
    }

    function sendMail() {
        require_once('/root/php/PHPMailer/class.phpmailer.php');
        require_once('/root/php/PHPMailer/class.smtp.php');
        require "/root/php/setEnv.php";

        $phpmail = new PHPMailer();
        $phpmail->IsSMTP(true);
        #$phpmail->IsHTML(true);
        $phpmail->Host = 'xxx.xxx.xxx.xxx';
        $phpmail->CharSet = "utf-8";
        $phpmail->From = 'mis@xxx.xxx.xxx.xxx';
        $phpmail->FromName = 'EIP 自動寄信通知';
        $phpmail->Subject = 'EIP 共用文件區新增檔案通知';

        $html = $GLOBALS['text'];
        #echo $html;
        #$phpmail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
        #$phpmail->Body = "<html><table style='border: 1px solid #ccc;'></table><html>";
        $phpmail->MsgHTML($html);
        #$phpmail->MsgHTML("test");
        #$phpmail->AddAttachment( "/tmp/MailNoPrice.csv" , '有庫存無訂價.csv' );

        #$phpmail->AddAddress( $mailNoPriceList,'商品行銷' );
        #$phpmail->AddAddress( $mailNoPriceListVGM,'副總' );
        #$phpmail->AddAddress( $mailNoPriceListFIN1,'財務主管1' );
        #$phpmail->AddAddress( $mailNoPriceListFIN2,'財務主管2' );
        $phpmail->AddAddress( "xxx@xxx.xxx.xxx.xxx",'全公司' );
        if(! $phpmail->Send())
        {
           echo "通知信件寄出失敗";
           echo "Mailer Error : " . $mail->ErrorInfo;
           exit;
        }
           echo "通知信件已寄出";
    }

    function main() {
        getData();
        if ($GLOBALS['cnt'] > 0) {
            sendMail();
        }
    }

    main();
?>

2015年11月4日 星期三

PHP date (BigInt to String) and mktime (String or Integer to BigInt) conversion

<?php
   echo date('H:i:s d-M-Y', 1446778800);
   echo "<br>";
   echo date('H:i:s d-M-Y', 1446786000);
   echo "<br>";

                                                //時,分,秒,月,日,年
  $mytimestamp = mktime(11,0,0,11,6,2015);
  
   echo "$mytimestamp";
   echo "<br>";

   echo date('H:i:s d-M-Y', 1446778800+36000);
   echo "<br>";
   echo date('H:i:s d-M-Y', 1446786000+36000);
   echo "<br>";
?>

11:00:00 06-Nov-2015
13:00:00 06-Nov-2015
1446778800
21:00:00 06-Nov-2015
23:00:00 06-Nov-2015

2015年11月1日 星期日

CSS 文字垂直置中技巧

http://www.wibibi.com/info.php?tid=151

CSS 文字垂直置中技巧

會寫這一篇是因為在 CSS 中要水平置中相當簡單,只要使用 text-align 即可,但是垂直置中就不是這麼容易的事情,其實說難也不難,只要用一點小技巧就可以做出文字垂直置中的效果,本篇用的是 line-height 行高的技巧。

CSS 文字垂直置中範例
<DIV style="border-style:solid;background-color:#C7FF91;width:300px;height:100px;text-align:center;line-height:100px;">
 測試文字垂直置中
</DIV>
呈現結果
測試文字垂直置中

test

由此範例可以看到文字已經在區塊垂直方向置中了,甚至連水平都置中了。

稍為解說一下這段語法,手先是 DIV 區塊將文字包在裡面,style 的部分,我們設定了背景顏色(background-color:#C7FF91)、寬度(width:300px)、高度 (height:100px)、水平置中對齊(text-align:center)以及最重要的 line-height100px。

由於 DIV 區塊的高度設定為 100px,這時候設定文字的 line-height(行高)也是 100px,就自然而然的垂直置中囉!

延伸閱讀

CSS position 觀念筆記心得

http://blog.rx836.tw/blog/css-positioning/

[CSS] CSS position 觀念筆記心得

css position 對於初學者來說觀念很容易混淆,我在剛學習時也很常搞不清楚relative和absolute之間的關係,但只要抓到幾個訣竅重點,其實可以很輕鬆的掌握它,這篇是紀錄我自己學習css position的心得,搭配幾個簡單易懂的範例,讓大家一起成長

Start

首先,css position 屬性共有四個值,分別為 staticrelativeabsolutefixed,其中,當你沒有設定position時,預設為static,下面就來介紹這四個值的差別

static

就如剛剛所提到的,static是預設值,意思是說,就算你沒宣告position這個屬性,默認還是為static,而通常這時候會影響到元素的位置,就是看它本身是 block 或是 inline,例如兩個<div>因為是block的關係,所以會上下各占據一行,那如果是兩個<span>,因為是inline,所以會在同一行裡面呈現
css
#d1{
    width: 100px;
    height: 100px;
    background: blue;
}
#d2{
    width: 100px;
    height: 100px;
    background: red;
}
#s1{
        background: blue;
    }
#s2{
        background: red;
    }
html
<div id="d1">
div1
</div>
<div id="d2">
div2
</div>
<span id="s1">span1</span><span id="s2">span2</span>


特別注意的是,static並不會受 topbottomleftright 這些屬性值影響

relative

假如元素的position屬性值設為relative,就會受到 topbottomleftright 這些值影響所在位置,利用剛剛的範例,我們增加position屬性值和一些位移看看結果
css
#d1{
    width: 100px;
    height: 100px;
    background: blue;
    position: relative;
    top: 20px;
    left: 20px;
}
#d2{
    width: 100px;
    height: 100px;
    background: red;
}
我們在id為d1的<div>裡面加上了 position: relativetop:20px 還有 left:20px,會看到下面如圖的結果

藍色的div從原本的位置往右下角位移了,從原始位置的左上角為起點,遠離左邊(left)20px的差距,遠離上面(top)也是20px的差距,但還是保留原本位置的空間,並且覆蓋到d2,注意我這邊特別註明是原本的位置,因為這會跟等下介紹的 absolute 有所不同,那有些人或許會有疑問,可以用 margin 取代嗎?我們來實驗一下
#d1{
    width: 100px;
    height: 100px;
    background: blue;
    margin-top: 20px;
    margin-left: 20px;
}
#d2{
    width: 100px;
    height: 100px;
    background: red;
}

有明顯的發現,利用屬性margin做位移,元素並沒有覆蓋堆疊的問題,但會影響到其它的元素位置,這是要特別注意小心的地方,不可不慎

absolute

absolute 跟relative很像,差別在於位移時是從哪個起始點開始算起,剛剛的relative是從原本的位置開始算,而absolute是從整個頁面的視窗開始算起(感謝網友底下留言補充,這邊應該講從最近一個有 "position: relative" 的 parent node 開始算),並且並不會保留它原本的空間,範例如下
#d1{
    width: 100px;
    height: 100px;
    background: blue;
    position: absolute;;
    top: 20px;
    left: 20px;
}
#d2{
    width: 100px;
    height: 100px;
    background: red;
}

有發現藍色的<div>完全無視其它的元素存在,也不會干擾到其它的元素,因為它的原始空間也消失了,自己獨立起來自成一格,看起來還 蠻容易了解的,不過有一個地方是初學者很容易混淆的,就是當relative和absolute一起使用時,那情形就會跟我們設想的不太一樣,範例如下
css
#d1{
    width: 100px;
    height: 100px;
    background: blue;
    position: absolute;;
    top: 20px;
    left: 20px;
}
#d2{
    width: 100px;
    height: 100px;
    background: red;
}

#d3{
    position: relative;
    width: 300px;
    height: 300px;
    border: solid 1px orange;
}
html
<div id="d3">
    <div id="d1">
    div1
    </div>
    <div id="d2">
    div2
    </div>
</div>
這裡多用一個id為d3的<div>包住兩個<div>,d3的position屬性值為relative,此時會看到藍色的<div>屬性值position雖然一樣是absolute,但會看到位移不太一樣了

會發現藍色的<div>是從id為d3的<div>左上角開始定位,這代表是說,如果屬性值為absolute的<div>,上面還有被其它元素包住,就要注意位移計算的起始值會有所不同,那如果將relative移除的話呢?

嗯!定位又從頁面視窗的左上角當作起始點囉,如果覺得範例感覺不到效果,可以將top和left的值加大,會更明顯

fixed

最後講到的是fixed,它常被用於在Menu bar,位置也是受到 topbottomleftright 這些值影響,跟absolute類似,但有兩個不一樣的地方
1.它的位移起始的依據永遠都是視窗頁面,也就是說就算它有relative的父元素,並不會受到影響
2.它會跟著scroll移動,也就是說當畫面被往下拉時,該元素會跟隨著移到相對的位置
基於以上兩點的特色,我們就可以做出永遠固定在視窗某個地方的元素

像是 pinterest 就有用到類似的效果,不過記得要搭配 * z-index* 來做元素堆疊

結論

其實網路上有很多很好的文章在討論關於css position的用法和觀念,也有很多很漂亮的排版,但只要掌握好基本觀念,我相信對於那些複雜的layout也可以輕鬆的理解
另外除了上面討論的四個屬性值以外,CSS3其實還有新增另外兩個,分別叫做 position: centerposition: page,不過因為非主流且各瀏覽器支援程度很低,有興趣的人在自行研究即可

參考資料:

CSS Positioning: A Comprehensive Look
Learn CSS Positioning in Ten Steps(10個步驟學習CSS Position)
CSS Position 位置
內容如有錯誤,歡迎指正

2015年8月28日 星期五

Resolving common Oracle Wait Events using the Wait Interface

http://gavinsoorma.com/wp-content/uploads/2011/12/Resolving-common-Oracle-Wait-Events-using-the-Wait-Interface.htm

Wait Event
Possible Causes
Actions
Remarks

db file sequential reads

Use of an unselective index

Fragmented Indexes

High I/O on a particular disk or mount point

Bad application design

Index reads performance can be affected by
 slow I/O subsystem and/or poor database
files layout, which result in a higher average
 wait time


Check indexes on the table to ensure
that the right index is being used

Check the column order of the index
with the WHERE clause of the Top
SQL statements

Rebuild indexes with a high clustering
factor

Use partitioning to reduce the amount
of blocks being visited

Make sure optimizer statistics are up
to date

Relocate ‘hot’ datafiles

Consider the usage of multiple buffer
pools and cache frequently used
indexes/tables in the KEEP pool

Inspect the execution plans of the
SQL statements that access data
through indexes

Is it appropriate for the SQL
statements to access data through
index lookups?

Is the application an online transaction
 processing (OLTP) or decision
support system (DSS)?

Would full table scans be more
efficient?

Do the statements use the right driving
 table?

The optimization goal is to minimize
 both the number of logical and
physical I/Os.


The Oracle process wants a block that is currently not in the SGA, and it is waiting for the database block to be read into the SGA from disk.
Significant db file sequential read wait time is most likely an application issue.
If the
DBA_INDEXES.CLUSTERING_FACTOR of the index approaches the number of blocks in the table, then most of the rows in the table are ordered. This is desirable.

 However, if the clustering factor approaches the number of rows in the table, it means the rows in the table are randomly ordered and thus it requires more I/Os to complete the operation. You can improve the index’s clustering factor by rebuilding the table so that rows are ordered according to the index key and rebuilding the index thereafter.

The OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING initialization parameters can influence the optimizer to favour the nested loops operation and choose an index access path over a full table scan.

Tuning I/O related waits Note# 223117.1

db file sequential read Reference Note# 34559.1


db file scattered reads

The Oracle session has requested and is
waiting for multiple contiguous database
blocks (up to DB_FILE_MULTIBLOCK_READ_COUNT) to be
 read into the SGA from disk.
Full Table scans

Fast Full Index Scans

Optimize multi-block I/O by setting the
parameter DB_FILE_MULTIBLOCK_READ_COUNT

Partition pruning to reduce number of
blocks visited

Consider the usage of multiple buffer
pools and cache frequently used
indexes/tables in the KEEP pool
Optimize the SQL statement that
initiated most of the waits. The goal is
to minimize the number of physical
and logical reads.
Should the statement access the data
by a full table scan or index FFS?
Would an index range or unique scan
 be more efficient?
Does the query use the right driving
table?
Are the SQL predicates appropriate
for hash or merge join?
 If full scans are appropriate, can
parallel query improve the response
time?
The objective is to reduce the
demands for both the logical and
physical I/Os, and this is best
achieved through SQL and application tuning.
Make sure all statistics are
representative of the actual data.
Check the LAST_ANALYZED date


If an application that has been running fine for a while suddenly clocks a lot of time on the db file scattered read event and there hasn’t been a code change, you might want to check to see if one or more indexes has been dropped or become unusable.
db file scattered read Reference Note# 34558.1

log file parallel write

LGWR waits while writing contents of the
redo log buffer cache to the online log files
on disk
I/O wait on sub system holding the online
 redo log files

Reduce the amount of redo being
generated

Do not leave tablespaces in hot
backup mode for longer than
necessary

Do not use RAID 5 for redo log files

Use faster disks for redo log files

Ensure that the disks holding the
archived redo log files and the online
redo log files are separate so as to
avoid contention

Consider using NOLOGGING or
UNRECOVERABLE options in SQL
statements


Reference Note# 34583.1

log file sync

Oracle foreground processes are waiting
for a COMMIT or ROLLBACK to complete


Tune LGWR to get good throughput to
 disk eg: Do not put redo logs on
RAID5

Reduce overall number of commits by
batching transactions so that there
are fewer distinct COMMIT operations

Reference Note# 34592.1

High Waits on log file sync Note# 125269.1

Tuning the Redolog Buffer Cache and Resolving Redo Latch Contention
Note# 147471.1


buffer busy waits

Buffer busy waits are common in an I/O-
bound Oracle system.
The two main cases where this can occur
are:
Another session is reading the block into the
buffer
Another session holds the buffer in an
incompatible mode to our request
These waits indicate read/read, read/write,
 or write/write contention.
The Oracle session is waiting to pin a buffer.
A buffer must be pinned before it can be
read or modified. Only one process can pin a
buffer at any one time.

This wait can be intensified by a large block
 size as more rows can be contained within
the block

This wait happens when a session wants to
access a database block in the buffer cache
but it cannot as the buffer is "busy

It is also often due to several processes
repeatedly reading the same blocks (eg: if
lots of people scan the same index or data
 block)

The main way to reduce buffer busy
waits is to reduce the total I/O on the
system

Depending on the block type, the
actions will differ

Data Blocks

Eliminate HOT blocks from the
application.

Check for repeatedly scanned /
unselective indexes.

Try rebuilding the object with a higher
PCTFREE so that you reduce the
number of rows per block.

 Check for 'right- hand-indexes'
(indexes that get inserted into at the
same point by many processes).

 Increase INITRANS and MAXTRANS
and reduce PCTUSED This will make
the table less dense .

Reduce the number of rows per block

Segment Header

Increase of number of FREELISTs
  and FREELIST GROUPs

Undo Header

Increase the number of Rollback
Segments


A process that waits on the buffer busy waits event publishes the reason code in the P3 parameter of the wait event.

The Oracle Metalink note # 34405.1 provides a table of reference - codes 130 and 220 are the most common.

Resolving intense and random buffer busy wait performance problems. Note# 155971.1


free buffer waits

This means we are waiting for a free buffer
but there are none available in the cache
because there are too many dirty buffers in
 the cache

Either the buffer cache is too small or the
DBWR is slow in writing modified buffers to
disk

DBWR is unable to keep up to the write
requests

Checkpoints happening too fast – maybe due
 to high database activity and under-sized
 online redo log files

Large sorts and full table scans are filling the
 cache with modified blocks faster than the
 DBWR is able to write to disk
If the  number of dirty buffers that need to be
 written to disk is larger than the number that
DBWR can write per batch, then these waits
 can be observed


Reduce checkpoint frequency  -
increase the size of the online redo
log files

Examine the size of the buffer cache
– consider increasing the size of the
buffer cache in the SGA

Set disk_asynch_io = true set
 
If not using asynchronous I/O 

increase the number of db writer 

processes or dbwr slaves
 
Ensure hot spots do not exist by
spreading datafiles over disks and
disk controllers

Pre-sorting or reorganizing data can
help


Note# 163424.1

enqueue waits

This wait event indicates a wait for a lock
that is held by another session (or sessions)
in an incompatible mode to the requested
mode.

TX Transaction Lock

Generally due to table or application set up
issues

This indicates contention for row-level lock.
 This wait occurs when a transaction tries to
update or delete rows that are currently
 locked by another transaction.

This usually is an application issue.

TM DML enqueue lock

Generally due to application issues, 

particularly if foreign key constraints have 

not been indexed.
 
ST lock
 
Database actions that modify the UET$ (used

extent) and FET$ (free extent) tables require 

the ST lock, which includes actions such as 

drop, truncate, and coalesce.
 
Contention for the ST lock indicates there are 

multiple sessions actively performing 

dynamic disk space allocation or deallocation 

in dictionary managed tablespaces



Reduce waits and wait times

The action to take depends on the lock
 type which is causing the most problems

Whenever you see an enqueue wait
event for the TX enqueue, the first
step is to find out who the blocker is
and if there are multiple waiters for
the same resource

Waits for TM enqueue in Mode 3 are primarily due to unindexed foreign key columns.

Create indexes on foreign keys  < 10g

Following are some of the things you
can do to minimize ST lock contention
in your database:
 
Use locally managed tablespaces
Recreate all temporary tablespaces
using the CREATE TEMPORARY
TABLESPACE TEMPFILE… command.
 


Maximum number of enqueue resources that can be concurrently locked is controlled by the ENQUEUE_RESOURCES parameter.

Reference Note# 34566.1

Tracing sessions waiting on an enqueue Note# 102925.1

Details of V$LOCK view and lock modes Note:29787.1






Cache buffer chain latch

This latch is acquired when searching
for data blocks
Buffer cache is a chain of blocks and
each chain is protected by a child
latch when it needs to be scanned
Hot blocks are another common
cause of cache buffers chains latch
contention. This happens when
multiple sessions repeatedly access
 one or more blocks that are
protected by the same child cache
buffers chains
latch.
 SQL statements with high
BUFFER_GETS (logical reads) per
EXECUTIONS are the main culprits
Multiple concurrent sessions are
executing the same inefficient SQL
that is going after the same data set

Reducing contention for the cache
buffer chains latch will usually require
reducing logical I/O rates by tuning
and minimizing the I/O requirements of
 the SQL involved. High I/O rates could
be a sign of a hot block (meaning a
block highly accessed).  

Exporting the table, increasing the
PCTFREE significantly, and importing
the data. This minimizes the number of
 rows per block, spreading them over
many blocks. Of course, this is at the
expense of storage and full table
scans operations will be slower

Minimizing the number of records per
block in the table
For indexes, you can rebuild them
with higher PCTFREE values, bearing
in mind that this may increase the
height of the index.
Consider reducing the block size
 Starting in Oracle9i Database, Oracle
supports multiple block sizes. If the
current block size is 16K, you may
move the table or recreate the index in
a tablespace with an 8K block size.
This too will negatively impact full
table scans operations. Also, various
 block sizes increase management
complexity.


The default number of hash latches is usually 1024

The number of hash latches can be adjusted by the parameter _DB_BLOCKS_HASH_LATCHES


Cache buffer LRU chain latch

Processes need to get this latch when they
need to move buffers based on the LRU
block replacement policy in the buffer cache
The cache buffer lru chain latch is acquired
in order to introduce a new block into the
buffer cache and when writing a buffer
back to disk, specifically when trying  to
scan the LRU (least recently used) chain
containing all the dirty blocks in the buffer
cache.
Competition for the cache buffers lru chain 

latch is symptomatic of intense buffer cache

 activity caused by inefficient SQL 

statements. Statements that repeatedly scan

 large unselective indexes or perform full 

table scans are the prime culprits.  
Heavy contention for this latch is generally 

due to heavy buffer cache activity which 

can be caused, for example, by:

 Repeatedly scanning large unselective 

indexes
 

Contention in this latch can be
avoided implementing multiple
buffer pools or increasing the
number of LRU latches with the
 parameter DB_BLOCK_LRU_LATCHES
(The default value is generally
 sufficient for most systems).

Its possible to reduce
contention for the cache buffer
lru chain
latch by increasing the
size of the buffer cache and
thereby reducing the rate at
which new blocks are
introduced into the buffer cache



Direct Path Reads

These waits are associated with direct read operations which read data directly into the sessions PGA bypassing the SGA

The "direct path read" and "direct path write" wait events are related to operations that are performed in PGA like sorting, group by operation, hash join

In DSS type systems, or during heavy batch periods, waits on "direct path read" are quite normal

However, for an OLTP system these waits are significant
These wait events can occur during sorting operations which is not surprising as direct path reads and writes usually occur in connection with temporary tsegments
SQL statements with functions that require sorts, such as ORDER BY, GROUP BY, UNION, DISTINCT, and ROLLUP, write sort runs to the temporary tablespace when the input size is larger than the work area in the PGA


Ensure the OS asynchronous IO is configured correctly.

Check for IO heavy sessions / SQL and see if the amount of IO can be reduced.

Ensure no disks are IO bound.

Set your PGA_AGGREGATE_TARGET to appropriate value (if the parameter WORKAREA_SIZE_POLICY = AUTO)

Or set *_area_size manually (like sort_area_size and then you have to set WORKAREA_SIZE_POLICY = MANUAL

Whenever possible use UNION ALL instead of UNION, and where applicable use HASH JOIN instead of SORT MERGE and NESTED LOOPS instead of HASH JOIN.


 Make sure the optimizer selects the right driving table. Check to see if the composite index’s columns can be rearranged to match the ORDER BY clause to avoid sort entirely.

Also, consider automating the SQL work areas using PGA_AGGREGATE_TARGET in Oracle9i Database.



Default size of HASH_AREA_SIZE  is twice that of SORT_AREA_SIZE

Larger HASH_AREA_SIZE will influence optimizer to go for hash joins instead of nested loops

Hidden parameter DB_FILE_DIRECT_IO_COUNT can impact the direct path read performance.It sets the maximum I/O buffer size of direct read and write operations. Default is 1M in 9i


Direct Path  Writes

These are waits that are associated with
direct write operations that write data from
users’ PGAs to data files or temporary
tablespaces

Direct load operations (eg: Create Table as
 Select (CTAS) may use this)

Parallel DML operations

Sort IO (when a sort does not fit in memory

If the file indicates a temporary
tablespace check for unexpected disk
sort operations.

Ensure
<Parameter:DISK_ASYNCH_IO> is
TRUE . This is unlikely to reduce wait
times from the wait event timings but
may reduce sessions elapsed times
(as synchronous direct IO is not
accounted for in wait event timings).

Ensure the OS asynchronous IO is
configured correctly.

Ensure no disks are IO bound




Latch Free Waits


















This wait indicates that the process is
waiting for a latch that is currently busy
(held by another process).

When you see a latch free wait event in the
V$SESSION_WAIT view, it means the
process failed to obtain the latch in the
willing-to-wait mode after spinning
_SPIN_COUNT times and went to sleep.
When processes compete heavily for
latches, they will also consume more CPU
resources because of spinning. The result is
a higher response time


If the TIME spent waiting for latches is
significant then it is best to determine
which latches are suffering from
contention
.



A latch is a kind of low level lock.

Latches apply only to memory
structures in the SGA. They do not
apply to database objects. An Oracle
SGA has many latches, and they
exist to protect various memory
structures from potential corruption
 by concurrent access.

The time spent on latch waits is an
effect, not a cause; the cause is that
you are doing too many block gets,
and block gets require
cache buffer chain latching



Library cache latch

The library cache latches protect the
cached SQL statements and objects
definitions held in the library cache within the
shared pool. The library cache latch must be
acquired in order to add a new statement to
the library cache

Application is making heavy use of literal
SQL- use of bind variables will reduce this
latch considerably


Latch is to ensure that the application
is reusing as much as possible SQL
statement representation. Use bind
variables whenever possible in the
application

You can reduce the library cache
latch hold time by properly setting the
SESSION_CACHED_CURSORS parameter

Consider increasing shared pool

Larger shared pools tend to have
long free lists and processes that
need to allocate space in them must
 spend extra time scanning the long
free lists while holding the shared
pool
latch

if your database is not yet on
Oracle9i Database, an oversized
shared pool can increase the
contention for the shared pool latch.

Shared pool latch

The shared pool latch is used to protect
critical operations when allocating and
freeing memory in the shared pool

Contentions for the shared pool and library
cache
latches are mainly due to intense hard
 parsing. A hard parse applies to new
cursors and cursors that are aged out and
must be re-executed

The cost of parsing a new SQL statement is
expensive both in terms of
CPU requirements and the number of times
the library cache and shared pool latches
may need to be acquired and released.

Ways to reduce the shared pool latch
are, avoid hard parses when
possible, parse once, execute many.
Eliminating literal SQL is also useful to
avoid the shared pool latch. The size
 of the shared_pool and use of MTS
(shared server option) also greatly
influences the shared pool latch.

The workaround is to set the
initialization parameter
CURSOR_SHARING to FORCE. This
allows statements that differ in literal
 values but are otherwise identical to
share a cursor and therefore reduce
latch contention, memory usage, and
 hard parse.


<Note 62143.1> explains how to
identify and correct problems with the
shared pool, and shared pool latch.


Row cache objects latch


This latch comes into play when user
processes are attempting to  access the
cached data dictionary values.


It is not common to have contention in
this latch and the only way to reduce
contention for this latch is by
increasing the size of the shared pool
(SHARED_POOL_SIZE).

Use Locally Managed tablespaces for
your application objects especially
indexes

Review and amend your database
logical design , a good example is to
merge or decrease the number of
indexes on tables with heavy inserts

Configuring the library cache to an
acceptable size usually ensures that
the data  dictionary cache is also
properly sized. So tuning Library
Cache will tune Row Cache indirectly