[Notes from Pinal]: First of all, last week SQL Server 2016 released. If you have not downloaded the developer version for free. You can download from here. SQL server 2016 has many different features which are related to performance and stability. One of the feature which attracted me very much is stretch database. I am sure of the name, you might have understood that it is about extending the current features of the SQL Server. Well, the feature is very interesting, and to understand how it works, you will have to read this entire blog post.
In this 127th episode of the Notes from the Fields series database expert Kenneth Urena (partner at Linchpin People) shares very interesting conversation related to how to use SQL Server 2016 new feature of Stretch Database.
Now that SQL Server 2016 is getting released, we all start asking our self, how can I utilize this new release of SQL Server to improve the company Database procedures. And one of the many features the product team decided to release this version of SQL server is, the ability to recover very very large databases quickly. And that is how Stretch Database enter to the game.
What is SQL Server Stretch Databases?
SQL Server Stretch is a technology introduced in SQL Server 2016 that allows to select tables (especially very large tables) and decide to keep part of the data in Azure Cloud and part of the data on premises. So yes, it is one of the first engagements from Microsoft to create a truly 100% integrated hybrid database.
Then essentially is to introduce the concept of keep cold data on the cloud and hot data on premises.
Are all the tables of my database eligible to be stretched?
Since it is the first delivery of this technology it had born with a lot of restrictions, so my recommendation is to download Microsoft SQL Server 2016 Upgrade advisor, and follow the next steps:
- Open the stretch Database Advisor
- Select the database to analyze
- Read the analysis report
As can be notice in the image 3, the sales table is not a candidate to be migrated to stretch databases, but the nice thing of the wizard is that It provides good insights of what can be done in order to make that table stretch; in this specific case is to remove a constraint.
Once I have an eligible table to be stretched, how can I start using this feature?
By Default, SQL Server 2016, or at least RC3 doesn’t come with stretch database enabled, then, in order to enable it you need to follow the next steps:
- Enable Stretch database at the instance level, don’t worry, by doing this you only are going to say to sql server “It is very likely that I plan to stretch some tables”.
use master -- Enable stretch database at the instance level exec sp_configure 'remote data archive', '1'; GO RECONFIGURE
- Select the database you want to enable stretch databases.
- Select the tables you want to enable stretch.
- Once the table has been selected, you can stretch the entire table or click over “Entire table” link and define the criteria of what rows will get migrated.
- Sign into the Azure account that will host the cold data.
- Create a new server or use an existing one on azure.
- Create a database master key.
- Select the address where this database is going to be accessed, it could be also a network subnet range.
- Review the summary data, including pricing in azure.
- Finally, the stretch database relationship gets stablished
Once Stretch database is configured how can be monitored and add tables, or pause migration?
To monitor the status of the migration, it can be in two ways.
- Using t-SQL
-- monitor syncronization status select * from sys.dm_db_rda_migration_status
- By the Wizard, select the monitor item in the stretch menu
Modify the stretch status of a table
This can be done by altering the migrate_state to outbound or paused, as follows.
alter table T1 set (REMOTE_DATA_ARCHIVE = ON(MIGRATION_STATE=OUTBOUND));
Restore a database that is stretched
You must restore the database using the normal procedures of backup/restore, but since the must of the data reside in the cloud, at the end of the restore the link to the Azure database need to be re-stablish, and that can be done with the follow command:
- Make sure you save the credential name, this can be get with the following t-sql
select name from sys.database_scoped_credentials
- Re-stablish the link as follow
exec sp_rda_reauthorize_db @credential = N'credential name', @with_copy = 0
How to quickly determine what tables are being stretched?
Well some modifications took place to system view like sys.databases and sys.tables. Then if you need to monitor the databases that are stretched the following t-sql can be executed:
select name from sys.databases where is_remote_data_archive_enabled = 1
what about the tables? in order to determine what tables are getting stretched, the following query becomes very handy:
select object_id, name , is_remote_data_archive_enabled from sys.tables where is_remote_data_archive_enabled = 1
- It is a great way to decrease the recovery time of a very large database in case of restore from backups.
- It is a great way to decrease storage billing for historical data, since the data is in azure and just what is getting used is what is getting bill.
- Since it is the first release of the technology, it comes with a lot of restrictions like:
- No Updates allowed (up to RC3)
- No Deletes Allowed
- Etc, the list is long.
- Set up a stage or pre-production environment is complicated since there is not a way to restore the database in stage and link it to a different Azure DB.
- Alter on the stretched tables are not allowed, so in case of modifications the data has to be migrated to a new structure.
Reference: Pinal Dave (https://blog.sqlauthority.com)