Rajasekhar Reddy Bolla
SQL AZURE Tip 1: Use auto-scaling to reduce costs during off hours.
Background: Below Tip can save you some money in Azure.
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:
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 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
SELECT * FROM sys.database_scoped_configurations
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 1
SQL AZURE Tip 5: Interesting facts about Azure SQL Databases:
Recovery model is FULL and you cannot change this
Backup are automatically scheduled and you cannot take manual database backup and Nol
restore DB using manual backups
You cannot download/see automated backups
No SQL agent but you can automate using windows scheduler and/or Azure Automation
Runbooks and/or elastic jobs.
Restore with Overwrite not supported on Azure SQL DB
If you delete the DB you can restore the Backup of it based on the retention period , But of you
delete the server you can’t restore the backup because the backup will be deleted with the
server
Rajasekhar Reddy Bolla
Hi, this is Raj, Azure DBA Trainer. Interested candidates
Reach me on WhatsApp- 9966246368 for AZURE SQLDBA Trainings.
These trainings are completely real time, hands-on, interview based.
My LinkedIn profile:
https://www.linkedin.com/in/rajasekhar-reddy-bolla/