Skip to Main Content
  • Questions
  • Tuning SQL not in v$sql with sqltrpt.sql

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, oracle.

Asked: August 10, 2016 - 6:25 am UTC

Last updated: August 11, 2016 - 3:25 pm UTC

Version: 11.2.0

Viewed 10K+ times! This question is

You Asked

Hi tom,

I have not very much in performance tuning but due to learn i am taking the performance related query also from user end.

For tuning i have generated awr report and get top 10 queries and take the execution plan of that and generate

@?/rdbms/admin/sqltrpt.sql; --And give that sql_id and get the recommendations but yesterday the end user provide the query like -

UPDATE NVT_VEHICLE set v2=nvl(:"SYS_B_0",v2) where vehicle_no=:"SYS_B_1" and company_id=:"SYS_B_2"

1. Hoq to get recommendations like if i have sql_id then pass in sqltrpt.sql .
2. how can i get sql_id from this sql_text if i will get sql_id then i will generate the same recommendations from sqltrpt.sql.

Because i tried to get sql_id from

select sql_id from v$sqlarea where sql_text like '%UPDATE NVT_VEHICLE set%';

But no rows returned.

Pls help me to findout this.

Thanks

and Chris said...

If the query isn't in v$sql/v$sqlarea then it's no longer cached. If it was captured by AWR, you can find its SQL_ID by querying dba_hist_sqltext:

select sql_id, sql_text from SYS.DBA_HIST_SQLTEXT
where  sql_text like '%UPDATE NVT_VEHICLE set%';


But AWR only captures some statements! So it's possible it isn't there. In which case you're stuck.

If this is a repeated problem you can tell Oracle to "color" the SQL. This ensures it will be in AWR, even if it isn't a "top" statement.

You do this with DBMS_WORKLOAD_REPOSITORY.ADD_COLORED_SQL:

http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_wkrpos.htm#sthref9966

You still need the SQL id to do this though! So you're going to need users to tell you as soon as they have a problem so you can get the id from v$sql. Or run in test so you can capture the SQL_ID there.

Once you've got the SQL_ID you can pass it to the sqltrpt script and let the advisor do its thing.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, August 11, 2016 - 4:18 am UTC

Thanks for reply.

I will do the as you advised and update the same.

Thanks

A reader, August 11, 2016 - 4:18 am UTC

Thanks for reply.

I will do the as you advised and update the same.

Thanks

A reader, August 11, 2016 - 1:58 pm UTC

Hi

A query which is calling by procedure everyday So my question is that the same query have the same sqlid n number of times or it may be change.


Thanks
Chris Saxon
August 11, 2016 - 3:25 pm UTC

The same query will have the same SQL ID.

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.