---
title: "Get-DbaSpinLockStatistic"
description: "Retrieves spinlock contention statistics from SQL Server's internal synchronization mechanisms"
url: "https://dbatools.io/Get-DbaSpinLockStatistic/"
availability: "Windows, Linux, macOS"
tags: ["Diagnostic", "SpinLockStatistics", "Waits"]
author: "Patrick Flynn (@sqllensman)"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaSpinLockStatistic.ps1"
last_updated: "2024-01-01"
---

# Get-DbaSpinLockStatistic

## Synopsis

Retrieves spinlock contention statistics from SQL Server's internal synchronization mechanisms

## Description

Queries sys.dm_os_spinlock_stats to return detailed statistics about SQL Server's spinlock usage and contention. Spinlocks are lightweight synchronization primitives that SQL Server uses internally for very brief waits when protecting critical code sections and memory structures.  
  
This information helps diagnose severe performance issues caused by spinlock contention, which typically manifests as high CPU usage with poor throughput. Common spinlock contention scenarios include tempdb allocation bottlenecks, excessive concurrent activity on specific database objects, or issues with SQL Server's internal data structures.  
  
Based on Paul Randal's advanced performance troubleshooting methodology, this data is essential when wait statistics show SOS_SCHEDULER_YIELD or other CPU-related waits that might indicate spinlock pressure.  
  
Returns:  
        SpinLockName - The type of spinlock (e.g., LOCK_HASH, LOGCACHE_ACCESS)  
        Collisions - Number of times threads had to wait for the spinlock  
        Spins - Total number of spin cycles before acquiring the lock  
        SpinsPerCollision - Average spins per collision (efficiency indicator)  
        SleepTime - Total time spent sleeping when spins were exhausted  
        Backoffs - Number of times the thread backed off before retrying  
  
Reference: https://www.sqlskills.com/blogs/paul/advanced-performance-troubleshooting-waits-latches-spinlocks/

## Syntax

```powershell
Get-DbaSpinLockStatistic
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Get SpinLock Statistics for servers sql2008 and sqlserver2012

```powershell
PS C:\> Get-DbaSpinLockStatistic -SqlInstance sql2008, sqlserver2012
```

### Example 2: Collects all SpinLock Statistics on server sql2008 into a Data Table

```powershell
PS C:\> $output = Get-DbaSpinLockStatistic -SqlInstance sql2008 | Select-Object * | ConvertTo-DbaDataTable
```

### Example 3: Get SpinLock Statistics for servers sql2008 and sqlserver2012 via pipline

```powershell
PS C:\> 'sql2008','sqlserver2012' | Get-DbaSpinLockStatistic
```

### Example 4: Connects using sqladmin credential and returns SpinLock Statistics from sql2008

```powershell
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Get-DbaSpinLockStatistic -SqlInstance sql2008 -SqlCredential $cred
```

### Required Parameters

##### -SqlInstance

The SQL Server instance. Server version must be SQL Server version 2008 or higher.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

### Optional Parameters

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

## Outputs

**PSCustomObject**

Returns one object per spinlock type found on the SQL Server instance. Each object contains statistics about spinlock usage and contention for a specific spinlock type.

**Properties:**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- SpinLockName: The type of spinlock (e.g., LOCK_HASH, LOGCACHE_ACCESS)
- Collisions: Number of times threads had to wait for the spinlock
- Spins: Total number of spin cycles before acquiring the lock
- SpinsPerCollision: Average spins per collision (efficiency indicator)
- SleepTime: Total time spent sleeping when spins were exhausted (milliseconds)
- Backoffs: Number of times the thread backed off before retrying

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
