搜尋本站文章

2010-11-17

新手學SQL Server 2008「公用程式控制點(UCP)」(2)

在前次的文章中,我們討論了認識「公用程式」與「公用程式控制點」,如何建立「公用程式控制點」、檢視「公用程式管理資料倉儲(UMDW)」資料庫以及註冊「Managed 執行個體」等主題。

在本期文章中,繼續延續先前的實作練習,討論如何註冊「資料層應用程式(DAC)」、組態「Managed 執行個體」的全域原則、組態「Managed 執行個體」的個別原則、監視「Managed 執行個體」等。



更多相關的技術文章,請參考:DB World 資料庫專家電子雜誌
http://www.dbworld.com.tw/




參考資料:
新手學SQL Server 2008「公用程式控制點(UCP)」(1)
http://sharedderrick.blogspot.com/2010/11/sql-server-2008ucp1.html

2010-11-15

在 SQL Server 上,是否該停用「超執行緒(HT,Hyper-Threading」?

筆者整理了以下的討論,作為各位的參考依據:

在「Microsoft SQL Server 2008 Tuning Tips for PeopleSoft Applications」一文中,提到以下的描述:
Hyper-threading is Intel’s implementation of simultaneous multithreading technology. 
The performance benefits of using hyper-threading are dependent upon workload. 

For PeopleSoft applications, it is recommended that you disable hyper-threading for the database server via the BIOS as our lab testing has shown little or no improvement.


Be aware: To Hyper or not to Hyper 一文中提到:
需要依據工作負載、使用的硬體設備,以及執行的作業方式等,經過測試後來決定是否停用 「超執行緒(HT,Hyper-Threading」。
Great! The experiment confirms the theory. So does it mean you have to disable HT when using SQL Server? 
The answer is it really depends on the load and hardware you are using. 
 
You have to test your application with HT on and off under heavy loads to understand HT's implications. 
Keep in mind that not only lazywriter thread can cause slowdown but any thread that performs large memory scan - for example a worker thread that scans large amount of data might be a culprit as well. 
For some customer applications when disabling HT we saw 10% increase in performance. 

So make sure that you do your home work before you decide to hyper on not to hyper :-)


Course 2786B: Designing a Microsoft SQL Server 2005 Infrastructure 中提到:
Hyperthreading allows a CPU to execute multiple threads simultaneously. 
Consequently, the CPU throughput increases. 
A CPU that supports hyperthreading contains two architectural states on a single physical core. 

Each state acts as a logical CPU for the operating system. 
However, the two logical CPUs use the same execution resources, so you do not get the performance benefits of using two physical CPUs.

以及以下的描述:
4. Is hyperthreading beneficial for a database server? Why or why not?
Answers will vary. 
Under certain conditions, the performance of a database server may improve if hyperthreading is enabled. 
However, a hyperthreaded CPU is not as effective as a dual core CPU or two individual CPUs.


摘錄與整理胡百敬老師 在 SQL Server 似乎因 Hyperthreading 誤判 一文內的建議:
今天看到 MVP 的 mailing list 中討論,就微軟的回答,似乎 Hyperthreading 只適用於 OLTP 大量使用者存取,但其語法都很簡單的情況。

若 OLTP 單一 batch 很複雜,或是 DW/DSS/OLAP 以分析為主,需要大量平行運算的的工作,最好都使用實體的 CPU 數(不是主機板上的 socket 數),其理由為:SQL Server 以所有的 CPU 運算力都相同為前提,設計平行計畫。但 Hyperthreading 的 CPU 並非如此。其建議是:

•在語法上採用 MAXDOP <實體 CPU 數>。 
•可以針對連接透過 Resource Governer 設定 CPU 數,但非所有版本的 SQL Server 都能使用這項功能。 
當然,也可以透過執行個體的 max degree of parallelism 設定

KB 322385 超執行緒的環境中的 SQL Server 支援(SQL Server support in a hyper-threaded environment) 一文討論如下:

Performance
The performance of hyper-threaded environments varies. 
Conservative testing has shown 10 to 20 percent gains for SQL Server workloads, but the application patterns have a significant affect. 

You might find that some applications do not receive an increase in performance by taking advantage of hyper-threading. 
If the physical processors are already saturated, using logical processors can actually reduce the workload achieved.

For example, applications that cause high levels of contention can cause decreased performance in a hyper-threaded environment. 
We recommend that you test your application thoroughly to make sure that a hyper-threaded environment provides you the performance gain that you want versus the purchase of equivalent physical CPUs. Hyper-threading can be very helpful but hyper-threading cannot replace the full power of an additional physical CPU.





以下資料摘錄自「超執行緒 - 维基百科」一文:

Intel Core i7 系列的 CPU 支援超執行緒的技術,令到四核心的處理器,有總共8個執行緒(2010年推出的Core i7 980X 6核心系列將有12個執行緒)。

超執行緒(HT, Hyper-Threading)是英特爾所研發的一種技術,於2002年發佈。
超執行緒技術原先只應用於Xeon處理器中,當時稱為“Super-Threading”。之後陸續應用在Pentium 4中,將技術主流化。

運作方式
每個單位時間內,CPU只能處理一個執行緒,以這樣的單位進行,如果想要在單位時間內處理超過一個的執行緒,是不可能的。
除非是有兩個核心處理單元,英特爾的HT技術便是以單個核心處理單元,去整合兩個邏輯處理單元,也就是一個實體核心,兩個邏輯核心,在單位時間內處理兩個執行緒,模擬雙核心運作。

顧慮
由於處理器實際上只有一個核心,能夠提升的效能約為5~15%左右,且萬一發生資源互搶的情形時,整體效能反而會下拉。
這亦是AMD不提供虛擬雙核心處理器的理由。

另外,由於架構的不同,AMD的處理器對多工處理的表現會較好,所以沒有迫切性令產品支援相關的技術。

要令到電腦支持超執行緒技術,必須要軟體和硬體的配合。
處理器本身要支援超執行緒,晶片組亦要支援相關處理器。

為此,當時的Intel推出了新的晶片組,i865PE和i875P。
要充分發揮超執行緒的效能,使用者要使用Windows 2000之後的作業系統,而Windows XP家用版亦同樣支援超執行緒技術。

除了微軟的Windows外,Linux kernel 2.4.x亦開始支援該技術。
軟體方面,不是所有程式都可以發揮超執行緒,通常優化了多處理器的程式都可以支援到。

此類軟體通常是图形或视频处理軟體。早期,遊戲軟體的支援是比較少。
但隨著多核心技術的普及,愈來愈多遊戲軟體支援多線程的處理器。


參考文件:
Microsoft SQL Server 2008 Tuning Tips for PeopleSoft Applications
http://download.microsoft.com/download/E/C/5/EC567749-20C0-4DC5-99B7-FA7C77A097EA/PeopleSoft%20on%20SQL%202008.docx

Performance Tuning Guidelines for Windows Server 2008 R2
http://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv-R2.mspx

Be aware: To Hyper or not to Hyper
http://blogs.msdn.com/b/slavao/archive/2005/11/12/492119.aspx

The Perils of Hyperthreading for SQL Server
http://sqlblog.com/blogs/kevin_kline/archive/2007/08/18/the-perils-of-hyperthreading-for-sql-server.aspx

Course 2786B: Designing a Microsoft SQL Server 2005 Infrastructure
http://www.microsoft.com/learning/en/us/course.aspx?ID=2786B&locale=en-us

超執行緒的環境中的 SQL Server 支援 SQL Server support in a hyper-threaded environment
http://support.microsoft.com/kb/322385/zh-tw

--
社群討論:
Is it still recommended to disable hyperthreading on computers running SQL Server?
http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/4180d5b8-f0ce-4d27-8e90-a5bc64c64ef2

SQL Server 2008 R2, Switch Hyperthreading and Turbo Mode On or Off?
http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/24b98bde-3b59-4f69-b9ba-2d7d931f7008

MICROSOFT SQL SERVER PERFORMANCE TUNNING
http://netic.wordpress.com/2010/02/17/microsoft-sql-server-performance-tunning/

SQL 2008 Hyper-Threading Support
http://stevenrobert.wordpress.com/2009/11/11/sql-2008-hyper-threading-support/

SQL Server 似乎因 Hyperthreading 誤判
http://byronhu.wordpress.com/2010/10/16/sql-server-%E4%BC%BC%E4%B9%8E%E5%9B%A0-hyperthreading-%E8%AA%A4%E5%88%A4/

超執行緒 - 维基百科
http://zh.wikipedia.org/zh/%E8%B6%85%E5%9F%B7%E8%A1%8C%E7%B7%92

--
Intel® Hyper-Threading Technology (Intel® HT Technology)
http://www.intel.com/technology/platform-technology/hyper-threading/index.htm

超執行緒有損伺服器效能?
http://www.zdnet.com.tw/enterprise/topic/server/0,2000085723,20102668,00.htm

KB:954835_有多核心處理器電腦上您可能無法安裝 SQL Server 2005
在 Microsoft SQL Server 2008 中,不會發生這個問題。
http://support.microsoft.com/kb/954835

2010-11-13

檢視 SQL Server 「登入失敗(Login Failures)」報表

適用版本:SQL Server 2005、2008、R2。

系統預設有啟動對「登入失敗」的事件執行記錄。

在 SSMS 管理工具上,可以使用以下的步驟來檢視此報表:
步驟01. 在「物件總管」上,連線到指定的執行個體。
步驟02. 展開「安全性」\「登入」。
步驟03. 在「登入」節點上,滑鼠右鍵,選擇「報表」\「標準報表」\「登入失敗」。
請參考下圖所示:

但在 SSMS 管理工具內的報表,在呈現細部資料上,有些問題,改要為匯出成 Excel 檔案後,就可以閱讀細部的資料。
步驟如下:
步驟01. 在報表上,滑鼠右鍵。
步驟02. 選擇「匯出」\「Excel」。
請參考下圖所示:




若需要以 Transact-SQL 方式來查詢登入失敗的紀錄,則是去查詢「預設的追蹤(default trace)」所記錄的檔案。
其實,前述的圖型介面的報表之資料,也是來自於「預設的追蹤(default trace)」。

請參考以下的範例:
declare @curr_tracefilename varchar(500); 
declare @base_tracefilename varchar(500); 
declare @indx int ;
declare @temp_trace table (
 Error int
 ,StartTime datetime
 ,NTUserName nvarchar(128)collate database_default 
 ,NTDomainName nvarchar(128) collate database_default 
 ,HostName nvarchar(128) collate database_default 
 ,ApplicationName nvarchar(128) collate database_default 
 ,LoginName nvarchar(128) collate database_default 
 ,SPID int
 ,ServerName nvarchar(128) collate database_default 
 ,TextData nvarchar (max) collate database_default );

select @curr_tracefilename = path FROM sys.traces where is_default = 1 ; 
set @curr_tracefilename = reverse(@curr_tracefilename)
select @indx  = PATINDEX('%\%', @curr_tracefilename) 
set @curr_tracefilename = reverse(@curr_tracefilename)
set @base_tracefilename = LEFT( @curr_tracefilename,len(@curr_tracefilename) - @indx) + '\log.trc';

insert into  @temp_trace
 select Error, StartTime, NTUserName, NTDomainName, HostName, ApplicationName, LoginName, SPID, ServerName, TextData
 from ::fn_trace_gettable( @base_tracefilename, default ) 
 where EventClass = 20 --signifies login failed

select dense_rank () over (order by S.loginname) loginrank, (dense_rank () over (order by S.loginname))%2 as l_loginrank , T.Error
 , convert(nchar(20), T.StartTime,120) "HitDate", T.NTUserName, T.NTDomainName, T.HostName, T.ApplicationName
 , T.LoginName, T.SPID, T.ServerName, T.TextData
 , case when S.loginname is null then 'InvalidLoginName' else S.loginname end as loginname_1
 , case when T.Error in (18462,18463,18464,18465,18466,18467,18468,18471,18487,18488) 
                 then 4 --''Password Related Problems''
                 else case when T.Error in (18458,18459,18460) 
                                   then 2 --''Licensing Related Problems''
                                        else case when T.Error in (18452,18450,18486,18457) 
                                                          then 1 --''Authentication Related Problems''
                                                          else case when T.Error in(18451,18461) 
                                                                                then 5 --''Server''''s Mode of Operation''
                                    else case when T.Error in (17197) 
                                                                                                  then 6 --''Slow Server Response''
                                          else 3 --''Others'' 
                                     end
                            end
                                                 end
                          end
        end  "Type"
,       (dense_rank() over ( order by (case when T.Error in (18462,18463,18464,18465,18466,18467,18468,18471,18487,18488) 
                                                                                then 4 -- ''Password Related Problems''
                                                                                else case when T.Error in (18458,18459,18460) 
                                                                                         then 2 --''Licensing Related Problems''
                                                                                         else case when T.Error in (18452,18450,18486,18457) 
                                                                                                  then 1 --''Authentication Related Problems''
                                                                                                  else case when T.Error in(18451,18461) 
                                                                                                           then 5 --''Server''''s Mode of Operation''
                                                                                                           else case when T.Error in (17197) 
                                                                                                                    then 6 --''Slow Server Response''
                                                                                                                        else 3-- ''Others'' 
                                                                                                                        end
                                                                                                           end
                                                                                                  end
                                                                                         end
                                                                                end )))%2  as l1
