The Database is Slow

Similar documents
Execution Plans: The Secret to Query Tuning Success. MagicPASS January 2015

Introduction. Part I: Finding Bottlenecks when Something s Wrong. Chapter 1: Performance Tuning 3

Query Performance Tuning: Start to Finish. Grant Fritchey

SQL Server 2012 Optimization, Performance Tuning and Troubleshooting

SQL Server 2012 Query. Performance Tuning. Grant Fritchey. Apress*

Dynamics NAV/SQL Server Configuration Recommendations

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

MS SQL Performance (Tuning) Best Practices:

Mind Q Systems Private Limited

SQL Server 2008 Designing, Optimizing, and Maintaining a Database Session 1

Microsoft SQL Server: MS Performance Tuning and Optimization Digital

SQL Server Performance Tuning and Optimization

SQL Server 2012 Database Administration With AlwaysOn & Clustering Techniques

How To Improve Performance In A Database

Microsoft SQL Database Administrator Certification

MS SQL Server 2014 New Features and Database Administration

SQL Server Query Tuning

Squeezing The Most Performance from your VMware-based SQL Server

Server 2008 SQL. Administration in Action ROD COLLEDGE MANNING. Greenwich. (74 w. long.)

SQL Server Query Tuning

Optimizing Performance. Training Division New Delhi

FHE DEFINITIVE GUIDE. ^phihri^^lv JEFFREY GARBUS. Joe Celko. Alvin Chang. PLAMEN ratchev JONES & BARTLETT LEARN IN G. y ti rvrrtuttnrr i t i r

Enhancing SQL Server Performance

The 5-minute SQL Server Health Check

W I S E. SQL Server 2012 Database Engine Technical Update WISE LTD.

Database Maintenance Essentials

Troubleshooting SQL Server Enterprise Geodatabase Performance Issues. Matthew Ziebarth and Ben Lin

Understanding SQL Server Execution Plans. Klaus Aschenbrenner Independent SQL Server Consultant SQLpassion.at

Best Practices. Best Practices for Installing and Configuring SQL Server 2005 on an LSI CTS2600 System

Microsoft SQL Server performance tuning for Microsoft Dynamics NAV

Throwing Hardware at SQL Server Performance problems?

Oracle Database In-Memory The Next Big Thing

ONSITE TRAINING CATALOG

Microsoft SQL Server OLTP Best Practice

Understanding Query Processing and Query Plans in SQL Server. Craig Freedman Software Design Engineer Microsoft SQL Server

Administering Microsoft SQL Server 2012 Databases

Oracle DBA Course Contents

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

Environment Optimization Guide

Tuning Microsoft SQL Server for SharePoint. Daniel Glenn

General DBA Best Practices

SQL Server Transaction Log from A to Z

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014

SQL Server Performance Tuning and Optimization. Plamen Ratchev Tangra, Inc.

Solving Performance Problems In SQL Server by Michal Tinthofer

Lecture 1: Data Storage & Index

Performance Verbesserung von SAP BW mit SQL Server Columnstore

Oracle Database 11g: SQL Tuning Workshop Release 2

DEMYSTIFY TEMPDB PERFORMANCE AND MANAGEABILITY

DBA 101: Best Practices All DBAs Should Follow

The Complete Performance Solution for Microsoft SQL Server

DMS Performance Tuning Guide for SQL Server

Analyzing & Optimizing T-SQL Query Performance Part1: using SET and DBCC. Kevin Kline Senior Product Architect for SQL Server Quest Software

Understanding and Controlling Transaction Logs

PERFORMANCE TUNING FOR PEOPLESOFT APPLICATIONS

Infor LN Performance, Tracing, and Tuning Guide for SQL Server

NIMSOFT SLM DATABASE

Oracle Database 11g: SQL Tuning Workshop

MOC 20461C: Querying Microsoft SQL Server. Course Overview

WITH A FUSION POWERED SQL SERVER 2014 IN-MEMORY OLTP DATABASE

Improve query performance with the new SQL Server 2016 Query Store!!

Best Practices Every SQL Server DBA Must Know

Course 55144: SQL Server 2014 Performance Tuning and Optimization

SQL Server 200x Optimizing Stored Procedure Performance

Improving SQL Server Performance

Database Administrator Certificate Capstone Project Evaluation Checklist

Hekaton: SQL Server s Memory-Optimized OLTP Engine

CHAPTER 8: OPTIMIZATION AND TROUBLESHOOTING

"Charting the Course... MOC AC SQL Server 2014 Performance Tuning and Optimization. Course Summary

Direct NFS - Design considerations for next-gen NAS appliances optimized for database workloads Akshay Shah Gurmeet Goindi Oracle

Performance rule violations usually result in increased CPU or I/O, time to fix the mistake, and ultimately, a cost to the business unit.

MOC 20462C: Administering Microsoft SQL Server Databases

Enterprise and Standard Feature Compare

Improve Business Productivity and User Experience with a SanDisk Powered SQL Server 2014 In-Memory OLTP Database

SQL Server Administrator Introduction - 3 Days Objectives

UBGP008: Maximizing SQL Server Performance with Microsoft Dynamics GP. John Lowther

1. This lesson introduces the Performance Tuning course objectives and agenda

Using Database Performance Warehouse to Monitor Microsoft SQL Server Report Content

ENHANCEMENTS TO SQL SERVER COLUMN STORES. Anuhya Mallempati #

Microsoft SQL Server 2008 Bible

Preview of Oracle Database 12c In-Memory Option. Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Environment Optimization Guide

Hardware/Software Guidelines

<Insert Picture Here> Best Practices for Extreme Performance with Data Warehousing on Oracle Database

There are four technologies or components in the database system that affect database performance:

Using SQL Server 2014 In-Memory Optimized Columnstore with SAP BW

Developing Microsoft SQL Server Databases 20464C; 5 Days

HP ProLiant BL660c Gen9 and Microsoft SQL Server 2014 technical brief

Microsoft SQL Server 2000 Index Defragmentation Best Practices

SQL Server 2012 Performance White Paper

Columnstore Indexes for Fast Data Warehouse Query Processing in SQL Server 11.0

SQL SERVER DEVELOPER Available Features and Tools New Capabilities SQL Services Product Licensing Product Editions Will teach in class room

Transcription:

The Database is Slow SQL Server Performance Tuning Starter Kit Calgary PASS Chapter, 19 August 2015 Randolph West, Born SQL Email: r@ndolph.ca Twitter: @rabryst

Basic Internals Data File Transaction Log File Data Page Indexes Statistics

Basic Internals: Data File Transaction Log File (LDF: Log Data File) Database File Group Data File (MDF: Main Data File) (NDF: Non-Primary Data File) 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8KB 8 x 8KB pages = 1 extent (64KB)

Basic Internals: Transaction Log File Group Transaction Log File (LDF: Log Data File) Database Commit On Write VLF VLF VLF VLF VLF VLF

Basic Internals: Page 8KB Page Header Rows ID 1: ID 2: ID 3: ID 4: ID 6: ID 5: Paul Randal (SQLskills.com): Anatomy of a Page http://goo.gl/gwnjto 5 6 4 3 2 1 Slot Array

Basic Internals: Tables IndexID PageID 1 2 Page 3 7 6 IndexID PageID 1 1 Page 2 IndexID PageID 7 5 Page 6 4 4 10 7 IndexID Province IndexID Province IndexID Province IndexID Province 1 AB 4 ON 7 SK 10 QC 2 ON 5 AB 8 YT 11 SK 3 ON 6 SK 9 YT 12 NU Page 1 Page 4 Page 5 Page 7

Basic Internals: Indexes Province PageID AB 2 Page 3 QC 6 Province PageID AB 1 Page 2 Province PageID QC 5 Page 6 ON 4 SK 5 Province IndexID Province IndexID Province IndexID Province IndexID AB 1 ON 2 QC 10 SK 11 AB 5 ON 3 SK 6 YT 8 NU 12 ON 4 SK 7 YT 9 Page 1 Page 4 Page 5 Page 7

Basic Internals: Indexes (Contd.) Heap No B-tree, no links all info stored in Index Allocation Map Clustered Index Non-Clustered Index Unique Indexes and Constraints Filtered Index Indexed View Fill Factor

Basic Internals: Statistics Distribution of Data (up to 200 steps) Density of Data (rows per step) Tipping Point (Selectivity of Data) Auto updated after 20% plus 500 rows changed All query plan costs are based on these values DBCC SHOW_STATISTICS Read more by Gail Shaw and Kimberly L Tripp

Where Do I Begin? Hardware Configuration Operating System SQL Server Configuration Monitoring Tools

Hardware CPU (SMP or NUMA?) RAM (Memory pressure?) Storage (Lots of things) Network (SAN? TCP offloading?)

Operating System Physical or Virtual? Version and Edition Drive allocation Also cluster size, partition alignment Instant File Initialization Power Saving What Else Is Running On This Server?

SQL Server Configuration Version, Edition, Build, and Licence Part of a Cluster, Mirror or Availability Group? Trace Flags (1118, 1117, 3226, and possibly 4199) sp_configure Cost Threshold for Parallelism? Appropriate to workload Max Degree of Parallelism (MAXDOP)? Cores in NUMA node Optimize for Ad-Hoc Queries? Turn it on Max Server Memory? Appropriate to environment Backup Compression? Turn it on Lightweight Pooling and Priority Boost? Turn it off Agent Jobs Maintenance tasks System Databases

User Databases Number of Databases Data and Transaction Log file allocation File growth, free space, location, VLFs I/O Performance Latency < 10ms Recovery Model Compatibility Level SQL Server 2014 Page Verify Option Always be CHECKSUM Auto-Update Statistics Always be on

Monitoring Tools WHAT IS THE BASELINE? Dynamic Management Views Missing Indexes: sys.dm_db_missing_index_details sys.dm_db_missing_index_groups Wait Statistics: sys.dm_os_wait_stats Sessions: sys.dm_exec_sessions Free Tools: sp_whoisactive (Adam Machanic) Diagnostic Scripts (Glenn Berry, SQLskills.com) sp_blitz (BrentOzar.com) sp_blitzindex (BrentOzar.com) sp_askbrent (BrentOzar.com)

Tuning Process tempdb performance Indexes Unique clustered indexes on all tables Non-clustered covering indexes (avoid key lookups) Included columns (2005+) Filtered indexes (2008+) (WHERE clause) Indexed views (materialised views) Statistics 20% plus 500 rows changed Query Tuning (the last resort)

Query Tuning Examine the longest running queries Memory consumers Sort, hash aggregate, hash join Blocking operators Sort, scalar aggregates, hash join, eager spool, any operation that can spill to disk (e.g. worktable) Types of join (nested loop, merge, hash) Key / Bookmark Lookups (try a covering index) Cursors vs CROSS APPLY Temp tables vs table variables Collation Implicit conversions Craig Freedman: http://goo.gl/h7ywsq

Tips and Tricks Stored procedures beat ad-hoc queries any day Statistics are updated at 20% plus 500 rows Avoid query hints at all costs Parameterised dynamic T-SQL can be good Tipping point (scans vs seeks) Parameter sniffing can be bad OPTIMIZE FOR UNKNOWN could be worse It depends