Showing posts with label Availability Groups. Show all posts
Showing posts with label Availability Groups. Show all posts

Friday, May 27, 2016

Move database from one AG to another AG - SQL 2014

Ok this seems like it'd be simple enough to do. For me, I already had one AG set up on a server. The natives got restless, and didn't want to play nice, and didn't want one groups' failover to affect the other group. I needed to separate the databases into two different AGs.

Seems totally straight-forward and simple enough.

So I set up the new AGs, set up the new listeners, no errors, life is good! I take one of the databases out of the old AG, and add it to the second, choosing Join Only as the database was already synchronized.

You'd think that's all there is to it.

But all I'm doing is watching the 'Joining <database> to availability group....' message sit there, with the little spinny thing going showing that it's really really trying to do what I ask, then it fails. Huh.

So I look in the error logs.

Nothing. At least nothing useful:

AlwaysOn Availability Groups connection with secondary database terminated for primary database '<database>' on the availability replica '<server>' with Replica ID: {d4811fa0-b284-4730-9879-95cdcca01d82}. This is an informational message only. No user action is required.


What the what? Whaddya mean no user action required? If you did what you were supposed to then maybe so, but this looks like a failure to me.

So then I look on the secondary server.

Wait...what? Where is my AG? I don't see it listed!!

Back to the primary. I open up the AG I was trying to add the database to, looking at everything, when I notice it's showing a little down red arrow on the secondary server.

This day is not going well. The server is up, I was able to connect when making the AG, so what in seven hells is going on here? I right-click the server and click JOIN.

BINGO!

After refreshing the view, red arrow gone, and I'm now able to add my database to the new group. I move the other databases from the old AG to the new, and everything is sunshine and kitties! Maybe some puppies too if they behave and don't chase the kitties.

So long story short, be aware that when creating the AG you should check that all parts are red-down-arrow free before attempting to add databases.

Tuesday, September 29, 2015

Remove-SqlAvailabilityDatabase -Path

Been playing a lot with PoSH lately, am now writing a script to automate the restore of a database that's in an availability group. One of the issues I kept running into was getting the correct path for the Remove-SqlAvailabilityDatabase cmdlet. The scripts I'd see online would only have a 'standard' path, like this:

Remove-SqlAvailabilityDatabase `
-Path SQLSERVER:\Sql\SecondaryComputer\InstanceName\AvailabilityGroups\MyAg\Databases\MyDb

Unfortunately that wasn't the path to my DB (and yes, before you say 'did you change the parameters'...yes....yes I did).

So anyways, to make a long story shorter, to find the path to your AG database, open up SSMS, expand AlwaysOn High Availability > Availability Groups > <your group>  and right-click on your database, choosing  Start Powershell. The prompt in the window that opens is the path to your database! So copy that and try the PoSH command Remove-SqlAvailabilityDatabase again and it'll work.

I'll probably post my automated restore solution when I'm done but wanted to get this off my chest.