Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the history of SQL queries

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

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

like image 680
sumit vedi Avatar asked Feb 12 '13 10:02

sumit vedi


People also ask

Can I see historical queries run on a SQL Server database?

Using a modern editor with "find in files" features will let you search your SQL history. You could even get fancy and scrape your files into a SQLite3 database to query your queries. Show activity on this post.

How do I get history of queries executed in Toad?

Toad saves all the work that was done in any of the editor windows. ALT+Up Arrow and Alt+Down Arrow walk through this storage area. Choose View → SQL Recall or press F8 (see Figure 3.26) to open the interface shown in Figure 3.27. Notice that the SQL Recall panel shows up as an autohide panel on the left side of Toad.

What is query history?

The query history shows SQL queries performed using SQL warehouses. You can use the information available through this screen to help you debug issues with queries. This section describes how to work with query history using the UI. To work with query history using the API, see Query History API 2.0.


1 Answers

    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) 

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

like image 167
bonsvr Avatar answered Sep 28 '22 21:09

bonsvr