『ORACLE』SPM(下)-baseline实验

查询baseline信息:

SQL>select sql_handle,sql_text,plan_name,origin,version,created,last_modified,last_executed,last_verified,enabled,accepted,fixed from dba_sql_plan_baselines;

no rows selected

SQL>alter system set optimizer_capture_sql_plan_baselines=true;(开启自动捕获)

System altered.

[email protected]>create table t3 (id int);

Table created.

[email protected]>insert into t3 select level from dual connect by level<=10000;

10000 rows created.

[email protected]>commit;

Commit complete.

模拟业务,第一次查询:

[email protected]>select count(*) from t3 where id=1;

COUNT(*)
----------
1

SQL>select sql_id,sql_text from v$sql where sql_text like ‘select count(*) from t3 where id=1‘;(查询shared pool中的关于这条sql的信息)

SQL_ID              SQL_TEXT
----------------- ----------------------------------------------
82w9knc509xx4  select count(*) from t3 where id=1

SQL>select sql_handle,sql_text,plan_name,origin,version,created,last_modified,last_executed,last_verified,enabled,accepted,fixed from dba_sql_plan_baselines;

no rows selected

模拟业务,第二次查询:

[email protected]>select count(*) from t3 where id=1;

COUNT(*)
----------
1

SQL>select sql_id,sql_text from v$sql where sql_text like‘select count(*) from t3 where id=1‘;(查询shared pool中的关于这条sql的信息)

SQL_ID               SQL_TEXT
-----------------  ------------------------------------
82w9knc509xx4   select count(*) from t3 where id=1

82w9knc509xx4   select count(*) from t3 where id=1

SQL>select sql_handle,sql_text,plan_name,origin,version,created,last_modified,last_executed,last_verified,enabled,accepted,fixed from dba_sql_plan_baselines where sql_text like ‘%select count(*) from t3 where id=1%‘;(查询baseline中的信息)

SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN VERSION CREATED LAST_MODIF
-------------------- --------------- --------------- -------------- ---------- ---------- ----------
LAST_EXECU LAST_VERIF ENA ACC FIX
---------- ---------- --- --- ---

SQL_f83b4cd9c6676181 select count(*) SQL_PLAN_ghfucv AUTO-CAPTURE 11.2.0.4.0 23-APR-17 23-APR-17
from t3 where 736fsc114fae16c 09.06.44.0 09.06.44.0
id=1 00000 PM 00000 PM
23-APR-17 YES YES NO
09.06.44.0
00000 PM

[email protected]>set autotrace traceonly(查看执行计划)

[email protected]>select count(*) from t3 where id=1;

Execution Plan
----------------------------------------------------------
Plan hash value: 463314188

---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 7 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
|* 2 | TABLE ACCESS FULL| T3 | 1 | 13 | 7 (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - filter("ID"=1)

Note
-----
- dynamic sampling used for this statement (level=2)
- SQL plan baseline "SQL_PLAN_ghfucv736fsc114fae16c" used for this statement

Statistics
----------------------------------------------------------
53 recursive calls
0 db block gets
82 consistent gets
0 physical reads
0 redo size
526 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
1 rows processed

时间: 2024-10-03 22:51:31

『ORACLE』SPM(下)-baseline实验的相关文章

『ORACLE』SPM

SPM(sql plan management)的主要作用:通过管理sql执行计划,提高和稳定系统性能. 应用场合:数据库升级.不间断的系统数据改变.业务系统新模块的开发 体系结构 sql plan baseline的管理流程: 第一步:捕获执行计划(主要作用:检测执行计划和记录的改变并记录到baseline中,捕获方式有两种:1.自动捕获 2.手工load) 手工load执行计划->from cursor cache DECLARE my_plans PLS_INTEGER; BEGIN my

『ORACLE』通过哪个视图来查看用户下的表

ORACLE下有三个视图 DBA_TABLES  拥有DBA角色的用户可以查看系统中的所有表 USER_TABLES 登录数据库的当前用户拥有的所有表 ALL_TABLES 登录数据库的当前用户有权限查看的所有表

『ORACLE』 约束实验(11g)

create table student (   sno                  NUMBER(5)            not null,   sname                VARCHAR2(20),   idcard               VARCHAR2(18),   createtime           DATE                 default SYSDATE,   nno                  NUMBER(2),   co

『ORACLE』DG搭建时备库的db_name报错

因为搭建DG时备库中的db_name为SBCD,实际应该是主库db_name的PROD1 所以在[主库]执行如下rman操作命令时会报错控制文件记录的数据库名与实际拷贝的数据库名不相同 RMAN> duplicate target database for standby from active database; Starting Duplicate Db at 01-MAY-17using target database control file instead of recovery ca

『ORACLE』移动数据(Directory Object)

SQL> create or replace directory dir_dt as '/home/oracle'; Directory created.SQL> grant read,write on directory dir_dt to scott; Grant succeeded. SQL*Loader 测试一:infile * 常用参数 参数名称 含义 userid ORACLE username/password control 控制文件 log 记录的日志文件 bad 坏数据文件

『ORACLE』 数据泵Data Pump中expdp导出(11g)

[[email protected] ~]$ mkdir datadump[[email protected] ~]$ cd datadump/[[email protected] datadump]$ pwd/home/oracle/datadump SQL> create or replace directory dir_dp as '/home/oracle/datadump'; Directory created. SQL> grant read,write on directory

『ORACLE』授予hr用户查看执行计划权限

SQL>@?/sqlplus/admin/plustrce.sql [email protected] hey~J->drop role plustrace; Role dropped. [email protected] hey~J->create role plustrace; Role created. [email protected] hey~J->[email protected] hey~J->grant select on v_$sesstat to plus

『ORACLE』 清理监听日志(11g)

停止监听服务进程(tnslsnr)记录日志.lsnrctl  set log_status off; 将监听日志文件(listener.log)复制一份,以listener.log.yyyymmdd格式命名cp listener.log listener.log.20170521 将监听日志文件(listener.log)清空. cat /dev/null > listener.log 开启监听服务进程(tnslsnr)记录日志lsnrctl set log_status on; 对于这种lis

『ORACLE』SPA性能分析器

SPA的主要作用:主要测试由于系统环境变更包括操作系统变更,数据库升级等对sql性能的影响.尽量减少由于系统环境的变更对业务的影响程度. 分析流程:1.获取sql存取到Tunning set=>2.准备测试环境并传输tunning set=>3.实施系统变更=>4.创建spa task=>5.spa分析产生系统改变前和改变后的对比报告=>6.根据对比结果对sql语句进行优化=>7.为了验证优化结果再次分析报告与系统改变前进行对比 EM创建tunning set set