Custom Alert - if a particular query is using more than N percentage of memory resources

As subjected need help in creating a custom alert for few SQL database instances where in if we can know if a particular query is using more than N percentage of memory resources.

Not sure if this is correct way to check against a SQL statement, as in i see most of the parameters its against is only Waittime

  • Would suggest looking at it a little differently. Perhaps create a custom metric that starts to plot out logical reads in aggregate for the instance and then you can start to get a better sense using query stats within DPA to do some simple math on which queries are doing the most logical reads and as a percentage of the aggregate. There are a few reasons I believe this would be a better approach than thinking of it as memory consumption for a given query that I can enumerate if that would help...

  • Here is a query that you could use to create a custom alert (single numeric custom alert):

    select  (
        select (sum(bgets) + sum(dreads))
        from con_stats_sum_2
        where datehour between dateadd(hour, -24, getdate()) and getdate()
        and period = 'H'
        and sqlhash = 3520226983)
    /
            (
        select (sum(bgets) + sum(dreads))
        from con_stats_sum_2
        where datehour between dateadd(hour, -24, getdate()) and getdate()
        and period = 'H') 
    *100

    Feel free to format it nicely, this was quick and dirty. Additionally, this will check for query logical + physical reads vs aggregate reads for the instance. Replace the sqlhash with one you want to focus on. See if this gets you close to what your are looking for..

  • let me test and know results by next week

  • using above - I have created alert where the query calculates the total memory usage (disk reads + buffer gets) over the past hour and determines the memory usage percentage for each SQL query, including details like SQL text, database name, application name, and username. It then filters and lists all the queries exceeding the specified memory usage threshold, ordered by their memory usage percentage.

    When I test it, can see results. but if threshold reduced to 0 can see no results at all. let me update in couple of days.