SQL Azure Tips
SQL Azure Tips
SQL AZURE Tip 1: Use auto-scaling to reduce costs during off hours.
Most databases have busier (Day time) and slower periods (Night Time) throughout a week or day.
Normally the DTU’s (CPU, Memory & IO) consumptions are lower at night times and higher at day times.
In this case, we can save some money by scaling down the databases at night times. Below simple
automation Job(attached) will do the same thing.
By moving from On-premise to AZURE, we can save lot of money. AZURE offers a range of uses and
benefits for organizations. In AZURE, maintenance is very easy and you can only pay for what you use
and you can also scale up on demand.
Below is the step by step document, how we implement this in windows scheduler
Note: To implement this, you can also use Runbooks, Elastic Jobs and other job schedulers
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:
You can see the restore progress using below queries in master Database in dev server
SQL AZURE Tip 3: How to check deadlock information in the azure DB?
Rajasekhar Reddy Bolla
Solution: Below query will show you, any database in the instance had any deadlock occurred or not
Need to run below query in Master DB.
SELECT * FROM sys.event_log
WHERE event_type = 'deadlock';
Once the Deadlocks have been found. You Can see in detail information on each deadlock.
Need to run below query in Master DB.
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
Once the results showed, save the deadlock_xml column data into the .xdl (example deadlock1.xdl)
format and open the saved file in the mgt studio. You can see the deadlock information in the graph(s).
Rajasekhar Reddy Bolla
Note: Like on premise, we don’t need to setup have trace flag 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
My LinkedIn profile:
https://www.linkedin.com/in/rajasekhar-reddy-bolla/