Thursday 6 March 2014

   
DBCC DROPCLEANBUFFERS and CHECKPOINT

DBCC DROPCLEANBUFFERS: is very useful command while doing the performance tuning of the queries. We can use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server.

Before we get into more detail, Let’s take a look sys.dm_os_buffer_descriptors DMV.

sys.dm_os_buffer_descriptors
Returns information about all the data pages which are currently in the SQL Server buffer pool, Output of the DMV will help us to determine the distribution of database pages in the buffer pool.

As you might know, when a data page is read from disk, it will first copy to buffer pool and cached for reuse. Each cached data page has one buffer descriptor.

Sys.dm_os_buffer_descriptors returns cached pages for all user and system databases.

You can use below query to check the buffer descriptor for the current database.

use SQLMonitor
select sysObj.name,*
from sys.dm_os_buffer_descriptors bufferDescriptors
INNER JOIN sys.allocation_units AllocUnits ON bufferDescriptors.allocation_unit_id = AllocUnits.allocation_unit_id
INNER JOIN sys.partitions Partitions ON AllocUnits.container_id = Partitions.hobt_id
INNER JOIN sys.objects sysObj ON Partitions.object_id = sysObj.object_id
WHERE bufferDescriptors.database_id = DB_ID()
AND sysObj.is_ms_shipped = 0

Execute below command, and again execute the sys.dm_os_buffer_descriptors bufferDescriptors query.
1
2
3
4
5
6
7
8
9
10
   
DBCC DROPCLEANBUFFERS

use SQLMonitor
select sysObj.name,*
from sys.dm_os_buffer_descriptors bufferDescriptors
INNER JOIN sys.allocation_units AllocUnits ON bufferDescriptors.allocation_unit_id = AllocUnits.allocation_unit_id
INNER JOIN sys.partitions Partitions ON AllocUnits.container_id = Partitions.hobt_id
INNER JOIN sys.objects sysObj ON Partitions.object_id = sysObj.object_id
WHERE bufferDescriptors.database_id = DB_ID()
AND sysObj.is_ms_shipped = 0

See the results of sys.dm_os_buffer_descriptors, still it has return 154 rows which means all the pages from buffer pool is not cleared.

SPRawmaterialReceiptDetails

No comments:

Post a Comment