[20230110]sql profile run standby database.txt
[20230110]sql profile run standby database.txt
--//理論講在standby database執行sql profile不可行的.因為要執行過程要寫資料檔案.
--//我以前的做法在主庫執行,然後在主庫運用並接受sql profile的建議.這樣備庫一樣可以應用sql profile建議.
--//能否直接在備庫執行sql profile呢?找到一些檔案,測試看看:
--//後記:節前做的測試,一直不成功,後來發現執行dbms_sqltune.execute_tuning_task的引數database_link_to的賦值一定要大寫.
--//一定可以透過,不知道為什麼,不再探究.
1.環境:
SYS@192.168.100.235:1521/orcl> @ pr
==============================
PORT_STRING : x86_64/Linux 2.4.xx
VERSION : 19.0.0.0.0
BANNER : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
BANNER_FULL : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
BANNER_LEGACY : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
CON_ID : 0
PL/SQL procedure successfully completed.
2.測試:
--//在主庫建立使用者SYS$UMF.在19c該使用者實際上存在的.
SYS@192.168.100.235:1521/orcl> select username,common,account_status from dba_users where username ='SYS$UMF';
USERNAME COM ACCOUNT_STATUS
-------- --- --------------
SYS$UMF YES LOCKED
SYS@192.168.100.235:1521/orcl> alter user SYS$UMF identified by o1r2c3l4 account unlock ;
User altered.
SYS@192.168.100.235:1521/orcl> select username,common,account_status from dba_users where username ='SYS$UMF';
USERNAME COM ACCOUNT_STATUS
-------- --- --------------
SYS$UMF YES OPEN
--//在主庫建立db_link.連線主庫自己:
SYS@192.168.100.235:1521/orcl> create database link link_to_primary connect to "SYS$UMF" identified by "o1r2c3l4" using '192.168.100.235:1521/orcl';
Database link created.
--//在備庫執行驗證db_link是否生效:
SYS@192.168.100.237:1521/orcldg> select db_unique_name from v$database@link_to_primary;
DB_UNIQUE_NAME
------------------------------
orcl
3.測試sql Profile over dblink:
--//在備庫執行如下指令碼sp1x.sql:
--//修改原來sp1.sql指令碼,dbms_sqltune.create_tuning_task 中加入引數database_link_to => 'LINK_TO_PRIMARY'以及
--//dbms_sqltune.execute_tuning_task( task_name=>'tuning &1' ,database_link_to => upper('&2') );
--//我的測試遇到一個古怪的問題,引數database_link_to賦值的變數一定要大寫.不然執行無法透過!!
--//做一個簡單例子驗證:
SYS@192.168.100.237:1521/orcldg> @ cs lis
alter session set current_schema=lis
Session altered.
SYS@192.168.100.237:1521/orcldg> select /*+ full(a) */ * from lis.LIS_CRIT_RESULT a where id=12752271;
...
SYS@192.168.100.237:1521/orcldg> @ hash
HASH_VALUE SQL_ID CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE HASH_HEX SQL_EXEC_START SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ---------- ------------------- -----------
2517908391 2yr2asfb18fx7 0 15271 1122455697 96143ba7 2023-02-09 10:34:41 16777219
SYS@192.168.100.237:1521/orcldg> @ sp1x 2yr2asfb18fx7 LINK_TO_PRIMARY
PL/SQL procedure successfully completed.
==============================================================================
tuning sql_id=2yr2asfb18fx7 : report
==============================================================================
REPORT_TUNING_TASK
-------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : tuning 2yr2asfb18fx7
Tuning Task Owner : SYS
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status : COMPLETED
Started at : 02/09/2023 10:35:42
Completed at : 02/09/2023 10:35:49
SQL Tuning at Standby TRUE
-------------------------------------------------------------------------------
Schema Name: LIS
SQL ID : 2yr2asfb18fx7
SQL Text : select /*+ full(a) */ * from lis.LIS_CRIT_RESULT a where
id=12752271
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- SQL Profile Finding (see explain plans section below)
--------------------------------------------------------
A potentially better execution plan was found for this statement.
Recommendation (estimated benefit: 99.9%)
-----------------------------------------
- Consider accepting the recommended SQL profile.
execute dbms_sqltune.accept_sql_profile(task_name => 'tuning
2yr2asfb18fx7', task_owner => 'SYS', replace => TRUE);
Validation results
------------------
The SQL profile was tested by executing both its plan and the original plan
and measuring their respective execution statistics. A plan may have been
only partially executed if the other could be run to completion in less time.
Original Plan With SQL Profile % Improved
------------- ---------------- ----------
Completion Status: COMPLETE COMPLETE
Elapsed Time (s): .025028 .00002 99.92 %
CPU Time (s): .013574 .00002 99.85 %
User I/O Time (s): 0 0
Buffer Gets: 3042 3 99.9 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
Rows Processed: 1 1
Fetches: 1 1
Executions: 1 1
Notes
-----
1. Statistics for the original plan were averaged over 10 executions.
2. Statistics for the SQL profile plan were averaged over 10 executions.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original With Adjusted Cost
------------------------------
Plan hash value: 1122455697
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 231 | 581 (1)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| LIS_CRIT_RESULT | 1 | 231 | 581 (1)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=12752271)
Hint Report (identified by operation id / Query Block Name / Object Alias):
Total hints for statement: 3 (U - Unused (3))
---------------------------------------------------------------------------
0 - STATEMENT
U - IGNORE_OPTIM_EMBEDDED_HINTS / hint overridden by another in parent query block
U - OPTIMIZER_FEATURES_ENABLE(default) / hint overridden by another in parent query block
1 - SEL$1 / A@SEL$1
U - full(a) / rejected by IGNORE_OPTIM_EMBEDDED_HINTS
2- Using SQL Profile
--------------------
Plan hash value: 1272079374
----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 231 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_CRIT_RESULT | 1 | 231 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | PK_LIS_CRIT_RESULT | 1 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=12752271)
Hint Report (identified by operation id / Query Block Name / Object Alias):
Total hints for statement: 1 (U - Unused (1))
---------------------------------------------------------------------------
1 - SEL$1 / A@SEL$1
U - full(a) / rejected by IGNORE_OPTIM_EMBEDDED_HINTS
-------------------------------------------------------------------------------
=================================================================================================================================================
if finished,drop tuning task , run:
execute dbms_sqltune.drop_tuning_task('tuning 2yr2asfb18fx7')
if accept sql profile, run:
execute dbms_sqltune.accept_sql_profile(task_name => 'tuning 2yr2asfb18fx7', replace => TRUE ,name=>'tuning 2yr2asfb18fx7');
execute dbms_sqltune.accept_sql_profile(task_name => 'tuning 2yr2asfb18fx7', replace => TRUE, name=>'tuning 2yr2asfb18fx7', FORCE_MATCH=>True)
if drop or alter sql profile ,run :
execute dbms_sqltune.drop_sql_profile(name => 'tuning 2yr2asfb18fx7')
execute dbms_sqltune.alter_sql_profile(name => 'tuning 2yr2asfb18fx7',attribute_name=>'STATUS',value=>'DISABLED')
=================================================================================================================================================
display SYS_AUTO_SQL_TUNING_TASK : report
select dbms_sqltune.report_tuning_task( 'SYS_AUTO_SQL_TUNING_TASK' ) report from dual;
SYS@192.168.100.237:1521/orcldg> execute dbms_sqltune.accept_sql_profile(task_name => 'tuning 2yr2asfb18fx7', replace => TRUE, name=>'tuning 2yr2asfb18fx7', FORCE_MATCH=>True);
PL/SQL procedure successfully completed.
SYS@192.168.100.237:1521/orcldg> select /*+ full(a) */ * from lis.LIS_CRIT_RESULT a where id=12752270;
no rows selected
SYS@192.168.100.237:1521/orcldg> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 2x11z62jv16y3, child number 0
-------------------------------------
select /*+ full(a) */ * from lis.LIS_CRIT_RESULT a where id=12752270
Plan hash value: 1272079374
-----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_CRIT_RESULT | 1 | 231 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | PK_LIS_CRIT_RESULT | 1 | | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / A@SEL$1
2 - SEL$1 / A@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=12752270)
Hint Report (identified by operation id / Query Block Name / Object Alias):
Total hints for statement: 3 (U - Unused (1))
---------------------------------------------------------------------------
0 - STATEMENT
- IGNORE_OPTIM_EMBEDDED_HINTS
- OPTIMIZER_FEATURES_ENABLE(default)
1 - SEL$1 / A@SEL$1
U - full(a) / rejected by IGNORE_OPTIM_EMBEDDED_HINTS
Note
-----
- SQL profile tuning 2yr2asfb18fx7 used for this statement
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
43 rows selected.
--//OK透過.
4.附上sp1x.sql指令碼:
$ cat sp1x.sql
set verify off
set long 20000000
set longchunksize 20000000
column report_tuning_task format a300
declare
a varchar2(200);
begin
a := dbms_sqltune.create_tuning_task(task_name=>'tuning &1',description=>'tuning sql_id=&1',scope=>dbms_sqltune.scope_comprehensive,time_limit=>1800,sql_id=>'&1',database_link_to => upper('&2'));
--// dbms_sqltune.execute_tuning_task( a );
dbms_sqltune.execute_tuning_task( task_name=>'tuning &1' ,database_link_to => upper('&2') );
end;
/
prompt
prompt =================================================================================================================================================
prompt tuning sql_id=&1 : report
prompt =================================================================================================================================================
select dbms_sqltune.report_tuning_task('tuning &1') report_tuning_task FROM dual;
prompt =================================================================================================================================================
prompt if finished,drop tuning task , run:
prompt execute dbms_sqltune.drop_tuning_task('tuning &1')
prompt if accept sql profile, run:
prompt execute dbms_sqltune.accept_sql_profile(task_name => 'tuning &1', replace => TRUE ,name=>'tuning &1');;
prompt execute dbms_sqltune.accept_sql_profile(task_name => 'tuning &1', replace => TRUE, name=>'tuning &1', FORCE_MATCH=>True)
prompt if drop or alter sql profile ,run :
prompt execute dbms_sqltune.drop_sql_profile(name => 'tuning &1')
prompt execute dbms_sqltune.alter_sql_profile(name => 'tuning &1',attribute_name=>'STATUS',value=>'DISABLED')
prompt =================================================================================================================================================
prompt display SYS_AUTO_SQL_TUNING_TASK : report
prompt select dbms_sqltune.report_tuning_task( 'SYS_AUTO_SQL_TUNING_TASK' ) report from dual;;
prompt
set serveroutput off
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2934662/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Profile(第三篇)SQL
- SQL Profile(第二篇)SQL
- SQL Profile(第四篇)SQL
- SQL Profile(第一篇)SQL
- [20181119]使用sql profile優化問題.txtSQL優化
- [20220324]toad與sql profile使用問題.txtSQL
- Oracle SQL Profile固定執行計劃的方法OracleSQL
- [20180302]sql profile能減少分析時間嗎?SQL
- [20221008]sql profile最佳化失效問題.txtSQL
- run_stats---sql效率測試工具(轉)SQL
- Convert a Physical Standby Database into a Snapshot Standby DatabaseDatabase
- Oracle優化案例-coe_xfr_sql_profile固定執行計劃與刪除profile(二十五)Oracle優化SQL
- .Oracle固定執行計劃之SQL PROFILE概要檔案OracleSQL
- [20210722]ORA-38760與flashback database.txtDatabase
- Failed to run 'create login' or 'sp_addsrvrolemeber' in sql Linux using windows authentcationAIVRSQLLinuxWindows
- [20181011]ORA-65086 cannot openclose the pluggable database.txtDatabase
- [20230220][20230110]生成相關備庫的awr報表
- [20230425]注意snapshot standby與activate standby的區別.txt
- Oracle利用coe_load_sql_profile指令碼繫結執行計劃OracleSQL指令碼
- (xml中sql語句為紅)解決No data sources are configured to run this SQL and provide advanced的問題XMLSQLIDE
- Oracle的快照standbyOracle
- 2 新增standby masterAST
- mac-profileMac
- Run-time Settings--General--Run Logic
- Performing a Failover to a Physical Standby DatabaseORMAIDatabase
- Oracle OCP(29):PROFILEOracle
- 【BASIS】系統profile
- SpringBoot 教程之 profileSpring Boot
- MAVEN中的profileMaven
- 邏輯STANDBY建立中碰到ORA-16146: standby destination control file enqueue unavailableENQAI
- Oracle優化案例-view merge與coe_load_sql_profile固定執行計劃(十五)Oracle優化ViewSQL
- npm run dev 和 npm run serve 區別NPMdev
- 主庫到standby報錯解決:Error 12154 received logging on to the standby ORA-12154Error
- Task.Run(async () =>{}) 和 Task.Run(() =>{})區別
- 【DG】Data Guard搭建(physical standby)
- Setup Standby Database on One PC(轉)Database
- Oracle DG Standby Database型別OracleDatabase型別
- Oracle DG建立Physical Standby DatabaseOracleDatabase