Azure SQL Database and Transaction Log

Checking out the transaction log in Azure SQL Database. If you are curious like me, you will want to know about what your transaction log is doing in the cloud. The following queries have been tested and run okay within Azure SQL Database. It gives you some great insight.

First up, the classic log_reuse_wait_desc.

 SELECT name, [log_reuse_wait_desc] FROM sys.databases WHERE name = 'customertwo'

nothingsql

I have no issues with VLF fragmentation. You can tell this is a small log file.

SELECT name AS 'Database Name', total_vlf_count AS 'VLF count'
FROM sys.databases AS s
CROSS APPLY sys.dm_db_log_stats(s.database_id)
WHERE name  'master'

vlfcount

How much space is used?

 DBCC SQLPERF(LOGSPACE)

logspace

So let’s get to work and start logging some information. As you can see below the space used % increases (and the actual file size).

griowth

The log grows and expect the VLF count to change too.

SELECT name AS 'Database Name', total_vlf_count AS 'VLF count'
FROM sys.databases AS s
CROSS APPLY sys.dm_db_log_stats(s.database_id)
WHERE name  'master'

vlf12

The purpose of this blog is to show you that you can see what is going on but unlike the classic on-premises SQL servers you cannot ALTER DATABASE and change file sizes. Don’t forget, Microsoft are doing the transaction log backups to keep the size in check for reuse anyways.


 SELECT name AS 'Database Name', log_backup_time AS 'last log backup time'
FROM sys.databases AS s CROSS APPLY sys.dm_db_log_stats(s.database_id)
WHERE name  'master'

It seems to be roughly every 10 minutes that a log backup is taken – nicely managed.

logbak

6 thoughts on “Azure SQL Database and Transaction Log

  1. Pingback: Dew Drop - January 23, 2019 (#2883) - Morning Dew

  2. Hello, Is there a way in Azure SQL Database that i can access the contents of the .LDF file. In other words, as transactions are happening i would like to be reading them out of the log file.

    Regards Ryan

    Like

    • Hey Ryan. No we cant query that LDF in Azure SQL. If you want to see statements running for performance reasons then I suggest Query Performance Insight, maybe query store or build extended event session.

      Like

      • Its the actual data i am interested in for warehousing reasons. Do you know if MS have this planned for the future?

        Like

      • So you mean like DBCC PAGE to see the raw data (hex/ ascii etc)? If so, no I dont think thats on any roadmap. I know that wont work right now in azure sql.

        Like

Leave a Reply