Written by Zakir Hossain, Manager Enterprise Architecture Configuration & Database US Dept. of Defense CEO, Data Group CS Graduate (OSU), OCP, OCA, MCDBA, MCITP-DBA, Security+, Oracle RAC-Admin, Oracle Backup/Recovery-Admin, Oracle Performance/Monitoring-Admin, Oracle App Server-Admin, System Admin (Windows/RedHat), ITIL V3, SCJP (Sun Certified Java Programmer)..::.. ALERT..::.. Altering, printing, and sharing with any training institute/individual or commercial/business use without written permission is 100% prohibited. It is a Federal Copy Right Violation of Intelligence Product. Violators will be prosecuted with the fullest Extent of Federal Law. Only for Data Group Students Do not share with outsiders and do not use for commercial purposes. 1/13
Commercial Third party Tools for Performance Management: Idera SQL Diagnostic Manager (DG): http://www.idera.com/products/sql-server/sql-diagnostic-manager/ Quest Foglight Performance Analysis For SQL Server: http://www.quest.com/foglight-performance-analysis-for-sql-server/ Quest spotlight for SQL Server Enterprise: http://www.quest.com/spotlight-on-sql-server-enterprise/ RedGate SQL Monitor: http://www.red-gate.com/products/dba/sql-monitor/ Free Third Party Tools: SQL Check v3.0 (SQL Server Monitoring Tools) http://www.idera.com/products/free-tools/sqlcheck/?s=bn120_mssqltips_chk SQL Job Manager: http://www.idera.com/products/free-tools/sql-job-manager/ SQL Permissions: http://www.idera.com/products/free-tools/sql-permissions/ http://www.spiceworks.com/free-sql-server-monitoring-tool Native Tools: Available Tools and Resources in SQL Server for Monitoring and Performance Tuning Primary monitoring tools: Performance Monitor (Perfmon: Start>type: perfmon) SQL Server Profiler Execution Plan Database Tuning Advisor Index Tuning Advisor (2000/for 2008/R2/2012) DBCC 2/13
Fragmentation Finder : T-SQL Stored Procedure (System) DMV (Dynamic Management View) Other resources for monitoring SQL Server Performance: Activity Monitor: Provides information on current users, processes, and locks How to use: Connect an instance of Database Engine Right-click on an instance Select Activity Monitor Security/Permission Require: VIEW SERVER STATE, CREATE DATABASE, ALTER ANY DATABASE, or VIEW ANY DEFINITION permission/grants To KILL a process, a user must be a member of the sysadmin or processadmin fixed server roles grant. Activity Monitor Refresh Interval: Default refresh Interval is 10 Seconds How to change/setup Refresh Interval: Open the Activity Monitor Right-click Overview Select Refresh Interval 3/13
Select the interval in which Activity Monitor should obtain new information about instance Open Activity Monitor when opening SQL Server Management Studio: On the Tools menu, click Options In the Options dialog box, expand Environment, and then select General In the At startup box, select Open Object Explorer and Activity Monitor To activate the changes, close and reopen SQL Server Management Studio SQL Server logs: SQL Server event logs provide activity information, auditing, warning, and error messages that can help to troubleshoot SQL Server problems It provides summary of activities. However, to read complete information, use the event logs How to use: Connect to an instance of Database Engine Expand Server Node Expand Management Node and Under Management Node, Expand SQL Server Logs Node Double-click Log you want to examine SQL Server Agent logs: SQL Server Agent event logs allows to view informational, auditing, warning, and error messages that can help to troubleshoot SQL Server Agent problems 4/13
How to use: Connect to an instance of Database Engine Expand Server Node Expand SQL Server Agent Node Under the SQL Server Agent node, Expand Error Logs Node Double-click Log you want to examine Special Note: According to Microsoft, SQL Server Logs and SQL Server Agent logs as error logs. However, in current implementation the logs are more accurately called event. Similar but detail information is managed in Microsoft Windows. These logs in SQL Server contain informational and security messages as well as error messages. Job Activity Monitor: Provides details status of SQL Server Agent jobs How to use: Connect to an instance of Database Engine Expand Server Node Expand SQL Server Agent Node Double-click Job Activity Monitor Event logs: Event logs allows to troubleshoot system wide problems, including SQL Server and SQL Server Agent problems How to use: 5/13
Click Start, click Administrative Tools, and then select Event Viewer Replication Monitor: Provides details status of Replication Allows to configure replication alerts How to use: Use Object Explorer view to access an instance of the Database Engine. Right-click the Replication node Select Launch Replication Monitor DBCC statements: There are set of DBCC Commands Allows to check SQL Server statistics, Trace activity, and Check database integrity How to use: sp_helpdb: This is a system stored procedure It displays information about databases How to use: sp_helpindex: sp_helpindex is a system stored procedure This provides reports information about indexes on a table or view sp_helpserver: sp_helpserver is a system stored procedure 6/13
It provides information in SQL Server instances configured for remote access or replication sp_monitor: sp_monitor is a system stored procedure It shows key SQL Server usage statistics, such as CPU idle time and CPU usage sp_spaceused: sp_spaceused is a system stored procedure It shows an estimate of disk space used by a table, indexed view, or Service Broker queue in the current database sp_who: sp_who is a system stored procedure It shows a snapshot of current SQL Server users and processes sys.dm_tran_locks: sys.dm_tran_locks is a dynamic management view (DMV) It shows information about object locks Special Note: sys.dm_tran_locks view replaces the sp_lock stored procedure. Database Performance Optimization: Optimize Disk Performance: o Use 64KB Pages File Allocation Unit. By default SQL Server uses 8KB Unit (Page/Extent) (Block size 64KB) o RPM (Rotation Per Minute) of HD: Laptops 5400 RPM (Lowest speed), 7200 RPM, 10000 RPM 7/13
o Solid State HD for SQL Server Engine and regular SAN for Data o RAID: Raid for Data 5/10/01and Raid for Log file: 1 Apply SP. There might be a MEMORY LEAK issue. For an Example, SQL Server 2005 has this issue. SP3 fixes this issue Enable Lock Pages: o This is Windows policy determines which accounts can use a process to keep data in physical memory o It prevents system from paging the data to virtual memory on disk Cache How to Setup: Use the Windows Group Policy tool (gpedit.msc) to enable this policy for the account used by SQL Server. You must be a system administrator to change this policy. To enable the lock pages in memory option o Start, click on Run. Now type gpedit.msc This will open the Group Policy dialog box o Expand Computer Configuration, and then expand Windows Settings o Expand Security Settings, and then expand Local Policies o Select User Rights Assignment folder The policies will be displayed in the details pane o Double-click Lock pages in memory o In the Local Security Policy Setting dialog box, click Add 8/13
o In the Select Users or Groups dialog box, add an account with privileges to run sqlservr.exe Configure SQL Server Memory: o When to configure this: Configure this option only if SQL Server is consuming too much memory or you are getting complaint that SQL Server is eating too much memory or all memory or you are adding memory and SQL Server is taking all of it o SQL Server uses two parameters to configure this min server memory is 0 megabytes (MB) (By Default) max server memory is 2147483647 megabytes (MB) (By Default) o Minimum Memory Amounts Allowable: For 32 Bit OS: 64 MB For 64 Bit OS: 128 MB o How to Configure: 1. Right-click on Instance and select Properties 2. Click Memory node 3. Under Server Memory Options, enter the amount that you want for Minimum server memory and Maximum server memory NOTE: Default setting allows SQL Server to change its memory requirements dynamically based on available system resources. Keep in mind that the default setting for min server memory is 0, and the default setting for max server memory is 2147483647 megabytes (MB) Affinity o Configure using T-SQL: 9/13
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'max server memory', 4096; GO RECONFIGURE; GO Maximize Data Throughput for Applications: To optimize system memory use for SQL Server, you should limit the amount of memory that is used by the system for file caching. To limit the file system cache, make sure that Maximize data throughput for file sharing is not selected. You can specify the smallest file system cache by selecting Minimize memory used or Balance. o How to setup: o Click Start, click Control Panel, double-click Network Connections, and then double-click Local Area Connection o On the General tab, click Properties, select File and Printer Sharing Microsoft Networks, and then click Properties o If Maximize data throughput for network applications is selected, choose any other option, click OK, and then close the rest of the dialog boxes Change Processors: Change this only heavily used systems and big database. Make sure server has enough CPU 10/13
ALTER SERVER CONFIGURATION SET PROCESS AFFINITY CPU = 0 to 15 Ensure Jobs are running: One of the most common causes of performance problems is Agent Jobs are not running, which in can cause the MessageBox and Tracking databases to grow unchecked. Follow the steps to ensure Jobs are running without problems: o Verify the SQL Server Agent service is running: If third party software is running to execute job, this will cause different problems o Verify jobs are completing in timely manner Microsoft System Center Operations Manager can be used to monitor jobs. It is widely used this days Purge Job History and related data: How to setup: o SQL Server Agent, and then click Jobs o Right click on Jobs and Select Manage Job Categories o Right click on Jobs and Select Manage Schedules o Right click on Jobs and Select View History o Right click on a job and Select Properties o Click on Step and Click on Edit and click OK and after modifying Configure more File and File Group Connection to SQL Server database/instance is Failing: Three ways to verify: 11/13
1. Ping 2. Ping with Port number 3. ODBC Database Monitoring and Performance Tuning Q. An application is getting refuse to connect to SQL Server. What is your approach to diagnose the problem? Three ways to verify: 1. Ping 2. Ping with Port number 3. ODBC (DB Server Name, DB Name, User Name, Password) Application Server: Where the application is running from CREATE DATABASE Perf_Monitoring go DB Server use Perf_Monitoring go create table t2 ( id uniqueidentifier, M_Name int, Y_Insert datetime ) App Server (Web Application/or Any other Application running from this machine) Web Server: IIS,Tomcat/Apache Tomcat SQL Server Client DB Server INSERT INTO t2 ( id, M_Name, Y_Insert, Name varchar (100) )Matin VALUES( 12/13
NEWID(), (CAST (100000*RAND() AS INT) %12) +1, GETDATE(), '' ) GO 100 select * from t2 order by M_Name desc select 'Matin' 13/13