Chapter 18
Provisioning Azure SQL Database managed instance

Azure SQL Database managed instance is a managed instance of SQL Server running in Azure. It is designed with almost full compatibility with the latest SQL Server engine. It offers easy migration from on-premises installations. Designed specifically to offer 99.99% availability with minimal management, this offering fills a space in Azure that is not available to organizations using strictly on-premise solutions.

What is a Managed Instance?

A Managed Instance is a Platform as a Service (PaaS) offering for SQL Server. It has nearly a 100% compatibility with the current Enterprise edition of the Database Engine. Azure SQL Database managed instance includes benefits such as automatic patching, version updates, automated backups, and high availability that come with a PaaS offering. This allows for an easy lift and shift from on-premises to the cloud with minimal to no application or database changes. The isolation and security of your Managed Instance is protected with native VNET and Private IP addresses.

It is also important when choosing a managed instance to understand what it is not. Managed instance is not an alternative for the SQL Server services. SQL Server Integration Services (SSIS) cannot be used in a managed instance in the traditional way. SSIS packages can be used with an integration run time in conjunction with Azure Data Factory, a PaaS offering, to create the same functionality. SQL Server Analysis Services (SSAS) needs to be a separate PaaS, and SQL Server Reporting Services (SSRS) needs to be replaced with either Power BI or SSRS IaaS. A managed Instance is intended for a traditional OLTP workload, but not to replace the other SQL Server services.

Although the majority of items that make up a managed instance are similar to the latest version of SQL Server, there are a few things that make it different as well.

Differences between SQL Server on-premises and in a Managed Instance

When assessing the benefits of a Managed Instance, it is important to compare like servers and services. The Managed Instance benefits from always being up to date in the cloud, which means that some features in on-premises SQL Server may be either unnecessary or have alternatives. There are also specific cases when a particular feature works in a slightly different way.

High Availability

High availability is built in and pre-configured using technology similar to Always On Availability Groups. If you currently use Always On you will find there are a number of statements that are not supported including:

  • Create Endpoint for database Mirroring

  • Create Availability group

  • Alter Availability group

  • Drop Availability group

  • Set HDR clause of the Alter database statement

There are a few features used in Managed instances to ensure high availability that are different from on-premises.

  • INSTANCE_LOG_GOVERNOR wait is a resource governor constraint that slows down logging to ensure replicas do not get out of sync. Index rebuilds, for example, are an activity that can be affected by this governor.

  • HADR_DATABASE_FLOW_CONTROL and HADR_THROTTLE_LOG_RATE_SEND_RECV are waits that you will see if the secondary’s get behind. They will slow the primary to prevent data loss.

SSIS, SSRS, and SSAS usage

Managed instance supports SQL Server Integration Services (SSIS) and can host SSIS catalog (SSISDB) that store SSIS packages, but they are executed on a managed Azure-SSIS Integration Runtime in Azure Data Factory (ADF). For details on how to use this see the Microsoft docs at https://docs.microsoft.com/azure/data-factory/create-azure-ssis-integration-runtime.

General Differences

Managed instance and an on-premises SQL Server have a few general differences that should be considered. These are behavior changes that can affect your decision on using a managed instance or how you use it.

  • All Managed Instance databases use full recovery model to guarantee high availability and no data loss. If you’re on-premises database is in simple or bulk logged mode, you may find the Managed Instance slower for bulk logged operations.

  • Transparent Data Encryption is on by default with a Managed Instance and that will affect performance. This can be turned off, but if any of the database in an instance is encrypted, tempdb will still be encrypted, so there will be at least some impact to all databases.

Time to provision

One of the limitations we see with Managed Instance is the delay in provisioning. It can take many hours to provision a Managed Instance. This can be reduced by using the same subnet when provisioning additional Managed Instances, since a large portion of the time to create the Managed Instance is in the provisioning of the subnet. There is no way to save that time when you first provision an instance. However, the limitations on how many Managed Instances you can have in a subnet can be an issue as well.

Backups and Restores

Backups from a Managed Instance can only be restored to another Managed Instance, not to an on-premises SQL Server, a single database, or an elastic pool without using a workaround method. There is no backup and restore to an on-premise native option in a managed instance. Managed Instances have automatic backups, which means the Managed Instance takes care of the backup for you, but it also means that you cannot take your own Differential, Log, File, Tape, or file snapshot backup. There are a couple of ways to get data back to an on-premises database for testing. The work arounds for this are to take a copy only backup or backup to a URL. In addition to this you can use the copy activity in Azure Data Factory. It has a number of supported data stores and formats. They are all listed at https://docs.microsoft.com/azure/data-factory/copy-activity-overview#supported-data-stores-and-formats.

There is a limitation of 32 stripes for the Managed Instance backup and a stripe size of 195GB. Your backup will not be restored when using the restore method for managed instance if your .bak file has any features that are not supported by Managed Instance. Backups containing databases that have active In-memory objects cannot, for example, be restored to a General-Purpose managed instance.

Managed Instance does not allow specifying full physical paths, so all corresponding scenarios have to be supported differently: RESTORE DB does not support WITH MOVE, CREATE DB doesn’t allow physical paths, and BULK INSERT works with Azure Blobs only. The limitations on Managed Instance are related to the specific use case of how they are intended to be used and what the managed instance was designed to do. For example, the Restore DB command does not support WITH Move because it should never be needed. The location of the database is handled by the Managed Instance.

