Book on Azure and SQL Server


image

My last contribution to a book was in 2012. With the advent of the cloud and my continuing work with SQL Server, I jumped at the opportunity when my friends and colleagues, Pranab Mazumdar [t] and Sourabh Agarwal [t], talked to me about contributing to a book on running SQL Server on Azure.

The book “Pro SQL Server on Microsoft Azure” attempts to teach the basics of Microsoft Azure and see how SQL Server on Azure VMs (Infrastructure-as-a-Service) and Azure SQL Databases (Platform-as-a-Service) work. This book will show you how to deploy, operate, and maintain your data using any one or more combinations of these offerings along with your on-premise environments. You will also find some architecture details which are very important for an end user to know in order to run operations using Azure.

The book is available on Apress and Amazon.

We would love to hear any feedback about the book. It could be good, bad or ugly. You will find the resources available for download on the site.

Advertisements

Upgrading a Replication Topology to SQL Server 2016


Cross posting from Tiger blog.

SQL Server Replication provides multi-faceted data movement capabilities across SQL Server releases which has been used by customers across the globe for a large number of years. When moving from one major release of SQL Server to another, replication topology upgrade has been a constant topic of lengthy discussions. In this post, we shall outline some of the challenges of upgrading SQL Server replication environments to SQL Server 2016. The requirements of upgrading a replication topology need to abide by the following guidelines:

  • A Distributor can be any version as long as it is greater than or equal to the Publisher version (in many cases the Distributor is the same instance as the Publisher).
  • A Publisher can be any version as long as it less than or equal to the Distributor version.
  • Subscriber version depends on the type of publication:
    • A Subscriber to a transactional publication can be any version within two versions (n-2) of the Publisher version. For example: a SQL Server 2012 Publisher can have SQL Server 2014 and SQL Server 2016 Subscribers; and a SQL Server 2016 Publisher can have SQL Server 2014 and SQL Server 2012 Subscribers.
    • A Subscriber to a merge publication can be any version less than or equal to the Publisher version.

If you had to draw a support matrix for the major release versions for transactional and merge replication, the output would be the two tables shown below.

For the remainder of this post, transactional replication refers to Transactional Replication excluding heterogeneous replication, P2P replication and updateable subscribers.

Transactional Replication Matrix

Publisher Distributor Subscriber
SQL Server 2016 SQL Server 2016 SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2014 SQL Server 2016SQL Server 2014 SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2008 R2

SQL Server 2008

SQL Server 2012 SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2008 R2

SQL Server 2008

SQL Server 2008 R2SQL Server 2008 SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2008 R2

SQL Server 2008

SQL Server 2014SQL Server 2012

SQL Server 2008 R2

SQL Server 2008

SQL Server 2005

SQL Server 2000

Merge Replication Support Matrix

Publisher Distributor Subscriber
SQL Server 2016 SQL Server 2016 SQL Server 2016SQL Server 2014

SQL Server 2012

SQL Server 2014 SQL Server 2016SQL Server 2014 SQL Server 2014SQL Server 2012

SQL Server 2008 R2

SQL Server 2008

SQL Server 2012 SQL Server 2012 SQL Server 2012SQL Server 2008 R2

SQL Server 2008

SQL Server 2008SQL Server 2008 R2 SQL Server 2008 R2SQL Server 2008 SQL Server 2008 R2SQL Server 2008

SQL Server 2005

SQL Server 2000

If you notice the line items for SQL Server 2016, you will see that a topology is unable to support SQL Server 2016 in a number of scenarios when you are running SQL Server 2016 as a publisher. Replication topologies have three common deployment patterns as shown in the visio diagram below. The distributor could be on the publisher or subscriber or a remote distributor. We do come across different deployments of the publisher and subscriber which are a mix of standalone instances, SQL Server failover cluster instances or Always On Availability Group replica instances.

image

