System database relocation

System database movement is one of the best practices after sql server installations.

It is important to keep SQL Server files away from C drive location where windows operating system is installed, in order to avoid corruption or crashes.

Steps need to follow for changing location of mdf and ldf:

1. Change the file locations with an ALTER DATABASE command:
USE master; --do this all from the master
ALTER DATABASE foo
MODIFY
FILE (name='logical name
,filename='Location'); --Filename is new location
Changing this path does not take effect immediately, but will be used the next time the database starts up.

2. Set the database offline
(use WITH ROLLBACK IMMEDIATE to close sessions that are active and rollback all currently open transactions)
ALTER DATABASE DBNAME SET OFFLINE WITH ROLLBACK IMMEDIATE;
3. Move/Copy the files to the new location
Just copy the files to new location
4. Bring the database online
ALTER DATABASE DBNAME SET ONLINE;
You can see this described in more detail here.

Example:

To Move system database files follow these steps:

To change master database location:
open SQL Server Configuration Manager.
Click on the SQL Server Service on the left side of the window and then locate SQL Server (MSSQLSERVER) on the right side and then right-click and select Properties.
By default three existing parameters listed as shown below in picture.  The master.mdf (-d)master.ldf (-l) and ERRORLOG (-e).
For moving the master database we will be modifying the -d and -l parameters.
Click on the parameter beginning with -d & -l. In the Specify a startup parameter text box, modify the path as needed.
Click Update.
Once done stop the SQL Service & physically move the master.mdf and master.ldf files to their new location.
After moving the files Start SQL Service. 



To move other system databases except master database:
  1. Log in as sa user in SSMS
  2. Take a backup of the user created database for safety.
  3. Kill all sessions connected to the Server from SSMS.
  4. Execute the following command to check the current file location of system databases:
    USE master;
    SELECT * FROM sys.master_files;
Identify the path and note the current path of the files.
  1. Use TSQL to change the file path for all database except master:
    ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name , FILENAME = 'new_path\os_file_name' )
Eg:
ALTER DATABASE tempdb
MODIFY
FILE ( NAME = tempdev
, FILENAME = "DestinationPath\tempdb.mdf");

ALTER DATABASE tempdb
MODIFY
FILE ( NAME = templog
, FILENAME = "DestinationPath\templog.ldf");

ALTER DATABASE model
MODIFY
FILE ( NAME = modeldev
, FILENAME = "DestinationPath\model.mdf");

ALTER DATABASE model
MODIFY
FILE ( NAME = modellog
, FILENAME = "DestinationPath\modellog.ldf");

ALTER DATABASE msdb
MODIFY
FILE ( NAME = MSDBData
, FILENAME = "DestinationPath\msdbdata.mdf");

ALTER DATABASE msdb
MODIFY
FILE ( NAME = MSDBLog
, FILENAME = "DestinationPath\msdblog.ldf");
Now the file location has been changed.
Make sure to move both ldf and mdf files except for tempdb.
  1. Stop the instance of SQL Server.
  2. Copy the file or files to the new location. 
Name

Azure Backup Database Clustering Crash Dumps DBCC Deadlock Link Server Log Shipping Maintenance Migration Mirroring Monitoring Performance Tuning Permissions Post Installations Prerequisites Replication Restore Database SQL Installations SQL on Linux SQL Uninstallations SSIS T-SQL Windows Server
false
ltr
item
hybriddba.blogspot.com: System database relocation
System database relocation
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnNj0YipUoVF5KoG4iC8WSmKJtgJ2QokHgRwwABF_kuKXVpYc6SS7pbtP0TsEjwTlEoLMNtkK9G-4pUOh3addBjBocHDyyJBJKLHTBQH19gAOcMlFfpnyCR0KpdklEHGkhfZiIrnDkrOt8/s1600/1579961874635199-0.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnNj0YipUoVF5KoG4iC8WSmKJtgJ2QokHgRwwABF_kuKXVpYc6SS7pbtP0TsEjwTlEoLMNtkK9G-4pUOh3addBjBocHDyyJBJKLHTBQH19gAOcMlFfpnyCR0KpdklEHGkhfZiIrnDkrOt8/s72-c/1579961874635199-0.png
hybriddba.blogspot.com
https://hybriddba.blogspot.com/2018/05/system-database-relocation.html
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/2018/05/system-database-relocation.html
true
7679493960263860249
UTF-8
Not found any posts Not found any related posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU Tag ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Contents See also related Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy