---
title: "Get-DbaDbMemoryUsage"
description: "Retrieves detailed buffer pool memory consumption by database and page type for performance analysis."
url: "https://dbatools.io/Get-DbaDbMemoryUsage/"
availability: "Windows, Linux, macOS"
tags: ["Memory", "Database"]
author: "Shawn Melton (@wsmelton), wsmelton.github.io"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaDbMemoryUsage.ps1"
last_updated: "2024-01-01"
---

# Get-DbaDbMemoryUsage

## Synopsis

Retrieves detailed buffer pool memory consumption by database and page type for performance analysis.

## Description

Analyzes SQL Server buffer pool memory usage by querying sys.dm_os_buffer_descriptors to show exactly how much memory each database consumes, broken down by page type (data pages, index pages, etc.). This helps DBAs identify memory-hungry databases that may be impacting instance performance and guides decisions about memory allocation, database optimization, or server capacity planning.  
  
The results include both raw page counts and percentage of total buffer pool consumed, making it easy to spot databases that are taking disproportionate memory resources. Use this when troubleshooting memory pressure, planning database migrations, or optimizing buffer pool utilization across multiple databases.  
  
This command is based on query provided by Aaron Bertrand.  
Reference: https://www.mssqltips.com/sqlservertip/2393/determine-sql-server-memory-use-by-database-and-object/

## Syntax

```powershell
Get-DbaDbMemoryUsage
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [-IncludeSystemDb]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Returns the buffer pool consumption for all user databases

```powershell
PS C:\> Get-DbaDbMemoryUsage -SqlInstance sqlserver2014a
```

### Example 2: Returns the buffer pool consumption for all user databases and system databases

```powershell
PS C:\> Get-DbaDbMemoryUsage -SqlInstance sqlserver2014a -IncludeSystemDb
```

### Example 3: Returns the buffer pool consumption for tempdb database only

```powershell
PS C:\> Get-DbaDbMemoryUsage -SqlInstance sql1 -IncludeSystemDb -Database tempdb
```

### Example 4: Returns the buffer pool consumption for all user databases and tempdb database

```powershell
PS C:\> Get-DbaDbMemoryUsage -SqlInstance sql2 -IncludeSystemDb -Exclude 'master','model','msdb','ResourceDb'
```

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

Restricts analysis to specific databases by name. Accepts multiple database names or wildcard patterns.  
Use this when investigating memory usage for particular databases rather than analyzing the entire instance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | true (ByPropertyName) |
| Default Value |  |

##### -ExcludeDatabase

Excludes specific databases from the memory analysis by name. Accepts multiple database names.  
Useful for filtering out known databases that aren't relevant to your current investigation or capacity planning.

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

##### -IncludeSystemDb

Includes system databases (master, model, msdb, tempdb, ResourceDb) in the memory consumption analysis.  
Use this when troubleshooting overall instance memory pressure or when tempdb memory usage is a concern.

| 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 page type per database showing buffer pool memory consumption.

**Default display properties (via Select-DefaultView):**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Database: Name of the database consuming the buffer pool pages
- PageType: Type of page in the buffer (e.g., data pages, index pages, etc.)
- Size: Amount of memory consumed by this database and page type (in MB, as DbaSize object)
- PercentUsed: Percentage of total buffer pool consumed by this database and page type (0-100)

**Additional properties available:**

- PageCount: The number of 8KB pages allocated to this database and page type in the buffer pool
All properties are accessible using Select-Object *.

---

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