Security

Managed Instance provides most of the same security features of the latest SQL Server on-premises Enterprise edition. It limits access in an isolated environment and uses identity authentication (Azure AD and SQL Authentication). Additional security features can be enabled, such as data masking and encryption, as well as additional authorization with role-based memberships and permissions enforced. There are a few items to draw your attention to, which may determine if a managed solution will work for your solution. The “Security” section in this chapter has more information on the details of the security options, but there are some limitations that may determine if the product is a fit for your architectural needs. Additional information about managing instances and database security can be found in Chapter 12, “Administering security and permissions.”

Certificates

Managed instances do not access file shares or Windows folders. So you cannot create from, or backup to a file share for certificates, nor can you backup or create from a file or assembly. Details on how to handle certificates can be found at https://docs.microsoft.com/sql/t-sql/statements/create-certificate-transact-sql?view=sql-server-ver15.

Azure Active Directory access

A managed instance needs permissions to read Azure Active Directory (AAD) to do tasks, such as authenticate users in security groups or create new users. Each managed instance starts with a single server administrator account that is the administrator of the managed instance. This is set up during or after provisioning, with an admin SQLServer account. It is called the Azure AD admin and has sysadmin permissions and creates AAD and SQL logins in the master database for the managed instance.

A second SQL Server administrator must be created, which is an Azure AD account. This account is called the Azure AD server principal and it’s created as a contained database user in the master database. As administrators, the server administrator accounts are members of the db_owner role in every user database, entering each user database as the dbo user.

For additional information on how to create Azure AD server principal logins for managed instances see the detailed instructions in Microsoft docs at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-aad-security-tutorial#create-an-azure-ad-server-principal-login-for-a-managed-instance-using-ssms.

Note

The Azure Active Directory principle is relatively new and only shows in SSMS at version 18.0.

Azure Active Directory Database principals are created at the database level. This account can be either a user or a group. It does not have to be an administrator, but it must be configured to use Azure Active Directory to connect Azure Active Directory accounts to the Azure SQL Database. Windows logins are not supported, and Azure Active Directory users should be used instead. Both server principals and admin accounts can overlap in permissions. The server principal takes precedence in the event of a conflict.

Additional details can be found later in this chapter in the “Security of Managed Instance” section.

Configurations differences

There are several configurations to note with Managed Instances that are different from the latest SQL Server engine:

  • Buffer pool extensions are not supported.

  • Compatibility levels below 100 are not supported.

  • Database mirroring is not supported.

  • Instant file initialization is not supported.

  • Multiple log files are not supported.

  • In memory is a Business-Critical tier only feature.

  • SQL Server Agent is always running.

  • Filestream and FileTable are not supported.

  • DBCC undocumented statements that are enabled in SQL Server do not function.

  • Session level trace flags are not supported.

  • Elastic Transactions are not supported.

  • PolyBase, R, and Python external libraries and tables are not supported.

  • Linked server is supported for SQL Server and Azure SQL Database targets only.

  • Cross instance service broker is not supported.

  • Extended stored procedures are not supported.

  • Managed instance automatically manages XTP filegroup and files for databases containing In-Memory OLTP objects.

  • Xp_cmdshell is not supported.

  • TempDB on the General tier cannot exceed 24GB.

  • TempDB is always split into 12 data files; the size per file cannot be changed and new files cannot be added.

There are several features and syntax that cannot be used in a managed instance, because those features are handled by the instance automatically and therefore are not relevant and can’t be changed. A list of them can be found here:

As of the writing of this book, there are a number of known issues with managed instances and they are being resolved quickly by the Microsoft engineering team. This is normal with any product, and one of the values of using a product like Managed Instance is that Microsoft’s impetus is to correct and then apply bug fixes rapidly for its large customer base.

You can keep up with the latest bugs and workarounds in Microsoft Docs at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-transact-sql-information#Issues.

Creating a managed instance

A managed instance can be created either through the portal or by using PowerShell, but they can only be created in supported regions. When creating a managed instance (MI) for the first time it is highly recommended that you use the portal. The portal steps make it simple, directing you in which v-nets to use and to ensure you have all of the necessary items before starting the deployment. A list of those regions can be found at https://azure.microsoft.com/global-infrastructure/services/?products=sql-database&regions=all.

An additional managed instance limitation is subscription types. A managed instance is supported only for the following subscription types.

  • Enterprise Agreement (EA)

  • Pay-as-you-go

  • Cloud Service Provider (CSP)

  • Enterprise Dev/Test

  • Pay-As-You-Go Dev/Test

  • Subscriptions with monthly Azure credit for Visual Studio subscribers

Selecting a pricing tier and service objective

Managed Instance is based on the VCore purchasing model. The intent of it is to make for an easier transition from on-premises machines, or IaaS in Azure, to independently choose to scale out compute and storage. There are two different service tiers for managed instances: General Purpose and Business Critical.

  1. General Purpose tiers are for balanced usage with scalable compute and storage options. High availability is built in based on Azure blob storage and Azure Service Fabric.

  2. Business Critical tiers are typically for applications with high I/O requirements that offer minimal impact due to maintenance operations. It offers the highest resilience to failures by using isolated replicas. High availability is built-in and is based on a technology similar to Always On availability groups and Azure Service Fabric. It has additional read-only replicas that can be used for reporting or other read-only workloads. Additional features include In-memory OLTP and SSD storage for increased performance.

All service tiers guarantee 99.99 % availability and independently scale size and compute.

Note

If you need guaranteed high availability higher than 99.99%, with no impact on maintenance operations and outages, there are other options beyond managed instances. Additionally, if the ability to handle critical servicing tasks, planned, and unplanned events is critical to your business, you should look at Chapter 17, “Provisioning Azure SQL Database,” for options outside of managed instance.

All options have hardware choices where you can choose the generation of hardware, and your options as of the writing of this book are:

  • Gen4: Up to 24 logical CPUs based on Intel E5-2673 v3 (Haswell) 2.4-GHz processors, vCore = 1 PP (physical core), 7 GB per core, attached SSD.

  • Gen5: Up to 80 logical CPUs based on Intel E5-2673 v4 (Broadwell) 2.3-GHz processors, vCore = 1 LP (hyper-thread), 5.1 GB per core, fast eNVM SSD.

For additional details on the different service-tiers, go to https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-resource-limits#service-tier-characteristics.

With software assurance from your on-premises offering, you can exchange existing licenses for discounted rates on a managed instance using Azure Hybrid Benefit for SQL Server at https://azure.microsoft.com/pricing/hybrid-benefit.

Provisioning a managed instance from the portal

Once the decision is made that Managed Instance is the best platform for your needs, the next step is provisioning. It is highly recommended that you use the portal for provisioning until you fully understand the experience, particularly the networking aspects because the portal automates much of it for you and limits the number of issues that can arise.

The following instructions can help you complete the task of creating a managed instance through the portal:

  • From the show portal menu, choose + Create A Resource.

  • In the search box type managed instance and choose the Azure SQL Instance option when displayed.

  • Select the create box, displaying the steps necessary to complete the creation of the managed instance.

  • The basics step includes all of the minimum required information to provision a managed instance. It requires a subscription (see previous note on available subscriptions) and a resource group. There is an option to create a new resource group.

  • Further down the page are the details that are needed, including the managed instance name, region, compute and storage. The portal guides you in the requirements for naming but not in what you will need for compute and storage. If you choose Configure Managed Instance inside the compute and storage section, you will go to another screen that will allow for customization of options and additional choices. This is also where you note you have your own license, an option that can save you money as the license is automatically included in a managed instance.

  • The final section of the basics is setting up the Administrator account. This can be any valid name, which is checked for in the portal, however the name “serveradmin” is a reserved server-level role and cannot be used as an administrator account here.

  • The next section is networking. This section defines the level of access and connection type. You can define your virtual network and public end points here.

  • Start by creating a virtual network. If you have a compliant virtual network it can be found in the list. Otherwise it is recommended to create a new one.

  • Choose a connection type to accelerate application access. The default value is proxy, however, it is recommended to use redirect. With proxy all connections are proxied via the Azure SQL Database gateways, which means to enable connectivity the client must have outbound firewall rules that allow only the IP address of the Azure SQL Database gateway port 1433. Although it is easier to set up, it is recommended that the redirect option is used for improved performance. The improvement comes with extra set up. The clients establish connections directly to the node hosting the database, which requires outbound firewall rules to all Azure IP address in the region using Network Security Groups (NSG) with service tags for ports 11000-11999, not just the Azure SQL Database gateway. This allows packets to go to the database directly and reduces latency and improves throughput and therefore performance.

  • The last part of networking is the public end point option. By default for security, the public endpoint is not enabled, as it allows access to the managed instance without a VPN and there can be a security risk. Once enabled you get the option of choosing from Azure Services, Internet, and no access. Ideally you would use the no access and enable only specific endpoints as needed. See these options for scenarios that may benefit from enabling a public end point at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-public-endpoint-securely.

  • Additional Settings on the next tab is where you choose a collation if you need to change the default, change the time zone, or setup geo-replication. Geo-replication is used to create a secondary managed instance as the failover group secondary. This step allows you to choose an already setup Primary to use and will allow the new instance to join the DNS of the primary you picked. After the secondary the following steps still need to be completed. Create a VPN between the primary and secondary. Setup inbound and outbound NSG rules and create an auto failover group between the two instances.

Note

Creating a Managed Instance can take many hours. On average you can expect six hours for the first instance with subsequent instances in the same pool being quicker. The VNet set up is usually what takes the time. If you have errors in your setup it has been known to take up to 24 hours to notify you of the issue. Don’t cancel the operation simply because it takes longer than you expect. Regardless of how long a process takes it is best to let the process fail on its own if it is going to fail, given how it makes the following steps simpler. If provisioning takes longer than 36 hours it is likely because the process failed and it is doing a roll back. Allowing the process to roll back will save many hours fixing, troubleshooting, and determining how to get back to a clean start.

Provisioning a managed instance using PowerShell

Creating a Managed Instance using PowerShell and the Azure Resource Manager template (ARM) requires you to have pre-created a valid v-net and subnet where you can deploy your Managed Instance. It is beneficial to use PowerShell or ARM templates if you are deploying more than one managed instance and it’s only recommended once you have some experience with it. It can take a long time for the process to complete and for you to find out you have missed a step or made a mistake. At minimum, it is highly recommended to complete at least one managed instance deployment in a test environment before attempting this to ensure you understand all the steps and pieces that are needed for the deployment.

V-net and subnet creation

