Using data-tier applications (BACPAC) to migrate a database from Managed Instance to SQL Server

Published 05-14-2021 09:50 AM 1,858 Views
Microsoft

Introduction

 

BACPAC is a ZIP file with an extension of BACPAC, containing both the metadata and data from SQL Server database. For more information you can refer to Data-tier Applications - SQL Server | Microsoft Docs.  A BACPAC file can be exported to Azure Blob storage or to local file system in an on-premises location and later imported into SQL Server or Azure SQL Managed Instance, or Azure SQL Database. Although BACPAC file contains data and metadata and can be used to deploy a copy of the source database, it is not a backup and shouldn’t be considered as such. However, in a situation where it’s not possible to use a database backup, BACPAC may be an acceptable substitute.

Note: With BACPACs, data consistency is guaranteed only at the point of execution against each individual database object, meaning that inflight transactions are missed. In other words, BACPAC does not guarantee transactional consistency. You will find more details about this later in Transactional consistency paragraph.

 

Performing export/import via SSMS and BACPAC

 

To migrate user database from Managed Instance to SQL Server, first you would need to export the database to a BACPAC file. That can be done from variety of tools: Azure Portal, SqlPackage command line utility, SSMS, Azure Data Studio or PowerShell. The export process is explained in the Azure documentation. The second step is creating a user database on SQL Server by importing created BACPAC. The process is covered in the documentation.

Let’s quickly go through the steps in SSMS. To migrate the database, we will export a BACPAC to Azure Storage (other options are available as well) and then import it from Azure Storage to a SQL Server. Here’s is what it looks like. In SSMS, from the context menu of a database you want to migrate choose Tasks, Export Data-tier Application. In Export settings, click Connect, connect with your Azure account, then choose target Container and File name and click Next.

SSMS_BACPAC_01.png

 

Follow through the Wizard. The final step will show the operation progress. When it reaches Operation Complete, your BACPAC will be saved in the Azure Storage account.

SSMS_BACPAC_02.png

 

Now, connect to the target SQL Server and from the Databases context menu choose Import Data-tier Application. On the Import Settings window click Connect, connect to your Azure account, then select Container and File name of the BACPAC previously saved and click Next.

SSMS_BACPAC_03.png

 

On Database Settings window, set the New database name. Follow the Wizard. The final step will show the operation progress and once it reaches Operation Complete the database will be ready.

SSMS_BACPAC_04.png

 

In SSMS, connect to the target SQL Server and you will find the database with schema and data.

SSMS_BACPAC_05.png

 

Performing BACPAC export/import via SqlPackage utility

 

If you need to migrate more databases, using a command line tool might be more convenient than SSMS. The utility also offers more parameters than SSMS, so it offers more flexibility and options for fine-tuning. SqlPackage utility can be downloaded from here. Once you install it on a client machine you will be able to run commands to export a BACPAC from Managed Instance, and then to import it into a SQL Server. Here is an example of that process.

Export command:

 

 

C:\Program Files\Microsoft SQL Server\150\DAC\bin>SqlPackage.exe /Action:Export /TargetFile:F:\DBs\AdventureWorks2019_w10lt_s.BACPAC
/SourceServerName:"****.****.database.windows.net" /SourceDatabaseName:AdventureWorks2019_w10lt_s00
/UniversalAuthentication:False /SourceUser:******* /SourcePassword:*******

 

 

SqlPackage_01.png

 

Import command:

 

 

C:\Program Files\Microsoft SQL Server\150\DAC\bin>SqlPackage.exe /Action:Import /SourceFile:F:/DBs/AdventureWorks2019_w10lt_s.BACPAC
/TargetServerName:******* /TargetDatabaseName:AdventureWorks2019_w10lt_s
/UniversalAuthentication:False /TargetUser:******* /TargetPassword:*******

 

 

 

SqlPackage_02.png

 

Limitations and workarounds

 

Export/Import performance

 

Overall performance of the export import process depends on the resources involved in the process. Source Managed Instance, its tier (GP or BC), number of cores, available IOPS, and resource utilization during the export will impact the performance as well as the network bandwidth between the source Managed Instance and the target storage. And finally, network bandwidth of the BACPAC storage and target SQL Server, and its resources (CPU and storage IO) will influence the import duration.

An example of expected performance for the export from GP Managed Instance, with default settings is:

  • StackOverflow 10GB sample database, was exported in ~20min (exported BACPAC had 1.7GB).
  • StackOverflow 50GB sample database, was exported in ~65min (exported BACKAC had 9.2GB).

Note: If the export operation exceeds 20 hours, it may be canceled, so optimizing for performance can make a difference between failure and success.

Here are some options for improving performance of export/import:

  • If you’re exporting from General Purpose Managed Instance (remote storage), you can increase remote storage database files to improve IO performance and speed up the export.
  • Temporarily increase your compute size.
  • Limit usage of database during export (like in Transactional consistency scenario consider using dedicated copy of the database to perform the export operation)
  • Consider using a clustered index with non-null values on all large tables. With clustered index, export can be parallelized, hence much more efficient. Without clustered indexes, export service needs to perform table scan on entire tables in order to export them, and this can lead to time-outs after 6-12 hours for very large tables.
    Hint: A good way to determine if your tables are optimized for export is to run DBCC SHOW_STATISTICS and make sure that the RANGE_HI_KEY is not null and its value has good distribution. For details, see DBCC SHOW_STATISTICS.

 

Database size

 

Although export to BACPAC file is one of the easiest options, it’s not possible to use it in every scenario. In case of exporting to blob storage, the maximum size of a BACPAC file is 200 GB. To archive a larger BACPAC file, export to local storage.

 

Transactional consistency

 

As mentioned in the introduction, BACPAC does not guarantee transactional consistency thus if a child table is modified after the parent table is exported, the database won’t be consistent. To avoid this, you must ensure that no write activity is occurring during the export. You can achieve this by setting read-only mode to your source database or restoring your database to the same instance (under different name) or to a different instance and using that copy as a source for export.

 

Cross-database references

 

DacFx (framework used to create and manage BACPAC files) was designed to block Export/Import when object definitions like views, procedures, etc. contain external references. This includes blocking Export/Import for databases with three-part references to themselves.

Possible resolutions for this situation are:

  • Modify your database schema, removing all self-referencing three-part name references, reducing them to a two-part name.
  • There are many 3rd party tools/mechanisms which can be used to fix schema and remove these external references. One option is to use SQL Server Data Tools (SSDT). In SSDT, you can create a database project from your Managed Instance database, setting the target platform of the resulting project to “SQL Azure”. This will enable Azure-specific validation of your schema which will flag all three-part name/external references as errors. Once all external reference errors identified in the error list have been remedied, you can publish your project back to your Managed Instance database and export/import your database.
  • Finally, if you have only a few database objects using three-part names, you can script them out, delete them, use BACPAC to migrate the database and in the end, use created scripts to manually recreate objects that are using three-part names.

 

Conclusion

 

Data-tier applications (BACPAC) offers a simple way to migrate a database from Managed Instance to SQL Server, with some outstanding limitations. For more information on the migration options, see Moving databases from Azure SQL Managed Instance to SQL Server.

3 Comments
Senior Member

Nice article! I think In the following sentence you mistakenly used replication instead of consistency:

As mentioned in the introduction, BACPAC does not guarantee transactional replication thus if a child table is modified after the parent table is exported

Microsoft

Hi @mverbaas! You're completely right! Thanks for noticing and reporting. The error is fixed now.

Senior Member

@sasapopo , small fix for an otherwise great article.

