简体   繁体   中英

How to check which SQL query is so CPU intensive

Is there any possible way to check which query is so CPU intensive in _sqlsrv2 process? Something which give me information about executed query in that process in that moment.

Is there any way to terminate that query without killing _sqlsrv2 process?

I cannot find any official materials in that subject.

Thank You for any help.

You could look into client database-request caching.

Code examples below assume you have ABL access to the environment. If not you will have to use SQL instead but it shouldn't be to hard to "translate" the code below

I haven't used this a lot myself but I wouldn't be surprised if it has some impact on performance.

You need to start caching in the active connection. This can be done in the connection itself or remotely via VST tables (as long as your remote session is connected to the same database) so you need to be able to identify your connections. This can be done via the process ID.

Generally how to enable the caching:

/* "_myconnection" is your current connection. You shouldn't do this */
FIND _myconnection NO-LOCK.

FIND  _connect WHERE _connect-usr = _myconnection._MyConn-userid.

/* Start caching */
_connect._Connect-CachingType = 3.

DISPLAY _connect WITH FRAME x1 SIDE-LABELS WIDTH 100 1 COLUMN.

/* End caching */
_connect._Connect-CachingType = 0.

You need to identify your process first, via top or another program.

Then you can do something like:

/* Assuming pid 21966 */
FIND FIRST _connect NO-LOCK WHERE _Connect._Connect-Pid = 21966 NO-ERROR.
IF AVAILABLE _Connect THEN
    DISPLAY _connect.

You could also look at the _Connect-Type. It should be 'SQLC' for SQL connections.

FOR EACH _Connect NO-LOCK WHERE _Connect._connect-type = "SQLC":
    DISPLAY _connect._connect-type.
END.  

Best of all would be to do this in a separate environment. If you can't at least try it in a test environment first.

Here's a good guide .

You can use a Select like this:

select
    c."_Connect-type",
    c."_Connect-PID" as 'PID',
    c."_connect-ipaddress" as 'IP',
    c."_Connect-CacheInfo"
from
    pub."_connect" c
where
    c."_Connect-CacheInfo" is not null 

But first you need to enable connection cache, follow this example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM