Moving System Databases – SQL Server 2005


Here I have tried to explain how we can move system databases from one place to another step by step from my experience.

Please follow the below 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 from registry editor.
b.) Stop the services.
c.) Move the master and resource database files to the new location
d.) 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)
e.) Execute the script given below from sqlcmd

USE master;
GO
alter database mssqlsystemresource MODIFY FILE (NAME = data,FILENAME=’NEW PATHmssqlsystemresource.mdf’);
go
alter database mssqlsystemresource MODIFY FILE (NAME = log,FILENAME=’NEW PATHmssqlsystemresource.ldf’);
go
alter database mssqlsystemresource set READ_ONLY;
go

f.) Stop the services

g.) Start sql services.

h.) Confirm if the data files and log files reside on desired path.

Thanks

Please give your comments /suggession for this article….

Advertisements

One Response

  1. Hope this link will help you.Just be careful when you are moving the master db files.

    http://msdn.microsoft.com/en-us/library/ms345408(v=sql.90).aspx

    You can run the following query to move tempdb,model and msdb.

    * each file to be moved, run the following statement.

    ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name , FILENAME = ‘new_pathos_file_name’ )
    * the instance of SQL Server or shut down the system to perform maintenance.

    * the file or files to the new location.

    * the instance of SQL Server or the server.

    * the file change by running the following query.

    SELECT name, physical_name AS CurrentLocation, state_desc
    FROM sys.master_files
    WHERE database_id = DB_ID(N”);

    The Resource database depends on the location of the master database. The Resource data and log files must reside together and must be in the same location as the master data file (master.mdf). Therefore, if you move the master database, you must also move the Resource database to the same location as the master data file. Do not put the Resource database in either compressed or encrypted NTFS file system folders. Doing so will hinder performance and prevent upgrades.

    To move the master and Resource databases, follow these steps.

    * the Start menu, point to All Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.

    * the SQL Server 2005 Services node, right-click the instance of SQL Server (for example, SQL Server (MSSQLSERVER)) and choose Properties.

    * the SQL Server (instance_name) Properties dialog box, click the Advanced tab.

    * the Startup Parameters values to point to the planned location for the master database data and log files, and click OK. Moving the error log file is optional.

    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 and log files.

    * FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAmaster.mdf;-eC:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLLOGERRORLOG;-lC:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAmastlog.ldf

    If the planned relocation for the master data and log files is E:SQLData, the parameter values would be changed as follows:

    * FilesMicrosoft SQL ServerMSSQL.1MSSQLLOGERRORLOG;-lE:SQLDatamastlog.ldf

    * the instance of SQL Server by right-clicking the instance name and choosing Stop.

    * the master.mdf and mastlog.ldf files to the new location.

    * the instance of SQL Server in master-only recovery mode by entering one of the following commands at the command prompt. The parameters specified in these commands are case sensitive. The commands fail when the parameters are not specified as shown.

    For the default (MSSQLSERVER) instance, run the following command.

    NET START MSSQLSERVER /f /T3608
    For a named instance, run the following command.

    NET START MSSQL$instancename /f /T3608

    Thanks,

    Banani Rath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: