第九十四期 19c OCM之路-第四堂(02)(20230725)
第四堂继续!
考点3:SQL statement tuning SQL语句调优
- 收集Schema统计信息
sql
exec dbms_stats.gather_schems_stats('HR');
- 开启制定表索引监控
sql
create index sh_cust_ind_1 on sh.customers(CUST_LAST_NAME));
select 'alter index sh.'||index_name||' monitoring usage;' from dba_indexes where owner='SH' and table_name='CUSTOMERS';
-- 执行输出结果
- 创建索引组织表
按照题目要求创建对应的表:
sql
create table oltp_user.students(stud_id number primary key,fname varchar2(20),lname varchar2(20));
create table oltp_user.classes(class_id number primary key,class_name varchar2(20));
CREATE USER oltp_attendees (
stud_id NUMBER,
class_id NUMBER,
constraint pk_s_c_pk ( stud_id, class_id ),
constraint fk_stud_id foreign key ( stud_id ) references oltp_user.students ( stud_id ),
constraint fk_class_id foreign key ( class_id ) references oltp_user.classes ( class_id )
) organization INDEX;
- 收集直方图统计信息
sql
exec dbms_stats.gather_table_stats('HR','EMPLOYEES', method_opt=>'for columns size skewolny');
- 创建位图索引(低选择性)
sql
create bitmap index sh.cust_c_bit on sh.customers(country_id);
- 压缩索引
sql
create index sh.cust_c_ind sh.customers(country_id,cust_city) compress 1;
- 共享池保存
sql
exec dbms_shared_pool.keep('STANDARD','P');
- 绑定变量配置为相似匹配
sql
alter system set cursor_sharing='SIMILAR';
- 段空间管理改为自动
需要将CUST_TBS表空间转换为级自动管理:
sql
select 'alter table '||owner||'.'||table_name||' move tablepsace users;' from dba_tables where tablespace_name='CUST_TBS';
select 'alter index '||owner||'.'||index_name||' rebuild tablepsace users;' from dba_indexes where tablespace_name='CUST_TBS';
-- 执行输出
drop tablespace cust_tbs including contents and datafiles;
create tablespace cust_tbs datafile '/u01/app/oracle/oradata/PROD4/cust_tbs' size 10m autoextend on;
-- 替换前面输出结果将表和索引表空间变更回cust_id
- 收集多列统计信息
sql
exec dbms_stats.create_extended_stats('HR','EMPLOYEES','(DEPARTMENT_ID,SALARY'));
exec dbms_stats.gather_table_stat('HR','EMPOLYEES',method_opt=>'for columns (DEPARTMEMT_ID,SALARY)');
- SPA
建议使用EMCC进行操作:
后续操作根据提示来做。如时间不足可放弃。 - SPM基线稳定
Oracle database 19c:
\qquad ->PL/SQL Packages and Types Reference
\qquad\qquad ->171 DBMS_SQLTUNE
\qquad\qquad\qquad ->171.5 Summary of DBMS_SQLTUNE Subprograms
\qquad\qquad\qquad\qquad ->171.5.8 CREATE_SQLSET Procedure and Function
\qquad\qquad\qquad\qquad ->171.5.35 SELECT_CURSOR_CACHE Function
\qquad\qquad\qquad\qquad ->171.5.19 LOAD_SQLSET Procedure
Oracle database 19c:
\qquad ->PL/SQL Packages and Types Reference
\qquad\qquad ->163 DBMS_SPM
\qquad\qquad\qquad ->163.6 Summary of DBMS_SPM Subprograms
\qquad\qquad\qquad\qquad ->163.6.15 LOAD_PLANS_FROM_SQLSET Function
\qquad\qquad\qquad\qquad ->163.6.9 EVOLVE_SQL_PLAN_BASELINE Function
sql
select * from scott.e1 where empno=7788;
exec dbms_sqltune.create_sqlset(sqlset_name=>'sqlset1',sqlset_owner=>'SYS');
declare
cur dbms_sqltune.sqlset_cursor;
a1 varchar2(100);
begin
a1 := 'upper(sql_text) like "SELECT % FROM SCOTT.E1 WHERE EMPNO=7788%';
open cur for
select value(p) from table(dbms_sqltune.select_cursor_cache(attribute_list=>'TYPICAL',base_filter=>a1)) p;
dbms_sqltune.load_sqlset(sqlset_name=>'sqlset1',populate_cursor=>cur,load_option=>'MERGE',update_option=>'ACCUMULATE',sqlset_owner=>'SYS');
end;
/
alter session set optimizer_capture_sql_plan_baseline=true;
declare
mp pls_integer;
begin
mp :=dbms_spm.load_plans_from_sqlset(sqlset_name=>'sqlset1');
end;
/
select * from scott.e1 where empno=7788;
select sql_handel,plan_name,accepted,enabled,fixed from dba_sql_plan_baselines; --结果A
create index scott.e1_ind on scott.e1(empno);
select * from scott.e1 where empno=7788;
select sql_handel,plan_name,accepted,enabled,fixed from dba_sql_plan_baselines; --结果B
declare
r clob;
begin
r:=dbms_spm.evolve_sql_plan_baseline(sql_handle=>'上面查出来的SQL_HANDLE');
-- dbms_output.put_line(r);
end;
/
select sql_handel,plan_name,accepted,enabled,fixed from dba_sql_plan_baselines; --结果变为相同
考点4:Create appropriate schema objects 创建Schema对象
lob列建表配置:
sql
create table ...,lob_col(clob),... tablespace user
lob(lob_col) store as (
tablespace lob_data
disable storage in row
chunk 16k
nocache
storage (
initial 2m
next 2m
)
)
;
考点5:Configuring parallel execution 配置并行执行
这里就要详见数据库管理-第九十一期 19c OCM之路-第三堂(20230711)考点9,上一期也讲了变更原因。
考点6:Instance tuning 实例调优
为某PDB或某实例设置最大使用2颗CPU资源:
sql
sqlplus sys/oracle@pdbprod2 as sysdba
alter system set cpu_count=2;
sqlplus sys/oracle@PROD4 as sysdba
alter system set cpu_count=2 scope=spfile;
shut immediate
startup
总结
第四堂考试基本结束。
老规矩,知道写了些啥。