Networking and specifically the v-net and subnet configuration have been a challenge for Managed Instance users. Often times it is the missed configuration of the v-net that causes the managed instance to not provision. To remedy this, managed instance is transitioning from manual to service-aided subnet configuration. The subnet configuration is now automated for you and will reduce many of the issues previously encountered. Managed instance now has service-aided subnet configuration, giving users full control of data traffic while managed instance takes full responsibility to ensure uninterrupted flow of the management traffic to ensure it can meet its SLA. This noted it is still possible to create your own subnet inside the virtual network. If you choose to do this, ensure you use a dedicated subnet. The subnet can’t contain any other cloud services associated with it, and it can’t be a gateway subnet. The subnet can’t contain any resource other than the managed instance, and you can’t later add other types of resources in the subnet. The managed instance’s subnet needs to be delegated to the Microsoft.SQL/managedInstance resource provider. For additional details about virtual networks see https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-create-vnet-subnet.

Delegating a subnet to an Azure service allows that service to establish basic network configuration rules for that subnet, which help operate their instances in a stable manner. It also provides full control to the customer on managing the integration of the Azure services into their virtual networks. A network security group (NSG) needs to be associated with the managed instance’s subnet. You can use an NSG to control access to the managed instance’s data endpoint by filtering traffic on port 1433 and ports 11000-11999 when managed instance is configured for redirect connections. Services will automatically add rules required to allow uninterrupted flow of management traffic. A list of these can be found at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-connectivity-architecture#mandatory-inbound-security-rules-with-service-aided-subnet-configuration. A user defined route table (UDR) needs to be associated with the managed instance’s subnet. You can add entries to the route table to route traffic that has on-premises private IP ranges as a destination through the virtual network gateway or virtual network appliance (NVA). You will need to ensure entries are added to allow an uninterrupted flow of management traffic. You can see the entries needed at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-connectivity-architecture#user-defined-routes-with-service-aided-subnet-configuration. Service endpoints can be used to configure virtual network rules and storage accounts that keep backups and audit logs.

  • Images Pre-creating the VNet requires you to properly size the subnet for the Managed Instance because it cannot be resized after you put resources inside it.

Once the VNet is installed, you can complete the installation using the Azure cloud shell as described at https://docs.microsoft.com/azure/sql-database/scripts/sql-managed-instance-create-powershell-azure-resource-manager-template#open-azure-cloud-shell.

Once you have the pre-requisites and networking set up you can create a Managed Instance either with PowerShell or an ARM Template. For PowerShell: https://docs.microsoft.com/azure/sql-database/scripts/sql-database-create-configure-managed-instance-powershell.

To create the managed instance using ARM templates: https://docs.microsoft.com/azure/sql-database/scripts/sql-managed-instance-create-powershell-azure-resource-manager-template.

Here are instructions for creating a Managed Instance using the portal: https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-get-started.

Establishing a connection

Once you have created your Managed Instance, consider how you will connect to it. The most secure and common way of connecting to the managed instance is via a subnet, whether that is a Gateway subnet for your on-premises solutions, web app frontend subnet, or IaaS apps subnet. Figure 18-1 provides an overview of the more common communication architectures.

This diagram displays the likely connection scenarios needed to use and manage the Managed Instance. There are two large boxes connected with a peering channel. Inside the center of the left box is the Managed Instance subnet, and contained in the MI subnet are the virtual cluster and the TDS endpoint (Private IP). Within the virtual cluster on the right is the SQL Management connected to the SQL Management (Public IP) residing outside the MI subnet on the left. To the right of the SQL Management in the Virtual cluster is the SQL Engine, which is connected to the TDS endpoint (Private IP). Above the MI subnet is the Front-end subnet containing a Web App with a connection to the TDS endpoint. Below the MI subnet is a Gateway subnet with a connection to the TDS endpoint as well and an incoming connection from an on-premises app. The box on the right signifies the Peered network. It is connected to the left box with the peering channel. Connecting across the peering channel is the connection from the App subnets in the peered network to the TDS endpoint. Located in the app subnet is both a web app and an IaaS App.

Figure 18-1 Managed Instance Connections Diagram.

Creating the endpoints via the portal

The recommended way to create the Public and Private endpoints shown in Figure 18-1 is to do it during the creation of the Managed instance itself. It was briefly mentioned in the section on “Provisioning a Managed Instance from the Portal” that you can define your Public and Private endpoints in the networking section. It is in that section on networking that you can define the Public endpoint under the section called “Connection type.” The default, Proxy, is recommended to use redirect mode because this enables direct connectivity to managed instance resulting in improved latency and throughput. This is ideal for peer-to-peer networking and use with other Azure services. The Public endpoint is the step directly after the connection type, allowing you to enable a public end point for the ability to connect to your managed instance from the Internet without using a VPN. It uses TDS only.

If you did not choose these during your managed instance you can still do it manually following the direction in the Microsoft docs at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-public-endpoint-configure.

Creating the VPN Gateway via PowerShell

Native virtual network implementation and connectivity to your on-premises environment will need a VPN Gateway. To complete this Microsoft has a handy PowerShell script available at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-p2s#attach-a-vpn-gateway-to-your-managed-instance-virtual-network.

Creating a VPN Gateway to the managed instance VNet is best done from your client machine.

Ensure that you have PowerShell 5.1 and Azure PowerShell 1.4.0 or newer installed on your on-premises client. Instructions for how to install the Azure PowerShell module can be found at https://docs.microsoft.com/powershell/azure/install-az-ps#install-the-azure-powershell-module.

To create the VPN gateway, you will need the subscription Id, resource group, and a virtual network name that you used to create your managed instance. You will also need to create a certificate name prefix. The prefix is a string that you choose. These items are used in the following PowerShell script:

$scriptUrlBase = ‘https://raw.githubusercontent.com/Microsoft/sql-server-samples/master/
samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway’
$parameters = @

{

  subscriptionId = ‘<subscriptionId>’
  resourceGroupName = ‘<resourceGroupName>’
  virtualNetworkName = ‘<virtualNetworkName>’
  certificateNamePrefix  = ‘<certificateNamePrefix>’
  }

Invoke- -ScriptBlock ([Scriptblock]::Create((iwr ($scriptUrlBase+’/attachVPNGateway.
ps1?t=’+ [DateTime]::Now.Ticks)).Content)) -ArgumentList $parameters, $scriptUrlBase

This code will create and install the required certificates on the client machine. It will calculate the IP subnet range needed for the gateway and then create the gateway. Finally, the script will deploy the Azure Resource Manager template that attaches the VPN Gateway to the VPN subnet.

If you prefer to create the VPN using the portal you can find those instructions in the Microsoft docs at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-p2s#create-a-vpn-connection-to-your-managed-instance.

Once you have completed the VPN connection and your TDS endpoints are ready to use, there are three main ways to connect to it.

  1. Connect from an on-premises computer, sometimes called a point-to-site connection.

  2. Connect from a Virtual Machine (VM); the process is different if your VM is an Azure VM or an on-premises VM.

  3. Connect applications from any location.

Connect from an on-premises computer

Connecting from an on-premises computer is sometimes called a point-to-site connection. To connect using SSMS (most recent version) start with making a connection to the VPN from your on-premises machine. From the network and Internet go to VPN, then choose your managed instance Vnet to choose the connection. If prompted for an elevated privilege, choose to elevate and continue to make the connection.

When connecting using SSMS remember to use the fully qualified host name of the Managed Instance in the Server name box (see Figure 18-2).

A point-to-site connection, showing the Connect To Server window with a Database Engine server type and a server name. For SQL Server Authentication there is a login and password.

Figure 18-2 Creating the VPN Gateway.

Connect from a Virtual Machine (VM)

When connecting to a Managed Instance from a Virtual Machine (VM), the process is different if your VM is an Azure VM or an on-premises VM.

Azure VM connections

For an Azure VM connection the connection is over a private IP to the TDS using a VM in a subnet separate to the one created for the managed instance. The VNet used to create the managed instance cannot be used, because it is dedicated to the managed instance. You will need to create an additional subnet in the managed instance VNet to put the VM in if you do not already have one. Direction on how to do this can be found at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-vm#create-a-virtual-machine-in-the-new-subnet-in-the-vnet.

Once you have the subnet details, create a VM in this subnet. Direction on how to add the virtual machine can be found at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-vm#create-a-virtual-machine-in-the-new-subnet-in-the-vnet.

Wait until the connection is completed, then you will need to ensure the VM is set up to allow a remote desktop connection, as shown at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-vm#connect-to-virtual-machine.

VM from on-premises

For the VM on-premises the method of connection is a bit different because you need to attach a VPN gateway to the managed instance. This is easily done with the script in the previous section, “Creating the VPN Gateway via PowerShell.” This script creates and installs the certificates on the client machine, calculates the VPN gateway subnet range, creates the subnet for the gateway, and deploys the ARM (Azure Resource Manager) template that attaches the VPN gateway to the VPN subnet that you need for access. You can also find the instructions on Microsoft docs at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-configure-p2s#attach-a-vpn-gateway-to-your-managed-instance-virtual-network.

Connect to applications

Applications can be connected to managed instances regardless of where they are hosted. In the cloud, on-premise, or a hybrid option, with Managed Instance you can choose what is best for your application. There are many options to choose from to connect.

Applications in the Cloud
  • An application inside the same V-net is the simplest, since even if they are in separate subnets, they can connect with the correct connection string making this the simplest way.

  • An application inside a different VNet is useful if you have VNets in different subscriptions because this method works for that scenario. This has two options: Azure Virtual Network peering is the preferable method because it uses the backbone Microsoft network so there are no latency issues between the peered VNets. The draw back to this is that the VNets have to be in the same region. If that is not an option, there is always the VNet to VNet using a VPN gateway.

Applications on-premises

Review the networking options and connections needed here to find the option that is best for your organization: https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-connect-app.

Migrating data to managed instance

Managed Instance targets the migration scenario, from Infrastructure as a Service (IaaS), or from on-premises. In both cases you will want to bulk move your data. There are two options for you to choose from the backup and restore method or Data Migration Service. Each has their own benefits as outlined in this section.

Data Migration Service

The Azure Database Migration Service is a managed service designed to enable migrations to Azure Data platforms with minimal downtime. This includes managed instance, but is not limited to it, so it can also be used for third party databases, and SQL Server databases to be moved to Azure SQL Database (single databases, or pooled databases in elastic pools) and SQL Server in an Azure VM. The third party databases that are supported for the online migration method are RDS SQL and Oracle.

There are online and offline migrations, depending on your business’ tolerance for down time. It is recommended you do a trial run with the offline migration to determine what your downtime will be before you decide on which method to use. Keep in mind that using the Azure Database Migration Service for online migrations requires using the Premium pricing tier.

Whether you use online or offline migration, be sure to create your Azure Database Migration Service in the same region as the Managed Instance you are migrating to. This will prevent errors, cut down the down time or migration time, and limit any movement of data across regions or geographies.

To do an offline migration you can follow the steps at https://docs.microsoft.com/azure/dms/tutorial-sql-server-to-managed-instance.

To do an online migration you can follow these steps at https://docs.microsoft.com/azure/dms/tutorial-sql-server-managed-instance-online.

There are several prerequisites. It is recommended that you review them before you begin. They can be found within the tutorial or directly at https://docs.microsoft.com/azure/dms/tutorial-sql-server-managed-instance-online#prerequisites.

Note

For online migrations using Azure Database Migration Service do not append multiple backups into a single backup media. Ensure instead that each backup is on a separate backup file. You will need both a backup and a subsequent log backup on the share that is used.

Backup and restore

The backup and restore method of migration leverages the simplicity of moving SQL backups to Azure Blob storage or backup directly to it. Backups in Azure blob storage can be directly restored into a managed instance using the traditional T-SQL restore command. The important part to remember is that the backup file must have been previously uploaded and secured with a Shared access signature (SAS) key. Details on how to do this are covered in Chapter 10, “Developing, deploying, and managing data recovery.”

RESTORE DATABASE { database_name | @database_name_var }
FROM URL = { ‘physical_device_name’ | @physical_device_name_var } [ ,...n ] ;

Here n can be up to 64 backup devices separated in a comma delimited list.

Note

The restore option on Managed Instance is asynchronous. Should your connection to your managed instance be lost or your Internet connection to it goes down, your operation continues. You can check the status of the operations with sys.dm_operation_status:

SELECT * FROM sys.dm_operation_status   
             WHERE major_resource_id = ‘myddb’   
 ORDER BY start_time DESC;

Backups from a Managed Instance can only be restored to another Managed Instance, not to an on-premises SQL Server, a single database, or an elastic pool.

The version of SQL Server you take your backup from is important as well. Backups from SQL 2012 SP1 CU2 and prior can only be directly uploaded as .bak files. For those greater than SQL 2012 SP1 CU2 a direct backup using the depreciated “WITH CREDENTIAL” syntax will work, and for 2016 and above you will want to backup direct using the “WITH SAS CREDENTIAL.”

If you are restoring a Transparent Data Encryption database using native restore, make sure you migrate the certificate first before you do the restore. This is done the same way should you have to move your certificate on-premises.

Deleting a managed instance

Deleting a managed instance is a basic command: DELETE. https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}?api-version=2015-05-01-preview.

Use Delete followed by a space and then the URL above with all the items in the curly braces resolved with the names of your managed instance items. This is simple when the Managed instance is working correctly. Issues arise when a Managed Instance is not correctly created, and you want to begin again. To avoid issues with deleting the instance, ensure you do not cancel a deployment. Complex challenges arise when deployments are only partially complete, and they are far more difficult to fix after the fact.

If the above does not resolve your issue, review your networking. Check the “Networking Provisioning” section in this chapter to confirm that you have the requirements set up correctly. Then try again. Do not try to delete a subnet before the Managed Instance.

Network requirements for managed instances

The dedicated subnet has already been mentioned for the managed instance in the “Establishing a connection” section, however, it is important enough to mention separately as it is an area that commonly causes issues. The network architecture is for connectivity as well as directing traffic to the managed instance. The important parts to remember are that the managed instances must be inside a subnet that is dedicated to managed instances and provides that ability to make the connections you need.

Note

Subnets can take a long time to create or configure. It is not uncommon for this process to take 24 hours or more if an issue arises as it needs to roll back the process before you are notified. To prevent issues when creating managed instances, do not cancel a creation. Let the creation fail on its own if there is an issue; do not cancel it.

One of the most common challenges with a managed instance are those related to networking. You can prevent these by ensuring you meet the requirements in the following sections before you begin provisioning any instances.

Subnet

Managed instances need a dedicated subnet that is not a gateway subnet. The subnet can only house managed instances. The subnet cannot be shared with other resources.

Network Security Group

The Network Security Group (NSG) that is associated with the managed instance must define the inbound and outbound security rules before any other rules. If you are doing transactional replication in your managed instance and have a publisher or distributor, you will need to open port 445 (outbound) as well to allow access to the Azure file share.

Note

It is important to note that there should be only one inbound rule for ports 9000, 9003, 1438, 1440, 1452, and one outbound rule for ports 80, 443, 12000. These are TCP management endpoint ports. Managed instance provisioning through Azure Resource Manager deployments will fail if inbound and outbound rules are configured separately for each port. If these ports are in separate rules, the deployment will fail with a “VnetSubnetConflictWithIntendedPolicy” error. Although these ports are open for Manager end points for NSG, they have a Managed Instance built in firewall at the network level for security.

User Defined Route table

A User Defined Route (UDR) table that’s associated with the virtual network must include specific entries at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-connectivity-architecture#user-defined-routes.

Endpoints

Managed instances should not have service end points. Make sure this option is disabled when you create the virtual network.

IP addresses

