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, May 17, 2016

How To Query Oracle Sys Views from MSSQL

So I'm now working in Oracle, but yet still working in SQL Server. Fun times (no sarcasm, I'm loving it)! But I ran into an issue today when trying to get information about Data Guard from Oracle into my SQL Server so I can report on latency.


I have the linked server set up (make sure you have the correct driver on your SQL box, edit the TNSNAMES.ORA file, then create the linked server, tons of info out there on how to do that). What I was having an issue with was getting the V$ views returned from a query without an error.


For instance, this throws an error:


SELECT * FROM &lt;your linked server&gt;..SYS.V$DATAFILE


You'll get:

Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "OraOLEDB.Oracle" for linked server "&lt;your linked server&gt;" does not contain the table ""SYS"."V$DATAFILE"". The table either does not exist or the current user does not have permissions on that table.

While this syntax works:

Select * from openquery (&lt;your linked server&gt;,'SELECT * FROM V$DATAFILE')

WOOHOO!

And obviously linked server names have been replaced.

Don't bother doing a Google search; I found a lot of nothing! Hence my post. Hope this helps!