T-SQL Tuesday #94 – Lets get all Posh!
Rob Sewell aka sqldbawithabeard (b|t) hosts this month T-SQL Tuesday and surprisingly his subject is PowerShell.
I will describe what I’ll use for testing against Best Practices Commands for SQL Server.
I got in contact with PowerShell some years ago, but was not satisfied with what needs to be done before maintaining SQL Server.
Meanwhile Microsoft has done a lot more and with the contribution from several PowerShell Experts and MVPs as Chrissy LeMaire, Claudio Silva, Rob Sewell, Constantine Kokkinos and many more, there is a module created that helps to maintain SQL Server 2005+. This is called dbatools and the website can be reached at https://dbatools.io. The Project is hosted on Github and using the commands is totally free of charge!
The community has grown to over 50 contributors and over 200 SQL Server best practices, administration and migration commands. An Overview of the commands can be found here: https://dbatools.io/functions/
Now I will describe some of the dbatools commands to Test our SQL Server against Best Practices mentioned by SQL Server Experts. You can find all of the information and Links in the description to the commands.
- Max Memory
- This tests the actual max memory setting against the recommended setting.
-
Test-DbaMaxMemory -SqlServer sqlserver01 # command to set the max memory to the recommended Set-DbaMaxMemory -SqlServer sqlserver01 # or to a fix value of 2 GB Set-DbaMaxMemory -SqlInstance sqlserver01 -MaxMb 2048
- TempDB
- with SQL Server 2016 you get the option to configure the TempDB Configuration during installation, with this commands you can control and fix it.
- Test-DbaTempDbConfiguration
- Evaluates tempdb against a set of rules to match best practices.
The rules are:
– Is Trace Flag 1118 enabled (See KB328551).
– File Count: Does the count of data files in tempdb match the number of logical cores, up to 8.
– File Growth: Are any files set to have percentage growth, as best practice is all files have an explicit growth value.
– File Location: Is tempdb located on the C:\? Best practice says to locate it elsewhere.
– File MaxSize Set(optional): Do any files have a max size value? Max size could cause tempdb problems if it isn’t allowed to grow. - (Screenshot from dbatools.io – my configurations are all fine 🙂 )
- The right configuration can be set by using the corresponding Set- command
- Disk-Configuration
- PowerPlan
- SPN
- We use DNS CNAMEs for referring to our SQL Server (2). We need to adjust the SPN Settings manually. That is easy with these commands:
Get-DbaSpn / Set-DbaSPN
- We use DNS CNAMEs for referring to our SQL Server (2). We need to adjust the SPN Settings manually. That is easy with these commands:
- SQL Server Name
- We created a Single VM template where all SQL Server are created from. With CPU, Memory and Disk Layout.
- After creating a new VM out of the template the Server Name changes but not the SQL Server Name internally. Help comes again with dbatools command: Repair-DbaServerName
Works fine for me!
Theses are the commands we use often in our environment, there are many more to choose from on the dbatools website.
Thanks to Rob for hosting this month T-SQL Tuesday and thanks to all other attendees to convince me writing a blog post. Thanks also to Adam Bertram who chooses me writing for #PSBlogWeek. You all can attend until this friday (2017-09-15). http://psblogweek.com/
Thanks for Reading,
Volker