Monday, July 19, 2021

Creation of AlwaysOn group failing as already another AlwaysOn Group exists with the same name.

When you uninstall SQL Server without manually dropping the existing AAG group and trying to create an AAG group with the same name after reinstalling the SQL Server. or if the existing AlwaysOn group was not dropped correctly and if we try to create a new AAG group with the same name. We sometimes receive the below error: 

 
 

"Create failed for Availability Group 'DBAG'. 

 
 

The availability group 'DBAG' already exists. This error could be caused by a previous failed CREATE AVAILABILITY GROUP or DROP AVAILABILITY GROUP operation. If the availability group name you specified is correct, try dropping the availability group and then retry CREATE AVAILABILITY GROUP operation. 

Failed to create availability group 'DBAG'." 

 
 

One of the reasons this error pops up is there will be a registry entry for the AAG name.  

 
 

To check if there is an entry in the registry for the AAG group with the same name already we can check in two ways: 

 
 

  1. Query the "sys.dm_hadr_name_id_map". 

  1. Check the registry location "HKEY_LOCAL_MACHINE\Cluster\HadrAgNameToldMap". 

  1.  
     

When you query "sys.dm_hadr_name_id_map" and if you see an entry with the same AAG group name in my example if there is an entry with the name "DBAG" then we need to drop it before creating a new AG group with the same name. 

 
 

Select * from "sys.dm_hadr_name_id_map" 


Go 

 
 

Use the below command to drop the AAG group: 

 
 

DROP AVAILABILITY GROUP DBAG; 

 
 

After dropping, we can verify the registry location "HKEY_LOCAL_MACHINE\Cluster\HadrAgNameToldMap" to make sure there is no entry with the same AAG name.  

 
 

Then if we try to create the AG with the name "DBAG" it will allow us. 

 
 

Please share if there is any easy way to fix this error in the comments section. 

 
 

 
 

Thanks VV!!