SQL Server 2016 Cloud Integration Enhancements

ITPro Today

September 22, 2015

10 Min Read
ITPro Today logo in a gray background | ITPro Today

Abstract

In earlier version of SQL Server (2014), the Microsoft Azure platform was meant for keeping the database backups as this platform is cost-effective, secure, and inherently offsite for keeping the backups. Later, it has been enhanced to provide disaster recovery by making cloud backup as asynchronous replica which will reduce CAPEX and OPEX cost of physically maintaining additional hardware in additional data centers.

In the latest version of SQL Server (2016), the Microsoft brought an ability to extend your on premise SQL database to Azure and perform queries seamlessly. In this article, an attempt has been made to explain this new feature of SQL Server.

Business Context

We know that the history data is critical for any organization to enable reporting and comply with the regulatory requirements. However, the retention of huge amount of history data in the primary database storage area will impact the performance of on-line transaction processing and increase the cost of storage. In order to overcome these limitations, Microsoft has introduced an option to expand your SQL Server database to the cloud. This option is called as “Stretch Database” that allows extension of SQL database from local SQL Server instance to Azure SQL database and the users will be able to access the data on Azure SQL database seamlessly.

Introduction

This “Stretch Database” feature lets you dynamically move portion of warm and cold transactional table data to Microsoft Azure. This feature is more beneficial to keep the on-line transactional data for longer periods of time on the On-premise storage and move the history data to cloud storage to save money on storage and improve on-line transaction processing performance. The history data is migrated to Azure seamlessly and the applications will be able to query the data without requiring any changes to application code.

This is required to enable “Stretch database option” at database level and identify the tables that are required to move to Azure so that the migration happens silently. In order to identify the candidate tables for migration, run a tool called “Stretch Database Advisor. The query optimizer is fully aware of the rows are on the server vs. the rows on the Azure, and divides the workload accordingly. Since the Azure takes care of the query processing for the data on Azure, the latency is attributed only to the network to return the data. Also, the user is charged whenever the data on Azure is queried, along with the Azure Blob storage. No additional software licensing costs are levied.

Prerequisites

The following are the prerequisites to leverage the Stretch Database feature.

 

·         Azure SQL database uses firewall rules to allow connections to the local SQL Server and databases. Hence, server-level and database-level firewall settings are to be defined for the master and the user databases in the Azure SQL database server to selectively allow access to the database. Microsoft recommends using database-level firewall rules whenever possible to make the user database more portable. The server-level firewall rules may be used when there are many databases exists with same access requirements.

 

·         Setting up of Azure account and subscription for billing

 

·         Enabling Stretch Database for a SQL Server instance - Change the "remote data archive" instance-level configuration option using sp_configure, as mentioned below. With this option enabled, one can configure databases for Stretch Database, migrate data, and query data on the remote endpoint.

--To verify the current setting for the instance

EXEC sp_configure 'remote data archive';

GO

--To set the option to ON at instance level

EXEC sp_configure 'remote data archive' , '1';

GO

RECONFIGURE;

GO

Note: This option is neither a switch that turns the Stretch Database feature on or off nor a permission setting for configuring Stretch Database.

 

·         Availability of Stretch Database Advisor tool which is part of SQL Server 2016 Upgrade Advisor. SQL Server 2016 Upgrade Advisor is a standalone tool that enables users of prior versions to run a set of upgrade rules against their SQL Server database to pinpoint breaking and behavior changes and deprecated features as well as providing help with the adoption of new features such as Stretch Database. This tool does not come along with SQL Server 2016 CTP2. It is to be downloaded from here.

 

Implementation

  1. Enable the “Stretch option” for a database using either SSMS wizard or T-SQL

SSMS Wizard:

  1. Use SSMS wizard to select the database and provide necessary server location information and login credentials for Azure. This will create a secure linked server definition on the local SQL Server instance to the remote SQL database on cloud as the end point.

 

  1. Create Credential for Azure SQL database using the SSMS wizard (at the time of enabling Stretch Database)

 

T-SQL:

  1. Create a CREDENTIAL for Azure SQL database server

CREATE CREDENTIAL WITH IDENTITY = , SECRET =

 

  1. Enable Stretch Database option by using T-SQL Statement from master database, as shown below.

ALTER DATABASE

SET REMOTE_DATA_ARCHIVE = ON (SERVER = );

GO;

 

  1. Run Stretch Database Advisor to identify the candidate tables for Stretch Database enablement.

 

  1. Enable stretch database option for the identified tables using SSMS or T-SQL option

 

  1. Select all the tables that require stretch enablement (as suggested by the Stretch Database Advisor) in the SSMS wizard. (or) use the following T-SQL code

ALTER TABLE dbo.

ENABLE REMOTE_DATA_ARCHIVE WITH (MIGRATION_STATE = ON);

