HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to change location of SQL Server 2012 database which is already configured with a merge replication

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
2012mergesqlwhichwithreplicationdatabasealreadyhowserver

Problem

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?

Solution

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

-
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');


-
Stop log reader agent, distribution and merge agent (if they are running).

-
Offline the database using alter database db_name set offline

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

-
Bring the database ONLINE alter database db_name set ONLINE

-
Start the jobs that were disabled in step 2.

Code Snippets

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');

Context

StackExchange Database Administrators Q#105586, answer score: 2

Revisions (0)

No revisions yet.