Recent Posts

  • 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

  • Find Transactional Replication Details

    Find Transactional Replication Details

    This will be a quick post about a script to find replication metadata in details.  You need to run this in your distributor (where distribution database reside) server and filter in various ways depending on your need.  Also modify order by based on what you are looking for.

    Run where distribution database reside

    USE distribution;
            p.publication ,
            p.publisher_db ,
            SUBSTRING(, 0, CHARINDEX('-', AS Source_Server ,
            a.article ,
            a.source_object ,
            s.subscriber_db ,
                              CHARINDEX('-', REVERSE( + 1,
                              ( ( CHARINDEX('-', REVERSE(,
                                            CHARINDEX('-', REVERSE( + 1) )
                                - ( CHARINDEX('-', REVERSE( ) - 1 ))) AS Destination_Server ,

  • Monitoring Transaction Replication Latency in Real Time

    Monitoring Transaction Replication Latency in Real Time

    This post will give a practical solution with complete code to monitor SQL server transactional replication latency in real time.  My solution assumes you are using common distribution agent.  With minor change you can also implement this for independent distribution agent.

    This solution is a implementation of Kendra Little’s blog post.

    Concept is to create a table with a single row storing current date-time (updated via a sql job every minute).  Replicate that data to your subscriber and measure the difference between current time and time-stamp in subscriber table.

    Before you run any of these code make sure you read …

  • WMI issue with SQL Server 2014

    WMI issue with SQL Server 2014

    Issue: I installed sql2014 enterprise edition with cu3 in following machine.  Just as a disclaimer I have been running a sql2012 edition on the same  host without any issue with WMI counters.



    I could not see any wmi counters for sql2014.  I tried perfmon.exe and also querying:

    SELECT * FROM sys.dm_os_performance_counters
    SELECT * FROM sys.sysperfinfo

    Then I snipped through sql server error log and found this:

    Cannot query value ‘First Counter’ associated with registry key ‘HKLMSYSTEMCurrentControlSetServicesMSSQL$SQL2014Performance’. SQL Server performance counters are disabled.

    So I went to registry and added a new key with value 4090 under  HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesMSSQL$SQL2014Performance


    Restarted sql …

  • Deadlock Detection and Reporting part-II

    Deadlock Detection and Reporting part-II

    This is a continuation of the series about deadlock.  First part was how you detect deadlock in SQL Server and collect that information.  This part will be about reporting from the collected information.

    On the 2nd step of the job the code below will purse the xml and send .xdl file along with information in tabular format.

    2nd step on the job:

    FROM tempdb.sys.tables
    WHERE name LIKE '##tmpDeadlockEvents%' )
    DROP TABLE ##tmpDeadlockEvents
    CREATE TABLE ##tmpDeadlockEvents ( [deadlock-list] XML )
    DECLARE @subjectText VARCHAR(250) ,
    @bodyText NVARCHAR(MAX)