Migrating to Azure SQL Database: Tips, Tricks, and Lessons Learned Randolph West DATA PLATFORM MVP @bornsql bornsql.ca/blog
PREPARE FOR OBSOLESCENCE Migrating to Azure Sql Database PREPARE FOR OBSOLESCENCE Everything I was going to tell you today was obsolete on Wednesday. This is how quickly things change. Azure SQL Database is always getting better: three ways to migrate speed was doubled across the board earlier this year databases larger than 1TB are supported all the things missing, are coming soon.
What is Azure SQL Database? This is a marketing slide What is Azure SQL Database? Azure SQL Database is a cloud-based relational database service, built on the Microsoft SQL Server engine, designed to deliver predictable performance and scalability, with virtually no downtime, and near- zero administration. Azure SQL delivers predictable performance, scalability with no downtime, business continuity and data protection—all with near-zero administration. Developers can focus on rapid app development and getting their apps and solutions into production instead of managing VMs and infrastructures. Since Azure SQL is based on the Microsoft SQL Server engine, it supports existing SQL Server tools, libraries and APIs, which makes it easy for developers and organizations to extend to the cloud. Source: Microsoft
Common Business Differentiators (TODAY) This is another marketing slide, which is now obsolete Common Business Differentiators (TODAY) Azure SQL Database SQL Server You’re building new cloud-based applications to take advantage of cost savings and performance. You want to build enterprise applications larger than 1 TB (4 TB). You want databases replicated in different regions of the world for backup. You have existing IT resources and can maintain stewardship over backups and database high availability. You want Microsoft to handle common management operations. Although there is a number of differences between Azure SQL and SQL Server, the primary differences have more to do with scale and resources than actual features. For developers there are minor differences in development, mostly around T-SQL variations, Most of the Transact-SQL features that applications depend on are supported in both Microsoft SQL Server and Azure SQL. Some unsupported features are data types, operators, as well as string, arithmetic, logical, and cursor functions. Another important difference is that Azure SQL is designed to isolate features from any dependency on the master database, and so some server-level activities are unsupported. NOTE: Features that are deprecated in SQL Server are generally not supported in Azure SQL.
Why are you migrating? Do you have to choose? Why? Are you sure? migrating to Azure SQL Database Why are you migrating? Do you have to choose? Why? Are you sure? Is your company going to benefit from this?
Platform as a service (Paas) migrating to azure sql database Platform as a service (Paas) Mostly compatible with SQL Server 2014, 2016 and 2017 Pay-as-you-go Scale-up or scale-out instantly* Automatically configured, patched, and upgraded Automated backups, Point-In-Time Restore, Geo-Restore, and Active Geo- Replication Pay per hour, per service tier and performance level Pay for data transfer Total cost of application = Highly minimized administration costs + software development costs + SQL Database service costs
Infrastructure as a service (iaas) Migrating to azure sql database Infrastructure as a service (iaas) SQL Server 2014, 2016, or 2017, installed on a virtual machine Per-minute licensing cost (Web, Standard, Enterprise) Or bring your own existing licence and only pay for Windows VM Fully customisable You are responsible for managing it (patching, maintenance, backups) Pay for premium storage (SSD drives: P10, P20, P30) Total cost of application = Minimized software development/modification costs + administration costs + SQL Server and Windows Server licensing costs + Azure Storage costs
Azure SQL Database Limitations (TODAY) Migrating to azure sql database Azure SQL Database Limitations (TODAY) https://docs.microsoft.com/en-us/azure/sql-database/sql-database- features/ Highlights: No Windows Authentication (Azure AD is supported) TCP/IP on port 1433 only No SQL Server Agent jobs (on-premises only) Fixed Collation (default SQL_Latin1_General_CP1_CI_AS) Restricted usernames (admin, administrator, guest, root, sa, ‘\’)
Transact-SQL Differences in Azure SQL Database (TODAY) Migrating to azure sql database Transact-SQL Differences in Azure SQL Database (TODAY) https://docs.microsoft.com/en-us/azure/sql-database/sql- database-transact-sql-information/ “Azure SQL Database is designed to isolate features from any dependency on the master database. As a consequence many server-level activities are inappropriate for SQL Database and are unsupported.” – Microsoft
Features Not Supported (TODAY) This is a slide you can’t read Features Not Supported (TODAY) Collation of system objects High availability: Syntax related to high availability, which is managed through your Microsoft Azure account. This includes syntax for backup, restore, Always On, database mirroring, log shipping, recovery modes. Server credentials: Use database scoped credentials instead. Trace flags: Some trace flag items have been moved to compatibility modes. Connection related: Endpoint statements, ORIGINAL_DB_NAME. SQL Database does not support Windows authentication, but does support the similar Azure Active Directory authentication. Some authentication types require the latest version of SSMS. For more information, see Connecting to SQL Database or SQL Data Warehouse By Using Azure Active Directory Authentication. Server-level items: Server roles, IS_SRVROLEMEMBER, sys.login_token. GRANT, REVOKE, and DENY of server level permissions are not available though some are replaced by database-level permissions. Some useful server-level DMVs have equivalent database-level DMVs. Transact-SQL debugging Triggers: Server-scoped or logon triggers USE statement: To change the database context to a different database, you must make a new connection to the new database. Log reader: Syntax that relies upon the log reader, which is not available on SQL Database: Push Replication, Change Data Capture. SQL Database can be a subscriber of a push replication article. SET REMOTE_PROC_TRANSACTI ONS Cross database queries using three or four part names. (Read- only cross-database queries are supported by using elastic database query.) Functions: fn_get_sql, fn_virtualfilestats, fn_virtualservernodes SHUTDOWN Global temporary tables sp_addmessage Cross database ownership chaining, TRUSTWORTHY setting Hardware: Syntax related to hardware-related server settings: such as memory, worker threads, CPU affinity, trace flags. Use service levels instead. sp_configure options and RECONFIGURE. Some options are available using ALTER DATABASE SCOPED CONFIGURATION. DATABASEPROPERTY Use DATABASEPROPERTYEX instead. sp_helpuser HAS_DBACCESS sp_migrate_user_to_contained EXECUTE AS LOGIN Use 'EXECUTE AS USER' instead. KILL STATS JOB SQL Server Agent: Syntax that relies upon the SQL Server Agent or the MSDB database: alerts, operators, central management servers. Use scripting, such as Azure PowerShell instead. Encryption is supported except for extensible key management OPENQUERY, OPENROWSET, OPENDATASOURCE, and four- part names Eventing: Events, event notifications, query notifications .NET Framework: CLR integration with SQL Server File placement: Syntax related to database file placement, size, and database files that are automatically managed by Microsoft Azure. SQL Server audit: Use SQL Database auditing instead. Semantic search SQL Server trace
Migrating a SQL Server Database to Azure SQL Database Migrating to Azure SQL Database Migrating a SQL Server Database to Azure SQL Database https://docs.microsoft.com/en-us/azure/sql-database/sql-database- cloud-migrate Check compatibility with Data Migration Assistant (DMA) Choose a Service Level and Performance Tier Three primary methods to migrate to Azure SQL Database: Migrate with downtime during migration (demo 😀) Transactional Replication (no demo 😟) Live migration through Azure Portal (coming soon)
Transactional replication method No demo, so here’s a picture Transactional replication method Configure your Azure SQL Database as a subscriber to the SQL Server instance that you wish to migrate. The transactional replication distributor synchronizes data from the database to be synchronized (the publisher) while new transactions continue occur. Source: Microsoft
LIVE MIGRATION THROUGH THE AZURE PORTAL No demo, so here’s a picture LIVE MIGRATION THROUGH THE AZURE PORTAL Source: Microsoft
LIVE MIGRATION THROUGH THE AZURE PORTAL No demo, so here’s a picture LIVE MIGRATION THROUGH THE AZURE PORTAL Source: Microsoft
LIVE MIGRATION THROUGH THE AZURE PORTAL No demo, so here’s a picture LIVE MIGRATION THROUGH THE AZURE PORTAL Source: Microsoft
LIVE MIGRATION THROUGH THE AZURE PORTAL No demo, so here’s a picture LIVE MIGRATION THROUGH THE AZURE PORTAL Source: Microsoft
LIVE MIGRATION THROUGH THE AZURE PORTAL No demo, so here’s a picture LIVE MIGRATION THROUGH THE AZURE PORTAL Source: Microsoft
sERVICE LEVEL AND PERFORMANCE TIER (CAD) want to spend some money? Here’s how sERVICE LEVEL AND PERFORMANCE TIER (CAD) Level Tier DTUs Size Cost p.m. Basic 5 2 GB $6.06 Standard S0 10 250 GB $18.28 S1 20 $36.46 S2 50 $91.19 S3 100 $182.38 Premium P1 125 500 GB $565.40 P2 250 $1,130.79 P4 500 $2,261.58 P6 1000 $4,523.15 P11 1750 4 TB $8,512.57 P15 4000 $19,458.59
What the heck is a dtu? Database Transaction Unit (DTU): THIS SLIDE POSES A PUZZLING QUESTION What the heck is a dtu? Database Transaction Unit (DTU): Combination of I/O, RAM, CPU and log writes in some magical* formula Azure SQL Database benchmark overview: https://docs.microsoft.com/en-us/azure/sql-database/sql-database- benchmark-overview/ DTU Calculator (3rd party product): http://dtucalculator.azurewebsites.net % Processor Time, Disk Reads/sec, Disk Writes/sec, Log Bytes Flushed/sec The DTU Calculator makes a recommendation of the minimum performance level and service tier that you need before you migrate to Azure SQL Database.
CAN I SHARE RESOURCES BETWEEN AZURE SQL DATABASES? ADD-ON QUESTION CAN I SHARE RESOURCES BETWEEN AZURE SQL DATABASES? Elastic pools are useful for managing and scaling multiple databases that have varying and unpredictable usage demands. The databases in an elastic pool are on a single Azure SQL Database server and share a set number of resources at a set price. Elastic pools thus have larger limits, but are for sharing between databases. One single database cannot exceed the limits noted previously.
DEMO
This is a TL;DR SLIDE TIPS AND TRICKS Always use the latest version of SQL Server Management Studio BACPAC files must be saved to standard Azure Blob Storage, not premium storage Make sure your database is compatible with SQL Server 2016 features Watch out for hidden costs when scaling out SQL Databases, or running VMs Elastic pools can get expensive De-allocate VMs, and delete databases, if not using them
something amazing this way comes … This is what’s coming something amazing this way comes … Migrate SQL Server to SQL as a Service with no changes SQL Agent, 3-part names, DBMail, CDC, Service Broker Cross-database and cross-instance querying Extensibility: CLR and R Services SQL Profiler (ugh!), additional DMVs support, XEvents Native backup and restore, log shipping, transactional replication
another screenshot Here’s the screenshot! Source: Microsoft
this is A summary slide summary DTUs do not map directly to resources, and require a workload to evaluate against (time-based evaluation) Some important on-premises features are not available in Azure SQL Database (YET!) For smaller databases, web-based applications, and specifically new development, Azure SQL Database may be appropriate SQL Server 2016 on Azure VM may be more appropriate for existing applications, and more cost-effective for larger databases, even with an Enterprise licence YMMV (your mileage may vary)
FIND OUT MORE Azure website: https://azure.microsoft.com/ LOTS OF LINKS HERE FIND OUT MORE Azure website: https://azure.microsoft.com/ Books Online: https://docs.microsoft.com/en-us/sql/sql-server/sql-server-technical- documentation John Sterrett’s Virtual PASS Chapter presentation: https://goo.gl/Ff6Hyg Andy Mallon Reverse Engineered the DTU Calculator: https://sqlperformance.com/2017/03/azure/what-the-heck-is-a-dtu