Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Active Node in SQL Failover Cluster

Tags:

Does anyone know how to determine the active node of a SQL Active-Passive Failover Cluster programmatically from T-SQL?

@@SERVERNAME only returns the virtual server name, which is identical from both nodes.

I don't plan to make any decisions based on the data - I trust the failover to do its thing - but I would like to include the information in an event log so I can tell which node in the cluster was active when the event occurred, or help determine if exceptions come up as a result of a failover.

like image 864
David Boike Avatar asked Apr 22 '09 17:04

David Boike


People also ask

How can we find the active node of the cluster from SQL query?

1. In “Failover Cluster Management” console, you can see the current active node under the label “Current Owner” from summary screen. 2. Run the following T-SQL in SQL Server Management studio.

How do you determine if a cluster is active active or active passive?

Like the active-active cluster configuration, an active-passive cluster also consists of at least two nodes. However, as the name "active-passive" implies, not all nodes are going to be active. In the case of two nodes, for example, if the first node is already active, the second node must be passive or on standby.

How would you check which node is active or whichever it is passive?

Use 'scstat -p' and look for online and offline. The output is ONLINE/OFFLINE if is online the current node is ACTIVE for the resource otherwise the current node is PASSIVE. If you have OFFLINE to all node the resource is down.


2 Answers

Select ServerProperty('ComputerNamePhysicalNetBIOS') 
like image 155
Stu Avatar answered Oct 14 '22 18:10

Stu


This works in newer versions:

SELECT * FROM fn_virtualservernodes(); 

full details at https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-virtualservernodes-transact-sql?view=sql-server-2017

SELECT * FROM sys.dm_os_cluster_nodes;  

full details at https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-os-cluster-nodes-transact-sql?view=sql-server-2017

like image 42
Haco Avatar answered Oct 14 '22 17:10

Haco