Recent Posts

  • TSQL Tuesday #79 -JSON Support in SQL 2016

    TSQL Tuesday #79 -JSON Support in SQL 2016

    I thank Michael J Swart (b|t) for hosting TSQL Tuesday #79. Topic for this month is to write about SQL Server 2016. This is my first time joining in TSQL Tuesday and I am excited about it.


    In my workplace we use MongoDB besides SQL Server. MongoDB save documents in binary form of  JSON called BSON. Our developers are excited to see JSON support in SQL 2o16.  I will give some simple examples about JSON support in SQL Server 2016.  Readers need to be aware that SQL Server is not supporting native JSON type.  In …

  • Schedule SQL Agent Job With Availability Group

    Schedule SQL Agent Job With Availability Group

    There was a tweet came last night from Lohit about “need guidance on how to enable a set of jobs on secondary AG as soon as failover happen from pri to sec AG”.  I have implemented a solution for most (I am using “most”  literally because I have not done this for all jobs) of the agent jobs so jobs will run always on primary node.  For example, I want to run DBCC CHECKDB, recycle error log on primary and all readable secondaries.  That way for the jobs that I want to run on primary node only  I do not …

  • Allocation Pages In SQL Server

    In order to understand how page/extent allocation works with in SQL Server for entities (objects) I was reading Paul Randal’s (B|T) blog. While reading different articles I thought of summarizing few critical information into a table. Which will help me consuming the information better and review easily when I need to. With Paul’s written consent I am sharing this and hope will help others.

    Allocation Page in SQL Server

    Download Poster

  • SQL Agent Jobs With Notification Enabled

    SQL Agent Jobs With Notification Enabled

    DBA team that I worked with manage 170+ SQL Servers. We do not enable notification on any SQL Agent job. We centrally monitor all jobs and send notification based on the tier (Business critical). Last night on call DBA got paged for a job failed in server we are doing proof of concept. By looking at the configuration in the central sever it should not send pager notification. Then I realized it was set in the job itself. This server has over 200 SQL Agent jobs. First I need to find out which jobs has notification enabled, what kind of …

  • What Is Consuming My Log Space

    What Is Consuming My Log Space

    Often times DBA’s (including myself at the beginning of my DBA career) struggle to find out what is causing the log files to grow. Or what is consuming all the space in my log files. I understand there are many factors that can impact the log file size beside all the active transactions.

    Such as:

    • Recovery Model
    • If replication/logshipping/mirroring is set up
    • Frequency of transaction log back up
    • Longest running transaction
    • and many more

    I wanted to see a list of all the sessions that are consuming more than 1kb off log space for all the databases in the server.…

  • Manage SQL Agent Job History

    Recently in one of our server row count in MSDB.DBO.SysJobHistory table exceeded 100 Million and looking at job history was slow via SSMS. It was impossible via the GUI. Because we had about 50 jobs that were running frequently (called from a listener mostly once in every 2 to 3 minutes). I was curious if we can manage the job history for individual job or job category. I also wanted different retention for success vs failure of the job. Meaning for the jobs that run every minute few days of history for success run is enough whereas for failed ones …

  • List All Objects In FileGroup with Size

    Recently at my work due low free space on a LUN I was forced to rebuild few indexes on a different filegroup (which resides on a different LUN). I wanted to list all user objects belong to a single filegroup including size. Did not find a query online with everything I needed. So I wrote this one and wanted to share.

    --Run this in the context of database that you are working on
        FileGroup = FILEGROUP_NAME(a.data_space_id) ,
        TableName = OBJECT_NAME(p.object_id) ,
        IndexName = ,
        8 * SUM(a.used_pages) AS 'Size(KB)' ,
        8 * SUM(a.used_pages) / 1024 AS 'Size(MB)' ,

  • Fix High or Low VLF Count

    Fix High or Low VLF Count

    We started collecting a count of all VLF across the enterprise and yes there were few with high counts. I know there are no SET guidelines how many is too low or too high. After chatting with MVP Allen Kinsel (Blog|Twitter) and Kevin Conan (Twitter) I decided to fix using this threshold. You will be able adjust these threshold in my script to whatever you deem reasonable.

    ( (vlfcount > 50
    AND tLogSizeMB <= 8 * 1024)
    (vlfcount > 200
    AND tLogSizeMB BETWEEN 8 * 1024 + 1 AND 36 * 1024)

  • Which Node SQL Cluster was Running

    Which Node SQL Cluster was Running

    While troubleshooting unplanned SQL cluster failover few questions are asked commonly.

    1. When did the last failover occur?
    2. How frequently you failover (planned and unplanned)?
    3. Did this happen recently.

    All these questions can be answered by this query.  You output will depend how frequently you recycle error log and retention of error log.

    You can also use this query to look for other items in your error log.

    LogDate DATETIME,
    ProcessInfo NVARCHAR(255),

  • Optimize SQL Backup

    Optimize SQL Backup

    Database backup is one of the regular tasks DBA’s perform but few explore all the options that are built in the product. Instead of exploring and using built in switches I noticed DBA’s try writing custom scripts or buying third party tools.
    I explored some of the options and was able to do a full backup of 8TB size database under 2.5 hours. I obtained a 30% performance improvement with using non default values for 3 of the switches that come with Backup command.

    • Number of BACKUP DEVICES (You can use up to 64)-These files can be in