Managed instances require 16 IP addresses, and a minimum (does not allow for scale out) of 32 are recommended. As Managed Instance VNet can use up to 256 IP addresses, the number of Managed Instances that can be deployed in a single subnet depends on the subnet range. A subnet with the prefix /27 or below is recommended.

Managed Instance administration features

It is the Managed Instances services that enable Database administrator to spend less time on administrative tasks that make the Managed Instance such an attractive option. The following services are either simplified for the administrator or handled completely, saving time and the need for the expertise.

High Availability

Managed Instance offers 99.99% up time without concern for maintenance and upgrade outages. This is accomplished by using something called retry logic in your apps. Retry logic essentially is code that can retry the call when a transient fault occurs. A transient fault occurs when Azure dynamically reconfigures servers for a heavy workload and can cause clients to lose their connection. It is recommended that the client program have retry logic so that it can reestablish the connection (ideally with a 5 second delay, growing up to 60 with each retry). This delay is called back-off logic and is to ensure that the database does not get overwhelmed in a retry situation with many connections.

High Availability for managed instance is achieved by employing two models for price options based on your tolerance for degradation during maintenance. If you can tolerate some degradation, then there is a model that uses a simple separation of compute and storage. For workloads that can not have that type of impact there is a cluster model that uses a quorum of engine nodes and can guarantee very minimal impact during maintenance. As with many PaaS instances there are continuous upgrades, and this potential impact is something to strongly consider when choosing tiers when installing the managed instance.

General purpose tier

This tier leverages the separation of compute and storage. This contains two layers: the stateless compute layer runs the SQL Server engine process and contains the cached data on SSD for things like TempDB, Plan cache, and buffer pool. This is operated by the Azure Service Fabric and controls the health of the node and performs any failovers. The stateful layer contains the database files that are stored in blob storage with built-in redundancy to guarantee the data in case of a failure.

When a failure or upgrade occurs the Azure Service Fabric moves the stateless process to a different node. The blob storage in the stateful layer is not affected. The data and log files are attached to the newly initialized SQL Server. This is when this tier can experience degradation as this transition occurs and the instance starts with an initialized cache. As mentioned earlier Managed Instance does not use instant file initialization, so it is important to understand all the aspects that can affect your degradations.

Business critical tier

This tier integrates the SQLServer engine and the storage into a single node and uses replication to additional nodes to create a three or four node cluster. The database files are on SSD storage to improve IO and high availability is achieved by using technology similar to the Always On Availability Groups seen on-premise. For more information on Always On Availability Groups see Chapter 11, “Implementing high availability and disaster recovery.”

The cluster includes a single primary, and up to three secondary replicas. To ensure durability the primary writes each transaction to at least one secondary before committing the transaction. This durability grantees there is always a node to fail over to incase of a crash on the primary. Should a crash occur, the failover is initiated by the Azure Service Fabric. When a new primary is created another node is set and an additional replica is created to ensure quorum and the connections are redirected to the new primary.

Replication

Managed Instance uses transactional replication to replicate data to another instance database, a SQL Server, database, a single database in Azure, or a pooled database in an Azure SQL database elastic pool. A managed instance can host a publisher, distributor and subscriber database. Common configurations can be found at https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-transactional-replication#common-configurations.

For the Managed Instance to be a publisher and or distributor there are a few requirements.

  • The instance cannot participate in geo-replication.

  • The publisher, distributor, and subscriber all must be on the same virtual network or have VNet peering set up between all three networks.

  • The authentication used between all parties must be SQL Authentication and the replication working directory must be an Azure Storage Account share and set up using TCP outbound port 445 in the security rules of NSG.

  • Bidirectional or one-way replication are both supported; however, updatable subscriptions are not.

Note

Single databases and pooled databases in Azure SQL Database can only be subscribers.

Details on how to set up replication set by step can be found at https://docs.microsoft.com/azure/sql-database/replication-with-sql-database-managed-instance#1---create-a-resource-group.

Scaling up or down

Manage Instances use vCores that allow you to define the CPU cores and configure the storage capacity you need for your instance within each tier. All databases in the managed instance share these resources. The storage and CPU can be scaled up or down as needed within the limits of the service tier, however, it does cause a downtime, and for this reason it is important to scale your resources appropriately. Keep in mind that managed instances cannot be turned off and on like other resources at will, and over provisioning will be an added cost.

Note that as you change tiers there are differences between the tiers that can affect the change. For example, if downgrading from critical to standard, the backup retention period is different. If a database exceeds the threshold database size, then extra storage costs will apply. If you are upgrading to a higher tier, you must explicitly increase the size.

Automated backups

Managed Instance uses automated backups. This service creates full backups every week, differential backups every 12 hours, and transaction log backups every 5-10 minutes. The specific frequency is based on the compute size and amount of database activity. The backups are stored in storage blogs and replicated to another data center for protection against data center outages or disasters. The default backup retention is 7 days for the general-purpose tier and up to 35 days for Business Critical.

Note

If you reduce your retention period by changing tiers or modifying them, then all backups older than the new retention period are no longer available.

The options to restore are:

Restore to a point in time. This can be a copy in the same or a different managed instance, but must be under the same subscription.

Restore a deleted database. This must be restored to the managed instance the backup was taken from.

Restore to a new region. This creates a new database in any existing server anywhere in the world and is used in case of a geographic disaster.

Restore from a specific long-term backup. This works only if a long-term policy has been set.

Azure SQL Analytics