,       (row_number() over ( order by (case when T.Error in (18462,18463,18464,18465,18466,18467,18468,18471,18487,18488) 
                                                                   then 4 --''Password Related Problems''
                                                                   else case when T.Error in (18458,18459,18460) 
                                                                                then 2--''Licensing Related Problems''
                                                                                else case when T.Error in (18452,18450,18486,18457) 
                                                                                         then 1 --''Authentication Related Problems''
                                                                                         else case when T.Error in(18451,18461) 
                                                                                                  then 5 --''Server''''s Mode of Operation''
                                                                                                  else case when T.Error in (17197) 
                                                                                                           then 6 --''Slow Server Response''
                                               else 3-- ''Others'' 
                                               end
                                          end
                                                                                         end
                                                                                end
                                                                   end ),T.StartTime desc))%2  as l2
from @temp_trace T 
left outer join sys.syslogins S on(T.LoginName = S.loginname)

請參考下圖所示:


參考資料:
預設的追蹤(Default Trace)之簡介,文章編號:S071006803
http://www.dbworld.com.tw/default.aspx

2010-11-10

下載 SQL Server code-named 「Denali」- Community Technology Preview 1 (CTP1)

在 2010/11/08,Microsoft 開發團隊公布了 SQL Server 2008 下一個版本 Code Name:Denali 的 Community Technology Preview 1 (CTP,社群技術預覽)版本的軟體,可供於下載與測試之用。

版本編號:11.0.1103.9。
目前僅提供英文版本。

下載的網址:
Microsoft® SQL Server® code-named 'Denali' - Community Technology Preview 1 (CTP1)



參考資料:
SQL Server Code-Named "Denali" CTP1 Release Notes
http://social.technet.microsoft.com/wiki/contents/articles/sql-server-code-named-quot-denali-quot-ctp1-release-notes.aspx

SQL Server Code-Named "Denali" CTP1 Release Notes
http://social.technet.microsoft.com/wiki/contents/articles/sql-server-code-named-quot-denali-quot-ctp1-release-notes/revision/17.aspx

SQL Server "Denali" What's New (Database Engine) -- MSDN 線上叢書
http://msdn.microsoft.com/en-us/library/bb510411(v=SQL.110).aspx

Microsoft® SQL Server® code-named 'Denali' - Community Technology Preview 1 (CTP1)
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6a04f16f-f6be-4f92-9c92-f7e5677d91f9

Microsoft Delivers SQL Server 2008 R2 Parallel Data Warehouse and the next version of SQL Server, SQL Server Code-Named “Denali”
http://blogs.technet.com/b/dataplatforminsider/archive/2010/11/09/microsoft-delivers-sql-server-2008-r2-parallel-data-warehouse-and-the-next-version-of-sql-server-sql-server-code-named-denali.aspx

2010-11-03

查詢 SQL Server 上面全部資料庫的檔案大小

可以快速查詢全部的資料庫,其包含了資料檔案、交易記錄檔案的大小。

適用版本:
SQL Server 2005、2008、2008 R2

SELECT DB_NAME(database_id) N'資料庫', physical_name N'實體檔案', type_desc N'檔案類型', state_desc N'檔案狀態', size*8.0/1024 N'檔案大小(MB)'
FROM sys.master_files

請參考下圖所示:


上述範例,只包含了資料檔案、交易記錄檔案的檔案大小,但不包含實際上使用的資料量。
可以參考:
顯示每一個資料庫的所使用的磁碟空間之完整版本


參考資料:
顯示每一個資料庫的所使用的磁碟空間之完整版本; Displays the disk space reserved and used by the each database
http://sharedderrick.blogspot.com/2008/01/displays-disk-space-reserved-and-used_02.html

檢視全部的資料庫,其交易記錄檔案所使用的空間資訊; Transaction log space usage statistics for all databases
http://sharedderrick.blogspot.com/2008/01/transaction-log-space-usage-statistics.html

檢視資料庫,其硬碟使用空間與資料實際使用空間;Displays the disk space reserved and used by the whole database
http://sharedderrick.blogspot.com/2008/05/displays-disk-space-reserved-and-used.html

查詢目前資料庫內,每一個資料表的磁碟空間使用資訊 -- Displaying disk space information about eyvery table
http://sharedderrick.blogspot.com/2008/05/displaying-disk-space-information-about.html

新手學SQL Server 2008「公用程式控制點(UCP)」(1)

在管理多台資料庫伺服器時,對於資料庫管理人員而言,需要一個能夠長時間觀察系統運行的工具,可以用來檢視系統在這段時間的執行狀況、耗用資源量等等

在 SQL Server 2008 R2 版本上提供了「公用程式控制點(UCP)」,讓資料庫管理人員可以長期間來觀察系統資源的使用量,藉此來分析系統的運作情形,以及推估系統的使用量。



更多相關的技術文章,請參考:DB World 資料庫專家電子雜誌
http://www.dbworld.com.tw/