2011年3月23日 星期三

select 是否會使用 undo segment?

根據 Ask Tom的文章,我做了些實驗,得到的結論如文章中所描述:
  • 單純的select 並不會使用到undo segment;
  • 對於一個有一筆紀錄以上的Table來說,只要select statement 尾巴多加了 for update,就會用到undo segment。
我先建立一個測試表格T(char(1)),並insert了一筆資料,隨後進行以下的測試:

SQL> select used_ublk from v$transaction;                                                              

沒有任何資料列被選取

SQL> truncate table t;

表格被截斷.

SQL> select used_ublk from v$transaction;

沒有任何資料列被選取

SQL> insert into t values('1');

已建立 1 個資料列.

SQL> commit;

確認完成.

SQL> select used_ublk from v$transaction;

沒有任何資料列被選取

SQL> select * from t for update;

T1
--
1

SQL> select used_ublk from v$transaction;

 USED_UBLK
----------
         1

SQL> commit;

確認完成.

SQL> select used_ublk from v$transaction;

沒有任何資料列被選取

SQL>
請注意以上紅色部分,不管你有沒有異動T Table內的資料,只要一旦下了 for update,undo space就會備準備出來儲存現有的資料列版本,而且更恐怖的是Table Lock也同時跟著發生。一旦有其它 transaction 要進行異動,那真的是死在那邊等你解了。所以千萬小心、在意 for update用完要趕快commit以釋放undo space跟table lock,否則大禍臨頭(DBA找出兇手的時候)可就糗了...

2011年3月17日 星期四

SQL Writer 自發性的啟動?

SQL Writer 預設和SQL Server一起安裝,主要目的在於和VSS互動,讓備份軟體可在SQL Server運行時,執行備份或復原鎖定的data files。

這個服務預設是Disabled的,但我試著把SQL 2005 sp2升級到sp4,卻發現升級精靈檢查鎖定檔案時,SQL Writer服務卻出現了!奇怪,難道我又誤入了什麼嗎? 查了一下文章,才發現SQL SQL 2005 上了 sp2後就會自動的啟動這項服務。原文如下:

The SQL Writer Service provides added functionality for backup and restore of SQL Server 2005 through the Volume Shadow Copy Service framework.
This SQL Writer Service is automatically installed but not enabled by default. It must be explicitly enabled to run on the server machine and must be running at the time that the Volume Shadow Copy Service (VSS) application requests a backup or restore. Use the Microsoft Windows Services applet to configure the service. The SQL Writer Service installs on all operating systems but is only needed on server systems. For Microsoft Windows XP, use the MSDE Writer.

SQL Server 2005 Service Pack 2 configures SQL Writer to start automatically.

真是差點以為自己見鬼了...(筆記)

2011年3月8日 星期二

關於log file sync兩三事

今天Top Activity突然發現有趣的wait class:commit。看起來像下面橘色的那一小塊(請點圖放大):
由於平常沒什麼特別注意,今日特別興起繼續往下追蹤,發現原來是 「log file sync」的wait event:

查了一下文章,原來是app可能大量用了batch transaction的寫法,但是log buffer或者redo log file所在的硬碟效率有待加強的時候,就容易發生。嗯,這個要開始注意了..