SQL_ID

Hii,
1. Is the SQL_ID same for a particular query throughout the database?
i.e. Even after shutdown/restart, will the SQL_ID for a particular query be the same always?
2. How do I take the explain plan of a query through TOAD (by passing SQL_ID)? Please let me know the steps!
Thanks!
Edited by: user9104898 on Sep 24, 2010 3:09 AM

As long as i know:
SQl id is presistent as long as the sql is running and after compeleting the query it become a part of history:
You can get the execution plan history for a specific sql_id using the following selects :
To display the explain plan history and the PLAN_HASH_VALUE of each change of the exec plan :
select sql_id, PLAN_HASH_VALUE, to_char(timestamp,'DD-MON-YYYY HH24:MI:SS')
from DBA_HIST_SQL_PLAN where sql_id='705ydchr6zaq4'
To get the actual explain plan mapped to PLAN_HASH_VALUE (each execution plan for the same sql_id has a unique PLAN_HASH_VALUE value , the following select will display each hash value and it is actual execution plan ancluding the access paths and the cost) :
SELECT tf.* FROM DBA_HIST_SQLTEXT ht, table
(DBMS_XPLAN.DISPLAY_AWR(ht.sql_id,null, null, 'ALL' )) tf
WHERE ht.sql_id='705ydchr6zaq4';
i think but i am not sure that each query has a sql_id that doesnot change even after the database restarts.
i wish this helps you.

