Download SQL Server Profiler

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Concurrency control wikipedia , lookup

Oracle Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Access wikipedia , lookup

Database wikipedia , lookup

Tandem Computers wikipedia , lookup

Btrieve wikipedia , lookup

Team Foundation Server wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Clusterpoint wikipedia , lookup

Open Database Connectivity wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Transcript
Prog 140

SQL Server Performance Monitoring and Tuning
Copyright Sammamish Software Services
2013. All rights reserved.
1
Performance Monitoring Tools






Optimizing queries using Execution Plans
DETA (Database Engine Tuning Advisor)
SQL Server Profiler
Activity Monitor
SQL Server Stored Procedures
System Monitor (Perfmon)/SQL Performance
Counters
2
Copyright Sammamish Software Services 2013. All rights reserved.
SS2012 Performance Tips setup


SQL Server 2012 supports named instances of SQL Server.
 You can run up to 16 concurrent instances of SQL Server 2012
on the same server.
 Each running instance of SQL Server takes up server
resources. Some resources are shared by multiple running
instances, i.e., MSDTC and Search services, but most aren’t.
Because of this, each additional instance of SQL Server
running on the same server has to fight for available
resources, hurting performance
For best performance, don't mix production databases and
development (test or staging) databases on the same physical
server.
 This not only serves to better separate the two functions
(production and development), but prevents developers from
using up server resources that could be better used by
production users.
3
Copyright Sammamish Software Services 2013. All rights reserved.
Disk IOs: Reads vs Writes


Find out if the disk I/O of your servers (and the databases on it) are
mostly reads or mostly writes. This info can be used to calculate the
ratio of writes to reads of your server
 If your server is heavy on writes, then you should avoid RAID 5,
and use RAID 10 instead. RAID 10 is more efficient for writes. Vice
versa if your system is Read heavy then RAID 5 is likely a better
choice
To find out the ratio of reads to writes run Task Manager and look at
the sqlservr.exe process (this is the mssqlserver or sqlserv
service);view the total number of I/O Read Bytes and I/O Write Bytes.


(If you don't see this in Task Manager, check the
“Show processes from all users box” then go to
View|Select Column, and add these two columns.)
The results you see tell you how many bytes of
data have been written and read from the SQL
Server service since it was last restarted. Because
of this, you don't want to read this figure
immediately after starting the SQL Server service,
but after several days of typical use.
4
Copyright Sammamish Software Services 2013. All rights reserved.
SS2012 Performance Tips: Dev




Use Truncate table instead of Delete. Truncate is “minimally
logged” ; then you must run Update Statistics!
If you must allow users to access to your data, e.g. using Excel or
Access, instead point them to a replicated reporting server i.e., a
DM or DW, rather than your OLTP
Use consistent coding style and format
Instead of SELECT COUNT(*) from <table_name> A much faster,
and more efficient, way of counting rows in a table is to run the
following query:
 SELECT rows
FROM sysindexes
WHERE id = OBJECT_ID('<table_name>') AND indid < 2
5
Copyright Sammamish Software Services 2013. All rights reserved.
Summary of query performance tips
in this course
Good db design = better performance
 Use joins instead of subqueries when possible
 The “like” operator (pattern matching) is a
performance hit – if you can substitute with a range
then do so.
 Limit nesting of objects like views, sprocs
 Limit use of triggers since the rollback is expensive
 Use of stored procedures and views are better
than scripts for performance since SS can store
execution plans and use caching
 Limit use of functions in large queries to enable
caching
6

Copyright Sammamish Software Services 2013. All rights reserved.
How SQL Processes queries



A SELECT statement is
nonprocedural; it does not state
the exact steps that the database
server should use to retrieve the
requested data. This means that
the database server must
analyze the statement to
determine the most efficient way
to extract the requested data.
This is referred to as optimizing
the SELECT statement. The
component that does this is
called the query optimizer.
The input to the optimizer
consists of the query, the
database schema (table and
index definitions), and the
database statistics. The output of
the optimizer is a query
execution plan
7
Copyright Sammamish Software Services 2013. All rights reserved.
Using Execution Plans

In SQL Server 2012, you can display
execution plans by using the following
methods:
 SQL Server Management
Studio

Displays either an estimated
graphical execution plan
(statements do not execute) or
an actual graphical execution
plan (on executed statements),
which you can save and view in
Management Studio.
Transact-SQL SET statement
options
When you use the Transact-SQL
SET statement options, you can
produce estimated and actual
execution plans in XML or text.
 SQL Server Profiler event
classes
 Icons:
http://msdn.microsoft.com/enus/library/ms175913(v=SQL.10
5).aspx
Copyright Sammamish Software Services 2013. All rights reserved.
8
SQL Server system stored procedures




sp_who/sp_who2 Reports snapshot information about
current SQL Server users and processes, including the
currently executing statement and whether the statement
is blocked.
sp_lock Reports snapshot information about locks,
including the object ID, index ID, type of lock, and type or
resource to which the lock applies.
sp_spaceused Displays an estimate of the current amount
of disk space used by a table (or a whole database).
sp_monitor Displays statistics, including CPU usage, I/O
usage, and the amount of time idle since sp_monitor was
last executed.
9
Copyright Sammamish Software Services 2013. All rights reserved.
Query optimizer hints:

Set Transaction Isolation Level Read Uncommitted
select
TesterContextID
, o.Name Operation
, elTester.Name Tester
, ts.ComputerName
, elGroup.Name TesterGroup
, elLine.Name Line
, s.Name Factory
FROM dbo.TesterContext tc
join dbo.Operation o with (nolock) on o.OperationID = tc.OperationID
left JOIN dbo.TesterStation ts with (nolock) on ts.TesterStationID = tc.TesterStationID
join dbo.EquipmentLocation ElTester with (nolock) on ElTester.equipmentLocationID =
tc.equipmentLocationID
left join dbo.EquipmentLocationHierarchy elh1 with (nolock) on elh1.childLocationID =
elTester.equipmentLocationID
left join dbo.EquipmentLocation ElGroup with (nolock) on ElGroup.equipmentLocationID
= elh1.ParentLocationID
left join dbo.EquipmentLocationHierarchy elh2 with (nolock) on elh2.childLocationID =
elGroup.equipmentLocationID
left join dbo.EquipmentLocation ElLine with (nolock) on ElLine.equipmentLocationID =
elh2.ParentLocationID
left join dbo.Site s with (nolock) on s.SiteID = ElTester.SiteID
10
Copyright Sammamish Software Services 2013. All rights reserved.
Performance Monitor


Perfmon
(Performance
Monitor)
You can view
SQL Server
objects,
performance
counters, and
the behavior of
other objects
 processors,
 memory,
 cache,
 threads,
 processes.
11
Copyright Sammamish Software Services 2013. All rights reserved.
Activity Monitor
12
Copyright Sammamish Software Services 2013. All rights reserved.
SQL Server Profiler

SQL Server Profiler is a graphical user interface to SQL Trace for
monitoring an instance of the SQL Server Database Engine or
Analysis Services. You can capture and save data about each
event to a file or table to analyze later. For example, you can
monitor a production environment to see which stored procedures
are affecting performance by executing too slowly.
13
Copyright Sammamish Software Services 2013. All rights reserved.
Database Engine Tuning Advisor
Details (DETA)


Database Engine Tuning Advisor evaluates more
types of events and structures, and provides
higher quality recommendations
DTA provides two interfaces:
 A standalone graphical user interface tool for
tuning databases, and viewing tuning
recommendations and reports
 A command-line utility program, dta.exe
14
Copyright Sammamish Software Services 2013. All rights reserved.
The database engine tuning advisor


Database Engine
Tuning Advisor
analyzes the
performance effects of
workloads run against
one or more databases.
 A workload is a set
of Transact-SQL
statements that
executes against
databases you want
to tune.
DTA provides
recommendations to
add, remove, or modify
physical design
structures:
 physical clustered
indexes,
 nonclustered
indexes,
 indexed views, and
 partitioning.
Copyright Sammamish Software Services 2013. All rights reserved.
15
Workloads



Database Engine Tuning Advisor requires a workload.
 A workload consists of a Transact-SQL script or a SQL Server Profiler
trace saved to a file or table.
Database Engine Tuning Advisor is designed to handle the following
workload types:
 Online transaction processing (OLTP) queries alone
 Online analytical processing (OLAP) queries alone
 Mixed OLTP and OLAP queries
 Query-heavy workloads (more queries than updates)
 Update-heavy workloads (more updates than queries)
You can create Workloads using the Tuning Template in SQL Server
Profiler.
 After the trace has captured a representative sample of normal
database activity, Database Engine Tuning Advisor analyzes the
workload and then recommends an optimal configuration of indexes,
indexed views, or partitions that improve database performance.
 You can also use as workloads: Problem queries that take a long time
to run.
16
Copyright Sammamish Software Services 2013. All rights reserved.
SQL 2012 Walk throughs

Exercise: DETA Walk-through
17
Copyright Sammamish Software Services 2013. All rights reserved.
Top 5 Performance techniques
1.
2.
3.
4.
5.
For best performance, don't mix production databases and
development (test or staging) databases on the same physical
server.
Index for performance
All dev’s must understand DB design techniques and all the
tools available
Understand Disk IO (reads vs. Writes)
Understand and utilize available tools: Perfmon, Profiler, DETA,
Execution Plans, good coding practices
18
Copyright Sammamish Software Services 2013. All rights reserved.
References



Excellent Technet article:
 http://social.technet.microsoft.com/wiki/contents
/articles/5957.sql-server-performance-survivalguide.aspx
SQL Server performance web site:
 http://www.sql-server-performance.com/
An expensive but useful book:
 SQL Tips and Techniques:
 http://www.amazon.com/Tips-TechniquesMiscellaneous-KonradKing/dp/1931841454/ref=sr_1_1?ie=UTF8&qi
d=1369327498&sr=81&keywords=sql+tips+and+tricks
19
Copyright Sammamish Software Services 2013. All rights reserved.