oracle 找出 SQL 查询的历史记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14830875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:51:23  来源:igfitidea点击:

Find out the history of SQL queries

oraclesql-updatedatabase-administration

提问by sumit vedi

An update SQL query was executed on the server, which caused many problems later.

在服务器上执行了更新SQL查询,导致后来出现很多问题。

How can I get the list of update queries executed in last 2 months, so that I can trace the exact problematic SQL query?

如何获取过去 2 个月内执行的更新查询列表,以便我可以准确跟踪有问题的 SQL 查询?

回答by bonsvr

    select v.SQL_TEXT,
           v.PARSING_SCHEMA_NAME,
           v.FIRST_LOAD_TIME,
           v.DISK_READS,
           v.ROWS_PROCESSED,
           v.ELAPSED_TIME,
           v.service
      from v$sql v
where to_date(v.FIRST_LOAD_TIME,'YYYY-MM-DD hh24:mi:ss')>ADD_MONTHS(trunc(sysdate,'MM'),-2)

whereclause is optional. You can sort the results according to FIRST_LOAD_TIME and find the records up to 2 months ago.

where条款是可选的。您可以根据 FIRST_LOAD_TIME 对结果进行排序,并查找最多 2 个月前的记录。

回答by grokster

For recent SQL:

对于最近的 SQL:

select * from v$sql

For history:

对于历史:

select * from dba_hist_sqltext

回答by Ashish Pandey

You can use this sql statement to get the history for any date:

您可以使用此 sql 语句来获取任何日期的历史记录:

SELECT * FROM V$SQL V where  to_date(v.FIRST_LOAD_TIME,'YYYY-MM-DD hh24:mi:ss') > sysdate - 60