In the last two days we saw whats stretch database and how to identify the tables. Today we will see how to stretch your database to Azure cloud. Before we start I would like mention it again that the tables you choose for streching will migrate all the data to Azure which means we can stretch only the archieve tables so dont just blindly add all the tables. Just include only the required archieve tables.
Configuring Stretch Dataabse
- Connect to SQL Server 2016
- By default remote data archieve is turned off so use the query below to turn it on. This will enable the feature at server level
IF( SELECT value_in_use
WHERE name = ‘remote data archive’ ) = 0
EXEC sp_configure ‘remote data archive’, 1;
- Now enable the same feature for a database. Right click on the database go to Tasks and then select Stretch and then Enable as shown in the below image.
- It will pop up new wizard for configuration. Please note that there are lot of difference compared to CTP 2.1 version. Click next
- Connecting to Azure cloud is encrypted by database key so you need to create master key (if it didnt created earlier) and then a database key. Just provide a new password in the screen and click next, GUI will do it for you.
- Now it will list all the tables, choose the tables you want to stretch it and then click next
- It will do all checks before enabling. If you remeber in the first article I said there are few limitations exists so it will validate those things. One more thing to note is that it wont create unique \ primary key in azure table.
- In this screen you need to provide Azure credentails to which the subscriptions are added and then click next
- In this screen you need to select the subscription and then the region. If you already have a Azure SQL Server then you can connect to it or else you can create a new one. In this one, I have a SQL Azure server so i used that.
- Since I used my existing Azure SQL Server it’s asking the admin username and password. In addition to this I can provide the IP range to access this db. Im sure we need to exclude atleast the inhouse server IP.
- Cross check the summary, if all looks good just click on finish
- Awesome, selected tables are now stretched to Azure database.
- Now if you look at the database symbol you can see it got changed. In addition to this I could find a external data source got created. I’m not able to guess what’s the the value appended after DBM.
All looks good. Let’s add some data to the table. I added couple of rows and it picked and migrated to Azure cloud
Insert works fine but Update \ Delete are not allowed. I believe since it’s an archieve table there wont be a need to update the data however delete is required to clean up older data or else we will again loosing cost in Azure storage. I assume we will get Delete \ Update functionality in RTM release.
Msg 14826, Level 16, State 1, Line 3 Update and delete of rows eligible for migration in table 'trip' is not allowed because of the use of REMOTE_DATA_ARCHIVE.
Since it’s an archieve table, volume of data might be huge so I want to check how it process the data from Inhouse to Azure cloud. For this I connected to the Azure SQL Server and executed the below query. The name of the Azure db is different again with some unique value appended to the end, Im not clear what that unique value is.
A new column will be added to the table as “batch–ObjectIDofInhouseTable”. From this we are clear that it will process the rows in batches. If you see it will pick a max of 4999 rows per batch which means the a batch size is less than 5000 rows. Cool 🙂
–Number of rows processed per batch
SELECT COUNT(*) [Number of Rows]
, [batchid–1285579618] [BatchID]
GROUP BY [batchid–1285579618];
Let’s assume you are in a situation where you dont want to migrate the data as soon as it arrives to avoid network traffice etc. For this we can simply disable the stretch and then we can enable it back when required, it will pick up from the point where it left.
Right Click on the Table and then Stretch and then Pause “Data Migration” or you can use the below query
[sql]ALTER TABLE TRIP
SET ( REMOTE_DATA_ARCHIVE ( MIGRATION_STATE = PAUSED ) ) ; — To resume change PAUSED to OUTBOUND
Enabling Stretch for additional tables at later point
Right click on the User database and then “Tasks” and then “Stretch” and then “Reconfigure”. now you will get the same wizard but now it will start from the table page, choose the tables and follow the wizard
Expand the user database, expand tables.
Right click on the table and then “Stretch” and then “Enable”
I’m done for this article, lets catch up tomorrow with some more details on database stretching.