How to check Oracle database for long running queries

前端 未结 8 1788
半阙折子戏
半阙折子戏 2020-12-02 04:03

My application, which uses an Oracle database, is going slow or appears to have stopped completely.

How can find out which queries are most expensive, so I can inves

8条回答
  •  长情又很酷
    2020-12-02 04:30

    You can use the v$sql_monitor view to find queries that are running longer than 5 seconds. This may only be available in Enterprise versions of Oracle. For example this query will identify slow running queries from my TEST_APP service:

    select to_char(sql_exec_start, 'dd-Mon hh24:mi'), (elapsed_time / 1000000) run_time,
           cpu_time, sql_id, sql_text 
    from   v$sql_monitor
    where  service_name = 'TEST_APP'
    order  by 1 desc;
    

    Note elapsed_time is in microseconds so / 1000000 to get something more readable

提交回复
热议问题