SQL Server 2012 – How to Change Location of Database with Merge Replication

sql serversql-server-2012

I have SQL Server 2012 configured with merge replication. currently the location of the replication database and the .mdf and .ldf files reside in C:\ drive.

The C:\ drive is now full due to that fact that these files reach over 80GB. Therefore, I want to relocate the files to another drive where I have more space with out affecting the replication and the data.

How do I do this safely?

Best Answer

Oh Boy! System Databases on C Drive are recipe for disaster !

Change the default database location away from C:\ drive.

You can do it using ALTER DATABASE .. MODIFY FILE

  1. Change the db file location

    ALTER DATABASE db_name
    MODIFY FILE (NAME = logical_data_file, 
         FILENAME = 'D:\data\physical_file.mdf');
    
    ALTER DATABASE db_name
    MODIFY FILE (NAME = logical_file, 
         FILENAME = 'L:\log\physical_file_log.ldf');
    
  2. Stop log reader agent, distribution and merge agent (if they are running).

  3. Offline the database using alter database db_name set offline

  4. Once offline, you have to PHYSICALLY move the data and log files to the new location that you put in in step 1.

  5. Bring the database ONLINE alter database db_name set ONLINE

  6. Start the jobs that were disabled in step 2.