SQL Server Articles, Tips, FAQs, Reviews, Whitepaper, News etc - MyTechMantra.com

How to Identify SQL Server Cluster Node and Shared Drives Information Using TSQL Queries

When you have a Multiple SQL Server Cluster Configuration and multiple shared drives it becomes tough to know which SQL Server Failover Cluster Instance is using which Shared Drives. This article has the collection of TSQL queries which can help you identify Cluster Node and Shared Drive Information when you have Multiple SQL Server Failover Cluster Configurations.

Identify is your SQL Server Clustered using TSQL Query

The below T-SQL query will help you identify where the SQL Server Instance you are supporting is clustered on non cluster instance.

SELECT SERVERPROPERTY('IsClustered')
GO

The above query will return either of the below mentioned options.

  • If clustered the above query will return the value as “1
  • If it’s a not clustered instance then the above query will return the value as “0

Identify SQL Server Machine Name, Instance Name and Server Name using TSQL Query

Execute the below query to identify SQL Server Machine Name, Instance Name and Server Name

SELECT SERVERPROPERTY('MachineName')
GO
SELECT SERVERPROPERTY('InstanceName')
GO
SELECT SERVERPROPERTY('ServerName')
GO

TechNet explanation for each of the above property is:-

  • MachineName: – Windows computer name on which the server instance is running. For a clustered instance, an instance of SQL Server running on a virtual server on Microsoft Cluster Service, it returns the name of the virtual server.
  • InstanceName: – Name of the instance to which the user is connected.
  • ServerName: – Both the Windows server and instance information associated with a specified instance of SQL Server.

Identify the Node on which SQL Server Instance is Currently Running using TSQL Query

Execute the below query to identify the node on which SQL Server instance is currently running.

SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS')
GO

TechNet explanation for the above property is: –

  • ComputerNamePhysicalNetBIOS: – NetBIOS name of the local computer on which the instance of SQL Server is currently running. For a clustered instance of SQL Server on a failover cluster, this value changes as the instance of SQL Server fails over to other nodes in the failover cluster. On a stand-alone instance of SQL Server, this value remains constant and returns the same value as the MachineName property.

Identify Nodes of SQL Server Failover Cluster using TSQL Query

You can identify the nodes of SQL Server Failover cluster either by using an inbuilt function or using a DMV. Below mentioned queries will return the same result.

/* Using In-Built Function Identify Nodes of SQL Server Failover Cluster */
SELECT * FROM fn_virtualservernodes()
GO

/* Using DMV Identify Nodes of SQL Server Failover Cluster */
SELECT * FROM sys.dm_os_cluster_nodes
GO

Identify all drives on the node and free space using TSQL queries

Now that you know the SQL Server Nodes the next thing which you would like to know will be the different drives which are available and the free space in each drive. This information you can quickly reterive using XP_FIXEDDRIVES undocumented extended stored procedure.

Use master
GO
EXEC XP_FIXEDDRIVES
GO
XP_FIXEDDRIVES Results

In the above snippet you could see that there are 9 drives available on the node. However, at this point you wont know which are the drives used by SQL Server Cluster.

Identify Shared Drives used by SQL Server Cluster using TSQL Queries

You can identify the shared drives used by SQL Server Failover Cluster Instance either by using an inbuilt function or using a DMV. Below mentioned queries will return the same result.

/* Using In-Built Function Identify Shared Drives Used by SQL Server Failover Cluster Instance */
SELECT * FROM fn_servershareddrives()
GO

/* Using DMV Function Identify Shared Drives Used by SQL Server Failover Cluster Instance */
SELECT * FROM sys.dm_io_cluster_shared_drives
GO

In the above snippet you could see that “F”, “J”, “I” an “H” is shared drives which belong to currently Instance of SQL Server Cluster.

Conclusion

All the above mentioned queries are very useful to a database administrator who has to manage a multiple failover cluster configurations in a very large SQL Server Environment.

References

Read more about SERVERPROPERTY on TechNet
Read more about fn_virtualservernodes() on TechNet
Read more about sys.dm_os_cluster_nodes on TechNet
Read more about fn_servershareddrives on TechNet
Read more about sys.dm_io_cluster_shared_drives on TechNet

Ashish Mehta

Ashish Mehta

Ashish Kumar Mehta is a database manager, trainer and technical author. He has more than a decade of IT experience in database administration, performance tuning, database development and technical training on Microsoft SQL Server from SQL Server 2000 to SQL Server 2014. Ashish has authored more than 325 technical articles on SQL Server across leading SQL Server technology portals. Over the last few years, he has also developed and delivered many successful projects in database infrastructure; data warehouse and business intelligence; database migration; and upgrade projects for companies such as Hewlett-Packard, Microsoft, Cognizant and Centrica PLC, UK. He holds an engineering degree in computer science and industry standard certifications from Microsoft including MCITP Database Administrator 2005/2008, MCDBA SQL Server 2000 and MCTS .NET Framework 2.0 Web Applications.

Add comment

Newsletter Signup! Join 15,000+ Professionals




Be Social! Like & Follow Us...

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Recent SQL Server Tips

Manning