How to Move System Databases in SQL 2005
-
Upload
vamsi-sagar -
Category
Documents
-
view
223 -
download
0
Transcript of How to Move System Databases in SQL 2005
-
8/6/2019 How to Move System Databases in SQL 2005
1/12
How to Move System Databases in SQL 2005
Many DBAs find this topic difficult and hence I thought of writing an article
with relevant screenshot for each step. Unlike user databases system
databases cannot be detached normally, we need to start SQL server insingle user mode and with Trace flag 3608. Lets discuss each one of those in
detail. The SQL Server instance which I am using is Deepak\Test.
How To move Tempdb in SQL 2005 :
Step 1: Check the path where the TEMPDB data and log files reside by using
the T-SQL or GUI as follows,
SP_HELPDB TEMPDB
In my case it was in C:\Program files default location and I am changing it to
F:\Data\ folder
Step 2: Use Alter Database Statement to modify the data and log files to
new location as follows,
ALTER DATABASE TEMPDB MODIFY
FILE(NAME=TEMPDEV,FILENAME='F:\DATA\TEMPDEV.MDF')
http://deepakrangarajan.blogspot.com/2007/08/moving-system-databases-in-sql-2005.htmlhttp://deepakrangarajan.blogspot.com/2007/08/moving-system-databases-in-sql-2005.html -
8/6/2019 How to Move System Databases in SQL 2005
2/12
GO
ALTER DATABASE TEMPDB MODIFY
FILE(NAME=TEMPLOG,FILENAME='F:\DATA\TEMPLOG.LDF')
GO
Step 3: Restart the SQL Services and check the new path by using,
SP_HELPDB TEMPDB
It will reflect the new path as F:\Data\Tempdev.mdf and
F:\Data\Templog.ldf.Refer the below screenshot shown below,
-
8/6/2019 How to Move System Databases in SQL 2005
3/12
How To move Model and Msdb in SQL 2005 :
Step 1: Check the current path where Model and Msdb currently resides by
using the following command,
SP_HELPDB MSDB
GO
SP_HELPDB MODEL
GO
In my case both the dbs ldf and mdf resides in C:\Program Files and I am
moving them to F:\Data\folder. Refer the below screenshot for reference,
Step 2: Go to Start All programs Microsoft SQL Server 2005
Configuration Tools SQL Server Configuration Manager SQL Server 2005
Services and on the right side pane double click SQL SERVER(TEST) and
navigate to advanced tab and choose the startup parameters option and
type c-m-T3608 @the last as shown in figure.Once it is done you need to
restart the sql services.
-
8/6/2019 How to Move System Databases in SQL 2005
4/12
Else you can also perform the same action as above through commmand
prompt as follows,
Go to Start Run type cmd then type the below command,
NET STOP MSSQL$TEST - To stop the SQL server
Now we need to restart the sqlserver with the parameter c-m-T3608
inorder to detach the system dbs.Type the below command in the commandprompt,
NET START MSSQL$TEST /c /m /T3608. Type the above command as given
because it is case sensitive.Refer the below screenshot,
-
8/6/2019 How to Move System Databases in SQL 2005
5/12
NOTE: If you are using default instance of SQL server you should useNET START MSSQLSERVER and for named instance it is as shown below
NET START MSSQL$InstanceName.
Step 3: Once you have started your Sql server in single user mode with
Trace flag 3608 you can detach your system dbs, but while you connect to
SSMS if you click the new query button you will get the below error,
SQL SERVER is in SINGLE USER MODE and only one administrator can
connect
-
8/6/2019 How to Move System Databases in SQL 2005
6/12
-
8/6/2019 How to Move System Databases in SQL 2005
7/12
Step 4: Now move the model and msdbs data and log files to the desiredlocation i.e F:\Data\folder and attach them using the below command,
SP_ATTACH_DB 'MODEL','F:\DATA\MODEL.MDF','F:\DATA\MODELLOG.LDF',
GO
SP_ATTACH_DB 'MSDB''F:\DATA\MSDBDATA.MDF','F:\DATA\MSDBLOG.LDF',
GO
Refer the below screenshot for reference,
NOTE : If you use this procedure together with moving the model database,
-
8/6/2019 How to Move System Databases in SQL 2005
8/12
you are trying to detach the msdb database while you detach the model
database. When you do this, you must reattach the model database first,
and then reattach the msdb database. If you reattach the msdb database
first, you receive the following error message when you try to reattach the
model database:
Msg 0, Level 11, State 0, Line 0 A severe error occurred on the current
command. The results, if any, should be discarded.
In this case, you must detach the msdb database, reattach the model
database, and then reattach the msdb database,
Step 5: Now stop and start Sql server in normal mode as shown below, and
perform as in step 1 to find the current path
-
8/6/2019 How to Move System Databases in SQL 2005
9/12
How To move Master database in SQL 2005 :Step 1: Check the path where master db ldf and mdf resides by using the
command,
SP_HELPDB MASTER
Currently it resides in C:\Program files and I am moving them to
F:\Data\folder.Refer the below figure,
Step 2: Stop the SQL Services through command prompt as explained
earlier and move the master db ldf and mdf files to F:\Data\folder and then
-
8/6/2019 How to Move System Databases in SQL 2005
10/12
proceed as below,
Go to Start All programs Microsoft SQL Server 2005 Configuration
Tools SQL Server Configuration Manager SQL Server 2005 Services and
on the right side pane double click SQL SERVER(TEST) and navigate to
advanced tab and choose the startup parameters and it will be like shown
below,
-dC:\Program Files\Microsoft SQL
Server\MSSQL.5\MSSQL\DATA\master.mdf;
-eC:\Program Files\Microsoft SQL
Server\MSSQL.5\MSSQL\LOG\ERRORLOG;
-lC:\Program Files\Microsoft SQL
Server\MSSQL.5\MSSQL\DATA\mastlog.ldf
Just change the above command as follows,
-dF:\DATA\master.mdf;
-eC:\Program Files\Microsoft SQL
Server\MSSQL.5\MSSQL\LOG\ERRORLOG;
-lF:\DATA\mastlog.ldf
-
8/6/2019 How to Move System Databases in SQL 2005
11/12
Step 3: After changing as above you need to restart the SQL Services and
then check the new path by using the below command,
SP_HELPDB MASTER
The output of the above command will reflect the new path as shown in the
below figure.
In SQL Server 2005, in order to move the resource database, first you need to make sure that you
stop the SQL Server service and then start it using either -m (single user mode) or -f (minimal
configuration) startup option which will start it in the maintenance mode. In addition, use the
-T3608 trace flag which will skip the recovery of all the databases other than the masterdatabase. By doing this, we are ensuring that there is no process using the Resource database.
After this, the move is the same as others by using the ALTER DATABASE command:
ALTER DATABASE mssqlsystemresource MODIFY FILE (NAME=data, FILENAME= \mssqlsystemresource.mdf)ALTER DATABASE mssqlsystemresource MODIFY FILE (NAME=log, FILENAME= \mssqlsystemresource.ldf)
-
8/6/2019 How to Move System Databases in SQL 2005
12/12
And once the move has been done, then stop and start the SQL Server service again - this time
without those startup option flags and without the trace flag and this time around, the new
location will be used for the resource database files.
Please do note that this behavior has changed in SQL Server 2008. In SQL Server 2008, the
resource database now resides under: