How to move Master/Model/MSDB/Tempdb System Database files in SQLServer?
There are times when you want to move the system databases files from installed locations to new location..... This can be accomplished without any errors if you follow the moving order of the database.
Microsoft recommends that SqlServer binaries (System database files and Installation files) should not be on System drive –“C”, the reason behind this is, if Operating System gets corrupted you will lose binaries otherwise if it is on nonsystem drive(other than C drive) you will not lose binaries.
Most of the companies use nonsystem drive for binaries… Let’s say one of the Junior DBA installed SqlServer but mistakenly used “C” drive for binaries and now you have to move them to nonsystem drive for example ”D” drive.
Following query tells you about the system database file locations.
SELECT physical_name
FROM sys.master_files
FROM sys.master_files
First we need to move Master, msdb, model and tempdb:
- From the Start menu, point to All Programs, point to Microsoft SQL Server, point to Configuration Tools, and then click SQL Server Configuration Manager.
- In the SQL Server Services node, right-click the instance of SQL Server (for example, SQL Server (MSSQLSERVER)) and choose Properties.
- In the SQL Server (instance_name) Properties dialog box, click the Startup Parameters tab.
- In the Existing parameters box, select the –d parameter to move the master data file. Click Update to save the change.
- In the Specify a startup parameter box, change the parameter to the new path of the master database.
In the Existing parameters box, select the –l parameter to move the master log file. Click Update to save the change. In the Specify a startup parameter box, change the parameter to the new path of the master database.
The parameter value for the data file must follow the -d parameter and the value for the log file must follow the -l parameter. The following example shows the parameter values for the default location of the master data file.
-dC:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf
-lC:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
If the planned relocation for the master data file is E:\SQLData, the parameter values would be changed as follows:
-dE:\SQLData\master.mdf
-lE:\SQLData\mastlog.ldf
- Stop the instance of SQL Server by right-clicking the instance name and choosing Stop.
- Move the master.mdf and mastlog.ldf files to the new location.
- Restart the instance of SQL Server.
Verify the file change for the master database by running the following query.
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID('master');
For MSDB and Model database perform following steps
- ALTER DATABASE MSDB/Model MODIFY FILE ( NAME = logical_name , FILENAME = 'new_path\os_file_name' )
- Stop the instance of SQL Server or shut down the system to perform maintenance. For more information, see Stopping Services.
- Move the file or files to the new location.
- Restart the instance of SQL Server or the server. For more information, see Starting and Restarting Services.
Now its turn to move Tempdb:
USE master;
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');
GO
After running above query, restart the SQL Services
After moving system data files, verify them by running following query.
SELECT physical_name
FROM sys.master_files
FROM sys.master_files
No comments:
Post a Comment