Similar Messages

  • Why are both SQL_ID and PREV_SQL_ID null?

    session A is blocking session B.
    it was row-level lock.
    But, why are both SQL_ID and PREV_SQL_ID null in session A?

    Well, what do we know?
    Session A must have an uncommitted transaction.
    That uncommitted transaction is blocking session B.
    But session A could well be doing nothing now, could be churning away doing some sort of processing outside of the database (java client you said), might well be off doing something elsewhere in a distributed transaction.
    Who knows?
    Not necessarily the database.
    If you have ASH licensed, you might, might get a better picture of what session A was doing by looking at DBA_HIST_ACTIVE_SESS_HISTORY but as this is sampled data and your statements might fly in and out, it might not be helpful.
    Note that even if prev_sql_id or sql_id were populated, these might not be the statements responsible for the lock.

  • How to get the SQL queries based on SQL_ID.

    Hi Experts,
    I want to get the SQL queries based on SQL_ID.
    I have tried the following query,but I am not getting full query.
    [code]SET linesize 132 pagesize 999
    column sql_fulltext format a60 word_wrap
    break on sql_text skip 1
    SELECT   REPLACE (TRANSLATE (sql_text, '0123456789', '999999999'), '9', ''),sql_id
    FROM   dba_hist_sqltext s
    WHERE   s.sql_id = '7tvurftg8zryb';[/code]
    One of my friend said use grid to get full query text.
    Can you please help me how to use grid ,else any other method to get the full query based on SQL_ID.
    Please help me.
    Thanks in advance.

    You have these many options to set, if sql_text is really huge. But better use a tool(TOAD) as it's really helpful and easy to use instead! (See my previous comment).
    column sql_text format A10000
    set echo off
    set head off
    set feed off
    set verify off
    set termout off
    set lines 10000
    set long 1000000
    set trimspool on
    set pages 0
    Thanks!

  • ORA-13786: missing SQL text of statement object - Unable to profile a sql_id in oracle 11g -

    11.2.0.3.5 / 2 node rac on rhel-6 / 64-bit
    I would like to a profile a sql_id since its following 4 plans and one of them is the optimal.
    But im unable to do it as it throwing ORA-13786.
    Steps I followed :
    {code}
    SET SERVEROUTPUT ON
    -- Tuning task created for specific a statement from the AWR.
    DECLARE
      l_sql_tune_task_id  VARCHAR2(100);
    BEGIN
      l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                              begin_snap  => 29676,
                              end_snap    => 29707,
                              sql_id      => 'fjndcnvzkjkb5',
                              scope       => DBMS_SQLTUNE.scope_comprehensive,
                              time_limit  => 60,
                              task_name   => '420tavt57dxkx_tuning_task',
                              description => 'Tuning task for statement 420tavt57dxkx in AWR.');
      DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
    END;
    EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'fjndcnvzkjkb5_CFO_tuning_task');
    SET LONG 10000;
    SET PAGESIZE 1000
    SET LINESIZE 200
    SELECT DBMS_SQLTUNE.report_tuning_task('420tavt57dxkx_tuning_task') AS recommendations FROM dual;
    SET PAGESIZE 24
    SQL>  execute dbms_sqltune.accept_sql_profile(task_name =>'420tavt57dxkx_tuning_task_task', replace => TRUE,force_match  => TRUE);
    BEGIN dbms_sqltune.accept_sql_profile(task_name =>420tavt57dxkx_tuning_task', replace => TRUE,force_match  => TRUE); END;
    ERROR at line 1:
    ORA-13786: missing SQL text of statement object "1" for tuning task "420tavt57dxkx_tuning_task"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
    ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 16442
    ORA-06512: at "SYS.PRVT_SQLPROF_INFRA", line 31
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 7544
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 7568
    ORA-06512: at line 1
    {code}
    Can somebody help me out on this?

    Hi Experts,
    i too getting this error while attaching the tuning task to the sql profiler, below are the details, appreciate any help on this.
    SQL> SQL> VAR profile_name VARCHAR2(30);
    SQL> BEGIN
       :profile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE(task_name => 'sql_tuning_task');
    END;
    /  2    3    4
    BEGIN
    ERROR at line 1:
    ORA-13786: missing SQL text of statement object "1" for tuning task "sql_tuning_task"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
    ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 16442
    ORA-06512: at "SYS.PRVT_SQLPROF_INFRA", line 31
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 7544
    ORA-06512: at line 2
    SQL> select banner from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

  • SQL_ID row locks

    Hi,
    Every day from 23.00 to 01.00 the performance of the database becomes slow, when i traced i found the following "The SQL statement with SQL_ID "4pgt142s271gy" was blocked on row locks.", which i think is the reason for poor performance and also i found the query with this SQL_ID.
    Dut to this my Application at this time Hangs.
    What should be my next step,i can't change this query because till last week the database was going fine.
    Please advice me ASAP.

    Hi,
    Do these tables involve Workspace Manager? If so, I would need a better understanding of exactly which operations you are performing before commenting on any performance issues.
    Otherwise, I would recommend to use the following forum for general database questions.
    General Database Discussions
    Regards,
    Ben

  • SQL_ID in oracle 10g

    Hi ,
    I have certain doubts regarding the SQL_ID which is introduced since 10g in oracle :
    1) Is SQL_ID unique for every SQL statement? Is it unique across databases? How is the sql_id for a statement decided?
    2) Suppose my Sql statement runs at time A and get sql_id of 'abcd1234' . Again after a few days ( a fortnight for eg ) the same statement (not a single change in my sql statement ) runs on my database at time B,this time however the bounce of the database has been taken. Will the sql_id allotted for the statement this time be 'abcd1234' or some different?
    3) I need this information on sql_id cos the sql adviser has suggested accepting a sql profile for a particular statement. However when i execute the command for accepting the profile,it shows the sql statement does not exist despite the same procedure which has the statement in it being executed very recently.
    Is there any other way i can implement/execute the sql advisor.
    Thanks a ton in advance,
    Regards
    rdxdba

    1) Is SQL_ID unique for every SQL statement? Is it unique across databases? How is the sql_id for a statement decided?SQL_ID is unique for every sql statement in the database and its a representation of the hash_value. Based on the sql statement its hash value is generated.
    2) Suppose my Sql statement runs at time A and get sql_id of 'abcd1234' . Again after a few days ( a fortnight for eg ) the same statement (not a single change in my sql statement ) runs on my database at time B,this time however the bounce of the database has been taken. Will the sql_id allotted for the statement this time be 'abcd1234' or some different?If there is no change in the sql syntax/statement, its the same as it was then sql_id would be the same.
    3) I need this information on sql_id cos the sql adviser has suggested accepting a sql profile for a particular statement. However when i execute the command for accepting the profile,it shows the sql statement does not exist despite the same procedure which has the statement in it being executed very recently.Is there any other way i can implement/execute the sql advisor.What are you running? Copy paste what you are doing to make it easier to understand.
    Anand

  • How to Force the Good Plan present in dba_hist_sql_plan for an SQL_ID

    Hi Folks
    Here i have a question on how to fix the query execution plan for which we are facing the problem. The current execution plan of the SQL ID is bad , but the execution plan in dba_hist_sql_plan or v$sql_plan is showing good one's.
    So how to force the plan_hash_value present in dba_hist_sql_plan or v$sql_plan to the current sql. Where in we cannot try using any kind of hints in the SQL so my question here , is there any way to update manually to update the plan_hash_value for the SQL_ID so that it can use the execution plan which we want to force.
    Regards,
    Phani.

    But my question is i have the good plan for the SQL_ID which is now running with the bad plan ( I am able to see the good plan in dba_hist_sql_plan view ) , my challenge here is how to force >the SQL_ID to take good plan PLAN_SQL_HASH_VALUE. Once the query is parsed and in memory I'm not aware of any way of changing the plan :(
    A day later a similar situation came up with one of our clients. I'm still not aware of any way to manually change the execution plan of an already parsed SQL but suspect histograms and/or bind peeking may be a way to explain this phenemenon
    Edited by: riedelme on Jun 18, 2010 6:13 AM

  • Sql_id of active session not in v$sql

    Hi all,
    How do you explain this?
    There is one active session in v$session with a sql_id. But when I query v$sql using that sql_id I got nothing back. Is this because the sql_id was pushed out of shared memory or some other reason? The connection is shared session.
    Our db is 10.2.0.3 and server is MS window 2003 server.
    Thanks,
    Shirley

    Hi,
    Can you check what is the wait event of that session? Also can you tell me how you decided its active?
    select sql_id, prev_sql_id, last_call_et, status, program, event, sid from v$session where sid = <sid>Regards
    Anurag

  • Sql_id in gv$sort_usage vs gv$session

    I've caught a strange(?) situation here.
    select sql_id from gv$sort_usage where session_addr='000000046A1932F0'; -- gives me 5bqt08ckavskx
    where as
    select sql_id from gv$session where saddr='000000046A1932F0'; -- gives me 1rztpy7a92vpn
    Because of this, I am not able to find the correct query which is consuming lots of temp segments. Well, actually, I am catching up those queries when things are apparent but I am now caught in a situation where two queries are somewhat similar and getting me confused. Why gv$sort_usage and gv$session are giving me different queries and which query is the one that is actually taking the huge temp segments?
    Any help is appreciated.
    Thanks
    gtcol

    You might find useful information in DBA_TEMP_FILES :
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:374218170986#76977305391283 (warning: long thread ;) ,but many alternatives)
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/tspaces.htm#sthref1323
    Also dbms_xplan can be used to show you the estimated temp space needed by a query, using column temp_space from the plan_table:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/ex_plan.htm#g30946

  • SQL Advisor with SQL_ID

    Hi All,
    I want to use SQL Advisor for SQL performance tuning. Here I don't want to create SQL and pass it to DBMS_SQLTUNE.create_tuning_task. I want to pass SQL_ID in this. So whenever I ran my SQL, I want to capture its SQL_ID. How can we get this. I used gv$sql, but it is not showing me my SQL.
    Regards,
    Danish
    Edited by: dbdan on Aug 7, 2009 9:42 AM
    changed view to use

    Hi Anantha,
    Is it not possible to RUN any SQL --> Get its SQL_ID --> Pass it to SQL Advisor? Without creating snapshots or tuning sets.
    regards,
    Danish
    Edited by: dbdan on Aug 10, 2009 12:20 AM

  • How to find aged out sql_id of shared pool / after flushed shared pool in oracle 10g/11g

    i have one sql_id that was not in v$sql / v$sqltext
    when i flushed the shared pool now where can i find old sql_id

    Shared Pool is part of the SGA in Main Memory. So once you flush it the information is gone. You cant get it back.

  • Tune the PL/SQL block with SQL_ID

    Hi There,
    I have found some recommendation in ADDM report as follows.
    "" Action
    Tune the PL/SQL block with SQL_ID "48trcns4mx5bk". Refer to the "Tuning
    PL/SQL Applications" chapter of Oracle's "PL/SQL User's Guide and
    Reference".
    Related Object ""
    can any one let me how to Tune the PL/SQL block with SQL_ID?
    looking forward.
    Db: 11.1.0.7
    OS: OracleLinux5-86*64
    Regards,
    Mohsin

    Hi,
    you can't tune a PL/SQL block directly. Instead, you'll need to profile it first (i.e. see how much time SQL statements inside it consume) using dbms_profiler or some other tool. If you find that the problem is that some SQL is called too frequently because of flawed PL/SQL logic, then you'll need to address that. Otherwise, you'll need to take the top time consuming statement(s) and tune it (them).
    Best regards,
    Nikolay

  • Log file sync waits with null sql_ids

    10.2.0.3
    I am querying V$ACTIVE_SESSION_HISTORY to drill into log file sync waits.
    select sql_id,sum(time_waited)
    from v$active_session_history
    where sample_time > sysdate - 1/24
    group by sql_id
    order by 2 desc
    All of my top sessions for this have null sql_ids. I did some google searches and these are the answers that I found have null sql_ids. There are some other sessions where the sql_id is not null, but they are not anywhere near the top.
    1. could be running pl/sql. yeah ok. but I would need to run 'dml' and issue a commit for this event to fire).
    2. no sql is running. does this mean the insert finished and then I am waiting on the 'commit' part?
    I want to track these sqls down so I can track them back to the application. I want to get the developers to limit their commit frequency and use batch (array based) DML. How do I track this down?
    Also, is there anyway to figure out how often different users are committing? I want to track back to the worst offenders. Could be some parts of the application are commit periodically and others are  not, but log file sync's could slow down everyone.

    You are either bored or suffer from Compulsive Tuning Disorder.
    It can be a challenge to solve  a problem that only exists between your ears
    post results from SQL below
    SELECT sql_id,
           SUM(time_waited) / 1000000
    FROM   v$active_session_history
    WHERE  sample_time > SYSDATE - 1 / 24
           AND time_waited > 0
    GROUP  BY sql_id
    ORDER  BY 2 DESC

  • How to run a SQL manually with the same SQL_ID

    I want to know how to run a SQL which comes from application side manually so that same SQL_ID is generated. I am aware that even if there is a small change in the sql(even a space) the sql_id gets changed. CURSOR_SHARING_PARAMETER is similar in my DB.
    Thanks
    Rudresh

    I think you really want is the execution plan (plan_hash_value), what about outlines ?
    HTH
    Antonio NAVARRO

  • Replace a sql_id with another

    Hi,
    i'm in 11.2 on Linux.
    I've an application that perform some queries with many function.
    For ex:
    select funct(field1,0),
    funct(field2,' '),
    funct(field3,' '),
    funct(field4,0),
    funct(field5,0)
    from ....
    This function is a custom NVL and the performance is poor.
    I cannot change the application and i want to know if i can use, for ex, stored outline to remap this sql_id to another using nvl function.
    Thank you.

    maybe you could use dbms_advanced_rewrite to map your query to another query: http://dioncho.wordpress.com/2009/03/06/optimizing-unoptimizeable-sql-dbms_advanced_rewrite/. But of course this could lead to grieve and sorrow - if the information of the use of this "workaround" is not given to all the people involved...

  • Dynamically apply gather_plan_statistics hint to a sql_id

    Hello,
    We have set statistics_level=typical in our production database. And we do not have GATHER_PLAN_STATISTICS hint in any of our queries either. The reason being it can be performance inhibitor in production.
    Now I want to get ALLSTATS for a particular sql_id that is running in production no matter what session it's in. My question is whether there is any way I can dynamically apply GATHER_PLAN_STATISTICS hint to a specific sql_id just for a few minutes in production and get detailed information for a few executions and then turn it off after a while? It would be tantamount to setting a 10046 trace for a session for a while.
    Does anyone know if and how to do this?
    Also, is there any way to add MONITOR hint to a sql_id in similar fashion?
    Thanks

    Hi,
    sure I can, but it's not suppressing anything:
    SQL> set termout off
    SQL> select 1 from dual connect by level<=50;
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
             1
    50 rows selected.
    SQL>Best regards,
    Nikolay

Maybe you are looking for

  • Trying to set up shared drive

    I am working on a MacBook Pro - connects to a wireless network via airport extreme but can't seem to connect my G4 tower as a shared drive. I have the USB connecting the two but can't locate. Please help....

  • Coloring the Blocks.

    Hi All, I have a query regarding XML Publisher. This is my requirement. Resource | Role | May-2008 | Jun-2008 | July-2008 | --- MON-YYYY 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | --- WEEK Mr.S | Mgr | ████ ██████████ ██ ██ Mr.X | Consultant | ████

  • Advice On Debugging Android Version

    Hello, I have created an app using Flex and Flash builder which runs fine on the iPad. When I test the app on the desktop by targeting it toward an Android tablet, it works fine also. However, when I try and run the app on the Android tablet, it runs

  • HT201177 Macbook Pro is turned on but the screen is black.

    Ok, I have read A LOT of discussions on this issue but it seems like nothing works. I bought my Macbook Pro 13" in September 2012 (so i've had it for a little over a year) in the States. So, I was just using the laptop a couple nights ago, then I clo

  • How to know the active users per HRMS module?

    Dear all, I am looking for a good way to find the number of concurrent active users per HRMS modules like payroll , human resources, etc ... What is the best way to do that calculation? Kindly advice, Thank you and best regards, C.