2026-07-11 16:10:12
This commit is contained in:
@@ -0,0 +1,131 @@
|
|||||||
|
-- ============================================================================
|
||||||
|
-- awrsqlidtabstat2.sql
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
-- Reference:
|
||||||
|
-- https://blogs.oracle.com/optimizer/post/check-sql-stale-statistics
|
||||||
|
-- Updated in 2026 july from Grand Canaria ;)
|
||||||
|
-- ============================================================================
|
||||||
|
|
||||||
|
SET PAGESIZE 100
|
||||||
|
SET LINESIZE 150
|
||||||
|
SET TRIMS OFF
|
||||||
|
SET TAB OFF
|
||||||
|
SET VERIFY OFF
|
||||||
|
|
||||||
|
COLUMN table_name FORMAT a25
|
||||||
|
COLUMN index_name FORMAT a25
|
||||||
|
COLUMN object_type FORMAT a20
|
||||||
|
COLUMN owner FORMAT a25
|
||||||
|
COLUMN object_owner FORMAT a25
|
||||||
|
COLUMN object_name FORMAT a25
|
||||||
|
COLUMN stale_stats FORMAT a30
|
||||||
|
COLUMN num_rows FORMAT 999,999,999,999
|
||||||
|
COLUMN visibility FORMAT a9
|
||||||
|
COLUMN status FORMAT a8
|
||||||
|
|
||||||
|
PROMPT
|
||||||
|
PROMPT ==================================
|
||||||
|
PROMPT Tables with Statistics Information
|
||||||
|
PROMPT ==================================
|
||||||
|
PROMPT
|
||||||
|
|
||||||
|
WITH plan_tables AS (
|
||||||
|
SELECT DISTINCT
|
||||||
|
object_name,
|
||||||
|
object_owner,
|
||||||
|
object_type
|
||||||
|
FROM dba_hist_sql_plan
|
||||||
|
WHERE object_type LIKE 'TABLE%'
|
||||||
|
AND sql_id = '&1'
|
||||||
|
AND plan_hash_value = '&2'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
t.object_owner AS owner,
|
||||||
|
t.object_name AS table_name,
|
||||||
|
t.object_type AS object_type,
|
||||||
|
tab.num_rows,
|
||||||
|
DECODE(
|
||||||
|
stale_stats,
|
||||||
|
'NO', 'OK',
|
||||||
|
NULL, 'NO STATS!',
|
||||||
|
'STALE!'
|
||||||
|
) AS staleness
|
||||||
|
FROM dba_tab_statistics s
|
||||||
|
JOIN plan_tables t
|
||||||
|
ON s.table_name = t.object_name
|
||||||
|
AND s.owner = t.object_owner
|
||||||
|
JOIN dba_tables tab
|
||||||
|
ON t.object_owner = tab.owner
|
||||||
|
AND t.object_name = tab.table_name
|
||||||
|
WHERE s.partition_name IS NULL
|
||||||
|
AND s.subpartition_name IS NULL
|
||||||
|
ORDER BY t.object_owner, t.object_name;
|
||||||
|
|
||||||
|
|
||||||
|
PROMPT
|
||||||
|
PROMPT ===================================
|
||||||
|
PROMPT Indexes with Statistics Information
|
||||||
|
PROMPT ===================================
|
||||||
|
PROMPT
|
||||||
|
|
||||||
|
WITH plan_indexes AS (
|
||||||
|
SELECT DISTINCT
|
||||||
|
object_name,
|
||||||
|
object_owner,
|
||||||
|
object_type
|
||||||
|
FROM dba_hist_sql_plan
|
||||||
|
WHERE object_type LIKE 'INDEX%'
|
||||||
|
AND sql_id = '&1'
|
||||||
|
AND plan_hash_value = '&2'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
i.object_owner AS owner,
|
||||||
|
i.object_name AS index_name,
|
||||||
|
i.object_type AS object_type,
|
||||||
|
idx.status,
|
||||||
|
idx.num_rows,
|
||||||
|
idx.visibility,
|
||||||
|
DECODE(
|
||||||
|
stale_stats,
|
||||||
|
'NO', 'OK',
|
||||||
|
NULL, 'NO STATS',
|
||||||
|
'STALE!'
|
||||||
|
) AS staleness
|
||||||
|
FROM dba_ind_statistics s
|
||||||
|
JOIN plan_indexes i
|
||||||
|
ON s.index_name = i.object_name
|
||||||
|
AND s.owner = i.object_owner
|
||||||
|
JOIN dba_indexes idx
|
||||||
|
ON s.owner = idx.owner
|
||||||
|
AND s.index_name = idx.index_name
|
||||||
|
WHERE s.partition_name IS NULL
|
||||||
|
AND s.subpartition_name IS NULL
|
||||||
|
ORDER BY i.object_owner, i.object_name;
|
||||||
|
|
||||||
|
|
||||||
|
PROMPT
|
||||||
|
PROMPT ===============
|
||||||
|
PROMPT Missing Indexes
|
||||||
|
PROMPT ===============
|
||||||
|
PROMPT
|
||||||
|
|
||||||
|
WITH plan_indexes AS (
|
||||||
|
SELECT DISTINCT
|
||||||
|
object_name,
|
||||||
|
object_owner,
|
||||||
|
object_type
|
||||||
|
FROM dba_hist_sql_plan
|
||||||
|
WHERE object_type LIKE 'INDEX%'
|
||||||
|
AND sql_id = '&1'
|
||||||
|
AND plan_hash_value = '&2'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
object_owner,
|
||||||
|
object_name
|
||||||
|
FROM plan_indexes
|
||||||
|
WHERE object_type = 'INDEX'
|
||||||
|
MINUS
|
||||||
|
SELECT
|
||||||
|
owner,
|
||||||
|
index_name
|
||||||
|
FROM dba_indexes;
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
SQL>SET SERVEROUT ON SIZE UNL;
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM $Header: coe_xfr_sql_profile.sql 2020/03/10 carlos.sierra $
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM AUTHOR
|
||||||
|
SQL>REM Carlos Sierra
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM SCRIPT
|
||||||
|
SQL>REM coe_xfr_sql_profile.sql
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM DESCRIPTION
|
||||||
|
SQL>REM This script generates another that contains the commands to
|
||||||
|
SQL>REM create a manual custom SQL Profile out of a known plan from
|
||||||
|
SQL>REM memory or AWR. The manual custom profile can be implemented
|
||||||
|
SQL>REM into the same SOURCE system where the plan was retrieved,
|
||||||
|
SQL>REM or into another similar TARGET system that has same schema
|
||||||
|
SQL>REM objects referenced by the SQL that generated the known plan.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM PRE-REQUISITES
|
||||||
|
SQL>REM 1. Oracle Tuning Pack license.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM PARAMETERS
|
||||||
|
SQL>REM 1. SQL_ID (required)
|
||||||
|
SQL>REM 2. Plan Hash Value for which a manual custom SQL Profile is
|
||||||
|
SQL>REM needed (required). A list of known plans is presented.
|
||||||
|
SQL>REM You may choose from list provided or enter a valid phv
|
||||||
|
SQL>REM from a version of the SQL modified with Hints.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM EXECUTION
|
||||||
|
SQL>REM 1. Connect into SQL*Plus as user with access to data dictionary.
|
||||||
|
SQL>REM Do not use SYS.
|
||||||
|
SQL>REM 2. Execute script coe_xfr_sql_profile.sql passing SQL_ID and
|
||||||
|
SQL>REM plan hash value (parameters can be passed inline or until
|
||||||
|
SQL>REM requested).
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM EXAMPLE
|
||||||
|
SQL>REM # sqlplus system
|
||||||
|
SQL>REM SQL> START coe_xfr_sql_profile.sql [SQL_ID] [PLAN_HASH_VALUE];
|
||||||
|
SQL>REM SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm 2055843663;
|
||||||
|
SQL>REM SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm;
|
||||||
|
SQL>REM SQL> START coe_xfr_sql_profile.sql;
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM NOTES
|
||||||
|
SQL>REM 1. For possible errors see coe_xfr_sql_profile.log
|
||||||
|
SQL>REM 2. If SQLT is installed in SOURCE, you can use instead:
|
||||||
|
SQL>REM sqlt/utl/sqltprofile.sql
|
||||||
|
SQL>REM 3. Be aware that using DBMS_SQLTUNE requires a license for
|
||||||
|
SQL>REM Oracle Tuning Pack.
|
||||||
|
SQL>REM 4. Use a DBA user but not SYS.
|
||||||
|
SQL>REM 5. If you get "ORA-06532: Subscript outside of limit, ORA-06512: at line 1"
|
||||||
|
SQL>REM Then you may consider this change (only in a test and disposable system):
|
||||||
|
SQL>REM create or replace TYPE sys.sqlprof_attr AS VARRAY(5000) of VARCHAR2(500);
|
||||||
|
SQL>REM
|
||||||
|
SQL>SET TERM ON ECHO OFF;
|
||||||
|
|
||||||
|
Parameter 1:
|
||||||
|
SQL_ID (required)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AVG_ET_SECS_MEM AVG_ET_SECS_AWR PLAN_HASH_VALUE EXECUTIONS_MEM EXECUTIONS_AWR
|
||||||
|
--------------- --------------- --------------- -------------- --------------
|
||||||
|
0.001152 0.001152 1509575125 2 2
|
||||||
|
|
||||||
|
Parameter 2:
|
||||||
|
PLAN_HASH_VALUE (required)
|
||||||
|
|
||||||
|
|
||||||
|
Values passed to coe_xfr_sql_profile:
|
||||||
|
SQL_ID : "9t7jvx0gm0m95"
|
||||||
|
PLAN_HASH_VALUE: "1509575125"
|
||||||
|
|
||||||
|
SQL>WHENEVER SQLERROR EXIT SQL.SQLCODE;
|
||||||
|
SQL>
|
||||||
|
SQL>-- trim parameters
|
||||||
|
SQL>COL sql_id NEW_V sql_id FOR A30;
|
||||||
|
SQL>COL plan_hash_value NEW_V plan_hash_value FOR A30;
|
||||||
|
SQL>SELECT TRIM('&&sql_id.') sql_id, TRIM('&&plan_hash_value.') plan_hash_value FROM DUAL;
|
||||||
|
|
||||||
|
SQL_ID PLAN_HASH_VALUE
|
||||||
|
------------------------------ ------------------------------
|
||||||
|
9t7jvx0gm0m95 1509575125
|
||||||
|
SQL>
|
||||||
|
SQL>VAR sql_text CLOB;
|
||||||
|
SQL>VAR sql_text2 CLOB;
|
||||||
|
SQL>VAR other_xml CLOB;
|
||||||
|
SQL>EXEC :sql_text := NULL;
|
||||||
|
SQL>EXEC :sql_text2 := NULL;
|
||||||
|
SQL>EXEC :other_xml := NULL;
|
||||||
|
SQL>
|
||||||
|
SQL>-- get sql_text from memory
|
||||||
|
SQL>DECLARE
|
||||||
|
2 l_sql_text VARCHAR2(32767);
|
||||||
|
3 BEGIN -- 10g see bug 5017909
|
||||||
|
4 FOR i IN (SELECT DISTINCT piece, sql_text
|
||||||
|
5 FROM gv$sqltext_with_newlines
|
||||||
|
6 WHERE sql_id = TRIM('&&sql_id.')
|
||||||
|
7 ORDER BY 1, 2)
|
||||||
|
8 LOOP
|
||||||
|
9 IF :sql_text IS NULL THEN
|
||||||
|
10 DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
|
||||||
|
11 DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
|
||||||
|
12 END IF;
|
||||||
|
13 -- removes NUL characters
|
||||||
|
14 l_sql_text := REPLACE(i.sql_text, CHR(00), ' ');
|
||||||
|
15 -- adds a NUL character at the end of each line
|
||||||
|
16 DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
|
||||||
|
17 END LOOP;
|
||||||
|
18 -- if found in memory then sql_text is not null
|
||||||
|
19 IF :sql_text IS NOT NULL THEN
|
||||||
|
20 DBMS_LOB.CLOSE(:sql_text);
|
||||||
|
21 END IF;
|
||||||
|
22 EXCEPTION
|
||||||
|
23 WHEN OTHERS THEN
|
||||||
|
24 DBMS_OUTPUT.PUT_LINE('getting sql_text from memory: '||SQLERRM);
|
||||||
|
25 :sql_text := NULL;
|
||||||
|
26 END;
|
||||||
|
27 /
|
||||||
|
SQL>
|
||||||
|
SQL>SELECT :sql_text FROM DUAL;
|
||||||
|
|
||||||
|
:SQL_TEXT
|
||||||
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
select * from t1 where i=5000
|
||||||
|
SQL>
|
||||||
|
SQL>-- get sql_text from awr
|
||||||
|
SQL>DECLARE
|
||||||
|
2 l_sql_text VARCHAR2(32767);
|
||||||
|
3 l_clob_size NUMBER;
|
||||||
|
4 l_offset NUMBER;
|
||||||
|
5 BEGIN
|
||||||
|
6 IF :sql_text IS NULL OR NVL(DBMS_LOB.GETLENGTH(:sql_text), 0) = 0 THEN
|
||||||
|
7 SELECT sql_text
|
||||||
|
8 INTO :sql_text2
|
||||||
|
9 FROM dba_hist_sqltext
|
||||||
|
10 WHERE sql_id = TRIM('&&sql_id.')
|
||||||
|
11 AND sql_text IS NOT NULL
|
||||||
|
12 AND ROWNUM = 1;
|
||||||
|
13 END IF;
|
||||||
|
14 -- if found in awr then sql_text2 is not null
|
||||||
|
15 IF :sql_text2 IS NOT NULL THEN
|
||||||
|
16 l_clob_size := NVL(DBMS_LOB.GETLENGTH(:sql_text2), 0);
|
||||||
|
17 l_offset := 1;
|
||||||
|
18 DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
|
||||||
|
19 DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
|
||||||
|
20 -- store in clob as 64 character pieces plus a NUL character at the end of each piece
|
||||||
|
21 WHILE l_offset < l_clob_size
|
||||||
|
22 LOOP
|
||||||
|
23 IF l_clob_size - l_offset > 64 THEN
|
||||||
|
24 l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, 64, l_offset), CHR(00), ' ');
|
||||||
|
25 ELSE -- last piece
|
||||||
|
26 l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, l_clob_size - l_offset + 1, l_offset), CHR(00), ' ');
|
||||||
|
27 END IF;
|
||||||
|
28 DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
|
||||||
|
29 l_offset := l_offset + 64;
|
||||||
|
30 END LOOP;
|
||||||
|
31 DBMS_LOB.CLOSE(:sql_text);
|
||||||
|
32 END IF;
|
||||||
|
33 EXCEPTION
|
||||||
|
34 WHEN OTHERS THEN
|
||||||
|
35 DBMS_OUTPUT.PUT_LINE('getting sql_text from awr: '||SQLERRM);
|
||||||
|
36 :sql_text := NULL;
|
||||||
|
37 END;
|
||||||
|
38 /
|
||||||
|
SQL>
|
||||||
|
SQL>SELECT :sql_text2 FROM DUAL;
|
||||||
|
|
||||||
|
:SQL_TEXT2
|
||||||
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
SQL>SELECT :sql_text FROM DUAL;
|
||||||
|
|
||||||
|
:SQL_TEXT
|
||||||
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
select * from t1 where i=5000
|
||||||
|
SQL>
|
||||||
|
SQL>-- validate sql_text
|
||||||
|
SQL>SET TERM ON;
|
||||||
|
SQL>BEGIN
|
||||||
|
2 IF :sql_text IS NULL THEN
|
||||||
|
3 RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
|
||||||
|
4 END IF;
|
||||||
|
5 END;
|
||||||
|
6 /
|
||||||
|
SQL>SET TERM OFF;
|
||||||
|
SQL>
|
||||||
|
SQL>-- get other_xml from memory
|
||||||
|
SQL>BEGIN
|
||||||
|
2 FOR i IN (SELECT other_xml
|
||||||
|
3 FROM gv$sql_plan
|
||||||
|
4 WHERE sql_id = TRIM('&&sql_id.')
|
||||||
|
5 AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
6 AND other_xml IS NOT NULL
|
||||||
|
7 ORDER BY
|
||||||
|
8 child_number, id)
|
||||||
|
9 LOOP
|
||||||
|
10 :other_xml := i.other_xml;
|
||||||
|
11 EXIT; -- 1st
|
||||||
|
12 END LOOP;
|
||||||
|
13 EXCEPTION
|
||||||
|
14 WHEN OTHERS THEN
|
||||||
|
15 DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
|
||||||
|
16 :other_xml := NULL;
|
||||||
|
17 END;
|
||||||
|
18 /
|
||||||
|
SQL>
|
||||||
|
SQL>-- get other_xml from awr
|
||||||
|
SQL>BEGIN
|
||||||
|
2 IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||||
|
3 FOR i IN (SELECT other_xml
|
||||||
|
4 FROM dba_hist_sql_plan
|
||||||
|
5 WHERE sql_id = TRIM('&&sql_id.')
|
||||||
|
6 AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
7 AND dbid = (SELECT dbid FROM v$database)
|
||||||
|
8 AND other_xml IS NOT NULL
|
||||||
|
9 ORDER BY
|
||||||
|
10 id)
|
||||||
|
11 LOOP
|
||||||
|
12 :other_xml := i.other_xml;
|
||||||
|
13 EXIT; -- 1st
|
||||||
|
14 END LOOP;
|
||||||
|
15 END IF;
|
||||||
|
16 EXCEPTION
|
||||||
|
17 WHEN OTHERS THEN
|
||||||
|
18 DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
|
||||||
|
19 :other_xml := NULL;
|
||||||
|
20 END;
|
||||||
|
21 /
|
||||||
|
SQL>
|
||||||
|
SQL>-- get other_xml from memory from modified SQL
|
||||||
|
SQL>BEGIN
|
||||||
|
2 IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||||
|
3 FOR i IN (SELECT other_xml
|
||||||
|
4 FROM gv$sql_plan
|
||||||
|
5 WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
6 --WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
7 AND other_xml IS NOT NULL
|
||||||
|
8 ORDER BY
|
||||||
|
9 child_number, id)
|
||||||
|
10 LOOP
|
||||||
|
11 :other_xml := i.other_xml;
|
||||||
|
12 EXIT; -- 1st
|
||||||
|
13 END LOOP;
|
||||||
|
14 END IF;
|
||||||
|
15 EXCEPTION
|
||||||
|
16 WHEN OTHERS THEN
|
||||||
|
17 DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
|
||||||
|
18 :other_xml := NULL;
|
||||||
|
19 END;
|
||||||
|
20 /
|
||||||
|
SQL>
|
||||||
|
SQL>-- get other_xml from awr from modified SQL
|
||||||
|
SQL>BEGIN
|
||||||
|
2 IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||||
|
3 FOR i IN (SELECT other_xml
|
||||||
|
4 FROM dba_hist_sql_plan
|
||||||
|
5 WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
6 --WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||||
|
7 AND dbid = (SELECT dbid FROM v$database)
|
||||||
|
8 AND other_xml IS NOT NULL
|
||||||
|
9 ORDER BY
|
||||||
|
10 id)
|
||||||
|
11 LOOP
|
||||||
|
12 :other_xml := i.other_xml;
|
||||||
|
13 EXIT; -- 1st
|
||||||
|
14 END LOOP;
|
||||||
|
15 END IF;
|
||||||
|
16 EXCEPTION
|
||||||
|
17 WHEN OTHERS THEN
|
||||||
|
18 DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
|
||||||
|
19 :other_xml := NULL;
|
||||||
|
20 END;
|
||||||
|
21 /
|
||||||
|
SQL>
|
||||||
|
SQL>SELECT :other_xml FROM DUAL;
|
||||||
|
|
||||||
|
:OTHER_XML
|
||||||
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
<other_xml><info type="has_user_tab">yes</info><info type="db_version">19.0.0.0</info><info type="parse_schema"><![CDATA["ADMINPDB"]]></info><info type="plan_hash_full">1975401683</info><info type="plan_hash">1509575125</info><info type="plan_hash_2">1975401683</info><stats type="compilation"><stat name="bg">0</stat></stats><qb_registry><q o="2" f="y"><n><![CDATA[SEL$1]]></n><f><h><t><![CDATA[T1]]></t><s><![CDATA[SEL$1]]></s></h></f></q></qb_registry><outline_data><hint><![CDATA[IGNORE_OPTIM_EMBEDDED_HINTS]]></hint><hint><![CDATA[OPTIMIZER_FEATURES_ENABLE('19.1.0')]]></hint><hint><![CDATA[DB_VERSION('19.1.0')]]></hint><hint><![CDATA[ALL_ROWS]]></hint><hint><![CDATA[OUTLINE_LEAF(@"SEL$1")]]></hint><hint><![CDATA[INDEX_RS_ASC(@"SEL$1" "T1"@"SEL$1" ("T1"."I"))]]></hint><hint><![CDATA[BATCH_TABLE_ACCESS_BY_ROWID(@"SEL$1" "T1"@"SEL$1")]]></hint></outline_data></other_xml>
|
||||||
|
SQL>
|
||||||
|
SQL>-- validate other_xml
|
||||||
|
SQL>SET TERM ON;
|
||||||
|
SQL>BEGIN
|
||||||
|
2 IF :other_xml IS NULL THEN
|
||||||
|
3 RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
|
||||||
|
4 END IF;
|
||||||
|
5 END;
|
||||||
|
6 /
|
||||||
|
SQL>SET TERM OFF;
|
||||||
|
SQL>
|
||||||
|
SQL>-- generates script that creates sql profile in target system:
|
||||||
|
SQL>SET ECHO OFF;
|
||||||
|
coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql.
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
SQL>REM
|
||||||
|
SQL>REM $Header: 215187.1 coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql 11.4.4.4 2026/07/08 carlos.sierra $
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM AUTHOR
|
||||||
|
SQL>REM carlos.sierra@oracle.com
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM SCRIPT
|
||||||
|
SQL>REM coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM DESCRIPTION
|
||||||
|
SQL>REM This script is generated by coe_xfr_sql_profile.sql
|
||||||
|
SQL>REM It contains the SQL*Plus commands to create a custom
|
||||||
|
SQL>REM SQL Profile for SQL_ID 9t7jvx0gm0m95 based on plan hash
|
||||||
|
SQL>REM value 1509575125.
|
||||||
|
SQL>REM The custom SQL Profile to be created by this script
|
||||||
|
SQL>REM will affect plans for SQL commands with signature
|
||||||
|
SQL>REM matching the one for SQL Text below.
|
||||||
|
SQL>REM Review SQL Text and adjust accordingly.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM PARAMETERS
|
||||||
|
SQL>REM None.
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM EXAMPLE
|
||||||
|
SQL>REM SQL> START coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql;
|
||||||
|
SQL>REM
|
||||||
|
SQL>REM NOTES
|
||||||
|
SQL>REM 1. Should be run as SYSTEM or SYSDBA.
|
||||||
|
SQL>REM 2. User must have CREATE ANY SQL PROFILE privilege.
|
||||||
|
SQL>REM 3. SOURCE and TARGET systems can be the same or similar.
|
||||||
|
SQL>REM 4. To drop this custom SQL Profile after it has been created:
|
||||||
|
SQL>REM EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_9t7jvx0gm0m95_1509575125');
|
||||||
|
SQL>REM 5. Be aware that using DBMS_SQLTUNE requires a license
|
||||||
|
SQL>REM for the Oracle Tuning Pack.
|
||||||
|
SQL>REM 6. If you modified a SQL putting Hints in order to produce a desired
|
||||||
|
SQL>REM Plan, you can remove the artifical Hints from SQL Text pieces below.
|
||||||
|
SQL>REM By doing so you can create a custom SQL Profile for the original
|
||||||
|
SQL>REM SQL but with the Plan captured from the modified SQL (with Hints).
|
||||||
|
SQL>REM
|
||||||
|
SQL>WHENEVER SQLERROR EXIT SQL.SQLCODE;
|
||||||
|
SQL>REM
|
||||||
|
SQL>VAR signature NUMBER;
|
||||||
|
SQL>VAR signaturef NUMBER;
|
||||||
|
SQL>REM
|
||||||
|
SQL>DECLARE
|
||||||
|
2 sql_txt CLOB;
|
||||||
|
3 h SYS.SQLPROF_ATTR;
|
||||||
|
4 PROCEDURE wa (p_line IN VARCHAR2) IS
|
||||||
|
5 BEGIN
|
||||||
|
6 DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
|
||||||
|
7 END wa;
|
||||||
|
8 BEGIN
|
||||||
|
9 DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
|
||||||
|
10 DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
|
||||||
|
11 -- SQL Text pieces below do not have to be of same length.
|
||||||
|
12 -- So if you edit SQL Text (i.e. removing temporary Hints),
|
||||||
|
13 -- there is no need to edit or re-align unmodified pieces.
|
||||||
|
14 wa(q'[select * from t1 where i=5000]');
|
||||||
|
15 DBMS_LOB.CLOSE(sql_txt);
|
||||||
|
16 h := SYS.SQLPROF_ATTR(
|
||||||
|
17 q'[BEGIN_OUTLINE_DATA]',
|
||||||
|
18 q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
|
||||||
|
19 q'[OPTIMIZER_FEATURES_ENABLE('19.1.0')]',
|
||||||
|
20 q'[DB_VERSION('19.1.0')]',
|
||||||
|
21 q'[ALL_ROWS]',
|
||||||
|
22 q'[OUTLINE_LEAF(@"SEL$1")]',
|
||||||
|
23 q'[INDEX_RS_ASC(@"SEL$1" "T1"@"SEL$1" ("T1"."I"))]',
|
||||||
|
24 q'[BATCH_TABLE_ACCESS_BY_ROWID(@"SEL$1" "T1"@"SEL$1")]',
|
||||||
|
25 q'[END_OUTLINE_DATA]');
|
||||||
|
26 :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
|
||||||
|
27 :signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
|
||||||
|
28 DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
|
||||||
|
29 sql_text => sql_txt,
|
||||||
|
30 profile => h,
|
||||||
|
31 name => 'coe_9t7jvx0gm0m95_1509575125',
|
||||||
|
32 description => 'coe 9t7jvx0gm0m95 1509575125 '||:signature||' '||:signaturef||'',
|
||||||
|
33 category => 'DEFAULT',
|
||||||
|
34 validate => TRUE,
|
||||||
|
35 replace => TRUE,
|
||||||
|
36 force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
|
||||||
|
37 DBMS_LOB.FREETEMPORARY(sql_txt);
|
||||||
|
38 END;
|
||||||
|
39 /
|
||||||
|
|
||||||
|
PL/SQL procedure successfully completed.
|
||||||
|
|
||||||
|
SQL>WHENEVER SQLERROR CONTINUE
|
||||||
|
SQL>SET ECHO OFF;
|
||||||
|
|
||||||
|
SIGNATURE
|
||||||
|
---------------------
|
||||||
|
7022249984800062696
|
||||||
|
|
||||||
|
|
||||||
|
SIGNATUREF
|
||||||
|
---------------------
|
||||||
|
17325452017562678592
|
||||||
|
|
||||||
|
|
||||||
|
... manual custom SQL Profile has been created
|
||||||
|
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
SPO coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.log;
|
||||||
|
SET ECHO ON TERM ON LIN 2000 TRIMS ON NUMF 99999999999999999999;
|
||||||
|
REM
|
||||||
|
REM $Header: 215187.1 coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql 11.4.4.4 2026/07/08 carlos.sierra $
|
||||||
|
REM
|
||||||
|
REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
|
||||||
|
REM
|
||||||
|
REM AUTHOR
|
||||||
|
REM carlos.sierra@oracle.com
|
||||||
|
REM
|
||||||
|
REM SCRIPT
|
||||||
|
REM coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql
|
||||||
|
REM
|
||||||
|
REM DESCRIPTION
|
||||||
|
REM This script is generated by coe_xfr_sql_profile.sql
|
||||||
|
REM It contains the SQL*Plus commands to create a custom
|
||||||
|
REM SQL Profile for SQL_ID 9t7jvx0gm0m95 based on plan hash
|
||||||
|
REM value 1509575125.
|
||||||
|
REM The custom SQL Profile to be created by this script
|
||||||
|
REM will affect plans for SQL commands with signature
|
||||||
|
REM matching the one for SQL Text below.
|
||||||
|
REM Review SQL Text and adjust accordingly.
|
||||||
|
REM
|
||||||
|
REM PARAMETERS
|
||||||
|
REM None.
|
||||||
|
REM
|
||||||
|
REM EXAMPLE
|
||||||
|
REM SQL> START coe_xfr_sql_profile_9t7jvx0gm0m95_1509575125.sql;
|
||||||
|
REM
|
||||||
|
REM NOTES
|
||||||
|
REM 1. Should be run as SYSTEM or SYSDBA.
|
||||||
|
REM 2. User must have CREATE ANY SQL PROFILE privilege.
|
||||||
|
REM 3. SOURCE and TARGET systems can be the same or similar.
|
||||||
|
REM 4. To drop this custom SQL Profile after it has been created:
|
||||||
|
REM EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_9t7jvx0gm0m95_1509575125');
|
||||||
|
REM 5. Be aware that using DBMS_SQLTUNE requires a license
|
||||||
|
REM for the Oracle Tuning Pack.
|
||||||
|
REM 6. If you modified a SQL putting Hints in order to produce a desired
|
||||||
|
REM Plan, you can remove the artifical Hints from SQL Text pieces below.
|
||||||
|
REM By doing so you can create a custom SQL Profile for the original
|
||||||
|
REM SQL but with the Plan captured from the modified SQL (with Hints).
|
||||||
|
REM
|
||||||
|
WHENEVER SQLERROR EXIT SQL.SQLCODE;
|
||||||
|
REM
|
||||||
|
VAR signature NUMBER;
|
||||||
|
VAR signaturef NUMBER;
|
||||||
|
REM
|
||||||
|
DECLARE
|
||||||
|
sql_txt CLOB;
|
||||||
|
h SYS.SQLPROF_ATTR;
|
||||||
|
PROCEDURE wa (p_line IN VARCHAR2) IS
|
||||||
|
BEGIN
|
||||||
|
DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
|
||||||
|
END wa;
|
||||||
|
BEGIN
|
||||||
|
DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
|
||||||
|
DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
|
||||||
|
-- SQL Text pieces below do not have to be of same length.
|
||||||
|
-- So if you edit SQL Text (i.e. removing temporary Hints),
|
||||||
|
-- there is no need to edit or re-align unmodified pieces.
|
||||||
|
wa(q'[select * from t1 where i=5000]');
|
||||||
|
DBMS_LOB.CLOSE(sql_txt);
|
||||||
|
h := SYS.SQLPROF_ATTR(
|
||||||
|
q'[BEGIN_OUTLINE_DATA]',
|
||||||
|
q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
|
||||||
|
q'[OPTIMIZER_FEATURES_ENABLE('19.1.0')]',
|
||||||
|
q'[DB_VERSION('19.1.0')]',
|
||||||
|
q'[ALL_ROWS]',
|
||||||
|
q'[OUTLINE_LEAF(@"SEL$1")]',
|
||||||
|
q'[INDEX_RS_ASC(@"SEL$1" "T1"@"SEL$1" ("T1"."I"))]',
|
||||||
|
q'[BATCH_TABLE_ACCESS_BY_ROWID(@"SEL$1" "T1"@"SEL$1")]',
|
||||||
|
q'[END_OUTLINE_DATA]');
|
||||||
|
:signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
|
||||||
|
:signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
|
||||||
|
DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
|
||||||
|
sql_text => sql_txt,
|
||||||
|
profile => h,
|
||||||
|
name => 'coe_9t7jvx0gm0m95_1509575125',
|
||||||
|
description => 'coe 9t7jvx0gm0m95 1509575125 '||:signature||' '||:signaturef||'',
|
||||||
|
category => 'DEFAULT',
|
||||||
|
validate => TRUE,
|
||||||
|
replace => TRUE,
|
||||||
|
force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
|
||||||
|
DBMS_LOB.FREETEMPORARY(sql_txt);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
WHENEVER SQLERROR CONTINUE
|
||||||
|
SET ECHO OFF;
|
||||||
|
PRINT signature
|
||||||
|
PRINT signaturef
|
||||||
|
PRO
|
||||||
|
PRO ... manual custom SQL Profile has been created
|
||||||
|
PRO
|
||||||
|
SET TERM ON ECHO OFF LIN 80 TRIMS OFF NUMF "";
|
||||||
|
SPO OFF;
|
||||||
|
PRO
|
||||||
|
PRO COE_XFR_SQL_PROFILE_9t7jvx0gm0m95_1509575125 completed
|
||||||
Reference in New Issue
Block a user