GO

 

Verification & Validation of Stretch Database setup

·         To know all the databases and tables that are stretch enabled on a particular instance, check the value of column is_remote_data_archive_enabled in sys.databases and sys.tables system tables (0 – not enabled, 1 – enabled, same column in both the tables)

 

·         To verify the status of data migration to Azure, use the sys.dm_db_rda_migration_status DMV.

 

·         To know all the remote databases and tables that are used by Stretch Database – use the catalog views sys.remote_data_archive_databases and sys.remote_data_archive_tables

 

Data Access

Stretch Database does not change the permission model for an existing database. The user logins will be able to access the Azure SQL database through the local instance database only. User logins cannot issue queries directly to the remote endpoint (Azure) through the linked server definition.

Data Backup

As of CTP2 release, SQL Server 2016 supports only shallow backup for a Stretch-enabled database. It means it does not include the data residing on the remote server. The shallow backup contains only the local data, along with the remote endpoint location where the data resides on Azure SQL database. The ability to take deep backup that includes local and remote data, is expected to be available with SQL Server 2016 RTM version.

Data Restore

  1. In order to restore the backup of stretched database, it is required for the local database instance to connect to the Azure SQL database. The connection to remote SQL database is established by using a stored procedure call - sys.sp_reauthorize_remote_data_archive

EXEC sys.sp_reauthorize_remote_data_archive @azure_username, @azure_password;

GO;

 

  1. Once the connection is re-established with the remote SQL database, Stretch Database attempts to reconcile eligible data in the local database with remote data by creating a copy of the remote data on the remote endpoint and linking it with the local database.

 

  1. Once reconciliation runs, the local database and the remote endpoint are in a consistent state. Then, the previous copy of remote data can be deleted.

 

Disable Stretch Database option for a Table

·         In order to disable stretch database option for a table, pause data migration on the table as a first step. This can be done either by using SSMS (select the table, right-click Go to Tasks à Stretch à Pause) or by using T-SQL, as shown below.

ALTER TABLE

ENABLE REMOTE_DATA_ARCHIVE WITH ( MIGRATION_STATE = OFF );

GO;

·         Create a new local table with some name but the same schema as the Stretch-enabled table.

·         Copy the data from the Stretch-enabled table into the new table by using an INSERT INTO … SELECT FROM statement.

·         Drop the Stretch-enabled table.

·         Rename the new table with the name of the Stretch-enabled table that has been dropped in the previous step

Disable and Drop Stretch Enabled Database

·         The Stretch database option can be disabled for a database only when all the tables with in the database are no longer enabled with the Stretch database option. The Stretch Database option can be disabled for a database using SSMS (right-click database, select Tasks à Disable Database for Stretch) or T-SQL statement, as shown below

ALTER DATABASE

SET REMOTE_DATA_ARCHIVE = OFF;

GO;

·         The database on local instance can be dropped using DROP DTABASE statement. However, the remote Azure SQL database will not be dropped. The remote database can be done by using the Azure Management portal.

Limitations imposed by SQL Server on the database objects to enable Stretch Database option

The Stretch Database option cannot be enabled on the following SQL server database objects.

·         Memory optimized tables, Replicated tables, Change Tracking enabled and CDC enabled tables

·         Uniqueness is not enforced for UNIQUE constraints and PRIMARY KEY constraints on a Stretch-enabled table

·         Tables containing FILESTREAM data and File Tables

·         Columns of types timestamp, sql_variant, XML, geometry, CLR-defined types, geography and columns that are “Always Encrypted”

·         Computed columns cannot be migrated

·         Constraints such as CHECK, DEFAULT and FK will not be migrated

·         XML, full-text, spatial, clustered column-store and indexed views that reference the Stretch-enabled table

·         DML operations, INDEX operations cannot be performed on a Stretch-enabled table

Known issues with Stretch Database Configuration

·         Azure SQL database firewall related - Verify the firewall rules configured for the database in the Azure Management Portal. In case of failure to connect with the Azure SQL database, try some of the following

·         Rows from the Stretch-enabled table are not being migrated to Azure. Verify the following

·         Queries accessing the Stretch-enabled table are running slow after Stretch enablement. Verify the following

·         The service tier or the performance level of the Azure SQL database server may not be sufficient to process the SQL queries quickly.

·         The network conditions might have got degraded. Contact network administrator for info about recent issues or outages.

Use cases for Stretch Database

The following are use cases where Stretch database option can be leveraged.

·         Archiving of data onto low-cost storage in order to satisfy the regulatory compliance requirements, such as Sarbanes-Oxley (SOX) and Dodd-Frank Act to meet additional history data reporting requirements

·         Shortening of database restore time in case of large SQL databases which is otherwise too long with the conventional database storage option.

References

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like