Gianluca Hotz: SQL Server Modernization
Gianluca Hotz: SQL Server Modernization
#sqlsat
Infrastructure
hardware, virtualization platforms, storage solutions, HA/DR & backup solutions…
Application development
Licensing
SQL Server flavors
On-Premises
SQL Server (Database Engine, SSAS, SSRS, SSIS, DQS, MDS, MLS)
Analytics Platform System (APS was SQL Server PDW)
IaaS
SQL Server (Database Engine, SSAS, SSRS, SSIS, DQS, MDS, MLS)
PaaS
Azure SQL Database, Azure SQL Data Warehouse
Amazon RDS for SQL Server
Richer Data Platform offering (e.g. Data Lake, Data Factory, etc.)
Changing platform
Can be easy
Migrating databases to PaaS or containerized versions (but same RDBMS)
or…
Hard: converting databases to other RDBMSs
data must be physically migrated (different types, different representations,…)
database code must be converted (constraints, triggers, functions, procedures,…)
Application code can be
converted completely, to a new platform
just adapted to run against the new RDBMS
adapted to support multiple RDBMSs
Different kind of projects
Migration
one time conversion
solution switch-over at a certain point
Porting
side-by-side conversion & evolution
no switch-over, current solutions remain
Migration Projects
Usually done by final customers (i.e. not ISVs)
Driving factors
cost reduction
move away from vendor(s)
solution obsolescence
unreliability and/or supportability problems
Application
may be converted to a new platform
may be adapted to run with new RDBMS
Porting Projects
Usually done by ISVs
Driving factors
get into new markets
cost reduction for customers (TCO)
more choice for customers
become less dependent from vendor(s)
Application
may be ported to new platform
happens rarely, means re-write or 2 codebases
may be adapted to run with new RDBMS
Different kind of Databases to migrate/port
Simple schema
all the logic is inside the application
simple access methods (mostly by cursors)
very limited use of SQL dialects
database is used mostly for storage
Complex schema
much of the logic is inside the database
heavy usage of SQL dialects
database used as a rule and inference engine
Origin of problems
Sometimes porting issues arise from
misusage of functionalities
bad decoupling of application/database code
too much row oriented code in the database
low technical skills of coders/architects
Never judge
every application has it own story
a lot of decisions may be compromises
a lot of money was probably already invested
Application portability
Code in the RDBMS
has been a best practice for years
still a very good solution for both
integrity
scalability
however… portability is an issue!
different SQL dialects
different type systems
different engine features
Changing Architecture
More complex
Low familiarity with non RBMS technologies
Low familiarity with unstructured dta
New implementation patterns
ML & AI will stop to be buzzwords…
Version Upgrades: motivations
Better Performance
New functionalities
Winter is coming!
Version Upgrades: barriers
Licensing Costs
Regressions risk
Application changes costs
Complexity
Testing changes (application or certification processes)
Planning for low downtime
Lack of time/resources/competencies
Edition upgrades/downgrades
Upgrades
Motivations similar to version upgrades
Barriers similar to version upgrades
Complexity usually lower because setup covers the scenario
Downgrades
Main motivation to save money
Barriers similar to version upgrades
Needs reinstallation, less impact for non production environment
Hardest problems
Factors that require application changes
Breaking changes
Discontinued functionalities
Plan affecting changes may cause performance regressions
New Cardinality Estimator
Hotfixes
New QP strategies/behavior (e.g. Intelligent Query Processing)
Testing changes is hard!
Complete Workload coverage
Concurrent access
Database Compatibility Level
Version Native Level Supported Levels
Sets behavior compatible with SQL Server 2019 150 150, 140, 130, 120,
110, 100
specified version of SQL Server SQL Server 2017 140 140, 130, 120, 110,
100
Azure SQL Database 130 140, 130, 120, 110,
100
SQL Server 2016 130 130, 120, 110, 100
https://blogs.msdn.microsoft.com/sql_server_team/developers-choice-hinting-query-execution-model
Query Optimizer Hints
USE HINT Trace Flag DB
DISABLE_OPTIMIZER_ROWGOAL 4138
ENABLE_HIST_AMENDMENT_FOR_ASC_KEYS 4139
ASSUME_JOIN_PREDICATE_DEPENDS_ON_FILTERS
9476 (New CE)
FORCE_DEFAULT_CARDINALITY_ESTIMATION 2312
QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_n
QUERY_PLAN_PROFILE
https://blogs.msdn.microsoft.com/sql_server_team/developers-choice-use-hint-query-hints
Microsoft recommended upgrade Plan
Upgrade to
latest SQL
Quickly fix
Server Move to
Create a regressions
version and Enable Query latest
baseline of by forcing
keeping Store compatibility
the workload last known
source level
good plan!
compatibility
level
Upgrade Strategies
Side-by-side In-Place
Allow OS Upgrade No additional Hardware
Easier testing No data migration
Easier rollback strategy
Less downtime
Side-by-side Upgrade Service Availability
Synchronization Strategy Notes
Log Shipping Cutover typically in minutes
Replication Cutover potentially in seconds
Backup/Restore From minutes to hours (depends on
strategy e.g. usage of differential and/or
log backups)
Filesystem/SAN Copy Dependent on technology
Database Mirroring/Availability Groups Cutover typically in seconds
Upgrade process to minimize risks
Functional &
Remediate
Performance
applications
tests
Data
Discover Assess Convert Cutover
Sync
Migrate
schema, Optimize
objects & data
Discover Phase
Which SQL Server versions do I have?
Source Destination
SQL Server 2005 SQL Server 2012
SQL Server 2008 SQL Server 2014
SQL Server 2008 R2 SQL Server 2016
SQL Server 2012 SQL Server 2017
SQL Server 2014 on Windows and Linux
Blog
https://blogs.msdn.microsoft.com/datamigration/tag/dea
Azure Database Migration Service
On-premises
My
Blog
https://blogs.msdn.microsoft.com/datamigration/tag/azure-database-
migration-service
https://blogs.msdn.microsoft.com/datamigration/tag/dms
SQL Server Migration Assistant
Migration effort assessment
Code conversion
Data migration
Testing
Deployment
Platforms supported by SSMA
Source Destination
Microsoft Access SQL Server 2008
DB2 SQL Server 2008 R2
MySQL SQL Server 2012
Oracle SQL Server 2014
SAP ASE (Sybase ASE) SQL Server 2016
SQL Server 2017 on Windows and Linux
SQL Server 2019 on Windows and Linux
Azure SQL Database
Azure SQL Database Managed Instance
Azure SQL Data Warehouse (Oracle only)
SSMA for Oracle: how it works (101)
Creates two “helper” databases
sysdb
ssmatesterdb
Stores metadata in the file system
data stored in xml compressed format
can rename to .gzip and uncompress it
shred xml into lot of files for caching
reports directory
can be safely deleted and re-generated
metadata reside in the original .mb files
SSMA for Oracle: sysdb helper database
Provides
code infrastructure to emulate features
system functions
schema features (e.g. sequences)
engine features (e.g. autonomous transactions)
session bound data storage
emulated metadata storage (e.g. packages)
Maintenance
protect metadata
performance related depends on workload
SSMA for Oracle: does it really work?
Yes, but don’t expect miracles!
Works well with simple schemas…
Usually won’t do all the work by itself
Very useful for
assessing efforts
assessing problems
doing prototypes
as a learning tool
to translate/emulate some functionalities
Testing
Nothing can replace good testing!
Hard to have tests with good coverage of the whole workload
Sometimes is more cost effective to run fewer tests and fix the
problems later…
https://github.com/spaghettidba/WorkloadTools
DBA Tools
Lot of PowerShell cmdlets to make the DBA life easier
https://dbatools.io
Start-DbaMigration
https://youtu.be/hg8tovMRX2k
After the upgrade: remember the plan
Upgrade to
latest SQL
Quickly fix
Server Move to
Create a regressions
version and Enable Query latest
baseline of by forcing
keeping Store compatibility
the workload last known
source level
good plan!
compatibility
level
Automatic Tuning
Automatic plan correction
Automatically force last good plan when regression detected
Minimum 10 CPU seconds improvement
sys.dm_db_tuning_recommendations for manual corrections
https://docs.microsoft.com/en-us/sql/relational-databases/automatic-tuning/automatic-tuning
Query Tuning Assistant
Well-defined workflow targeting patterns for query regressions
Independence vs. Correlation
Simple Containment vs. Base Containment
Multi-statement table-valued function (MSTVF) fixed cardinality guess
https://docs.microsoft.com/en-us/sql/relational-databases/performance/upgrade-dbcompat-using-qta
Modernization Stream Phases in a SQL
Project
Partner Collect Inspire
Cloud network
SQL DB
Managed Instance
On-Premise
Other on-premises to PaaS strategies
Method 1 Method 2 Method 3
SQL Server
SQL Server SQL Server
Visual
1. Import
Source
Studio
Source Source
DB Database
DB
DB Project
1. Export 4. Copy
1. Generate
2. Transform
5. Publish
SSMS OR 1. Deploy
SQL Azure Data
SSMS Copy *.sql Migratio
T-SQL
.bacpac
Migration DB n
Wizard Assistant
2. Import 2. Execute
6.
3. Edit, Build
Export/
& Test
Import
or Deploy 4. Publish (schema only)
Target Target
DB Target
DB
DB
Compatible database: manual Database almost compatible: Refactor with Visual Studio and Data
copy or deploy wizard in SSMS SQL Azure Migration Wizard Migration Assistant, final deploy with
DMA and SSMS SSMS
Migration with minimal downtime
Transactional Replication
Data Migration Resources
Blog
https://blogs.msdn.microsoft.com/datamigration
Upgrade SQL Server
https://docs.microsoft.com/sql/database-engine/install-windows/upgrade-sql-
server
Post-migration validation and optimization guide
https://docs.microsoft.com/sql/relational-databases/post-migration-validation-
and-optimization-guide
Azure Database Migration Guide
https://datamigration.microsoft.com
Q&A