Note to self on AlwaysOn...

Published Mar 23 2019 12:47 PM 145 Views
Microsoft
First published on TECHNET on May 09, 2012

I came up with the idea that perhaps we could let clients connect to a database in an AlwaysOn Availability Group (AG) by the current instance name instead of the virtual network name (VNN) if the cluster service crashed. This idea does not work.


Microsoft Consultant Don Scott set up a very simple 2-node cluster with a stand-alone instance of SQL Server 2012 on each node and 1 availability group with 1 database in it, and we could connect to the database by it's VNN or by connecting to the current instance name, as expected. However, when we turned off the cluster service on both nodes to simulate a cluster service failure, we could no longer connect to the database by it's virtual name, as expected, but we could also not connect to the database through the current instance name. In SQL Server Management Studio (SSMS), the database icon listed "Recovery pending" after the name of the database, even though this was the primary replica. The secondary replica didn't even show up in SSMS with the cluster service off.


Even though the "recovery pending" status didn't make sense to us, we tried "RESTORE DATABASE <dbname> WITH RECOVERY" and got a very strange error message: "Msg 3148, Level 16, State 3; This restore statement is invalid in the current context. The 'Recover Data Only' option is only defined for secondary filegroups when the database is in an online state. When the database is in an offline state filegroups cannot be specified." This is strange because this database only had the default primary filegroup and it was online. We checked SSMS to confirm the database was online, and the "Bring Online" option was not available in SSMS, but the "Take Offline" option was available, confirming the database was still online despite the error message.


Moral of the story: When using AlwaysOn, keep at least half your cluster nodes/witness healthy, because if the cluster goes down completely, AlwaysOn goes down.


Other notes:

  • With this test configuration (2-node cluster, each with Non-FCI, 1 availability group, all functioning correctly): When we evicted the primay replica node from the cluster and restarted the node, we expected the availability group to be disabled, but instead it completely ceased to exist (no trace of it remained to be displayed in SSMS). The database was then a normal database without an availability group.

  • When creating or altering an Availability Group, SQL Server interacts with the Windows cluster service to automatically create the Virtual Network Name for the AG in the cluster service.


%3CLINGO-SUB%20id%3D%22lingo-sub-384085%22%20slang%3D%22en-US%22%3ENote%20to%20self%20on%20AlwaysOn...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-384085%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20May%2009%2C%202012%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EI%20came%20up%20with%20the%20idea%20that%20perhaps%20we%20could%20let%20clients%20connect%20to%20a%20database%20in%20an%20AlwaysOn%20Availability%20Group%20(AG)%20by%20the%20current%20instance%20name%20instead%20of%20the%20virtual%20network%20name%20(VNN)%26nbsp%3Bif%20the%20cluster%20service%20crashed.%26nbsp%3BThis%20idea%26nbsp%3Bdoes%20%3CB%3E%20not%20%3C%2FB%3E%20work.%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%3EMicrosoft%20Consultant%20Don%20Scott%26nbsp%3Bset%20up%26nbsp%3Ba%20very%20simple%202-node%20cluster%20with%20a%20stand-alone%20instance%20of%20SQL%20Server%202012%20on%20each%20node%20and%201%20availability%20group%20with%201%20database%20in%20it%2C%20and%20we%20could%20connect%20to%20the%20database%20by%20it's%26nbsp%3BVNN%26nbsp%3Bor%20by%20connecting%20to%20the%20current%20instance%20name%2C%20as%20expected.%20However%2C%20when%20we%20turned%20off%20the%20cluster%20service%20on%20both%20nodes%20to%20simulate%20a%20cluster%20service%20failure%2C%20we%20could%20no%20longer%20connect%20to%20the%20database%20by%20it's%20virtual%20name%2C%20as%20expected%2C%20but%20we%20could%20also%20not%20connect%20to%20the%20database%20through%20the%20current%20instance%20name.%20In%20SQL%20Server%20Management%20Studio%20(SSMS)%2C%20the%20database%20icon%20listed%20%22Recovery%20pending%22%20after%20the%20name%20of%20the%20database%2C%20even%20though%20this%20was%20the%20primary%20replica.%20The%20secondary%20replica%20didn't%20even%20show%20up%20in%20SSMS%20with%20the%20cluster%20service%20off.%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3EEven%20though%20the%20%22recovery%20pending%22%20status%20didn't%20make%20sense%20to%20us%2C%20we%20tried%20%22RESTORE%20DATABASE%20%3CDBNAME%3E%20WITH%20RECOVERY%22%20and%20got%20a%20very%20strange%20error%20message%3A%20%22Msg%203148%2C%20Level%2016%2C%20State%203%3B%20This%20restore%20statement%20is%20invalid%20in%20the%20current%20context.%20The%20'Recover%20Data%20Only'%20option%20is%20only%20defined%20for%20secondary%20filegroups%20when%20the%20database%20is%20in%20an%20online%20state.%20When%20the%20database%20is%20in%20an%20offline%20state%20filegroups%20cannot%20be%20specified.%22%20This%20is%20strange%20because%20this%20database%20only%20had%20the%20default%20primary%20filegroup%20and%20it%20was%20online.%20We%20checked%20SSMS%20to%20confirm%20the%20database%20was%20online%2C%20and%20the%20%22Bring%20Online%22%20option%20was%20not%20available%20in%20SSMS%2C%20but%20the%20%22Take%20Offline%22%20option%20was%20available%2C%20confirming%20the%20database%20was%20still%20online%20despite%20the%20error%20message.%3C%2FDBNAME%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3EMoral%20of%20the%20story%3A%20When%20using%20AlwaysOn%2C%20keep%20at%20least%20half%20your%20cluster%20nodes%2Fwitness%20healthy%2C%20because%20if%20the%20cluster%20goes%20down%20completely%2C%20AlwaysOn%20goes%20down.%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%20Other%20notes%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EWith%20this%20test%20configuration%20(2-node%20cluster%2C%20each%20with%20Non-FCI%2C%201%20availability%20group%2C%20all%20functioning%20correctly)%3A%20When%20we%20evicted%20the%20primay%20replica%20node%20from%20the%20cluster%20and%20restarted%20the%20node%2C%20we%20expected%20the%20availability%20group%20to%20be%20disabled%2C%20but%20instead%20it%20completely%20ceased%20to%20exist%20(no%20trace%20of%20it%20remained%20to%26nbsp%3Bbe%20displayed%26nbsp%3Bin%20SSMS).%20The%20database%20was%26nbsp%3Bthen%20a%26nbsp%3Bnormal%20database%20without%20an%20availability%20group.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EWhen%20creating%20or%20altering%20an%20Availability%20Group%2C%20SQL%20Server%20interacts%20with%20the%20Windows%20cluster%20service%20to%20automatically%20create%20the%20Virtual%20Network%20Name%20for%20the%20AG%20in%20the%20cluster%20service.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%3C%2FDIV%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-384085%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20May%2009%2C%202012%20I%20came%20up%20with%20the%20idea%20that%20perhaps%20we%20could%20let%20clients%20connect%20to%20a%20database%20in%20an%20AlwaysOn%20Availability%20Group%20(AG)%20by%20the%20current%20instance%20name%20instead%20of%20the%20virtual%20network%20name%20(VNN)%26nbsp%3Bif%20the%20cluster%20service%20crashed.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-384085%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerSecurity%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 23 2019 12:47 PM
Updated by: