Sql-server – How to change DB file location with Replication

sql serversql-server-2008

I need to move few DB files to another location on same server due to low disk space. Replication is present with that DB and this scenario is on subscriber server. Is there any way to do this without doing reconfiguration?

Best Answer

Here's how I'd do it:

  1. Schedule some time where the database can be down for the amount of time to move the files
  2. Execute a series of 'alter database [foo] modify file (name = 'foo_1', filename = 'new location here') statements
  3. alter database [foo] set offline (you'll have to kill any active spids in the db or wait for them to finish their business)
  4. move your files
  5. alter database [foo] set online

If you want to be really clean about this, you can stop the distribution agent while the database is offline and restart it when it's back online. But that's not necessary. Just so you know, I've also done this with a distribution database and would imagine that it would work fine with a publisher, too.