Troubleshooting the Performance of a SQL Server Solution(讀書筆記,全是copy原文的)

來源:互聯網
上載者:User

調試sql server 的效能問題是一個非常耗時的過程,兩個基本方法:
1。proactive approach :預先估計可能出現的問題。
2。reactive 根據使用者體驗來解決問題。
影響 sql server2005效能的幾個要素:
1。硬體
2。網路
3。SqlServer database engine(配置參數
4.sql server components(SSIS SSAS...)
5.database
6.client application
可以歸結為三大問題:
Physical server
SQL Server instance
Database
常用工具:
Task Manager  
This displays information about programs and processes running on the server (or desktop computer). You can use it to get an immediate overview of your server’s performance.
System Monitor  
System Monitor (perfmon.exe) is used to track resource usage on Windows operating systems through a set of installed performance object counters.
Performance Logs and Alerts  
The Performance Logs and Alerts tool allows you to collect performance data automatically from local or remote computers.
Network Monitor Agent  
This detects network problems and identifies network traffic patterns.

SQL Server ProfilerSQL Server Profiler is a graphical tool for using traces. A trace captures event data such as Transact-SQL (T-SQL) statements, the start of a stored procedure executing, a lock being acquired or released on a database object, or security permission checks against objects. You can save the captured data in a file or a table for later analysis. You can also use SQL Server Profiler for monitoring Analysis Services. Another advantage of SQL Server Profiler in SQL Server 2005 is the option to correlate a trace with Windows performance log data.

 

In this exercise, you will create a deadlock and see it reflected in the SQLServer:Lock : Number of Deadlocks/sec counter. First you will set up the performance log and start a trace; after that you will run some simple T-SQL statements to create a deadlock. SQL Server Profiler can be of great help in detecting the cause of a deadlock. However, for this demonstration, you will use it just to record the T-SQL statements that will generate the deadlock.

1.      Use the Windows Start menu, and choose All Programs Administrative Tools Performance.

2.      Expand Performance Logs and Alerts (in the Windows Performance tool), right-click Counter Logs, and click New Log Settings.

3.      Type Deadlock Log as the name for the counter log, and click OK.

4.      On the General tab, click Add Counters.

5.      In the Performance Object box, select SQLServer:Locks.

      6.Add the Number of Deadlocks/sec counter, and leave _Total selected in the list of instances.
 

7.      Click Close.

8.      Enter 1 as the value for the Interval box under Sample Data Every.

9.Click the Log Files tab, and choose Text File (Comma Delimited) from the Log File Type list (so you can share the log file among different versions of Windows or view the log files later with Microsoft Excel).
 

10.      On the Schedule tab, specify Manually for both the Start Log and Stop Log options.

11. Click OK to create the performance log.

12. Click the Counter Logs node, right-click Deadlock Log, and select Start from the context menu. Leave the System Monitor console open.

13。      From the Windows Start menu, choose All Programs Microsoft SQL Server 2005, and click SQL Server Management Studio. For this exercise, leave SQL Server Management Studio open.

14. Connect to your SQL Server, and then from the Tools menu click SQL Server Profiler.

15. In the File menu (of SQL Server Profiler), select New Trace, and connect to your SQL Server.

16. On the General Tab, enter Correlation Trace as the trace name, select the TSQL_Replay template, and check the Save to File box to specify the trace file location and filename. (We used C:"Correlation Trace.trc.) Click Run.

 

17. Switch back to SQL Server Management Studio.Open a new query window, and run the following query:

       USE tempdb ;
       GO
       CREATE TABLE Employee (
       EmployeeID INT,
     EmployeeName VARCHAR(64)
      )
       GO
    CREATE TABLE Orders (
         OrderID INT,
  Amount INT
    )
       GO
     INSERT INTO Employee VALUES (69, 'Angelina Jolie')
      GO
       INSERT INTO Orders VALUES (1000, 200)
GO

19. Type the following statements in the query window, but do not run the query yet:

       USE tempdb ;
      GO
       BEGIN TRAN
     UPDATE Employee
     SET EmployeeName = 'Lara Croft'
   WHERE EmployeeID = 69
   WAITFOR DELAY '00:00:10'
     UPDATE Orders
       SET Amount = 300
WHERE OrderID = 1000

20. Open a new query window, and type the following statements:

     USE tempdb ;
      GO
      BEGIN TRAN
      UPDATE Orders
   SET Amount = 350
    WHERE OrderID = 1000
      WAITFOR DELAY '00:00:10'
       UPDATE Employee
     SET EmployeeName = 'Aeon Flux'
WHERE EmployeeID = 69

21. Run the query, and then switch to the first query to run it. It should create a deadlock. In one of the query windows you will get an error message “Msg 1205, Level 13, State 45, Line 6 Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.”

22. Switch to System Monitor, and stop the Deadlock log. (Click the Counter Logs node, right-click Deadlock Log, and select Stop from the context menu.)

23. Switch to SQL Server Profiler, stop the trace, and then close it.

24. From the File menu of SQL Server Profiler, select Open, and then click Trace File. Open the trace file you just created (C:"Correlation Trace.trc).

25. From the File menu, select Import Performance Data, and select the log file recorded previously (the default path and name are C:"PerfLogs"Deadlock log_000001.csv).

26. In the Performance Counters Limit Dialog window, check the instance name of your server.

27. You can play with the pointer both from the trace and from the Performance Data window to get a feel for the tool. You can go directly to the maximum value of the counter (the value 1 in this case) by right-clicking the counter (you have just one counter) and selecting Go to Max Value.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.