---
title: "Get-DbaDbLogSpace"
description: "Retrieves transaction log space usage and capacity information from SQL Server databases."
url: "https://dbatools.io/Get-DbaDbLogSpace/"
availability: "Windows, Linux, macOS"
tags: ["Storage", "Space", "Log", "File"]
author: "Jess Pomfret, JessPomfret.com"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaDbLogSpace.ps1"
last_updated: "2024-01-01"
---

# Get-DbaDbLogSpace

## Synopsis

Retrieves transaction log space usage and capacity information from SQL Server databases.

## Description

Collects detailed transaction log metrics including total size, used space percentage, and used space in bytes for databases across SQL Server instances. Uses the sys.dm_db_log_space_usage DMV on SQL Server 2012+ or DBCC SQLPERF(logspace) on older versions.  
  
Essential for proactive log space monitoring to prevent unexpected transaction log growth, identify databases approaching log capacity limits, and plan log file sizing. Helps DBAs avoid transaction failures caused by full transaction logs and optimize log file allocation strategies.

## Syntax

```powershell
Get-DbaDbLogSpace
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-ExcludeDatabase] <String[]>]
    [-ExcludeSystemDatabase]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Returns the transaction log usage information for all databases on Server1

```powershell
PS C:\> Get-DbaDbLogSpace -SqlInstance Server1
```

### Example 2: Returns the transaction log usage information for both Database1 and Database 2 on Server1

```powershell
PS C:\> Get-DbaDbLogSpace -SqlInstance Server1 -Database Database1, Database2
```

### Example 3: Returns the transaction log usage information for all databases on Server1, except Database3

```powershell
PS C:\> Get-DbaDbLogSpace -SqlInstance Server1 -ExcludeDatabase Database3
```

### Example 4: Returns the transaction log usage information for all databases on Server1, except the system databases

```powershell
PS C:\> Get-DbaDbLogSpace -SqlInstance Server1 -ExcludeSystemDatabase
```

### Example 5: Returns the transaction log usage information for Database1 for a group of servers from SQL Server Central...

```powershell
PS C:\> Get-DbaRegisteredServer -SqlInstance cmsServer | Get-DbaDbLogSpace -Database Database1
```

Returns the transaction log usage information for Database1 for a group of servers from SQL Server Central Management Server (CMS).  

### Required Parameters

##### -SqlInstance

SQL Server name or SMO object representing the SQL Server to connect to. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

| 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 |  |

##### -Database

Specifies which databases to check for transaction log space usage. Accepts wildcards for pattern matching.  
Use this when you need to monitor specific databases instead of checking all databases on the instance, particularly useful for focusing on high-growth or critical databases.

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

##### -ExcludeDatabase

Specifies databases to skip when checking transaction log space usage. Accepts wildcards for pattern matching.  
Use this to exclude databases you don't need to monitor regularly, such as test databases, read-only databases, or databases with known stable log usage patterns.

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

##### -ExcludeSystemDatabase

Excludes system databases (master, model, msdb, tempdb) from the transaction log space report.  
Use this when focusing on user databases only, as system database log usage is typically managed differently and may not require the same monitoring attention.

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

##### -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 database containing transaction log space usage metrics.

**Properties:**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name (service name)
- SqlInstance: The full SQL Server instance name (computer\instance format)
- Database: The name of the database
- LogSize: The total size of the transaction log file(s) for the database, formatted as a dbasize object (e.g., "10 MB", "1 GB")
- LogSpaceUsedPercent: The percentage of the transaction log that is currently in use (0-100)
- LogSpaceUsed: The amount of space currently used in the transaction log file(s), formatted as a dbasize object
The command uses sys.dm_db_log_space_usage DMV on SQL Server 2012+ or DBCC SQLPERF(logspace) on earlier versions, but returns identical output structure for both.

---

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