Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
SQL Server Best Practices
Install SQL Server like a boss
Andre Essing
1
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
The Key for a Perfect System
• Balanced system without bottlenecks
• SQL Server is only a small part
• Plan your system before you build it
Processor Memory Storage HBA Networking
2
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Andre Essing
Technology Solutions Professional
Microsoft Deutschland GmbH
Andre advises, in his role as Technology Solutions
Professional, customers in topics all around the
Microsoft Data Platform. He is specialized in mission
critical systems, high-availability, security, operating
and of course the cloud.
/aessing @aessing aessingandre.essing@microsoft.com /Andre_Essing
3
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Pre-Deployment
4
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Hardware & Storage
• Use the optimal storage
• Handle volumes the right way
• Implement a good disk layout
• Do backups remotely
• Don’t save power
▪ Use the right storage
▪ HDD, SSD or Flash
▪ RAID Level
▪ Direct Attached or SAN
▪ iSCSI or FibreChannel
▪ Read caching isn’t necessary, SQL Server does the buffering
▪ Prefer more smaller disks than one large
▪ Low latency (Disk Access) is important
▪ Don’t use thin provisioning
▪ Handle volumes the right way
▪ Check partition alignment
http://msdn.microsoft.com/en-us/library/dd758814.aspx
▪ Format volumes the right way
▪ NTFS, 64KB, no quick format
▪ Disable file indexing and automatic defragmentation
▪ Implement a good disk layout
▪ Use more than one disks
▪ Separate disks for data, transaction log and TempDB
▪ Use mountpoints
▪ Consider max IOPs / size per disk
▪ Do backups remotely
▪ Consider a remote backup location
▪ UNC Path works great
5
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
▪ Backup to Azure Blob Storage as offsite backup
▪ Don’t save power
▪ Disable power savings everywhere
SQL Server Best Practices
SQL Server Konferenz 2017 14.02.2017
5
Operating System
• Performance is important
• Don’t forget about security…
• … and the user permissions
• Just in case, I talk about Windows here
▪ Performance is important
▪ Set power plan to high performance
▪ Check what’s better: Hyperthreading off or on
▪ Don’t forget about security…
▪ Antivirus software & exclusions
https://support.microsoft.com/en-us/kb/309422
▪ Windows Firewall & User Access Control is a good thing, enable them
▪ A server is not a workstation, so don’t use it as one
▪ Think about Windows Server Core for SQL Server installations
▪ … and the user permissions
▪ Local Security Policy -> SQL Server Service account rights are a must have
▪ Lock Pages In Memory
▪ Perform Volume Maintenance Tasks
6
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Setup
7
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Installation
• How much SQL you need
• Don’t repeat yourself
• Security… again!
• A server is not a workstation
▪ How much SQL you need
▪ Only install components you really need
▪ Choose the correct collation
▪ Don’t repeat yourself
▪ Install using a configuration file
▪ Security… again!
▪ Don‘t forget to install updates
▪ Use Service Accounts instead of “Local System”
▪ BUILTINAdministrators isn’t a good idea for SQL Server DBAs
▪ Use a domain group for DBAs only
▪ A server is not a workstation
8
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Post-Deployment
9
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Instance
• Make it easy to connect
• Security… again… are you kidding?
• Perhaps, Trace Flags
• Instance Settings
▪ Make it easy to connect
▪ Use same port for all instances / availability groups
▪ Easier for migrations
▪ Easier to remember
▪ Use DNS alias for easy access
▪ Use A-Records to avoid problems with Kerberos Auth
▪ Transparent access for the users
▪ No application changes on migrations and database moves
▪ Security… again… are you kidding?
▪ Don’t use SQL Logins, Windows Auth is more secure
▪ Set SPNs to use Kerberos authentication with Windows Auth
▪ Perhaps, Trace Flags
▪ Trace Flag 1117
▪ Equally grows all data files
▪ Replaced in 2016 by filegroup option
(AUTOGROW_ALL_FILES - sys.filegroups)
▪ Recommended for all filegroups and databases
▪ Trace Flag 1118
▪ Force use of unified extents for objects
▪ Replaced in 2016 by database option
(MIXED_PAGE_ALLOCATION - sys.databases)
▪ Default in SQL Server 2016 for new databases
▪ Instance Settings
10
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
▪ Configure memory limits, especially “max server memory“
▪ Enable “Optimize for ad hoc workloads”
▪ Configure Max Degree of Parallelism
▪ Not higher than cores per socket / NUMA Node
▪ Some apps need a value of 1, check documentation
▪ Configure Cost Threshold for Parallelism
▪ Good start value for OLTP workloads: 40
▪ Good start value for DWH and mixed workloads: 25
SQL Server Best Practices
SQL Server Konferenz 2017 14.02.2017
10
TempDB
• Split into multiple files
• Size and growth does matter
• Keep an eye on it
• Before SQL 2016, remember the Trace Flags
▪ Split into multiple files
▪ There are a lot of complicated rules out there
▪ Just use TempDB with 8 files, more usually achieve no big advantage
▪ Always 8 files is easier to maintain
▪ In some rare cases more then 8 files brings some advantage
▪ Size and growth does matter
▪ Size depends on TempDB usage
▪ Monitor old system, ask the vendor or guess
▪ Start with 2GB per data file and 8GB log (if you don’t know)
▪ Growth: 256MB for data and 1GB for log
▪ Keep an eye on it
▪ Monitor TempDB usage
▪ If TempDB grows, set new size as initial size (include a buffer)
▪ Before SQL 2016, remember the Trace Flags
▪ Set Trace Flag 1117 and 1118
11
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
Database
• Take care of the defaults
• Keep as reliable as you can
• The physical design matters
• Don’t mess-up with the security
▪ Take care of the defaults
▪ Set the default fill factor
▪ 0 means 100%
▪ Best practice is 70% or 80%
▪ The setting is just for “new” objects
▪ Keep an eye on fragmentation
▪ Never enable Auto_Close or Auto_Shrink
▪ It always leads you into performance issues
▪ With Auto_Shrink enabled, disk fragmentation is your new friend ;o)
▪ Enable Auto_Create_Statistics and Auto_Update_Statistics
▪ Most database haven’t the right statistics implemented
▪ Normally the settings increase the speed of your queries
▪ Should be enabled if not forbidden by the software vendor
▪ Keep as reliable as you can
▪ Always use Full Recovery Model, without exception
▪ For temporary databases and staging databases the Single Recovery Model is ok
▪ Usually reliability is more important than speed
▪ Don’t be afraid, using Full Recovery Model is easier than it sounds
▪ Don’t forget to do transaction log backups
▪ The physical design matters
▪ When possible, primary filegroup only for MDF
▪ Create extra filegroups for your data
▪ If not possible, just add files to primary filegroup
▪ Start with 4 files per filegroup
▪ Set size and growth of files
▪ Estimate the database size for the next year(s)
12
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
▪ The files shouldn’t grow automatically
▪ Keep autogrowth enabled for safety reasons
▪ 256MB autogrowth for data and 1GB for log
▪ Keep an eye on VLFs
▪ DBCC LOGINFO
▪ Don’t mess-up with the security
▪ Don’t assign DB_Owner role to users
▪ Build user roles with the right permissions instead
▪ Don’t assign the dbo to a normal user
▪ Assign to sa or to special login
SQL Server Best Practices
SQL Server Konferenz 2017 14.02.2017
12
Maintenance
• Don’t forget instance and database maintenance
• Backup checksum and compression
• Don‘t do plans, script the tasks
• Never shrink during maintenance
▪ Don’t forget instance and database maintenance
▪ Daily Backups (Full and perhaps differential)
▪ Transaction log backups (every 5 – 15 minutes)
▪ Integrity checks (daily)
▪ Index reorganize or rebuild (daily)
▪ Update statistics (daily)
▪ Clean up backup and job history (daily)
▪ Cleanup mail items (daily)
▪ Backup checksum and compression
▪ Enable Compress Backups by default
▪ Saves I/O and disk space
▪ Faster backups
▪ A bit more CPU usage during backup
▪ No reason to not turn it on
▪ Checksum default
▪ No GUI, not documented, but ok to use
▪ EXEC sp_configure ‘backup checksum default’, 1; GO RECONFIGURE
WITH OVERRIDE; GO
▪ No reason to not turn it on
▪ Don‘t do plans, script the tasks
▪ Don’t use maintenance plans
▪ Scripts are…
▪ …better reuseable
▪ …more flexible
▪ …more intelligent
▪ Use maintenance scripts
13
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
▪ Ola Hallengren (https://ola.hallengren.com/)
▪ or from other vendors
▪ or build your own
▪ Never shrink during maintenance
▪ Same problems as AUTO_SHRINK
SQL Server Best Practices
SQL Server Konferenz 2017 14.02.2017
13
Questions & answers…
14
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017
15
14.02.2017
SQL Server Best Practices
SQL Server Konferenz 2017

More Related Content

SQL Server Best Practices - Install SQL Server like a boss (RELOADED)

  • 1. SQL Server Best Practices Install SQL Server like a boss Andre Essing 1 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 2. The Key for a Perfect System • Balanced system without bottlenecks • SQL Server is only a small part • Plan your system before you build it Processor Memory Storage HBA Networking 2 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 3. Andre Essing Technology Solutions Professional Microsoft Deutschland GmbH Andre advises, in his role as Technology Solutions Professional, customers in topics all around the Microsoft Data Platform. He is specialized in mission critical systems, high-availability, security, operating and of course the cloud. /aessing @aessing aessingandre.essing@microsoft.com /Andre_Essing 3 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 4. Pre-Deployment 4 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 5. Hardware & Storage • Use the optimal storage • Handle volumes the right way • Implement a good disk layout • Do backups remotely • Don’t save power ▪ Use the right storage ▪ HDD, SSD or Flash ▪ RAID Level ▪ Direct Attached or SAN ▪ iSCSI or FibreChannel ▪ Read caching isn’t necessary, SQL Server does the buffering ▪ Prefer more smaller disks than one large ▪ Low latency (Disk Access) is important ▪ Don’t use thin provisioning ▪ Handle volumes the right way ▪ Check partition alignment http://msdn.microsoft.com/en-us/library/dd758814.aspx ▪ Format volumes the right way ▪ NTFS, 64KB, no quick format ▪ Disable file indexing and automatic defragmentation ▪ Implement a good disk layout ▪ Use more than one disks ▪ Separate disks for data, transaction log and TempDB ▪ Use mountpoints ▪ Consider max IOPs / size per disk ▪ Do backups remotely ▪ Consider a remote backup location ▪ UNC Path works great 5 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 6. ▪ Backup to Azure Blob Storage as offsite backup ▪ Don’t save power ▪ Disable power savings everywhere SQL Server Best Practices SQL Server Konferenz 2017 14.02.2017 5
  • 7. Operating System • Performance is important • Don’t forget about security… • … and the user permissions • Just in case, I talk about Windows here ▪ Performance is important ▪ Set power plan to high performance ▪ Check what’s better: Hyperthreading off or on ▪ Don’t forget about security… ▪ Antivirus software & exclusions https://support.microsoft.com/en-us/kb/309422 ▪ Windows Firewall & User Access Control is a good thing, enable them ▪ A server is not a workstation, so don’t use it as one ▪ Think about Windows Server Core for SQL Server installations ▪ … and the user permissions ▪ Local Security Policy -> SQL Server Service account rights are a must have ▪ Lock Pages In Memory ▪ Perform Volume Maintenance Tasks 6 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 8. Setup 7 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 9. Installation • How much SQL you need • Don’t repeat yourself • Security… again! • A server is not a workstation ▪ How much SQL you need ▪ Only install components you really need ▪ Choose the correct collation ▪ Don’t repeat yourself ▪ Install using a configuration file ▪ Security… again! ▪ Don‘t forget to install updates ▪ Use Service Accounts instead of “Local System” ▪ BUILTINAdministrators isn’t a good idea for SQL Server DBAs ▪ Use a domain group for DBAs only ▪ A server is not a workstation 8 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 10. Post-Deployment 9 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 11. Instance • Make it easy to connect • Security… again… are you kidding? • Perhaps, Trace Flags • Instance Settings ▪ Make it easy to connect ▪ Use same port for all instances / availability groups ▪ Easier for migrations ▪ Easier to remember ▪ Use DNS alias for easy access ▪ Use A-Records to avoid problems with Kerberos Auth ▪ Transparent access for the users ▪ No application changes on migrations and database moves ▪ Security… again… are you kidding? ▪ Don’t use SQL Logins, Windows Auth is more secure ▪ Set SPNs to use Kerberos authentication with Windows Auth ▪ Perhaps, Trace Flags ▪ Trace Flag 1117 ▪ Equally grows all data files ▪ Replaced in 2016 by filegroup option (AUTOGROW_ALL_FILES - sys.filegroups) ▪ Recommended for all filegroups and databases ▪ Trace Flag 1118 ▪ Force use of unified extents for objects ▪ Replaced in 2016 by database option (MIXED_PAGE_ALLOCATION - sys.databases) ▪ Default in SQL Server 2016 for new databases ▪ Instance Settings 10 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 12. ▪ Configure memory limits, especially “max server memory“ ▪ Enable “Optimize for ad hoc workloads” ▪ Configure Max Degree of Parallelism ▪ Not higher than cores per socket / NUMA Node ▪ Some apps need a value of 1, check documentation ▪ Configure Cost Threshold for Parallelism ▪ Good start value for OLTP workloads: 40 ▪ Good start value for DWH and mixed workloads: 25 SQL Server Best Practices SQL Server Konferenz 2017 14.02.2017 10
  • 13. TempDB • Split into multiple files • Size and growth does matter • Keep an eye on it • Before SQL 2016, remember the Trace Flags ▪ Split into multiple files ▪ There are a lot of complicated rules out there ▪ Just use TempDB with 8 files, more usually achieve no big advantage ▪ Always 8 files is easier to maintain ▪ In some rare cases more then 8 files brings some advantage ▪ Size and growth does matter ▪ Size depends on TempDB usage ▪ Monitor old system, ask the vendor or guess ▪ Start with 2GB per data file and 8GB log (if you don’t know) ▪ Growth: 256MB for data and 1GB for log ▪ Keep an eye on it ▪ Monitor TempDB usage ▪ If TempDB grows, set new size as initial size (include a buffer) ▪ Before SQL 2016, remember the Trace Flags ▪ Set Trace Flag 1117 and 1118 11 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 14. Database • Take care of the defaults • Keep as reliable as you can • The physical design matters • Don’t mess-up with the security ▪ Take care of the defaults ▪ Set the default fill factor ▪ 0 means 100% ▪ Best practice is 70% or 80% ▪ The setting is just for “new” objects ▪ Keep an eye on fragmentation ▪ Never enable Auto_Close or Auto_Shrink ▪ It always leads you into performance issues ▪ With Auto_Shrink enabled, disk fragmentation is your new friend ;o) ▪ Enable Auto_Create_Statistics and Auto_Update_Statistics ▪ Most database haven’t the right statistics implemented ▪ Normally the settings increase the speed of your queries ▪ Should be enabled if not forbidden by the software vendor ▪ Keep as reliable as you can ▪ Always use Full Recovery Model, without exception ▪ For temporary databases and staging databases the Single Recovery Model is ok ▪ Usually reliability is more important than speed ▪ Don’t be afraid, using Full Recovery Model is easier than it sounds ▪ Don’t forget to do transaction log backups ▪ The physical design matters ▪ When possible, primary filegroup only for MDF ▪ Create extra filegroups for your data ▪ If not possible, just add files to primary filegroup ▪ Start with 4 files per filegroup ▪ Set size and growth of files ▪ Estimate the database size for the next year(s) 12 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 15. ▪ The files shouldn’t grow automatically ▪ Keep autogrowth enabled for safety reasons ▪ 256MB autogrowth for data and 1GB for log ▪ Keep an eye on VLFs ▪ DBCC LOGINFO ▪ Don’t mess-up with the security ▪ Don’t assign DB_Owner role to users ▪ Build user roles with the right permissions instead ▪ Don’t assign the dbo to a normal user ▪ Assign to sa or to special login SQL Server Best Practices SQL Server Konferenz 2017 14.02.2017 12
  • 16. Maintenance • Don’t forget instance and database maintenance • Backup checksum and compression • Don‘t do plans, script the tasks • Never shrink during maintenance ▪ Don’t forget instance and database maintenance ▪ Daily Backups (Full and perhaps differential) ▪ Transaction log backups (every 5 – 15 minutes) ▪ Integrity checks (daily) ▪ Index reorganize or rebuild (daily) ▪ Update statistics (daily) ▪ Clean up backup and job history (daily) ▪ Cleanup mail items (daily) ▪ Backup checksum and compression ▪ Enable Compress Backups by default ▪ Saves I/O and disk space ▪ Faster backups ▪ A bit more CPU usage during backup ▪ No reason to not turn it on ▪ Checksum default ▪ No GUI, not documented, but ok to use ▪ EXEC sp_configure ‘backup checksum default’, 1; GO RECONFIGURE WITH OVERRIDE; GO ▪ No reason to not turn it on ▪ Don‘t do plans, script the tasks ▪ Don’t use maintenance plans ▪ Scripts are… ▪ …better reuseable ▪ …more flexible ▪ …more intelligent ▪ Use maintenance scripts 13 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 17. ▪ Ola Hallengren (https://ola.hallengren.com/) ▪ or from other vendors ▪ or build your own ▪ Never shrink during maintenance ▪ Same problems as AUTO_SHRINK SQL Server Best Practices SQL Server Konferenz 2017 14.02.2017 13
  • 18. Questions & answers… 14 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017
  • 19. 15 14.02.2017 SQL Server Best Practices SQL Server Konferenz 2017