%3CLINGO-SUB%20id%3D%22lingo-sub-2358570%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20data-tier%20applications%20(BACPAC)%20to%20migrate%20a%20database%20from%20Managed%20Instance%20to%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2358570%22%20slang%3D%22en-US%22%3E%3CP%3ENice%20article!%20I%20think%20I%E2%80%99m%20the%20following%20sentence%20you%20mistakenly%20used%20replication%20instead%20of%20consistency%3A%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3EAs%20mentioned%20in%20the%20introduction%2C%20BACPAC%20does%20not%20guarantee%20transactional%20%3CI%3Ereplication%3C%2FI%3E%20thus%20if%20a%20child%20table%20is%20modified%20after%20the%20parent%20table%20is%20exported%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2359996%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20data-tier%20applications%20(BACPAC)%20to%20migrate%20a%20database%20from%20Managed%20Instance%20to%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2359996%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F310754%22%20target%3D%22_blank%22%3E%40mverbaas%3C%2FA%3E!%20You're%20completely%20right!%20Thanks%20for%20noticing%20and%20reporting.%20The%20error%20is%20fixed%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2360028%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20data-tier%20applications%20(BACPAC)%20to%20migrate%20a%20database%20from%20Managed%20Instance%20to%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2360028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F749038%22%20target%3D%22_blank%22%3E%40sasapopo%3C%2FA%3E%26nbsp%3B%2C%20small%20fix%20for%20an%20otherwise%20great%20article.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2335643%22%20slang%3D%22en-US%22%3EUsing%20data-tier%20applications%20(BACPAC)%20to%20migrate%20a%20database%20from%20Managed%20Instance%20to%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2335643%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--466932970%22%20id%3D%22toc-hId--468778990%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Frelational-databases%2Fdata-tier-applications%2Fdata-tier-applications%23bacpac%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EBACPAC%3C%2FA%3E%20is%20a%20ZIP%20file%20with%20an%20extension%20of%20BACPAC%2C%20containing%20both%20the%20%3CSTRONG%3Emetadata%3C%2FSTRONG%3E%20and%20%3CSTRONG%3Edata%3C%2FSTRONG%3E%20from%20SQL%20Server%20database.%20For%20more%20information%20you%20can%20refer%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fdata-tier-applications%2Fdata-tier-applications%3Fview%3Dsql-server-ver15%23Anchor_4%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EData-tier%20Applications%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E.%26nbsp%3B%20A%20BACPAC%20file%20can%20be%20exported%20to%20Azure%20Blob%20storage%20or%20to%20local%20file%20system%20in%20an%20on-premises%20location%20and%20later%20imported%20into%20SQL%20Server%20or%20Azure%20SQL%20Managed%20Instance%2C%20or%20Azure%20SQL%20Database.%20Although%20BACPAC%20file%20contains%20data%20and%20metadata%20and%20can%20be%20used%20to%20deploy%20a%20copy%20of%20the%20source%20database%2C%20it%20is%20not%20a%20backup%20and%20shouldn%E2%80%99t%20be%20considered%20as%20such.%20However%2C%20in%20a%20situation%20where%20it%E2%80%99s%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fsqlmi-to-sqlserver-blog%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Enot%20possible%20to%20use%20a%20database%20backup%3C%2FA%3E%2C%20BACPAC%20may%20be%20an%20acceptable%20substitute.%3C%2FP%3E%0A%3CP%3ENote%3A%20With%20BACPACs%2C%20%3CSTRONG%3Edata%20consistency%3C%2FSTRONG%3E%20%3CSTRONG%3Eis%20guaranteed%20only%20at%20the%20point%20of%20execution%3C%2FSTRONG%3E%20against%20each%20individual%20database%20object%2C%20meaning%20that%20inflight%20transactions%20are%20missed.%20In%20other%20words%2C%20BACPAC%20does%20not%20guarantee%20transactional%20consistency.%20You%20will%20find%20more%20details%20about%20this%20later%20in%20Transactional%20consistency%20paragraph.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2020579863%22%20id%3D%22toc-hId-2018733843%22%3EPerforming%20export%2Fimport%20via%20SSMS%20and%20BACPAC%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20migrate%20user%20database%20from%20Managed%20Instance%20to%20SQL%20Server%2C%20first%20you%20would%20need%20to%20export%20the%20database%20to%20a%20BACPAC%20file.%20That%20can%20be%20done%20from%20variety%20of%20tools%3A%20Azure%20Portal%2C%20SqlPackage%20command%20line%20utility%2C%20SSMS%2C%20Azure%20Data%20Studio%20or%20PowerShell.%20The%20export%20process%20is%20explained%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-sql%2Fdatabase%2Fdatabase-export%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20documentation%3C%2FA%3E.%20The%20second%20step%20is%20creating%20a%20user%20database%20on%20SQL%20Server%20by%20importing%20created%20BACPAC.%20The%20process%20is%20covered%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fdata-tier-applications%2Fimport-a-bacpac-file-to-create-a-new-user-database%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edocumentation%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20quickly%20go%20through%20the%20steps%20in%20SSMS.%20To%20migrate%20the%20database%2C%20we%20will%20export%20a%20BACPAC%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Fcommon%2Fstorage-account-create%3Ftabs%3Dazure-portal%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Storage%3C%2FA%3E%20(other%20options%20are%20available%20as%20well)%20and%20then%20import%20it%20from%20Azure%20Storage%20to%20a%20SQL%20Server.%20Here%E2%80%99s%20is%20what%20it%20looks%20like.%20In%20SSMS%2C%20from%20the%20context%20menu%20of%20a%20database%20you%20want%20to%20migrate%20choose%20Tasks%2C%20Export%20Data-tier%20Application.%20In%20Export%20settings%2C%20click%20Connect%2C%20connect%20with%20your%20Azure%20account%2C%20then%20choose%20target%20Container%20and%20File%20name%20and%20click%20Next.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SSMS_BACPAC_01.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279682i7ABF0394F4D316A5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SSMS_BACPAC_01.png%22%20alt%3D%22SSMS_BACPAC_01.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20through%20the%20Wizard.%20The%20final%20step%20will%20show%20the%20operation%20progress.%20When%20it%20reaches%20Operation%20Complete%2C%20your%20BACPAC%20will%20be%20saved%20in%20the%20Azure%20Storage%20account.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SSMS_BACPAC_02.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279683iB048BDDC4C45490C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SSMS_BACPAC_02.png%22%20alt%3D%22SSMS_BACPAC_02.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20connect%20to%20the%20target%20SQL%20Server%20and%20from%20the%20Databases%20context%20menu%20choose%20Import%20Data-tier%20Application.%20On%20the%20Import%20Settings%20window%20click%20Connect%2C%20connect%20to%20your%20Azure%20account%2C%20then%20select%20Container%20and%20File%20name%20of%20the%20BACPAC%20previously%20saved%20and%20click%20Next.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SSMS_BACPAC_03.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279684iFE3B86251B311073%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SSMS_BACPAC_03.png%22%20alt%3D%22SSMS_BACPAC_03.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOn%20Database%20Settings%20window%2C%20set%20the%20New%20database%20name.%20Follow%20the%20Wizard.%20The%20final%20step%20will%20show%20the%20operation%20progress%20and%20once%20it%20reaches%20Operation%20Complete%20the%20database%20will%20be%20ready.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SSMS_BACPAC_04.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279685i13509AFE76516029%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SSMS_BACPAC_04.png%22%20alt%3D%22SSMS_BACPAC_04.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20SSMS%2C%20connect%20to%20the%20target%20SQL%20Server%20and%20you%20will%20find%20the%20database%20with%20schema%20and%20data.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SSMS_BACPAC_05.png%22%20style%3D%22width%3A%20453px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279686i9DEADD89233F059F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SSMS_BACPAC_05.png%22%20alt%3D%22SSMS_BACPAC_05.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-213125400%22%20id%3D%22toc-hId-211279380%22%3EPerforming%20BACPAC%20export%2Fimport%20via%20SqlPackage%20utility%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20need%20to%20migrate%20more%20databases%2C%20using%20a%20command%20line%20tool%20might%20be%20more%20convenient%20than%20SSMS.%20The%20utility%20also%20offers%20more%20parameters%20than%20SSMS%2C%20so%20it%20offers%20more%20flexibility%20and%20options%20for%20fine-tuning.%20SqlPackage%20utility%20can%20be%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Ftools%2Fsqlpackage%2Fsqlpackage%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edownloaded%20from%20here%3C%2FA%3E.%20Once%20you%20install%20it%20on%20a%20client%20machine%20you%20will%20be%20able%20to%20run%20commands%20to%20export%20a%20BACPAC%20from%20Managed%20Instance%2C%20and%20then%20to%20import%20it%20into%20a%20SQL%20Server.%20Here%20is%20an%20example%20of%20that%20process.%3C%2FP%3E%0A%3CP%3EExport%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EC%3A%5CProgram%20Files%5CMicrosoft%20SQL%20Server%5C150%5CDAC%5Cbin%26gt%3BSqlPackage.exe%20%2FAction%3AExport%20%2FTargetFile%3AF%3A%5CDBs%5CAdventureWorks2019_w10lt_s.BACPAC%0A%2FSourceServerName%3A%22****.****.database.windows.net%22%20%2FSourceDatabaseName%3AAdventureWorks2019_w10lt_s00%0A%2FUniversalAuthentication%3AFalse%20%2FSourceUser%3A*******%20%2FSourcePassword%3A*******%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SqlPackage_01.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279669i3F2641490C73F7BE%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SqlPackage_01.png%22%20alt%3D%22SqlPackage_01.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EImport%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EC%3A%5CProgram%20Files%5CMicrosoft%20SQL%20Server%5C150%5CDAC%5Cbin%26gt%3BSqlPackage.exe%20%2FAction%3AImport%20%2FSourceFile%3AF%3A%2FDBs%2FAdventureWorks2019_w10lt_s.BACPAC%0A%2FTargetServerName%3A*******%20%2FTargetDatabaseName%3AAdventureWorks2019_w10lt_s%0A%2FUniversalAuthentication%3AFalse%20%2FTargetUser%3A*******%20%2FTargetPassword%3A*******%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SqlPackage_02.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279670iC7D99BD176002F64%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SqlPackage_02.png%22%20alt%3D%22SqlPackage_02.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1594329063%22%20id%3D%22toc-hId--1596175083%22%3ELimitations%20and%20workarounds%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--903767589%22%20id%3D%22toc-hId--905613609%22%3EExport%2FImport%20performance%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOverall%20performance%20of%20the%20export%20import%20process%20depends%20on%20the%20resources%20involved%20in%20the%20process.%20Source%20Managed%20Instance%2C%20its%20tier%20(GP%20or%20BC)%2C%20number%20of%20cores%2C%20available%20IOPS%2C%20and%20resource%20utilization%20during%20the%20export%20will%20impact%20the%20performance%20as%20well%20as%20the%20network%20bandwidth%20between%20the%20source%20Managed%20Instance%20and%20the%20target%20storage.%20And%20finally%2C%20network%20bandwidth%20of%20the%20BACPAC%20storage%20and%20target%20SQL%20Server%2C%20and%20its%20resources%20(CPU%20and%20storage%20IO)%20will%20influence%20the%20import%20duration.%3C%2FP%3E%0A%3CP%3EAn%20example%20of%20expected%20performance%20for%20the%20export%20from%20GP%20Managed%20Instance%2C%20with%20default%20settings%20is%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EStackOverflow%2010GB%20sample%20database%2C%20was%20exported%20in%20~20min%20(exported%20BACPAC%20had%201.7GB).%3C%2FLI%3E%0A%3CLI%3EStackOverflow%2050GB%20sample%20database%2C%20was%20exported%20in%20~65min%20(exported%20BACKAC%20had%209.2GB).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ENote%3A%20If%20the%20export%20operation%20exceeds%2020%20hours%2C%20it%20may%20be%20canceled%2C%20so%20optimizing%20for%20performance%20can%20make%20a%20difference%20between%20failure%20and%20success.%3C%2FP%3E%0A%3CP%3EHere%20are%20some%20options%20for%20improving%20performance%20of%20export%2Fimport%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20you%E2%80%99re%20exporting%20from%20General%20Purpose%20Managed%20Instance%20(remote%20storage)%2C%20you%20can%20%3CA%20href%3D%22https%3A%2F%2Fmedium.com%2Fazure-sqldb-managed-instance%2Fincreasing-data-files-might-improve-performance-on-general-purpose-managed-instance-tier-6e90bad2ae4b%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eincrease%20remote%20storage%20database%20files%3C%2FA%3E%20to%20improve%20IO%20performance%20and%20speed%20up%20the%20export.%3C%2FLI%3E%0A%3CLI%3ETemporarily%20increase%20your%20compute%20size.%3C%2FLI%3E%0A%3CLI%3ELimit%20usage%20of%20database%20during%20export%20(like%20in%20Transactional%20consistency%20scenario%20consider%20using%20dedicated%20copy%20of%20the%20database%20to%20perform%20the%20export%20operation)%3C%2FLI%3E%0A%3CLI%3EConsider%20using%20a%20clustered%20index%20with%20non-null%20values%20on%20all%20large%20tables.%20With%20clustered%20index%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-sql%2Fdatabase%2Fdatabase-import-export-hang%23things-to-consider-when-you-export-or-import-a-database%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eexport%20can%20be%20parallelized%3C%2FA%3E%2C%20hence%20much%20more%20efficient.%20Without%20clustered%20indexes%2C%20export%20service%20needs%20to%20perform%20table%20scan%20on%20entire%20tables%20in%20order%20to%20export%20them%2C%20and%20this%20can%20lead%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-sql%2Fdatabase%2Fdatabase-export%23considerations%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Etime-outs%20after%206-12%20hours%3C%2FA%3E%20for%20very%20large%20tables.%3CBR%20%2F%3E%3CSTRONG%3EHint%3A%20%3C%2FSTRONG%3EA%20good%20way%20to%20determine%20if%20your%20tables%20are%20optimized%20for%20export%20is%20to%20run%20DBCC%20SHOW_STATISTICS%20and%20make%20sure%20that%20the%20RANGE_HI_KEY%20is%20not%20null%20and%20its%20value%20has%20good%20distribution.%20For%20details%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Ft-sql%2Fdatabase-console-commands%2Fdbcc-show-statistics-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EDBCC%20SHOW_STATISTICS%3C%2FA%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1583745244%22%20id%3D%22toc-hId-1581899224%22%3EDatabase%20size%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlthough%20export%20to%20BACPAC%20file%20is%20one%20of%20the%20easiest%20options%2C%20it%E2%80%99s%20not%20possible%20to%20use%20it%20in%20every%20scenario.%20In%20case%20of%20exporting%20to%20blob%20storage%2C%20the%20maximum%20size%20of%20a%20BACPAC%20file%20is%20200%20GB.%20To%20archive%20a%20larger%20BACPAC%20file%2C%20export%20to%20local%20storage.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--223709219%22%20id%3D%22toc-hId--225555239%22%3ETransactional%20consistency%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20mentioned%20in%20the%20introduction%2C%20BACPAC%20does%20not%20guarantee%20transactional%20consistency%20thus%20if%20a%20child%20table%20is%20modified%20after%20the%20parent%20table%20is%20exported%2C%20the%20database%20won%E2%80%99t%20be%20consistent.%20To%20avoid%20this%2C%20you%20must%20ensure%20that%20%3CSTRONG%3Eno%20write%20activity%3C%2FSTRONG%3E%20is%20occurring%20during%20the%20export.%20You%20can%20achieve%20this%20by%20setting%20read-only%20mode%20to%20your%20source%20database%20or%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-sql%2Fmanaged-instance%2Fpoint-in-time-restore%3Ftabs%3Dazure-portal%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Erestoring%3C%2FA%3E%20your%20database%20to%20the%20same%20instance%20(under%20different%20name)%20or%20to%20a%20different%20instance%20and%20using%20that%20copy%20as%20a%20source%20for%20export.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--2031163682%22%20id%3D%22toc-hId--2033009702%22%3ECross-database%20references%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Ftools%2Fsqlpackage%2Fsqlpackage-download%23dacfx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EDacFx%3C%2FA%3E%20(framework%20used%20to%20create%20and%20manage%20BACPAC%20files)%20was%20designed%20to%20block%20Export%2FImport%20when%20object%20definitions%20like%20views%2C%20procedures%2C%20etc.%20contain%20external%20references.%20This%20includes%20blocking%20Export%2FImport%20for%20databases%20with%20three-part%20references%20to%20themselves.%3C%2FP%3E%0A%3CP%3EPossible%20resolutions%20for%20this%20situation%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EModify%20your%20database%20schema%2C%20removing%20all%20self-referencing%20three-part%20name%20references%2C%20reducing%20them%20to%20a%20two-part%20name.%3C%2FLI%3E%0A%3CLI%3EThere%20are%20many%203%3CSUP%3Erd%3C%2FSUP%3E%20party%20tools%2Fmechanisms%20which%20can%20be%20used%20to%20fix%20schema%20and%20remove%20these%20external%20references.%20One%20option%20is%20to%20use%20SQL%20Server%20Data%20Tools%20(SSDT).%20In%20SSDT%2C%20you%20can%20create%20a%20database%20project%20from%20your%20Managed%20Instance%20database%2C%20setting%20the%20target%20platform%20of%20the%20resulting%20project%20to%20%E2%80%9CSQL%20Azure%E2%80%9D.%20This%20will%20enable%20Azure-specific%20validation%20of%20your%20schema%20which%20will%20flag%20all%20three-part%20name%2Fexternal%20references%20as%20errors.%20Once%20all%20external%20reference%20errors%20identified%20in%20the%20error%20list%20have%20been%20remedied%2C%20you%20can%20publish%20your%20project%20back%20to%20your%20Managed%20Instance%20database%20and%20export%2Fimport%20your%20database.%3C%2FLI%3E%0A%3CLI%3EFinally%2C%20if%20you%20have%20only%20a%20few%20database%20objects%20using%20three-part%20names%2C%20you%20can%20script%20them%20out%2C%20delete%20them%2C%20use%20BACPAC%20to%20migrate%20the%20database%20and%20in%20the%20end%2C%20use%20created%20scripts%20to%20manually%20recreate%20objects%20that%20are%20using%20three-part%20names.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2041666786%22%20id%3D%22toc-hId--2043512806%22%3EConclusion%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EData-tier%20applications%20(BACPAC)%20offers%20a%20simple%20way%20to%20migrate%20a%20database%20from%20Managed%20Instance%20to%20SQL%20Server%2C%20with%20some%20outstanding%20limitations.%20For%20more%20information%20on%20the%20migration%20options%2C%20see%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fsqlmi-to-sqlserver-blog%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EMoving%20databases%20from%20Azure%20SQL%20Managed%20Instance%20to%20SQL%20Server.%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2335643%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Teaser-BACPAC.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280221i2A3AE8F9B4712CFF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Teaser-BACPAC.png%22%20alt%3D%22Teaser-BACPAC.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EWant%20to%20move%20your%20database%20from%20Managed%20Instance%20to%20SQL%20Server%3F%20Let%E2%80%99s%20see%20how%20this%20can%20be%20done%20with%20BACPAC.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2335643%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%20Managed%20Instance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jun 02 2021 06:20 AM
Updated by: