Memory Consumption by Object
SQL Server caches object data in memory in the buffer pool. Understanding memory consumption by object can be crucial for performance. For instance, you may have a large logging table consuming 90% of the buffer…
dm_db_database_page_allocations
sys.dm_db_database_page_allocations is an undocumented SQL Server T-SQL Dynamic Management Function. This DMF provides details about allocated pages, allocation units, and allocation extents. The function definition in SQL Server 2016 is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
create function sys.dm_db_database_page_allocations ( @DatabaseId SMALLINT, @TableId INT = NULL, @IndexId INT = NULL, @PartitionId BIGINT = NULL, @Mode NVARCHAR(64) = 'LIMITED' ) returns table as return select DA.[database_id], DA.[object_id], DA.[index_id], DA.[partition_id], DA.[rowset_id], DA.[allocation_unit_id], DA.[allocation_unit_type], IP.[name] as 'allocation_unit_type_desc', DA.[data_clone_id], DA.[data_clone_state] as 'clone_state', case (DA.[data_clone_state]) when 0 then N'PRIMARY' else N'SECONDARY' end AS clone_state_desc, DA.[extent_file_id], DA.[extent_page_id], DA.[allocated_page_iam_file_id], DA.allocated_page_iam_page_id, DA.[allocated_page_file_id], DA.allocated_page_page_id, DA.is_allocated, DA.is_iam_page, DA.is_mixed_page_allocation, DA.page_free_space_percent, DA.page_type, DA.page_type_desc, DA.page_level, DA.next_page_file_id, DA.next_page_page_id, DA.previous_page_file_id, DA.previous_page_page_id, DA.is_page_compressed, DA.has_ghost_records from openrowset (table DM_DB_DATABASE_ALLOCATIONS, @DatabaseId, @TableId, @IndexId, @PartitionId, @Mode) DA JOIN sys.syspalvalues IP ON IP.[class] = 'AUTY' AND IP.[value] = DA.[allocation_unit_type] |
The function definition tells…
Using Dynamic SQL inside a Stored Procedure
Preventing direct access to database tables for users is a widely considered “best practice” for many DBAs. The pattern typically looks like User -> Stored Procedure -> Tables. Since the stored procedure owner has access…
Configure a SQL Server Agent Operator
SQL Server Agent operators are used by SQL Server Agent to send notifications about events as they happen. Typically, this would include notifications that a SQL Server Agent Job failed during execution. You might also…
How to Corrupt a Database
Microsoft goes to great lengths to ensure data integrity remains its paramount concern with SQL Server data. After all, ACID compliance doesn’t mean much if the underlying data is corrupt. Having said that, there are…
Automating Alerts
SQL Server Agent provides a great mechanism for sending alerts via email in response to various events. Once you’ve setup Database Mail, and configured a SQL Server Agent Operator, you should add alerts for severe…