Managed Instance is included in the services that access Azure SQL Analytics. Azure SQL Analytics is a monitoring tool for performance. It collects and visualizes performance metrics and has built-in intelligence for trouble shooting. The metrics help you customize monitoring rules, alerts and identify issues. This cloud-only solution can be used in conjunction with other single or pooled databases to be looked at individually or collectively and across subscriptions. The service is found in the Log Analytics workspace. Details on how to set it up can be found at https://docs.microsoft.com/azure/sql-database/sql-database-metrics-diag-logging#configure-streaming-of-diagnostics-telemetry-for-managed-instances.

Security of Managed Instance

Security for Managed Instance is provided by a number of different features, including Azure Active Directory, multifactor authentication, and authorization.

Azure Active Directory (Azure AD)

Azure AD enables Microsoft services to integrate with centrally managed identities and permissions to enhance security. Combined with Multi-factor authentication you can increase data security and still support a single sign-on process for easy use. For details on how to set up Multi-factor authentication see this link at https://docs.microsoft.com/azure/sql-database/sql-database-ssms-mfa-authentication-configure. If using a hybrid option or you need to connect to legacy or on-premises applications, Azure AD can also be an on-premises Active Directory Domain Service that is federated with the Azure AD. The benefits of this centralized authentication include:

  1. Provides an alternative to native SQL Server authentication.

  2. Discourages the creation of multiple user identities across database servers.

  3. Allows centralized and simple password changes.

  4. Allows for external (Azure AD) groups.

  5. Enables integrated Windows authentication and other forms of authentication supported by Azure Active Directory.

  6. Azure AD authentication uses contained database users to authenticate identities at the database level.

  7. Azure AD supports token-based authentication for applications connecting to Azure SQL Database.

  8. Azure AD authentication supports ADFS (domain federation) or native user/password authentication for a local Azure Active Directory without domain synchronization.

  9. Azure AD supports Multi-Factor Authentication (MFA) when using SSMS.

  10. Azure AD supports Active Directory Interactive Authentication when using SQL Server Data Tools (SSDT). Active Directory Integrated Authentication connects to the Managed Instance by using identities. This is similar to the connection from a federated domain.

Access control using Azure AD

Azure Active Directory (AAD) is slightly different for Managed Instances compared to Azure Data Warehouse or Azure SQL database. It is critical that the subscription associated with Active directory and the Managed Instance are the same. An Azure Active Directory (AAD) administrator is needed to read AAD. This also allows the administrator to complete authentication of users through security group membership, or creation of new users, a task that can only be executed by Global/Company administrator in Azure AD. Once you have provisioned an Azure AD admin for your Managed Instance, you can create Azure AD server logins.

Detailed steps to complete this can be found at https://docs.microsoft.com/azure/sql-database/sql-database-aad-authentication-configure#provision-an-azure-active-directory-administrator-for-your-managed-instance.

Azure Active Directory set-up

Managed Instance is most often used to replace a traditional SQL Server installation, so it is natural that it supports the traditional SQL server Database engine logins and logins integrated with Azure Active Directory (AAD). Azure Active Directory server principals, previously called logins, are the Azure version of on-premises database logins in your SQL Server. These let you specify users and groups from your Azure Active Directory tenant (think AD Groups on-premises). They are capable of any instance-level operation, including cross-database queries within the same managed instance. To create the login for these specific server-level principals in conjunction with the Azure AD, a new option has been created for the CREATE LOGIN syntax that is relevant for server-level principals mapped to Azure AD accounts only and when left out creates the traditional SQL login. The new option is (FROM EXTERNAL PROVIDER).

When FROM EXTERNAL PROVIDER is specified the login_name must represent an existing Azure AD account that is accessible in Azure AD by the current Managed Instance.

Data protection features

Managed instances secure your data by providing built-in security features to make administering it easier. Some of them you should be familiar with are listed here in this section.

Isolation

Security Isolation is achieved in Managed Instance by the use of VNet implementations and using VPNs and express gateways to connect to your on-premises machines. The only endpoints exposed are through private IP addresses. The underlying infrastructure is always dedicated ensuring a single-tenant infrastructure completes the trifecta of isolation security.

Auditing

Managed Instance auditing is used to track events in the audit log file of the Azure storage account. The audit file is used to maintain regulatory compliance, gain insight into discrepancies, or review for suspected security violations using threat detection. Threat detection is built-in and used to detect unusual attempts to access databases. There are alerts regarding suspicious activities, potential vulnerabilities, SQL injection attracts, and anomalous database access patterns. These alerts can be viewed from Azure Security Center and provide details of suspicious activity, offering recommendations on how to resolve the issues.

Data encryption

Data encryption is provided in motion using Transport Layer Security (TLS). Always Encrypted is offered for protection of data in flight, at rest, and during query processing. Although not strictly encryption, Dynamic data masking is used to limit exposure by masking the data. This allows an added layer of protection and the ability to determine who has access to sensitive data. This allows the data to look different to specific users without actually changing the underlaying data. Data at rest is encrypted with Transparent data encryption (TDE). TDE encrypts the data and log files, using real-time I/O encryption and decryption when it is accessed.

Row-level security

Row-level security is used to control the access to specific rows of data in a table based on the user executing a query. Row-level security simplifies design and coding by enabling you to implement restrictions on the user and not on other factors. Combined with an Azure Active Directory, this can be a powerful security feature.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset