Download DB312: SQL Server 2005 Manageability SP2 Improvements

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

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Access wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Team Foundation Server wikipedia , lookup

Relational model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Transcript
Nye teknikker for SQL Server
Optimalisering
Jon Jahren
Produktsjef, Microsoft Norge
[email protected]
New and changed optimization features with
SP2
Best Practices Analyzer
DMV & DMVStats
Performance Dashboard
Plan Guides
LINQ
VSTS DBPro, aka “Datadude”
Microsoft Confidential
Customer Pain Points
3 New Features
Difficulty administrating
multiple instances
Desire to customize
Management Studio
Need for a best practices
tool
SQL Server 2000 “take
away” features
Multi-instance
administration
Custom Reports in
Management Studio
SQL Server 2005 Best
Practices Analyzer
VarDecimal storage
format (EE)
2 major improvements
Script Generation
Copy Database
Microsoft Confidential
Custom reports
Open your own reports without installing SSRS
Standard Reports improved scalability
New Disk Usage reports have been tested on SAP
Improved discoverability
Reports can be accessed from Object Explorer
context menu
Improved usability
Open reports in new window
Compare reports
List of most recently used
Microsoft Confidential
Reduces time spent in diagnosing root cause
of problems
Scans multiple servers remotely
Helps identify potential problems as defined by
Microsoft
Educates users on best practices
Provides interactive reporting
Each rule has corresponding article
Microsoft Confidential
The SQL Server 2005 Management Pack
monitors performance and availability of:
SQL Server agent
Database health and transaction log free space
SQL Server clustering and named instances
Local and remote connectivity
Security
SQL Server replication
Microsoft Confidential
6
Management Pack Benefits:
•
Granular discovery, monitoring and reporting of SQL
Server components
•
Client perspective of SQL database availability
•
Database space and growth monitoring
•
Replication discovery and monitoring
•
SQL agent job discovery and monitoring
•
Blocking processes, long running jobs and general
performance monitoring of SQL
•
SQL Configuration monitoring
•
Granularity to change monitoring behavior on a per
object level
Microsoft Confidential
7
Perfmon
SQL Trace (profiler)
DBCC
DMVs and DMFs
DAC (Dedicate Admin Connection)
DTA (Database Tuning Advisor)
Physical Dump
Microsoft Confidential
Dynamic Management Views
Also known as DMVs
Expose server state as a relational rowset
State is generally in memory (not persisted)
Not new. DMVs in SQL2000 (sysprocesses)
Low overhead (approx 2%)
Many DMVs expose information that needs to be
maintained anyway
What’s new for SQL2005?
Many more DMVs and a new framework
Microsoft Confidential
General Server DMVs and DMFs
Server level
Component level
dm_exec_*
dm_repl_*
Execution of user code and
associated connections
Replication
dm_os_*
dm_broker_*
low level system (serverwide) info such as memory,
locking & scheduling
SQL Service Broker
dm_fts_*
dm_tran_*
Transactions & isolation
Full Text Search
dm_io_*
dm_qn_*
Input/Output on network
and disks
Query Notifications
dm_db_*
dm_clr_*
Databases and database
objects
CLR execution of managed
code
Microsoft Confidential
DMV Examples
sys,.dm_io_virtual_file_stats
Sys.dm_os_scheduler
Sys.dm_tran_active_transactions
Sys.dm_exec_query_stats
sys,.dm_exec_requests
Sys.dm_db_index_usage_statistics
sys.dm_db_index_operational_stats
Sys.dm_os_wait_stats
Microsoft Confidential
How to use DMVs
Challenge
Need to know a lot about SQL Internals
Need to apply a specific methodology to identify
problems
Solution
Use scripts for common performance issues
Use DMVstats Tool
Microsoft Confidential
What is DMVstats?
DMV collection, analysis, and reporting
application
Data collection managed by SQLAgent jobs
DMVstatsDB - performance data warehouse
repository of DMV statistics
Analysis and reporting provided by DMVstats
Reports
Microsoft Confidential
DMVstats Objectives
Provide Expert Guidance from the experience,
lessons learned, and best practices from
Microsoft's SQL Server Development
Customer Team.
Methodology: Provides performance analysis
by using the proven Waits and Queues
Educate user
Microsoft Confidential
SQL Server Best Practices Site
On TechNet
Get the real-world guidelines, expert tips, and rock-solid guidance to
take your SQL Server implementation to the next level.
http://www.microsoft.com/technet/prodtechnol/sql/bestpracti
ce/default.mspx
Contents
Technical Whitepapers
ToolBox
Top 10 Lists
Ask a Question
Other Resources
SQLCAT Blog: http://blogs.msdn.com/sqlcat/
SQL ISV PM Blog: http://blogs.msdn.com/mssqlisv/
Microsoft Confidential
SQL Server has three types are hints
JOIN hint
Use loop, hash, merge to join table
Can specify side for REMOTE join
QUERY hint
Many of these
TABLE hint
Use table scan
Use one or more indexes
Locking hints
Microsoft Confidential
{ HASH | ORDER } GROUP
{ CONCAT | HASH | MERGE } UNION
{ LOOP | MERGE | HASH } JOIN
FAST number_rows
FORCE ORDER
MAXDOP number_of_processors
OPTIMIZE FOR ( @variable_name = literal_constant [ ,…n ]]
PARAMETERIZATION { SIMPLE | FORCED }
RECOMPILE
ROBUST PLAN
KEEP PLAN
KEEPFIXED PLAN
EXPAND VIEWS
MAXRECURSION number
USE PLAN N'xml_plan'
Microsoft Confidential
Query hints cannot be applied if you don’t have
access to the source code
Dynamically generated
Purchased package
Query hints tie the hint to the source code
No straightforward way to disable
Always using procedures helps this
Enter plan guides…
Microsoft Confidential
Plan guide is a named database object
Only available in Standard and Enterprise
Associates a hint with a query
Lives at database scope
Defined and maintained through system procs
sp_create_plan_guide
Can be enabled or disabled
sp_control_plan_guide
sp_create and sp_control flush appropriate query
cache entries
sys.plan_guides holds plan guide metadata
Microsoft Confidential
Query must match exactly
Including whitespace and CR/LF
Use profiler to capture query
Right click and choose Extract Command
Paste command into sp_create_plan_guide
Use XML query plan to ensure its working
Plan guide used is in query plan
Enabling plan guides clears plan cache
Microsoft Confidential
If the existing query uses a hint, the hint text
must be specified in the plan guide
The plan guide hint(s) takes the place of the
hint specified in the query
You can include the original hint in the plan guide if
additive hints are desired
Microsoft Confidential
Plan guides "pin" an object, i.e. can't change
until you drop the plan guide
Plan guides can be done anywhere you use a
query hint
SELECT, INSERT, UPDATE, DELETE
Plan forcing - only SELECT, SELECT INTO
Text must match character for character
Cannot be used with encrypted objects or DDL
triggers
A "few dozen" queries is limit of plan guides
Do not hand-edit XML showplans
Microsoft Confidential
Specified via USE PLAN query hint
Capture XML showplan
Paste into sp_create_plan_guide
Or paste into query directly
Plan guide not required
Make sure all single quotes are escaped
Plan forcing works with
SELECT
SELECT INTO
Microsoft Confidential
Isn’t plan forcing a security problem?
No, it must be
A plan that matches the query
A plan that the optimizer would normally consider
Is plan forcing faster because plan doesn’t
need to be chosen?
No
The plan must be parsed and checked
It’s actually a little slower (optimization times are slightly
increased)
Should I turn off statistics if I force plans?
No, stats are used for memory estimates
Microsoft Confidential
C# 3.0
VB 9.0
Others…
.NET Language Integrated Query
LINQ to
Objects
LINQ to
DataSets
LINQ to
SQL
LINQ to
Entities
LINQ to
XML
<book>
<title/>
<author/>
<year/>
<price/>
</book>
Objects
Relational
Microsoft Confidential
XML
Accessing data today
SqlConnection c = new
SqlConnection(…);
c.Open();
SqlCommand cmd = new
SqlCommand(
@"SELECT c.Name, c.Phone
FROM Customers c
WHERE c.City = @p0");
cmd.Parameters.AddWithValue("@p0",
"London“);
DataReader dr = c.Execute(cmd);
while (dr.Read()) {
string name = dr.GetString(0);
Microsoft Confidential
Queries in
quotes
Loosely
bound
arguments
Loosely
typed result
sets
No compile
time checks
Accessing data with LINQ
public class Customer { … }
public class Northwind :
DataContext
{
public Table<Customer>
Customers;
Northwind db = new
…
Northwind(…);
}var contacts =
from c in db.Customers
where c.City == "London"
select new { c.Name, c.Phone
Microsoft Confidential
Classes
describe
data
Tables are
like
collections
Strongly
typed
connections
Integrated
query
syntax
Strongly
typed
results
from c in db.Customers
where c.City == "London"
select c.CompanyName
Application
db.Customers.Add(c1);
c2.City = “Seattle";
db.Customers.Remove(c3);
LINQ Query Objects SubmitChanges()
LINQ to SQL
SQL Query Rows
DML or SProcs
INSERT INTO Cust …
UPDATE Cust …
DELETE FROM Cust …
SELECT CompanyName
FROM Cust
WHERE City = 'London'
SQL Server
Microsoft Confidential
Database Schema
Class Schema
Microsoft Confidential
Other names you might hear:
Data Dude
K2
TSData
DBPro
Microsoft Confidential
Incorporate the Database Professional into the software lifecycle and
provide them with a foundation for change management and process
integration.
Change Management
Project Based Development
Project Model in Visual Studio with Support for Team Collaboration via Team
Foundation Server Automated Change Support
Rename Refactoring, Schema & Data Comparison Tools, and Version Control
Database Unit Testing
Leverages the existing Test Project Infrastructure with support for data generation
Build / Deployment
MSBuild and Team Build integration
Microsoft Confidential
Writes DB Code
Creates New DB
Project
Reverse Engineers DB
to Project
Creates Data
Generation Plan
Refactors
Runs Tests
Reviews Changes
Checks In
Compares Updates to
Production
Works with other
developers to
integrate
Builds Deploy
Package
Deploys to Production
Manage
DBA
Develop
DB DEVELOPER
Microsoft Confidential
Deploy
DBA
Team Database Development with Data Dude
Writes Tests
Schema Change now managed in VSTS
and TFS
Production Database is now “One version
of the truth” only for Data
DBA doesn’t have access to changes until
he/she has deploy or reject choice
“One Version of the truth for Schema” is
kept under Source Control
Production
Database
Schema
“One Version of the
Truth” for Schema
• Offline
• Under Source Control
Schema Changes
Microsoft Confidential
SQL Server 2005
Management Studio
Tuning
Monitoring
“One Version of
the Truth” for Data
Changes can be rolled out
in a scheduled, managed
way
Scripts allow administrators
to manage change updates
Rich engine allows for sample data generation
Useful because it’s often not feasible (or even
legal) to use production data
Allows for repeatable test scenarios
Support for different types of generators
Simple for standard data types
Complex for regular expressions, foregin key
lookup, data bound
And yes, you can write your own
Microsoft Confidential
New and changed optimization features with
SP2
Best Practices Analyzer
DMV & DMVStats
Performance Dashboard
Plan Guides
LINQ
VSTS DBPro, aka “Datadude”
Microsoft Confidential