Thursday, March 14, 2013

Find Processes which are consuming Memory in SQL Server


Which Individual Processes are taking up Memory in SQL SERVER
Here is the simple script that can be used to find individual processes which are taking up memory in SQL Server. This will include program name, login name and read, write etc. Also this script will provide CPU time for each process.
I have used top 10 in the script just to find out the top most 10 processes which are taking or consuming much memory in SQL Server.

SELECT TOP 10
            SESSION_ID,
            LOGIN_TIME,
            HOST_NAME,
            PROGRAM_NAME,
            LOGIN_NAME,
            STATUS,
            CPU_TIME,
            MEMORY_USAGE,
            TOTAL_SCHEDULED_TIME,
            TOTAL_ELAPSED_TIME,
            LAST_REQUEST_START_TIME,
            LAST_REQUEST_END_TIME,
            READS,
            WRITES,
            LOGICAL_READS,
            TRANSACTION_ISOLATION_LEVEL,
            LOCK_TIMEOUT,
            DEADLOCK_PRIORITY,
            ROW_COUNT,
            PREV_ERROR

FROM SYS.DM_EXEC_SESSIONS ORDER BY MEMORY_USAGE DESC