Tuesday, August 6, 2019

Azure SQL Managed Instance High Availability and Disaster Recovery options




The below blog is to summarize every High Availability and Disaster Recovery options available in Azure SQL Database Managed Instance and a few methods to make use of them.

Before we proceed, I would like to refresh your knowledge about the below two key parameters which are often discussed in every DR Strategy meeting between system administrators and other stake holders.


RPO (Recovery Point Objective) : It decides the maximum amount of data loss the IT system or the business can afford in an event of disaster. For an example, if your log backup is set to run every 30 min, you are practically having an option to recover your data to any point in time, at least 30 min before the time a disaster bring down your system.


RTO (Recovery Time Objective): Time in hours/Days which indicates the maximum downtime, you can have in your system as agreed with your client or business .

The better your Disaster Recovery setups, the lower will be your systems' RPO and RTO.


Below are the Disaster Recovery and High availability options we have in Azure SQL database managed instance.


1. Read Scale-out


By Default each Azure SQL database in managed instance of business Critical service tier is given with three replicas , one of which is provisioned as Read-Only. None of these extra replicas are sharing the compute resources you have allocated to your Managed instance . The read only replica can be used for offloading some of your read only work load from your Primary instance and can be connected by mentioning 'Application intent' as 'Readonly' in an OLeDB connection String. You can also create a linked server which is again built on an Oledb provider by mentioning the same property value.

Other two replicas are maintained for High Availability during events such as service patching .



T-SQL query to fetch the synchronization status and health of your replicas.


Use master
go
SELECT
db.name as [db_name],
rpl.replica_id,
rpl.group_database_id,
rpl.is_local,
rpl.is_primary_replica,
rpl.synchronization_state_desc AS syncro_state,
rpl.synchronization_health_desc AS synchro_health,
rpl.database_state_desc AS db_state,
rpl.log_send_queue_size,
rpl.redo_queue_size
FROM sys.dm_hadr_database_replica_states AS rpl
join sys.databases AS db ON db.database_id = rpl.database_id



Sample Output








T-SQL Script to create a linked server for your read only replica






EXEC sp_addlinkedserver @server=N'ReadOnlyReplica', --Change the name as you need
@srvproduct=N'',
@provider=N'SQLNCLI',
@provstr = N'ApplicationIntent=ReadOnly',
@datasrc= @@SERVERNAME;












Another important point to note is that there will only be Tables and views present here in this replica and not procedures and functions.


2. Failover Groups

It is a Disaster Recovery setup built based on always-on Feature of SQL servers and made available in azure SQL space, in addition to the availability replicas described above .The reason why we might need it, is that the replicas that come free with the instance can not guarantee safeguarding against a region/data center wise outage. Azure Managed instances support single fail-over group consisting of all the databases in the instances and it is created with automatic fail-over plan by default (Can be turned off). To begin with the configuration, one must create a secondary empty instance in another region entirely and work for enabling two directional traffic between the VNets hosting both the primary and secondary instance.


If you are using automatic failover option, make sure you understand and configure the 'GracePeriodWithDataLossHours' Property correctly as it decides how many hours the system will wait for a graceful failover with no data loss. Its minimum allowed value is one hour at present. You can also perform manual fail-over with the failover groups.


Azure SQL DBaaS offerings other than managed instance supports a similar feature called Geo-Replication and the below table can be used to differentiate between the two.






3. Geo-Restore


The automated backups that are taken and retained based on the retention period you define (Between 7-35 days) are made geo-redundant by default. Hence these backups can be used to restore the databases even when they are dropped by a mistake or on purpose. Managed instances does not have long term retention plan as they support Copy-only backup already which could be taken and maintained as per users' choice. Other two DBaaS offerings support Long term retention policies yet do not have copy only backups.


Below is a table depicting the RPO RTOs for the various DR methods discussed till now.








4. Database Replication


Database replication is supported in managed instances , but with certain restrictions. On-premise databases can be made as both source and target for the Transactional replication in managed instances. Managed instances do not support merge replication , peer to peer replication and transactional replication with update-able subscribers. And another limitation for Managed instance to Managed instance replication is,it supports only push subscription and  the distributor and the publisher has to be in the same managed instance.

But I am hopeful that there are improvements coming in future days for the replication in managed instance as its only in public preview for managed instances.


I will be writing a different blog on configuring steps with a demo for a thorough analysis.


































Saturday, August 3, 2019

What to Consider before choosing an Azure DBaaS offering


            The below blog content is intended to help the readers in choosing the right DBaaS offering from Azure and the common criteria to be considered while choosing one. This is written based on my own experience with Azure migration POC projects I could be associated with as a DBA, in my recent past .It would be sinful if I don't start with expressing my admiration for Microsoft for developing a cloud platform like Azure that is the coolest in market in terms of cost effectiveness and ease of migration and the level of compatibility it offers with a wide range of Microsoft's own products in the on-premise environments. Those are certainly the reasons why 95% of the fortune 500 companies have decided to migrate to Azure cloud instead of choosing its competitors. 

          If you have decided to go with Azure for both your application deployment and Infrastructure migration, PaaS offering  for the Database (Otherwise known as DBaaS) is certainly the area to focus on,  as IaaS offerings are comparatively expensive for any cloud platform. One needs to start to list down the features he look for in the DBaaS offering. You can look at your On-premise set up to find this out and brainstorm with your peers in the Infra/Application teams to list them.  You should also consider installing Database migration Assistant and run it against a copy of your database backup to find the potential blockers for migration if any for all SQL offerings from Azure. Please download it from here. This will help us to understand the common blockers and compatibility issues one might encounter while attempting to migrate the on-premise database to a DBaaS or SQL on Azure VM. I am adding a screenshot for a preview purpose. 







Below are the DBaas Offerings from Microsoft and some of the features it provides .All of them are built on the latest Standard edition of SQL server and shares features such as built in high availability, automated backups,  online scaling up, and service updates with no interruption to the database service.


1. Single Database


        You can treat them similar to the contained databases we have in on-premise and this is meant for the modern applications that don't need all T-SQL features and are single tenant systems. It has its own set up merits such as the absence of shared resources and better control from an operational standpoint . 


2.Elastic Pool



       These are collection of databases residing in a single Azure SQL server and are meant for multi Tenant SaaS Apps that dont need all instance T-SQL functionalities , SSRS , CLR and service broker . It gives the ability to assign resources to individual databases as per need and both the single and elastic pool DBaas suport size upto a 100 TB (in HyperScale Service tier)  which makes them a great for very large yet simpler systems. For disaster recovery, both elastic pool and single database supports Geo replication which is built on Always-On feature along with Geo-restore (Longer RPO). 

3.Managed Instance


      This is my personal favorite among the azure DBaaS,  as it offers near 100% compatibility with the on-premise SQL server and the no-friction migration it offers. Managed instance supports a wide range of features such as  SSRS , Service broker , CLR,  linked servers . It is comparatively the newest DBaaS from Azure and it got released only in the month of October, 2018.  Managed instance supports size upto 8 TB for General purpose and 4TB for Business critical Service Tiers. Though we can overcome this limitation by having multiple managed instances and having databases spread across them.For disaster recovery , managed instance supports Auto-failover groups ,which is again an extension of Always-on onto the cloud with some operational dissimilarities with the active Geo-replication .

Managed instance also provides support for Transactional replication for all three roles which are publisher, distributor and subscriber while the other two DBaaS can be configured only as Subscribers. 


You can find more feature differences in the azure DBaas offerings  here .

Good luck with your Azure SQL journey!