[20180316]共享服务模式和直接路径读.txt

--//在共享服务器模式下,执行计划不会选择直接路径读,通过例子证明.

1.环境:
SYS@book> @ &r/ver1
PORT_STRING          VERSION    BANNER
-------------------- ---------- ----------------------------------------------------------------------------
x86_64/Linux 2.4.xx  11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYS@book> alter system set filesystemio_options=asynch scope=spfile;
System altered.

--//重启数据库.

SCOTT@book> show sga
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes

SCOTT@book> create table t as select rownum id from dual connect by level<=2;
Table created.

SCOTT@book> ALTER TABLE t MINIMIZE RECORDS_PER_BLOCK ;
Table altered.
--//这样可以实现每块2条记录.

SCOTT@book> insert into t select rownum+2 from dual connect by level <=8e4-2;
79998 rows created.

SCOTT@book> commit ;
Commit complete.

--//分析表略.

SCOTT@book> select OWNER,SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK,BYTES,BLOCKS from dba_segments where owner=user and segment_name='T';
OWNER  SEGMENT_NAME         SEGMENT_TYPE       HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS
------ -------------------- ------------------ ----------- ------------ ---------- ----------
SCOTT  T                    TABLE                        4          546  333447168      40704

--//占用 333447168/1024/1024 = 318M

SCOTT@book> select object_id,data_object_id from dba_objects where owner=user and object_name='T';
 OBJECT_ID DATA_OBJECT_ID
---------- --------------
     90467          90467

SCOTT@book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
     36020
    
2.测试分析:
SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> alter session set statistics_level=all;
Session altered.

SCOTT@book> @ &r/spid
       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
       274         11 46995                    DEDICATED 46996       21          6 alter system kill session '274,11' immediate;

--//server=DEDICATED采用专用模式.

SCOTT@book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         0

SCOTT@book> @ &r/viewsess "physical reads direct"
NAME                                       STATISTIC#      VALUE        SID
------------------------------------------ ---------- ---------- ----------
physical reads direct                              97          0        274
physical reads direct temporary tablespace        110          0        274
physical reads direct (lob)                       176          0        274

SCOTT@book> select count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@book> @ &r/viewsess "physical reads direct"
NAME                                       STATISTIC#      VALUE        SID
------------------------------------------ ---------- ---------- ----------
physical reads direct                              97      40217        274
physical reads direct temporary tablespace        110          0        274
physical reads direct (lob)                       176          0        274

--//可以发现执行计划走的physical reads direct.physical reads direct=40217.通过执行后数据缓存数量也可以推定:

SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         0

SCOTT@book> select count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  cyzznbykb509s, child number 0
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows | Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  |
----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        | 10963 (100)|          |      1 |00:00:00.17 |   40227 |  40222 |
|   1 |  SORT AGGREGATE    |      |      1 |      1 |            |          |      1 |00:00:00.17 |   40227 |  40222 |
|   2 |   TABLE ACCESS FULL| T    |      1 |  89876 | 10963   (1)| 00:02:12 |  80000 |00:00:00.17 |   40227 |  40222 |
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   2 - SEL$1 / T@SEL$1

Note
-----
   - dynamic sampling used for this statement (level=2)

SCOTT@book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         5
--//仅仅缓存5个数据块.

3.测试分析:
$ rlsql scott/book@127.0.0.1:1521/book

--//我以前多次提到dispatchers包括服务.ezconenct优先使用共享服务器模式:

SCOTT@127.0.0.1:1521/book> show parameter dispatchers
NAME            TYPE     VALUE
--------------- -------- -------------------------------------
dispatchers     string   (PROTOCOL=TCP) (SERVICE=book,bookXDB)
max_dispatchers integer

SCOTT@127.0.0.1:1521/book>  alter session set statistics_level=all;
Session altered.

SCOTT@127.0.0.1:1521/book> alter system flush buffer_cache;
System altered.

SCOTT@127.0.0.1:1521/book> @ &r/spid
       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
       261          1 47005                    SHARED    46300       20          1 alter system kill session '261,1' immediate;

--//server=SHARED,采用共享服务器模式.

SCOTT@127.0.0.1:1521/book> @ &r/viewsess "physical reads direct"
NAME                                       STATISTIC#      VALUE        SID
------------------------------------------ ---------- ---------- ----------
physical reads direct                              97          0        261
physical reads direct temporary tablespace        110          0        261
physical reads direct (lob)                       176          0        261

SCOTT@127.0.0.1:1521/book> select count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@127.0.0.1:1521/book> @ &r/viewsess "physical reads direct"
NAME                                                                   STATISTIC#      VALUE        SID
---------------------------------------------------------------------- ---------- ---------- ----------
physical reads direct                                                          97          0        261
physical reads direct temporary tablespace                                    110          0        261
physical reads direct (lob)                                                   176          0        261

--//可以发现在共享服务器模式下执行计划不选择直接路径读.通过缓存数量也可以证明:
SCOTT@127.0.0.1:1521/book> alter system flush buffer_cache;
System altered.

SCOTT@127.0.0.1:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         0
SCOTT@127.0.0.1:1521/book> select count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@127.0.0.1:1521/book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  cyzznbykb509s, child number 0
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows | Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  |
----------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        | 10963 (100)|          |      1 |00:00:00.34 |   40236 |  40222 |
|   1 |  SORT AGGREGATE    |      |      1 |      1 |            |          |      1 |00:00:00.34 |   40236 |  40222 |
|   2 |   TABLE ACCESS FULL| T    |      1 |  89876 | 10963   (1)| 00:02:12 |  80000 |00:00:00.34 |   40236 |  40222 |
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   2 - SEL$1 / T@SEL$1
Note
-----
   - dynamic sampling used for this statement (level=2)

SCOTT@127.0.0.1:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
     40222
--//全表扫描后数据块大量进入数据缓存.

3.但是在并行的情况下共享模式情况就不同:

SCOTT@127.0.0.1:1521/book> @ &r/spid
       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
       261          1 47005                    SHARED    46300       20          1 alter system kill session '261,1' immediate;

SCOTT@127.0.0.1:1521/book> alter system flush buffer_cache;
System altered.

SCOTT@127.0.0.1:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         0

SCOTT@127.0.0.1:1521/book> @ &r/viewsess "physical reads direct"
NAME                                                                   STATISTIC#      VALUE        SID
---------------------------------------------------------------------- ---------- ---------- ----------
physical reads direct                                                          97          0        261
physical reads direct temporary tablespace                                    110          0        261
physical reads direct (lob)                                                   176          0        261

SCOTT@127.0.0.1:1521/book> select /*+ parallel(t 8) */ count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@127.0.0.1:1521/book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  965gv5rh77t0c, child number 0
-------------------------------------
select /*+ parallel(t 8) */ count(*) from t
Plan hash value: 3126468333

--------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers |
--------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |  1522 (100)|          |        |      |            |      1 |00:00:00.22 |      15 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |          |        |      |            |      1 |00:00:00.22 |      15 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |          |        |      |            |      8 |00:00:00.22 |      15 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |
|   4 |     SORT AGGREGATE     |          |      0 |      1 |            |          |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
|   5 |      PX BLOCK ITERATOR |          |      0 |  89876 |  1522   (0)| 00:00:19 |  Q1,00 | PCWC |            |      0 |00:00:00.01 |       0 |
|*  6 |       TABLE ACCESS FULL| T        |      0 |  89876 |  1522   (0)| 00:00:19 |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
--------------------------------------------------------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

1 - SEL$1
   6 - SEL$1 / T@SEL$1

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

6 - access(:Z>=:Z AND :Z<=:Z)

Note
-----
   - dynamic sampling used for this statement (level=2)

SCOTT@127.0.0.1:1521/book> @ &r/viewsess "physical reads direct"
NAME                                       STATISTIC#      VALUE        SID
------------------------------------------ ---------- ---------- ----------
physical reads direct                              97      40217        261
physical reads direct temporary tablespace        110          0        261
physical reads direct (lob)                       176          0        261

--//可以发现physical reads direct上升.

SCOTT@127.0.0.1:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
       314
--//从数据缓存的数量也可以看出.

4.附上viewsess.sql脚本:
set verify off
column name format a70
SELECT b.NAME, a.statistic#, a.VALUE,a.sid
  FROM v$mystat a, v$statname b
 WHERE lower(b.NAME) like lower('%&1%') AND a.statistic# = b.statistic# ;
 --and a.value>0;

[20180316]共享服务模式和直接路径读.txt的更多相关文章

  1. [20190306]共享服务模式与SDU.txt

    [20190306]共享服务模式与SDU.txt --//一些文档提到共享服务模式,服务端SDU=65535,测试验证看看.--//链接:https://blogs.sap.com/2013/02/0 ...

  2. [20171120]11G关闭直接路径读.txt

    [20171120]11G关闭直接路径读.txt --//今天做filesystemio_options参数测试时,遇到一个关于直接路径读的问题.--//如果看以前的博客介绍,设置"_ser ...

  3. [20191112]oracle共享连接模式端口.txt

    [20191112]oracle共享连接模式端口.txt --//如果使用共享服务模式,你可以发现每次重启数据库对应的端口号会发生变化.# netstat -tunlp | egrep "A ...

  4. Cluster基础(一):配置iSCSI服务、编写udev规则、配置并访问NFS共享、部署Multipath多路径环境

    一.配置iSCSI服务 目标: 本案例要求先搭建好一台iSCSI服务器,并将整个磁盘共享给客户端: 虚拟机添加新的磁盘 将新添加的磁盘分区并创建两个逻辑卷 逻辑卷名称分别为:/dev/myvg/isc ...

  5. samba共享服务

    方法一 1.安装samba:可以先检查下是否已经安装:rpm -qa | grep samba,没有的话自己安装下,这里介绍下基于RPM包的一种在线安装模式yumyum是一种快速安装模式,它会自动解决 ...

  6. hive使用derby的服务模式(可以远程模式)

    hive默认使用的derby的嵌入模式.这个就面临着,无法多个并发hive shell共享的问题. 使用MySQL服务器也可以解决问题,但安装.配置太麻烦了. 可以使用轻量级的derby的c/s服务模 ...

  7. 网络共享服务(三)之SAMBA

    前面说到了FTP和NFS,由于FTP是客户端和服务器基于ftp应用协议进行交换数据的,它不支持挂载共享目录的方式,而NFS又不支持跨平台,所以就催生了第三种网络共享服务:samba Samba是在Li ...

  8. 公共卫生GIS共享服务平台

    1   系统详细设计 1.1 GIS共享服务管理 1.1.1 概述 GIS共享服务管理是本系统的重要组成部分,它实现了对各类地图数据.业务资源数据的集成统一管理,提供了一个平台级的管理解决方案,能够往 ...

  9. SQLite剖析之异步IO模式、共享缓存模式和解锁通知

    1.异步I/O模式    通常,当SQLite写一个数据库文件时,会等待,直到写操作完成,然后控制返回到调用程序.相比于CPU操作,写文件系统是非常耗时的,这是一个性能瓶颈.异步I/O后端是SQLit ...

随机推荐

  1. Hbase shell基本操作

    1.启动cd <hbase_home>/bin$ ./start-hbase.sh 2.启动hbase shell # find hadoop-hbase dfs fileshadoop ...

  2. Spark SQL读取hive数据时报找不到mysql驱动

    Exception: Caused by: org.datanucleus.exceptions.NucleusException: Attempt to invoke the "BoneC ...

  3. Java:Cookie实现记住用户名、密码

    package com.gamecenter.api.util; import java.io.IOException; import java.io.PrintWriter; import java ...

  4. Android_Studio_Checkout_Github_Error"Cannot run program "git.exe":CreateProcess error = 2

    答案都在这了,如果你有下载过git而不是github,那么你可以指定git.exe给android studio 正如这样:

  5. Eureka单机高可用伪集群配置

    Eureka Server高可用集群理论上来讲,因为服务消费者本地缓存了服务提供者的地址,即使Eureka Server宕机,也不会影响服务之间的调用,但是一旦新服务上线,已经缓存在本地的服务提供者不 ...

  6. Asp.net Webform 使用Repository模式实现CRUD操作代码生成工具

    Asp.net Webform 使用Repository模式实现CRUD操作代码生成工具 介绍 该工具是通过一个github上的开源项目修改的原始作者https://github.com/Supere ...

  7. IntelliJ IDEA 2018.3 for Mac 注册码激活

    一.前往 jetbrains 官网下载 IDEA Ultimate版本,地址: https://www.jetbrains.com/idea/download/#section=mac 二.安装 ID ...

  8. Postman接口测试_添加断言

    1.设置环境变量 postman.setEnvironmentVariable("key", "value");  例子: postman.setEnviron ...

  9. 图像处理中kmeans聚类算法C++实现

    Kmeans聚类算法是十分常用的聚类算法,给定聚类的数目N,Kmeans会自动在样本数据中寻找N个质心,从而将样本数据分为N个类别.下面简要介绍Kmeans聚类原理,并附上自己写的Kmeans聚类算法 ...

  10. [Luogu 3613] 睡觉困难综合征

    Description 给定一棵 \(n\) 个点的树,每个点上有位运算 \(opt\) 和一个权值 \(x\),位运算有 &,|,^ 三种. 要求支持: 修改点 \(v\) 的 \(opt\ ...