How to Move the Model and MSDB Databases in SQL Server 2008 R2
Published: Feb 10, 2014
This came to light when I was working with a company who were struggling with their MSDB database. They had a requirement to maintain huge volumes of historical job data and backup information and didn't want to archive this to another database. Therefore this meant a large MSDB which had filled their drive and they needed to relocate it.

To move the Model and MSDB databases in SQL Server 2008 R2 follows the same pattern as with tempDB. However, the reason I have put this in a seperate article is that I will also cover the steps involved in moving these databases under SQL Server 2005 (though not in great detail).

Firstly we find the current location of the Model and MSDB files:

In SQL Server 2008 R2 all you need to do is run the following:

Then you need to stop the SQL Server:

Move the physical files on your operating system, and then start you SQL Server once more:

That's it.

This is FAR simpler than the method for SQL Server 2005. For this method we need a completely different approach.

As above we check for the current location of the files. Once found we then have to open SQL Server Configuration Manager and click on SQL Server Services on the left hand side:

In here, locate the main SQL Server Service, right click, and select Properties:

Click on Advanced:

And you should be able to see “Startup Parameters”:

Clicking the drop down arrow will let you see a nice text box which will tell you exactly what parameters are being used for startup:

You need to add ;-c-m-T3608 to the end of this:

Then start the service and SQL Server will start in single user mode.

Connect to SQL Server using Management Studio...

If you see the following error...

It is because you already have a connection in Object Explorer. Therefore Disconnect this...

You will now be able to open a solitary Query window...

Once you have done this you will be able to detach the msdb and model databases...
sp_detach_db 'msdb'
go
sp_detach_db 'model'
go 
Now move your files in the file system to the location you want them and then re-attach the databases:
sp_attach_db 'model',
    'D:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\model.mdf',
    'D:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\modellog.ldf',
go
sp_attach_db 'msdb'
    'D:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf',
    'D:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf',
go 
NOTE: If you move both model and msdb together then you HAVE to complete this in the correct order otherwise you will get errors. You must detach MSDB first, then model, and then you must attach model before MSDB.

Remove the parameters from the startup line and start SQL Server. The databases are now being used from their new locations.
Leave a Comment
Your email address will not be published. All fields are mandatory.
NB: Comments will only appear once they have been moderated.

Your SQL Trainer
Kevin Urquhart

I am a SQL Server DBA, Architect, Developer, and Trainer for SQL Training. This is my blog in which I’m simply trying to share my SQL knowledge and experiences with the world.

Kevin Urquhart
SQL Server Consultant, London

Categories


Archives


Copyright © 2018 London SQL Server Training Courses @ SQL Training | Website Design From Scott Heron