Move SQL Server Database Files



  • My current environment is Always On with asynchronous mode with readable secondary's, but no failover. I wanted to move database file which is already in AG. But I can't failover AG. Please advise best possible way .



  • EDITED

    I had a very lengthy write-up on this. However, it turns out that SQLShack already has a great https://www.sqlshack.com/a-walk-through-of-moving-database-file-in-sql-server-always-on-availability-group/ .

    Without going into too much detail, here is a high level summary of what they suggest.

    1. Connect to your secondary replica.
    2. Remove the database from the Availaibly Group on the secondary replica. It should now show as Restoring.
    3. Issue the move files command from the master database.
    4. Stop the SQL service on the secondary replica.
    5. move the files to the new location.
    6. Start the SQL service
    7. Check the file location in sys.master_files
    8. Join the database back to the Availability Group.

    Repeat for all remaining replicas. For your primary replica, you're going to need to failover.

    If that's not an option, scrap the above method all together and do the following...

    1. Remove the database from the Availability Group
    2. Issue the move file command
    3. Set the database to OFFLINE
    4. Move the data and log files
    5. Bring the database back ONLINE
    6. Add the database back to the Availability Group.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2