Get-DbaDbVirtualLogFile
View SourceSynopsis
Retrieves detailed virtual log file (VLF) metadata from transaction logs for performance analysis and troubleshooting.
Description
This function uses DBCC LOGINFO to return detailed metadata about each virtual log file (VLF) within database transaction logs. The output includes VLF size, file offsets, sequence numbers, status, and parity information that’s essential for analyzing transaction log structure and performance.
Having a transaction log file with too many virtual log files (VLFs) can hurt database performance. Too many VLFs can cause transaction log backups to slow down and can also slow down database recovery and, in extreme cases, even affect insert/update/delete performance.
Common use cases include identifying databases with excessive VLF counts (typically over 50-100), analyzing VLF size distribution to spot fragmentation issues, and monitoring VLF status during active transactions. This data helps DBAs make informed decisions about log file growth settings and maintenance schedules.
References:
http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/
http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx
If you’ve got a high number of VLFs, you can use Expand-DbaDbLogFile to reduce the number.
Syntax
Get-DbaDbVirtualLogFile
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <Object[]>]
[[-ExcludeDatabase] <Object[]>]
[-IncludeSystemDBs]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Get-DbaDbVirtualLogFile -SqlInstance sqlcluster
Returns all user database virtual log file details for the sqlcluster instance.
Example: 2
PS C:\> Get-DbaDbVirtualLogFile -SqlInstance sqlserver | Group-Object -Property Database | Where-Object Count -gt 50
Returns user databases that have 50 or more VLFs.
Example: 3
PS C:\> 'sqlserver','sqlcluster' | Get-DbaDbVirtualLogFile
Returns all VLF information for the sqlserver and sqlcluster SQL Server instances. Processes data via the pipeline.
Example: 4
PS C:\> Get-DbaDbVirtualLogFile -SqlInstance sqlcluster -Database db1, db2
Returns the VLF counts for the db1 and db2 databases on sqlcluster.
Required Parameters
-SqlInstance
The target SQL Server instance or 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 analyze for VLF information. Accepts wildcards for pattern matching.
Use this when you need to focus on specific databases instead of checking all databases on the instance.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-ExcludeDatabase
Specifies which databases to skip during VLF analysis. Accepts wildcards for pattern matching.
Use this to exclude problematic databases or those you don’t need to monitor for VLF issues.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-IncludeSystemDBs
Include system databases (master, model, msdb, tempdb) in the VLF analysis.
By default, only user databases are checked since system database VLF counts are typically less critical for performance tuning.
| 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 virtual log file (VLF) found in each database transaction log.
Properties:
- ComputerName: The name of the computer hosting the SQL Server instance
- InstanceName: The name of the SQL Server instance
- SqlInstance: The full SQL Server instance name (ComputerName\InstanceName)
- Database: The name of the database containing the virtual log file
- RecoveryUnitId: The recovery unit identifier for the VLF
- FileId: The transaction log file ID (typically 0 for the primary log file)
- FileSize: The size of the virtual log file in bytes
- StartOffset: The starting offset of this VLF within the transaction log file in bytes
- FSeqNo: The virtual log file sequence number - indicates the order of VLFs in the transaction log
- Status: The status of the VLF (0=unused, 1=active, 2=recoverable)
- Parity: The parity value used for recovery tracking and alternate backup validation
- CreateLsn: The Log Sequence Number (LSN) at which this VLF was created
dbatools