MSSQL cannot remove orphan/stuck data base from Availability Group

Mitu Daniel Marius (IBM) 6 Reputation points
2024-08-05T10:06:50.4766667+00:00

Hello,

I have a cluster setup with availability group and a database was part of this AG, but something happened and I can see it in the AG, but with an exclamation mark.

I tried to alter the availability group and remove it, but the error was that the database is not part of the AG.

I added a picture with the AG.

Image

Can someone tell me how I can remove that database from the AG and added again in the AG?

Thanks,

Daniel

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,695 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LucyChenMSFT-4874 4,430 Reputation points
    2024-08-06T02:50:26.0166667+00:00

    Hi @Mitu Daniel Marius (IBM) ,

    Thank you for your reaching out and welcome to Microsoft Q&A!

    I tried to alter the availability group and remove it, but the error was that the database is not part of the AG.

    We'd better verify whether the database joined the AG. If you refreshed and it was still not there, then this means that the database does not exist. The reason would/could be that something went wrong with automatic seeding.

    You should try executing these commands on the secondary instance:

    ALTER AVAILABILITY GROUP [agname] JOIN; 
    GO 
    ALTER AVAILABILITY GROUP [agname] GRANT CREATE ANY DATABASE; 
    GO 
    

    After this you should retry automatic seeding & validate that the database was created and fully seeded on the secondary instance.

    You can also use sys.databases which has a column called group_database_id. If this column is null then the database is not participating in an availability group. To only get user databases, restrict the query to database_id > 4.

    SELECT name From sys.databases WHERE database_id > 4 AND group_database_id IS NULL
    

    Can someone tell me how I can remove that database from the AG and added again in the AG?

    Please check out this article first, it shows the method how to resolve the error message you posted.

    In addition to that article, you can try to pull the oldest full backup you can find to restore that over the Restoring db using:

    RESTORE DATABASE [ZOMBIEDB] FROM  DISK = N' ' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 5
    
    

    Then you can try to remove the database again.

    If you want to remove the database directly, please try to disable all backup jobs in the primary.

    Then, right click on the availability group name on primary server and remove the database from the availability group.

    NOTE: Could you please provide the detailed log here to help us narrow down the issue?

    Thanks for your understanding. Your time and cooperation are much valued by us. We are looking forward to hearing from you to assist further.

    Best regards,

    Lucy Chen


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.