Depending on the deployment pattern, the upgrade path to SQL Server 2016 would be different. Let us explore the different possibilities. SQL Server offers two upgrade paths in general:

  • Side-by-side: This approach involves setting up a new parallel environment and moving the databases along with the associated instance level objects like logins, jobs etc. to the new environment.
  • In-place upgrade: With this approach, the SQL Server setup program upgrades the existing SQL Server installation by replacing the existing SQL Server bits with the SQL Server 2016 bits and then upgrades each of the system and user databases. For environments running SQL Server failover cluster instances or Always On Availability Groups, an in-place upgrade is combined with a rolling upgrade to minimize downtime.

The scenarios below apply to Transactional Replication (without P2P Replication, Queued Updating Subscription and Immediate Updating Subscription) and Merge Replication. The options below outline how a phased approach can be adopted for your replication topology upgrade so that you don’t have to upgrade all the SQL Server instances in one big upgrade operation.

A common approach that has been adopted for side-by-side upgrades of replication topologies is to move publisher-subscriber pairs in parts to the new side-by-side environment as opposed to a movement of the entire topology. This phased approach helps to control downtime and minimize the impact to a certain extent for the businesses dependent on replication.

Upgrading a Replication Topology with a Remote Distributor

Transactional Replication

Upgrading from

Distributor

Publisher/Subscriber

SQL Server 2014

SQL Server 2012

Step 1:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology*

Step 2:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade of subscriber requires reinitialization of subscriber

Side-by-side upgrade of publisher requires reconfiguring all the publisher-subscriber pairs

The publisher and subscriber can be upgraded in any order

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology*

Step 2:

In-place upgrade would need to occur for both publisher and subscriber at the same time as publisher and subscriber need to be within two major releases. A SQL Server 2008/R2 publisher/subscriber cannot have a SQL Server 2016 publisher/subscriber.

OR

Intermediate In-place upgrade to SQL Server 2012/2014 of publisher or subscriber

The other server in the publisher/subscriber pair can then be upgraded to SQL Server 2016

OR

Side-by-side upgrade will require the upgrade of publisher and subscriber to happen together and requires a re-setup of the publisher/subscriber pairs

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Merge Replication

Upgrading from

Distributor

Publisher

Subscriber

SQL Server 2014

SQL Server 2016

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology*

Step 2:

In-place upgrade

OR

Side-by-side upgrade of publisher requires reconfiguring all the publisher-subscriber pairs

Step 3:

In-place upgrade

OR

Side-by-side upgrade of subscriber requires reinitialization of subscriber

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology*

Step 2:

In-place upgrade

OR

Side-by-side upgrade of publisher requires reconfiguring all the publisher-subscriber pairs. Needs to happen with the upgrade of the subscriber.

Step 3:

In-place upgrade

OR

Side-by-side upgrade of subscriber requires reinitialization of subscriber. Needs to happen with the upgrade of the publisher.

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Upgrading a Replication Topology with Publisher acting as the Distributor

Transactional Replication

Upgrading from

Publisher/Distributor

Subscriber

SQL Server 2014

SQL Server 2012

Step 1:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology*

Step 2:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade of subscriber requires reinitialization of subscriber

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade (Requires subscriber to be upgraded because publisher and subscriber need to be within two major releases. A SQL Server 2016 publisher cannot have a SQL Server 2008/R2 subscriber.)

OR

Intermediate in-place upgrade to SQL Server 2012/2014 for the publisher which is acting as the distributor also

The subscriber can be upgrade to SQL Server 2016 post the intermediate publisher upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs served by this distributor in the replication topology. Needs to happen with the upgrade of the subscriber.

Step 2:

In-place upgrade would need to occur for both publisher and subscriber at the same time as publisher and subscriber need to be within two major releases. A SQL Server 2008/R2 publisher/subscriber cannot have a SQL Server 2016 publisher/subscriber.

OR

Intermediate In-place upgrade to SQL Server 2012/2014 of the publisher

The subscriber can then be upgraded to SQL Server 2016

OR

Side-by-side upgrade will require the upgrade of subscriber to happen together with the publisher and requires a re-initialization of the subscribers. Needs to happen with the upgrade of the publisher.

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Merge Replication

Upgrading from

Publisher/Distributor

Subscriber

SQL Server 2014

SQL Server 2016

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs served by this distributor in the replication topology*

Step 2:

In-place upgrade

OR

Side-by-side upgrade of subscriber requires reinitialization of subscriber

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs served by this distributor in the replication topology. Needs to happen with the upgrade of the subscriber.

Step 2:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology. Needs to happen with the upgrade of the publisher.

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Upgrading a Replication Topology with Subscriber acting as the Distributor

Transactional Replication

Upgrading from

Distributor/Subscriber

Publisher

SQL Server 2014

SQL Server 2012

Step 1:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade requires re-setup of publisher/subscriber pairs in the replication topology served by this distributor*

Step 2:

In-place upgrade (Can be upgraded due to n-2 support)

OR

Side-by-side upgrade of subscriber requires re-setup of all the publisher/subscriber pairs

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade (Requires publisher to be upgraded also because subscriber and publisher need to be within two major releases. A SQL Server 2008/R2 publisher cannot have a SQL Server 2016 subscriber.)

OR

Intermediate in-place upgrade to SQL Server 2012/2014 for the subscriber which is acting as the distributor also

The publisher can then be upgraded to SQL Server 2016 post this intermediate distributor upgrade

OR

Side-by-side upgrade of distributor/subscriber requires re-setup of all the publisher/subscriber pairs served by this distributor. Needs to happen with the upgrade of the publisher.

Step 2:

In-place upgrade would need to occur for both publisher and subscriber at the same time as publisher and subscriber need to be within two major releases. A SQL Server 2008/R2 publisher/subscriber cannot have a SQL Server 2016 publisher/subscriber.

OR

The publisher can then be upgraded to SQL Server 2016 (Requires

intermediate In-place upgrade to SQL Server 2012/2014 of the subscriber)

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology. Needs to happen with the upgrade of the distributor/subscriber.

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Merge Replication

Upgrading from

Distributor/Subscriber

Publisher

SQL Server 2014

SQL Server 2016

Step 1:

In-place upgrade

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology served by this distributor*. This also requires upgrade of the publisher as the publisher version has to be higher than the subscriber.

Step 2:

In-place upgrade

OR

Side-by-side upgrade of subscriber requires reinitialization of all publisher/subscriber pairs. Requires simultaneous upgrade of the subscriber because it is acting as the distributor.

SQL Server 2008 R2

SQL Server 2008

Step 1:

In-place upgrade (Requires simultaneous upgrade of the publisher)

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology. Requires simultaneous upgrade of the publisher.

Step 2:

In-place upgrade (Requires simultaneous upgrade of the subscriber acting as the distributor)

OR

Side-by-side upgrade requires re-setup of all the publisher/subscriber pairs in the replication topology. Requires simultaneous upgrade of the subscriber because it is acting as the distributor.

*See “Side-by-side Upgrade of the Distributor without re-initialization” below

Side-by-side Upgrade of the Distributor without re-initialization

If you are running your SQL Server instance to be upgraded on Windows Server 2008 or Windows Server 2008 R2, then you will need to perform a side-by-side upgrade of the distributor first to Windows Server 2012 R2 or Windows Server 2016 before upgrading to SQL Server 2016. The reason for this intermediate OS upgrade is that SQL Server 2016 cannot be installed on a Windows Server 2008/2008 R2 server. The side-by-side approach can also help reduce downtime if you are upgrading the hardware of the Windows Server hosting the distributor instance. Downtime of the publisher and subscriber can be reduced using SQL Server Failover Cluster instances or Always On Availability Groups.

The assumption here is that the edition of the SQL Server instance will not change and a failover cluster instance of SQL Server will be upgraded to a failover cluster instance where as a standalone instance will be upgraded to a standalone instance using the steps mentioned below.

Steps for side-by-side migration of the distributor to Windows Server 2012 R2

  • Setup a new failover cluster or standalone instance running the same major release, edition and version as your distributor on Windows Server 2012 R2/2016 with a different windows cluster and SQL Server FCI name or standalone host name. You will need to keep the directory structure same as the old distributor to ensure that the replication agents executables, replication folders and database file paths are found at the same path on the new environment. This will reduce any post migration/upgrade steps required.
  • Make sure that the current synchronization is complete and post that shut down all the replication agents
  • Shut down the current SQL Server failover cluster instance or standalone instance running as the distributor. If this is a standalone instance of SQL Server, you will need to shutdown the Windows Server hosting  the SQL Server instance to ensure that there is no conflict while renaming the server.
  • Remove the DNS entries for the old (current distributor instance) environment and the AD entries for the computer object for the SQL Server FCI
  • If this is a SQL Server Failover Cluster instance, rename the new SQL Server Failover Cluster instance name with the old virtual server name. If this is a standalone SQL Server instance, then rename the new standalone host with the old hostname.
  • Copy the database files from the previous instance using SAN redirection or storage copy or file copy
  • Bring the new SQL Server instance online
  • Restart all the replication agents and verify if the agents are running successfully
  • Validate if replication is working as expected

In-place upgrade to SQL Server 2016

  • Run in-place upgrade for SQL Server 2016 on the new cluster
  • If required, rebuild old nodes and add to the cluster to re-use existing hardware
  • Validate if replication is working fine

If you want to reduce the downtime, we recommend that you perform the side-by-side migration of the distributor as one activity and the in-place upgrade to SQL Server 2016 as another activity. This will allow you to take a phased approach, reduce risk and minimize downtime.

Summary

Upgrading a replication topology is a multi-step process. We recommend attempting an upgrade of a replica of your replication topology in a test environment before running the upgrade on the actual production environment. This will help iron out any operational documentation that is required for handling the upgrade smoothly without incurring expensive and long downtimes during the actual upgrade process. We have seen customers reduce downtime significantly with the use of Always On Availability Groups and/or SQL Server Failover Cluster Instances for their production environments while upgrading their replication topology. Additionally, we recommend taking backups of all the databases including MSDB, Master, Distribution database(s) and the user databases participating in replication before attempting the upgrade.

Resources

Recovering a Deleted Cluster Name Object (CNO) in a Windows Server 2008 Failover Cluster

Upgrade Replicated Databases

Supported Version and Edition Upgrades for SQL Server 2016

Hardware and Software Requirements for SQL Server 2016

SQL Server Upgrade

Rename a Computer that hosts a Standalone instance of SQL Server

Rename a SQL Server Virtual Server Name

Introducing VDC_Complete for Backup and Restore applications using SQLVDI


Cross post from Tiger team blog.

In addition to its built-in functionality for backup and restore, SQL Server is supported by a large number of third-party backup solutions. SQL Server provides application programming interfaces (APIs) that enable independent software vendors to integrate SQL Server backup and restore operations into their products. These APIs are engineered to provide maximum reliability and performance, and support the full range of SQL Server backup and restore functionality, including the full range of hot and snapshot backup capabilities. In the current implementation of the SQL Server Virtual Backup Device Interface (VDI) protocol, the last message sent from SQL Server to the VDI client will be a VDC_Flush command. To prevent data loss, the VDI client must finish the backup before responding to the VDC_Flush command. There are certain situations like during backups of filestream enabled databases where a VDC_Flush command can be sent more than once during a backup operation. For certain backup applications, processing more than one VDC_Flush might be a challenge. If the VDI client responds to a VDC_Flush command without ensuring the backup is hardened when more data is coming after the VDC_Flush, SQL Server may truncate the transaction log. However, if the backup eventually fails on the VDI client, and the transaction log is also truncated, data loss might occur. If you don’t test your log backups at regular intervals, you wouldn’t figure out that you have a broken transaction log chain till the time you need to actually execute disaster recovery.

If you want to simulate a backup for your SQL Server instance, then you use the SQL Server Backup Simulator which is available on our tigertoolbox GitHub repository. The updated SQLVDI header files required to use VDC_Complete is available on the Microsoft SQL Server Samples GitHub repository.

Improvement

A new change was introduced in SQL Server 2012, SQL Server 2014 and SQL Server 2016 to allow backup and restore applications to know when SQL Server has completed sending the data to the client (VDI) so that it can perform the necessary end of backup tasks. KB3188454 has details about the change. This update adds a new VDI command VDC_Complete that indicates SQL Server has completed sending data to the VDI client. Therefore, the VDI client will be able to finish the backup before it sends response to SQL Server. This functionality allows the VDI client to fail the backup in case something goes wrong, and also prevents the transaction log being truncated without hardening the log backup by the client application.

The improvement was designed keeping backward compatibility in mind since backup applications can target multiple releases and versions of SQL Server at the same time. There can be four different scenarios which are outlined in the table below.

SQL Server Instance (VDI Server) Backup Application (VDI Client) Behavior
Supports VDC_Complete Supports VDC_Complete Client has to request VDF_RequestComplete while fetching the configuration to let the server know that it understands VDC_Complete. Once the server sends back a confirmation using the VDI configuration that it supports VDC_Complete, the client needs to execute the appropriate code path to handle VDC_Complete
Supports VDC_Complete Does not support VDC_Complete Since client does not request VDF_RequestComplete while fetching the configuration, server proceeds using previous behavior to maintain backward compatibility
Does not support VDC_Complete Supports VDC_Complete Server will return a NULL response because it does not support VDC_Complete for the requested feature VDF_RequestComplete
Does not support VDC_Complete Does not support VDC_Complete Behaves with legacy behavior of using only VDC_Flush

VDC_Complete is available for both scenarios backup and restore. If you want to use VDC_Complete for a database restore, then that is possible as well. If you choose to do so, then you will need to negotiate (as shown in the sample below) the use of VDC_Complete before the restore while fetching the VDI configuration.

Sample Code

Let us now look at the code changes required on the client side application which will help backup application work

I am going to use references from the sample simple.cpp file available in “SQL Server Virtual Backup Device Interface (VDI) Specification”. The download location is available in the references listed at the end of this post.

A handshake was implemented for the server and client to negotiate if VDC_Complete is supported by either. This can be done by the client requesting for the VDF_RequestComplete configuration. When the server receives this feature request, it will know that the client understands VDC_Complete and will respond accordingly indicating that it supports VDC_Complete.

      // Setup the VDI configuration we want to use.

      memset (&config, 0, sizeof(config));

      config.deviceCount = 1;

 

    // Request for VDC_Complete feature from the server

    config.features = VDF_RequestComplete;

Once the client receives the configuration, it needs to check the features available (see below) by determining if VDF_CompleteEnabled is set. Once the client determines that the server supports VDC_Complete, it can execute the code path which does the appropriate processing (end of backup book keeping, closing the backup etc.) after it receives the VDC_Complete message.

    hr = vds->GetConfiguration (10000, &config);

      

    if (!SUCCEEDED (hr))

    {

             printf_s (“\nError: VDS::Getconfig fails: 0x%X\n”, hr);

        if (hr == VD_E_TIMEOUT)

        {

                    printf_s(“\nError: Failed to retrieve VDI configuration due to timeout value (10,000 ms).\n”);

        }

        goto shutdown;

    }

      

    // Determine if the server supports VDC_Complete based on configuration parameters returned

if (!(config.features & VDF_CompleteEnabled))

       {

             printf_s(“\nServer does not support VDC_Complete.”);  

       }

       else

       {

             printf_s(“\nServer supports VDC_Complete.”);

       }

      

When the backup application receives a VDC_Complete, the backup application will need to harden the backup and complete book keeping tasks before it acknowledges success for the VDC_Complete message (see below). This will ensure that SQL Server does not advance the LSN without the client application hardening the backup which could lead to a potential data loss situation.

case VDC_Complete:

// Ensure that book keeping is completed.

printf_s(“\n\nSQL Server has signaled the end of the operation.”);

// Harden the backup and close the file

       completionCode = ERROR_SUCCESS;

       break;

Reference

How It Works: SQL Server Backup Buffer Exchange (a VDI Focus)

SQL Server Virtual Backup Device Interface (VDI) Specification

SQL Server Backup Simulator

Updated SQLVDI Header files required for VDC_Complete