I have high availability enabled with two servers and when trying to restore a database I realised I had to un-synchronize the database and then remove it from the availability group.

I use Ola Hallagrens maintenance solution. Is there something I can amend with Ola's script to automatically remove DB from availability group when I run the restore job or is there a script already available, or simply not do-able?


  • 1
    How are you restoring a DB using Ola's scripts?
    – S3S
    Commented Oct 16, 2019 at 13:13

1 Answer 1


I think you need to revise your question with clarity:

Olas scripts meant for following, not for restoring database.

  1. Backup
  2. DBCC - Integrity Check
  3. Maintenance - Index and Statistics

Aside from this, you cannot DROP or RESTORE a database while it's part of Availability Group. You can remove a database from availability group with following commands:

PRIMARY Replica:

ALTER AVAILABILITY GROUP AGName remove database DatabaseName;


ALTER database DatabaseName set HADR OFF;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.