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

简介: [20180316]共享服务模式和直接路径读.txt --//在共享服务器模式下,执行计划不会选择直接路径读,通过例子证明. 1.环境: SYS@book> @ &r/ver1 PORT_STRING          VERSION    BANNER...

[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;

目录
相关文章
|
2月前
|
PyTorch TensorFlow API
大模型中 .safetensors 文件、.ckpt文件、.gguf和.pth以及.bin文件区别、加载和保存以及转换方式
本文讨论了大模型中不同文件格式如`.safetensors`、`.ckpt`、`.gguf`、`.pth`和`.bin`的区别、用途以及如何在TensorFlow、PyTorch和ONNX等框架之间进行加载、保存和转换。
572 2
|
7月前
|
存储 文件存储
<文件操作> 文件的打开与关闭,顺序读写,随机读写,二进制文件,读取结束的判定,文件缓冲区
<文件操作> 文件的打开与关闭,顺序读写,随机读写,二进制文件,读取结束的判定,文件缓冲区
44 1
|
7月前
如何批量复制多个文件到多个目录中(批量复制文件,多对多文件高效操作的方法)
该文介绍了如何使用一个工具进行文件批量复制的操作。首先,提供了百度网盘和蓝奏云的链接,附有提取码,以获取所需工具。接着,展示了一个包含三个文件夹和两张图片的示例。操作步骤包括:打开工具,使用Ctrl+5进入批量复制模块,选择图片并拖拽至复制区域,然后选择目标文件夹(在这里是三个命名的空文件夹),点击“开始复制”,等待过程完成。工具提供复制选项供用户按需选择,且支持保存操作路径以备后续使用。完成后,目标文件夹将包含复制的图片,整个过程简便快捷。
|
Windows
[20180522]避免删除共享打印机.txt
[20180522]避免删除共享打印机.txt --//一些用户经常莫名其妙删除共享打印机,在windows下,应该可以通过修改注册表,控制这种操作行为. --//google看一些文档,记录如下: --//执行regedit: REGEDIT4 [HKEY...
1033 0
|
C#
原 BinaryWriter和BinaryReader(二进制文件的读写)
原文 BinaryWriter和BinaryReader(二进制文件的读写) C#的FileStream类提供了最原始的字节级上的文件读写功能,但我们习惯于对字符串操作,于是StreamWriter和 StreamReader类增强了FileStream,它让我们在字符串级别上操作文件,但有的时候我们还是需要在字节级上操作文件,却又不是一个字节 一个字节的操作,通常是2个、4个或8个字节这样操作,这便有了BinaryWriter和BinaryReader类,它们可以将一个字符或数字按指定 个数字节写入,也可以一次读取指定个数字节转为字符或数字。
1631 0
|
SQL Oracle 关系型数据库
[20180319]直接路径读特例12c.txt
[20180319]直接路径读特例12c.txt --//昨天的测试突然想起以前遇到的直接路径读特例,在12c重复测试看看. 1.环境: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION...
981 0
|
测试技术
[20180316]异步IO和共享服务模式.txt
[20180316]异步IO和共享服务模式.txt --//在共享服务器模式下,不会使用异步IO,通过例子证明. 1.环境: SYS@book> @ &r/ver1 PORT_STRING          VERSION    BANNER --...
1081 0
|
缓存 关系型数据库 Oracle
[20171120]11G关闭直接路径读.txt
[20171120]11G关闭直接路径读.txt --//今天做filesystemio_options参数测试时,遇到一个关于直接路径读的问题. --//如果看以前的博客介绍,设置"_serial_direct_read"=never或者events '10949 trace name context forever';就可以关闭直接路径读.
1028 0