There are lots of articles, Links and sites that describe how to move system databases from the SQL default location to the location described by the DBA but still lot of users find difficult while moving them and land up in trouble. So I thought of wiriting an article for moving the databases so that the users can use the same and enjoy the task.
Tasks for moving system databases:
1.Moving tempdb databases.
a.) Execute the script below.
USE master;
GO
alter database tempdb MODIFY FILE (NAME = tempdev,FILENAME='NEW PATH');
GO
alter database tempdb MODIFY FILE (NAME = templog,FILENAME='NEW PATH');
GO
b.) Restart services.
c.) Confirm path of database files.
2. Moving model and msdb databases.
a.) Execute the script below.
USE master;
GO
alter database msdb MODIFY FILE (NAME = MSDBData,FILENAME='NEW PATH');
go
alter database msdb MODIFY FILE (NAME = MSDBLog,FILENAME='NEW PATH');
go
USE master;
GO
alter database model MODIFY FILE (NAME = modeldev,FILENAME='NEW PATH');
go
alter database model MODIFY FILE (NAME = modellog,FILENAME='NEW PATH');
go
b.) Stop services
c.) Copy the files to the new location
d.) Restart services.
e.) Confirm path of database files.
3.) Moving master database:
a.) Edit the startup parameters to reflect the new path for –d, –l and -e parameters.
b.) Stop the services.
c.) Move the master and resource database files to the new location
d.) Change the sql port to different one than usual to avoid excess connections and create an alias with that port
e.) Start the services using NET START MSSQLSERVER /f /T3608 (*MSSQLSERVER is for default instance, if you have installed named instance then you need to use NET START MSSQL$Instancename /f /T3608)
f.) Execute the script given below from sqlcmd
USE master;
GO
alter database mssqlsystemresource MODIFY FILE (NAME = data,FILENAME='NEW PATH\mssqlsystemresource.mdf');
go
alter database mssqlsystemresource MODIFY FILE (NAME = log,FILENAME='NEW PATH\mssqlsystemresource.ldf');
go
alter database mssqlsystemresource set READ_ONLY;
go
g.) Stop the services
h.) Change the port back to 1433
i.) Remove the alias
j.) Start sql services.
k.) Confirm if the data files and log files reside on desired path.
Wow! Wow! Wow! THANK YOU!
-
I announced my retirement from SQL/tech here and your comments on my blog,
on LinkedIn, and on Facebook were overwhelming and humbling! I’m so touched
by t...
11 months ago
3 comments:
Worked like a champ! Excellent document.
-Alan - Louisville, KY
Geez mate, you could have been more specific with the 'NEW PATH' bit. Reading that made me think that it meant the path only, but it actually means the new path and filename. Perhaps change it to 'NEW PATH AND FILENAME'?
I just spent hours trying to get things going again after it was broken when I only put the PATH in.
Thanks anyway!
Thanks for your manual.
Worked for me quite good.
(SQL Server starts and system databases are accessible)
But since I moved the files, I have a error in the event log that says that the "Service Broker" in msdb is deactivated or msdb cannot be started.
The msdb-database is attached. But how can I start the service broker?
Thanks
M.
Post a Comment