Common SQL Server Mistakes and How to Avoid Them with Tim Radney

13
EMBARCADERO TECHNOLOGIES Common SQL Server Mistakes and How to Avoid Them Tim Radney SQL Server MVP

description

Watch the companion webinar at: http://embt.co/1ueUSsP Making mistakes is human nature, avoiding them comes from experience and shared wisdom from others. Tim Radney, Production DBA and Manager, and Embarcadero’s Scott Walz would like to share some SQL server wisdom on “gut check” strategies that can help you avoid making SQL server mistakes. Making mistakes is human nature, avoiding them comes from experience and shared wisdom from others. Tim Radney, Production DBA and Manager, and Embarcadero’s Scott Walz would like to share some SQL server wisdom on “gut check” strategies that can help you avoid making SQL server mistakes. Watch the webinar to learn: - Backups – are yours good enough? - Maintenance – learn about regular a maintenance that can keep your SQL Server running its best. - Instance Configurations - Which settings should you be aware of that can make a huge difference? - Baselines and why they are important.

Transcript of Common SQL Server Mistakes and How to Avoid Them with Tim Radney

Page 1: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIES

Common SQL Server Mistakes and How to Avoid ThemTim RadneySQL Server MVP

Page 2: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

2www.linchpinpeople.com

Tim Radney

@tradneytimradney.com

linked.com/in/tradneyfacebook.com/radneysqlgoogle.com/+TimRadney

Specialties / Focus Areas / Passions:• Performance Tuning &

Troubleshooting• Capacity Management• Infrastructure• Virtualization• SQL Consolidation

• High Availability• Disaster Recovery• Health Monitoring• Architecture• License Efficiency• Chicken & Tilapia

Farmer

Linchpin People - Partner

Microsoft MVPChapter Leader “Columbus GA SQL Users Group”Pass Regional Mentor “South East USA”

Page 3: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

3

Backups

Do you have recent backups

• Is the current backup strategy adequate for the SLA of the system• How often is it being backed up, can you do a point in time recovery• Do you have the right recovery model

• Is there a plan in place to validate the backups• When is the last time a test recovery was performed

• Script to check for frequency of backups• http://timradney.com/backups

Page 4: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

4

Consistency Checks

Do you have corruption in your newly acquired databases

• Is there a scheduled task/job to run DBCC CHECKDB• It is debatable how often this should be ran. Some say daily and others say weekly, as with everything

SQL Server related “IT DEPENDS”, in this case, how much data loss can you handle

DBCC CHECKDBDBCC CHECKALLOCDBCC CHECKFILEGROUP

Page 5: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

5

Log Cleanup

Pruning Records• MSDB stores all backup and restore history

• sp_delete_backuphistoryUSE msdb;GOEXEC sp_delete_backuphistory '01/01/2014'

• Error Log Cleanup• EXEC sp_cycle_errorlog• Increase default value from 6 to some number up to 99

http://www.littlehouseinthebigweeds.com/wp-content/uploads/2008/02/pruning.jpeg

Page 6: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

6

Statistics

Are your statistics up to date

•Are your statistics up to date• sp_updatestats• Is there a job to manually update stats• Ola Hallengren – excellent process for updating statistics• Is “Auto Update Statistics” turned on

• Auto Update Statistics typically update after 20% of the rows change

•Impact of Statistics to the Query Optimizer• The Query Optimizer uses statistics to build the execution plan. Without current statistics you are pretty much

guaranteed to NOT have the “good enough” execution plan

Page 7: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

7

Index Maintenance

• What causes fragmentation• Data modifications (Insert, Delete, Updates)

• Why should you care about fragmented indexes• Whitepaper from Microsoft stated fragmentation can slow down systems from 13% to 460% based on the size of the environment and

fragmentation level

• How do you fix this• You can rebuild, reorganize, or drop and recreate your indexes.• Can schedule rebuilds using a maintenance plan (ok for small db’s).• You can use a custom script and run it in a SQL Job• You can use third party tools• Check out ola.hallengren.com

• Duplicate Indexes• Indexes that are exact duplicates are bad and should be removed• Lots of scripts and apps to detect duplicate indexes out there

Page 8: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

8

Memory Settings

Set Limits• Max and Min Values 2008R2 and below

• Max Default is 2147483647 or 2 PB• Min value is set to 0• Potential for SQL to starve the OS and OS to starve SQL• Max memory applies to the buffer pool

• SQL 2012• Memory Manager redesign• Max memory applies to all memory manager allocations• Can consider letting SQL Server dynamically manage memory

Page 9: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

9

Max DOP & Cost Threshold

Defaults need tweaking• MAXDOP = Max Degree of Parallelism

• Default is set to zero (0)• Default means ‘unlimited’ number of CPU’s could

be used to execute a parallel region of a query• Microsoft recommendation states if more than 8 CPU’s

start with 8 and modify from there.• For 8 or fewer processors use 0 to N.• http://support.microsoft.com/kb/2806535

• Cost Threshold for Parallelism• Query cost/subtree cost• Default value is 5. Many in the industry recommend

increasing this value to 30 and adjust up from there

Page 10: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

10

TempDB

Unique Database• Special Characteristics

• Recreated at startup• Serves entire instance• Modeled after the model database*• Cannot be backed up

• Considerations• When 8 cores or less, one per core. Greater than 8 cores start with 8 and increase by 4 based on

contention. (http://support.microsoft.com/kb/2154845)• Place data files on separate disk with fast IO

Page 11: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

11

SQL Server Alerts

Proactive Monitoring• Requires Database Mail

• Configure a mail operator to send alerts to• Include a distribution group that would work the issues

• Agent Alerts• Severity 16 – 25 errors and errors 823 - 825• Agents can be created through GUI or Script

Page 12: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

12

Power Savings

Power Savings = Loss of power• Power Savings has negative impact for SQL Server

• Can under clock your CPU• Not conducive to SQL CPU behavior• Set power setting to “High Performance” rather than “Balanced Power”• Disable power savings in BIOS• Free tool CPUz is great at showing clock speed in use• Other power settings can be bad to such as putting a NIC to sleep

Page 13: Common SQL Server Mistakes and How to Avoid Them with Tim Radney

EMBARCADERO TECHNOLOGIES

13