MS-SQL Server

DBCC DROPCLEANBUFFERS 를 수행하면 Buffer Pool에 존재하는 데이터 페이지가 사라질까?

송혁 - HyokSong 2008. 4. 23. 18:02

DBCC DROPCLEANBUFFERS Buffer Pool 존재하는 데이터 페이지를 제거하는 구문입니다.
하지만 DBCC DROPCLEANBUFFERS 수행하면 정말 Buffer Pool 있는 데이터 페이지가 사라질까요?
간단히 결론만을 말하면 아직 disk 플러시 되지 않는 페이지는 구문으로 내려갈 없습니다.
모든 Buffer Pool 있는 페이지를 내리려면 checkpoint 통해서 Dirty페이지를 마크 후에 DBCC DROPCLEANBUFFERS 수행 하면됩니다.

아래는 테스트 예제입니다.


USE TEST

GO

--DROP TABLE tbl1

 

--샘플 테이블 만들기

SELECT

       TOP 1000

       ROW_NUMBER() over(order by (select 1)) as col1

       ,cast('Hyoksong' as char(5000)) as col2

INTO tbl1

from sys.sysindexes A,sys.sysindexes B,sys.sysindexes C,sys.sysindexes B1

 

--Buffer Pool에있는 데이터 페이지를 날리자.

EXEC sp_msforeachdb 'USE ? CHECKPOINT 1'

DBCC DROPCLEANBUFFERS

 

--500 행에 대해서 업데이트를 치자.

UPDATE tbl1

SET col2 = 'Test'

WHERE col1 > 500

(500개행적용됨)

 

--Buffer Pooltbl1 테이블 데이터 페이지의 수는 몇개?

select

       COUNT(*)

from sys.allocation_units a

       right outer join  sys.dm_os_buffer_descriptors b

             ON a.allocation_unit_id = b.allocation_unit_id

       left outer join sys.partitions p

             ON a.container_id = p.hobt_id

WHERE B.database_id = db_id('Test')

       and (p.object_id IS NULL OR p.object_id > 100)

      and object_name(object_id,database_id) = 'tbl1'

       and page_type = 'DATA_PAGE'

/*

       결과: 1001

*/

--DBCC DROPCLEANBUFFERS 를수행하고Buffer Pool에는몇개?

DBCC DROPCLEANBUFFERS

 

select

       COUNT(*)

from sys.allocation_units a

       right outer join  sys.dm_os_buffer_descriptors b

             ON a.allocation_unit_id = b.allocation_unit_id

       left outer join sys.partitions p

             ON a.container_id = p.hobt_id

WHERE B.database_id = db_id('Test')

       and (p.object_id IS NULL OR p.object_id > 100)

       and object_name(object_id,database_id) = 'tbl1'

       and page_type = 'DATA_PAGE'

/*

       결과: 500

*/

 

--그럼Checkpoint를후에DBCC DROPCLEANBUFFERS을수행하면?

CHECKPOINT 1

DBCC DROPCLEANBUFFERS

 

select

       COUNT(*)

from sys.allocation_units a

       right outer join  sys.dm_os_buffer_descriptors b

             ON a.allocation_unit_id = b.allocation_unit_id

       left outer join sys.partitions p

             ON a.container_id = p.hobt_id

WHERE B.database_id = db_id('Test')

       and (p.object_id IS NULL OR p.object_id > 100)

       and object_name(object_id,database_id) = 'tbl1'

       and page_type = 'DATA_PAGE'

/*

       결과: 0

*/

 

송 혁, SQL Server MVP
sqler.pe.kr
sqlleader.com
hyoksong.tistory.com
nexondbteam.tistory.com