SQL AZURE Tips
SQL AZURE Tips
SQL AZURE Tips
SQL AZURE Tip 2: How to refresh/restore a Database from prod to dev in Azure?
Background: There is a database called RajSQLDB in Prod server name called ProdDBServer under
premium tier. This database need to restore in my DEV server with standard tier (I don’t want to
keep same premium tier as this db is in prod. In dev workload is low and keeping low tier always
saves the money for the clients)
Solution:
RUN the below query in management studio in Dev server
CREATE DATABASE RajSQLDB AS COPY OF ProdDBServer.RajSQLDB
(EDITION = 'standard', SERVICE_OBJECTIVE = 'S12', MAXSIZE = 250 GB ) ;
You can see the restore progress using below queries in master Database in dev server
SELECT * FROM sys.dm_database_copies where name=’RajSQLDB’
SELECT state_desc, * FROM sys.databases where name=’RajSQLDB’
SQL AZURE Tip 3: How to check deadlock information in the AZURE SQL DB?
Solution: We can track the deadlocks using below query. Please execute below query in Master DB.
SELECT * FROM sys.event_log
WHERE event_type = 'deadlock';
Once you found the Deadlocks, you can further dig and find in-detail information on each deadlock
using below query.
Need to run below query in Master DB only.
WITH CTE AS (
SELECT CAST(event_data AS XML) AS [target_data_XML]
FROM sys.fn_xe_telemetry_blob_target_read_file('dl', null, null, null)
)
SELECT target_data_XML.value('(/event/@timestamp)[1]', 'DateTime2') AS Timestamp,
target_data_XML.query('/event/data[@name=''xml_report'']/value/deadlock') AS deadlock_xml,
target_data_XML.query('/event/data[@name=''database_name'']/value').value('(/value)[1]',
'nvarchar(100)') AS db_name
FROM CTE
--where target_data_XML.value('(/event/@timestamp)[1]', 'DateTime2')>='2020-03-01'
--and target_data_XML.query('/event/data[@name=''xml_report'']/value/deadlock') like
'%Employee%'
order by Timestamp desc
You can copy and save the deadlock_xml column data in notepad file and same with extension of .x
dl (example deadlock1.xdl) and open the saved file in the Management Studio. You can see the
deadlock information in the graph(s).
Note: Like on premise, we don’t need to setup any trace flag in azure sql db. Even you cannot enable
any trace flags here
SQL AZURE Tip 4: How to change MAXDOP Setting in the azure DB?
Solution: We (SQL DBA Guys) all know the what is MAXDOP? YES!! The Maximum Degree of
Parallelism (MAXDOP) is a server, database or query level option that is used to limit the number of
processors that the parallel plan can use.
Below in azure, once you changed the MAXDOP setting to 1. You can see only serial execution plans.
Just
SQL AZURE Tip 7: Can we enable Trace flags in Azure SQL databases?
Ans) No. We can’t enable trace flags in Azure SQL databases. But, we can see some of the trace flags
which were already enabled in Azure SQL Databases.
Note: Total 25 Trace flags are there and all these were globally enabled.
SQL AZURE Tip 9: How to optimize the performance of Microsoft SQL Server workloads running in an
Azure Virtual Machine environment?
Note: Above uses results from specific test scenarios to provide guidance and best practices for
optimizing the performance of SQL Server workloads running in Azure virtual machine (VM).
SQL AZURE Tip 10: AZURE SQL DATABASE Backup Storage Types