第四堂继续!
exec dbms_stats.gather_schems_stats('HR');
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';
-- 执行输出结果
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;
exec dbms_stats.gather_table_stats('HR','EMPLOYEES', method_opt=>'for columns size skewolny');
create bitmap index sh.cust_c_bit on sh.customers(country_id);
create index sh.cust_c_ind sh.customers(country_id,cust_city) compress 1;
exec dbms_shared_pool.keep('STANDARD','P');
alter system set cursor_sharing='SIMILAR';
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
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)');
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
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; --结果变为相同
lob列建表配置:
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
)
)
;
这里就要详见数据库管理-第九十一期 19c OCM之路-第三堂(20230711)考点9,上一期也讲了变更原因。
为某PDB或某实例设置最大使用2颗CPU资源:
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
第四堂考试基本结束。
老规矩,知道写了些啥。