Skip to content

Commit a8cfb13

Browse files
Alexander SheleminAlexander Shelemin
Alexander Shelemin
authored and
Alexander Shelemin
committed
new cool stuff from generous community
1 parent 7d1a1b1 commit a8cfb13

3 files changed

+74
-0
lines changed

MaintenanceSolution.sql

464 KB
Binary file not shown.

cache_usage_per_db.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
DECLARE @total_buffer INT;
3+
4+
SELECT @total_buffer = cntr_value
5+
FROM sys.dm_os_performance_counters
6+
WHERE RTRIM([object_name]) LIKE '%Buffer Manager'
7+
AND counter_name = 'Total Pages';
8+
9+
;WITH src AS
10+
(
11+
SELECT
12+
database_id, db_buffer_pages = COUNT_BIG(*)
13+
FROM sys.dm_os_buffer_descriptors
14+
--WHERE database_id BETWEEN 5 AND 32766
15+
GROUP BY database_id
16+
)
17+
SELECT
18+
[db_name] = CASE [database_id] WHEN 32767
19+
THEN 'Resource DB'
20+
ELSE DB_NAME([database_id]) END,
21+
db_buffer_pages,
22+
db_buffer_MB = db_buffer_pages / 128,
23+
db_buffer_percent = CONVERT(DECIMAL(6,3),
24+
db_buffer_pages * 100.0 / @total_buffer)
25+
FROM src
26+
ORDER BY db_buffer_MB DESC;

cache_usage_per_dbobject.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
;WITH src AS
3+
(
4+
SELECT
5+
[Object] = o.name,
6+
[Type] = o.type_desc,
7+
[Index] = COALESCE(i.name, ''),
8+
[Index_Type] = i.type_desc,
9+
p.[object_id],
10+
p.index_id,
11+
au.allocation_unit_id
12+
FROM
13+
sys.partitions AS p
14+
INNER JOIN
15+
sys.allocation_units AS au
16+
ON p.hobt_id = au.container_id
17+
INNER JOIN
18+
sys.objects AS o
19+
ON p.[object_id] = o.[object_id]
20+
INNER JOIN
21+
sys.indexes AS i
22+
ON o.[object_id] = i.[object_id]
23+
AND p.index_id = i.index_id
24+
WHERE
25+
au.[type] IN (1,2,3)
26+
AND o.is_ms_shipped = 0
27+
)
28+
SELECT
29+
src.[Object],
30+
src.[Type],
31+
src.[Index],
32+
src.Index_Type,
33+
buffer_pages = COUNT_BIG(b.page_id),
34+
buffer_mb = COUNT_BIG(b.page_id) / 128
35+
FROM
36+
src
37+
INNER JOIN
38+
sys.dm_os_buffer_descriptors AS b
39+
ON src.allocation_unit_id = b.allocation_unit_id
40+
WHERE
41+
b.database_id = DB_ID()
42+
GROUP BY
43+
src.[Object],
44+
src.[Type],
45+
src.[Index],
46+
src.Index_Type
47+
ORDER BY
48+
buffer_pages DESC;

0 commit comments

Comments
 (0)