Skip to main content

Changes to the default installation of SQL Server

SQL Server pretty much works out of the box – go through the install wizard, click Next, Next, Next… create a database and off you go. However, that doesn't mean that everything is taken care of and no further changes are required.

There are some changes that I like to make to the vanilla installation – some of these are personal preference but I think all of them afford benefits. As I work for a project team I often have to install SQL Server on new hardware. I follow through the list below to ensure I have covered everything.

I have a selection of SQL jobs I like to set up and some server configuration options. I won’t be dealing with hardware aspects or RAID configuration but with changes to SQL Server software configuration itself, however, I may write a post about those in the future.

So here it is:

Model Database

Change Model DB to SIMPLE Recovery Model and that files are set to grow by megabytes and not percent - so any future databases created inherit these properties.

Configure database mail

Some of the scripts below rely on an Operator to be configured to send alerts to so we will need to configure Database Mail. This is out of scope for this article but details can be found here.

Configure SQL Agent job notification emails 

After you have configured Database Mail you need to configure the SQL Agent to use it. Follow these steps:

  1. Right Click on SQL Server Agent, Select properties.
  2. Select Alert System.
  3. Select Enable mail profile.
  4. Select your mail profile
  5. Select OK
  6. Restart SQL Agent service

SQL jobs

This is a list of jobs I create by default on every new server:
  • MaintenanceSolution  By Ola Hallengren - includes backup and some maintenance jobs. Only the jobs are created, you will need to create the schedules manually. You may possibly want to make changes to the steps such as adding compression to the backup one.
  • Weekly Cycle of Error Logs by Paul Hewson – prevents the error log from bloating by cycling it every week (this script includes the schedule)
  • SP_WhoIsActive by Adam Machanic – useful diagnostic query
  •  dbWarden by Stevie Rounds and Michael Rounds – daily health report emailed to your inbox each day.
  • sp_blitz by Brent Ozar – check that everything is configured correctly.
  • Monitor File Growth by Paul Hewson – useful for keeping a  record of the growth of data and log files. This can be queried at a later time by using SSRS or Excel.
  • Agent Alerts Management Pack by Tibor Karaszi 
When you have run all the scripts above it could be worth running the following script so that we log all SQL Agent job history we can:
Enable additional logging for SQL Agent jobs by Paul Hewson

SQL Agent History

I find that the default number of records recorded for SQL Agent job history at 1000\100 is usually not enough so I like to increase this value by several orders of magnitude by using this command.
Click to enlarge

USE [msdb]
EXEC msdb.dbo.sp_set_sqlagent_properties @jobhistory_max_rows=100000,

NB, this will increase the size of the msdb slightly so another reason to keep it off the C: drive.

Configure TempDB  with additional files if required

This a little contentious but if I know the database is going to be used quite heavily with several large databases installed I will move TempDB to its own LUN/drive and split it into several separate but equally sized files.

Manually alter the default database to be 1024MB then add additional files with a script similar to this:

ADD FILE (NAME = tempdev2, FILENAME = 'F:\MSSQL\Data\tempdb2.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev3, FILENAME = 'F:\MSSQL\Data\tempdb3.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev4, FILENAME = 'F:\MSSQL\Data\tempdb4.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev5, FILENAME = 'F:\MSSQL\Data\tempdb5.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev6, FILENAME = 'F:\MSSQL\Data\tempdb6.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev7, FILENAME = 'F:\MSSQL\Data\tempdb7.mdf', SIZE = 1024);

ADD FILE (NAME = tempdev8, FILENAME = 'F:\MSSQL\Data\tempdb8.mdf', SIZE = 1024);

Change memory settings

This is pretty much an essential change to make as the default is that SQL Server will use all of the available memory on the server which may cause problems. I use the details from this post by Glenn Berry to determine the values:

Configure the Trace Flags

By default SQL captures only limited details on deadlocks when they occur so I enable trace 1222 for more verbose logging. So this trace is enabled every time the server starts I alter the properties of the SQL Server service as below. I also think it is convenient to know when Auto Update Statistics events have occurred so I enable trace 8721. The screen shot below is taken from SQL 2008 using SQL Server Configuration Manager:

Click to enlarge

Check Configuration

After you have done all the above you could run sp_blitz against the server to see if you have missed anything.

That's it! I may amend this posting from time to time but generally if you follow the steps above you should have a well configured and stable server. If you can think of anything else, please let me know.


Popular posts from this blog

How to move the Microsoft Assessment and Planning Toolkit (MAP) database to a different drive

The Microsoft Assessment and Planning Toolkit (MAP) is a very useful tool for scanning your network to find instances of SQL Server plus all manner of detailed information about the installed product, OS and hardware it sits on.

<Click image to enbiggen>
There is an issue with it the database it uses to store the data it collects, however. Assuming you don't have an instance called MAPS on your server, the product will install using LocalDB (a cut down version of SQL Server Express) and puts the databases on your C: drive. If you then scan a large network you could easily expand the database to 10GB which may cause issues on a server when that drive is often one of the smallest. However, there is a simple solution: connect to LocalDB using Management Studio, detach the databases, move to a different drive, set permissions on the new location if required and reattach the database. How do you connect to LocalDB? Here you go:

Connect to (localdb)\MAPTOOLKIT

The databases I move…

Generate scripts to attach multiple databases

There is a handy little "by product", if you like, when running queries which means you can quickly generate scripts to do different things. Below is an example of generating multiple "attach" commands that you can copy from the results pane into the main SSMS window for execution. I have found this very handy in the past:

SELECT 'CREATE DATABASE ['+name+'] ON ( FILENAME = N''F:\MSSQL\Data\'+name+'.mdf'' ), ( FILENAME = N''E:\MSSQL\Log\'+name+'_log.ldf'' )  FOR ATTACH GO ' FROMmaster.dbo.sysdatabases WHEREnamenotin('master','msdb','model','tempdb')

The AcquireConnection method call to the connection manager failed with error code 0xC0202009

I had one of those annoying problems with executing a SSIS package that took up most of the morning today (and a couple of hours yesterday) where you get an error which many people have had, but none of their solutions work. I guess it is such a generic error code it can relate to many different issues hence dozens of different (wrong) suggestions. What confused matters was that although it completed successfully in SSDT, it failed when being validated on our newly created SSISDB Catalog. I didn't know whether it was a problem with the package and/or its parameters or the SSISDB Catalog installation or Environment.

If you haven't set up an Integration Services Catalog (a new feature of SQL 2012) yet I definitely think it is worth looking at. I found an excellent guide here that takes you through it all.

In our case we had two connection managers, the source was a table in a SQL Server 2012 database and the destination a table in an Access 2010 database. The server with the Int…