Saturday 29 April 2017

SQL Server 2017 Hidden Gems – Part 1

In this blog post series I will be covering the new features and enhancements brought in SQL Server 2017. With SQL Server 2017 CTP 2.0 release, new column modified_extent_page_count is introduced in sys.dm_db_file_space_usage to track differential changes in each database file of the database. This feature was requested by customers and community in this connect item.

With this, now you can configure your differential backup with an extra piece of code to determine the percentage of pages changed since last full backup. With large number of changes in the database, cost and time to complete differential backup is similar to that of full database backup so there is no real benefit of taking differential backup in this case but it can rather increase the restore time of database.

Let’s do a quick demo to see how it works

I am creating a new database and the running sys.dm_db_file_space_usage on the new database.

CREATE DATABASE vNext
GO
USE vNext
GO
SELECT modified_extent_page_count, * FROM SYS.dm_db_file_space_usage













As full backup will be the base for the differential backup, we are not seeing any pages to be tracked under modified extent page column. If you take a full backup and then run the same command, then you should see some value.
Now I am going to load some test data, take a full backup and then check the value in modified_extent_page_count column.

--Creating a test table and inserting 100 records
CREATE TABLE Test (ID INT IDENTITY(1,1), NAME CHAR(8000))
GO
INSERT INTO Test values ('This is a test data')
GO 100

--Perform a full backup of vNext database to create a base for differential backup
BACKUP DATABASE vNext to disk='NUL'

--Take a look at the modified_extent_page_count column
SELECT modified_extent_page_count, * FROM sys.dm_db_file_space_usage

















Again I am inserting 500 more records to show that whatever changes we do on that file is being tracked

--Let's insert 500 more records
INSERT INTO Test values ('This is a test data')
GO 500

--Take a look at the modified_extent_page_count column
SELECT modified_extent_page_count, * FROM sys.dm_db_file_space_usage














Now let’s see what happens when you take a differential backup.

BACKUP DATABASE vNext TO DISK='vNext_Differential_1.bak' WITH DIFFERENTIAL















You can see 584 pages were processed in the data file with differential backup. This was the same number which was shown in modified_extent_page_count column.
Let’s do couple of backup test to see how the modified_extent_page_count column value changes. First, we’ll take a copy_only full backup

--value of modified_extent_page_count column
SELECT modified_extent_page_count AS 'Before full backup' FROM sys.dm_db_file_space_usage

--Copy only full backup
BACKUP DATABASE vNext TO DISK='NUL' WITH COPY_ONLY

--value of modified_extent_page_count column
SELECT modified_extent_page_count AS 'After COPY ONLY full backup' FROM sys.dm_db_file_space_usage



















As expected, copy_only full backup will not make any change to the backup chain. Now let’s take a full backup of the database

--value of modified_extent_page_count column
SELECT modified_extent_page_count AS 'Before full backup' FROM sys.dm_db_file_space_usage

--Full backup
BACKUP DATABASE vNext TO DISK='NUL'

--value of modified_extent_page_count column
SELECT modified_extent_page_count AS 'After full backup' FROM sys.dm_db_file_space_usage






















So once a fresh full backup is taken that will be the base for next differential backup. So modified_extent_page_count will have a new value.

Hope this helps. Please do share your thoughts in the comments below

Cheers,
Naveen

6 comments:

  1. That's really very good.

    ReplyDelete
  2. Great of informative post

    ReplyDelete
  3. Neveen I have a doubt just want to know curiosity this may be silly question comes to point the screen which you have shared second one you have inserted 100 records but in the column modified extent column we will get only 76 wt about remaing is records

    ReplyDelete
    Replies
    1. After inserting 100 records, I am taking a full backup of the database. So that will reset the value of modified_extent_page_count.

      Delete