Query is running slow for long time for SQL_ID captured
Run SQL Tuning Adviosor for the sql_id
--------------------------------------
Statement with SQL_ID captured is taking long time, we need to set best Execution Plan for the SQL_ID.
So, we need to submit to Oracle Tuning Advisor(sqltrpt.sql) and then check the FINDINGS SECTION for Findings and Recommendations for the SQL_ID.Recommendations from sqltrpt.sql will be providing the best Explain Plan. We can implement these profiles/index rebuild/... suggested after checking with the SME of the database.
Location: $ORACLE_HOME/rdbms/admin/sqltrpt.sql
$sqlplus "/as sysdba"
Query to see current running sqls
set pages 50000 lines 32767
col program format a40
col sql_text format a130
select b.sid,b.status,b.last_call_et,b.program,c.sql_id,c.sql_text from v$session b,v$sqlarea c
where b.sql_id=c.sql_id
/
Run SQL Tuning Advisor for the SQL_ID
SQL> @?/rdbms/admin/sqltrpt.sql
In case the recommendation is for creation of SQL PROFILE, sqltrpt.sql will provide the command too as below.
Command to Create and Implement SQL Profile in Oracle for the SQL_ID:
--------------------------------------------------------------------
SQL> execute dbms_sqltune.accept_sql_profile(task_name => '<TASK_NAME>',task_owner => 'SYS', replace => TRUE, FORCE_MATCH => TRUE);
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created, LAST_MODIFIED FROM dba_sql_profiles ORDER BY created DESC;
Command to Drop SQL Profile in Oracle for the SQL_ID:
----------------------------------------------------
SQL> execute dbms_sqltune.drop_sql_profile('<SQL_PROFILE_NAME>');
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created FROM dba_sql_profiles ORDER BY created DESC;
Command to Alter SQL Profile in Oracle for the SQL_ID:
-----------------------------------------------------
SQL> EXEC DBMS_SQLTUNE.ALTER_SQL_PROFILE('<SQL_PROFILE_NAME>','STATUS','DISABLED');
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created FROM dba_sql_profiles ORDER BY created DESC;
If you don't know the name of the SQL Profile then use the below query
SQL> select NAME,SQL_TEXT from DBA_SQL_PROFILES where SQL_TEXT like '%SELECT%TABLE%NAME%';
Query
-----
The SQL_ID is not stored with the profiles.
You can see if a statement is using a profile by querying v$sql where sql_profile is not null.
select sql_id, child_number, plan_hash_value plan_hash, sql_profile,
executions execs,
(elapsed_time/1000000)/decode(nvl(executions,0),0,1,executions) avg_etime,
buffer_gets/decode(nvl(executions,0),0,1,executions) avg_lio,
sql_text
from v$sql s
where upper(sql_text) like upper(nvl('&sql_text',sql_text))
and sql_text not like '%from v$sql where sql_text like nvl(%'
and sql_id like nvl('&sql_id',sql_id)
and sql_profile like nvl('&sql_profile_name',sql_profile)
and sql_profile is not null
order by 1, 2, 3
/
For More:-
--------
Migrate Oracle SQL Profile
http://www.allguru.net/database/migrate-oracle-sql-profile/
Swapping SQL Profiles
http://www.dba-oracle.com/t_swapping_sql_profiles.htm
Tuning queries with SQL Tuning Advisor and SQL Profiles
http://troubleshooot.wordpress.com/2011/01/14/43/
Run SQL Tuning Adviosor for the sql_id
--------------------------------------
Statement with SQL_ID captured is taking long time, we need to set best Execution Plan for the SQL_ID.
So, we need to submit to Oracle Tuning Advisor(sqltrpt.sql) and then check the FINDINGS SECTION for Findings and Recommendations for the SQL_ID.Recommendations from sqltrpt.sql will be providing the best Explain Plan. We can implement these profiles/index rebuild/... suggested after checking with the SME of the database.
Location: $ORACLE_HOME/rdbms/admin/sqltrpt.sql
$sqlplus "/as sysdba"
Query to see current running sqls
set pages 50000 lines 32767
col program format a40
col sql_text format a130
select b.sid,b.status,b.last_call_et,b.program,c.sql_id,c.sql_text from v$session b,v$sqlarea c
where b.sql_id=c.sql_id
/
Run SQL Tuning Advisor for the SQL_ID
SQL> @?/rdbms/admin/sqltrpt.sql
In case the recommendation is for creation of SQL PROFILE, sqltrpt.sql will provide the command too as below.
Command to Create and Implement SQL Profile in Oracle for the SQL_ID:
--------------------------------------------------------------------
SQL> execute dbms_sqltune.accept_sql_profile(task_name => '<TASK_NAME>',task_owner => 'SYS', replace => TRUE, FORCE_MATCH => TRUE);
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created, LAST_MODIFIED FROM dba_sql_profiles ORDER BY created DESC;
Command to Drop SQL Profile in Oracle for the SQL_ID:
----------------------------------------------------
SQL> execute dbms_sqltune.drop_sql_profile('<SQL_PROFILE_NAME>');
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created FROM dba_sql_profiles ORDER BY created DESC;
Command to Alter SQL Profile in Oracle for the SQL_ID:
-----------------------------------------------------
SQL> EXEC DBMS_SQLTUNE.ALTER_SQL_PROFILE('<SQL_PROFILE_NAME>','STATUS','DISABLED');
If successful, you should see the following:
PL/SQL procedure successfully completed.
SQL> SELECT name, created FROM dba_sql_profiles ORDER BY created DESC;
If you don't know the name of the SQL Profile then use the below query
SQL> select NAME,SQL_TEXT from DBA_SQL_PROFILES where SQL_TEXT like '%SELECT%TABLE%NAME%';
Query
-----
The SQL_ID is not stored with the profiles.
You can see if a statement is using a profile by querying v$sql where sql_profile is not null.
select sql_id, child_number, plan_hash_value plan_hash, sql_profile,
executions execs,
(elapsed_time/1000000)/decode(nvl(executions,0),0,1,executions) avg_etime,
buffer_gets/decode(nvl(executions,0),0,1,executions) avg_lio,
sql_text
from v$sql s
where upper(sql_text) like upper(nvl('&sql_text',sql_text))
and sql_text not like '%from v$sql where sql_text like nvl(%'
and sql_id like nvl('&sql_id',sql_id)
and sql_profile like nvl('&sql_profile_name',sql_profile)
and sql_profile is not null
order by 1, 2, 3
/
For More:-
--------
Migrate Oracle SQL Profile
http://www.allguru.net/database/migrate-oracle-sql-profile/
Swapping SQL Profiles
http://www.dba-oracle.com/t_swapping_sql_profiles.htm
Tuning queries with SQL Tuning Advisor and SQL Profiles
http://troubleshooot.wordpress.com/2011/01/14/43/
No comments:
Post a Comment