[20180316]共用服務模式和直接路徑讀.txt

来源:https://www.cnblogs.com/lfree/archive/2018/03/16/8579279.html
-Advertisement-
Play Games

[20180316]共用服務模式和直接路徑讀.txt--//在共用伺服器模式下,執行計劃不會選擇直接路徑讀,通過例子證明.1.環境:SYS@book> @ &r/ver1PORT_STRING VERSION BANNER x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle ...


[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/[email protected]:1521/book

--//我以前多次提到dispatchers包括服務.ezconenct優先使用共用伺服器模式:

[email protected]:1521/book> show parameter dispatchers
NAME            TYPE     VALUE
--------------- -------- -------------------------------------
dispatchers     string   (PROTOCOL=TCP) (SERVICE=book,bookXDB)
max_dispatchers integer

[email protected]:1521/book>  alter session set statistics_level=all;
Session altered.

[email protected]:1521/book> alter system flush buffer_cache;
System altered.

[email protected]: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,採用共用伺服器模式.

[email protected]: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

[email protected]:1521/book> select count(*) from t;
  COUNT(*)
----------
     80000

[email protected]: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

--//可以發現在共用伺服器模式下執行計劃不選擇直接路徑讀.通過緩存數量也可以證明:
[email protected]:1521/book> alter system flush buffer_cache;
System altered.

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

[email protected]: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)

[email protected]:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
     40222
--//全表掃描後數據塊大量進入數據緩存.

3.但是在並行的情況下共用模式情況就不同:

[email protected]: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;

[email protected]:1521/book> alter system flush buffer_cache;
System altered.

[email protected]:1521/book> select count(*) from v$bh where OBJD=90467 and STATUS<>'free';
  COUNT(*)
----------
         0

[email protected]: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

[email protected]:1521/book> select /*+ parallel(t 8) */ count(*) from t;
  COUNT(*)
----------
     80000

[email protected]: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)

[email protected]: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上升.

[email protected]: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;


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • window eclipse連接hadoop集群,本地運行wordcount,報以下錯誤,嘗試網路上的方法無果,如:換64JDK,添加hadoop_home,path,以及在hadoop\bin和c:\windows\system32下放hadoop.dll。 解決:刪除hadoop\bin\had ...
  • 在MySQL中,它是按什麼順序或規律去讀取my.cnf配置文件的呢?其實只要你花一點功夫,實驗測試一下就能弄清楚,下麵的實驗環境為5.7.21 MySQL Community Server。其它版本如有不同,請以實際情況為準。 其實,MySQL是按照下麵這個順序來讀取my.cnf: 1: /etc/... ...
  • 一、環境 二、官方源 獲取官方源: 安裝: 安裝之後, /etc/yum.repos.d/目錄下會產生兩個文件:mysql-community-source.repo、mysql-community.repo。 三、創建組和用戶 四、安裝MySQL 由於RHEL7.3中預設安裝了Mariadb,安裝 ...
  • 一、索引的含義和特點 索引是一個單獨的、存儲在磁碟上的資料庫結構,他們包含著對數據表裡所有記錄的引用指針。使用索引用於快速找出某個或多個列中有一特點值的行,所用MySQL列類型都可以被索引,對相關列使用索引是提高查詢操作速度的最佳途徑。 索引是在儲存引擎中實現的,因此,每種存儲引擎的索引都不一定完全 ...
  • 嵌套子查詢是SQL語句中比較常用的一種查詢方法,開發過程中遇到查詢需要將自己的某列作為待查詢的數據,在參考別人的SQL語句的寫法終於實現了自己需要的功能。 不太和諧查詢語句如下: SELECT DISTINCT dbo.a.ProxyID, dbo.a.account AS adminAccount ...
  • MySQL日誌管理 查詢有關日誌的變數:show global variables like '%log%' ; 特別提醒: 如果不明白mysql中的變數請點擊 找到其中的 ”mysql伺服器變數“ 部分 錯誤日誌: 記錄內容: 伺服器啟動和關閉過程中的信息 伺服器運行過程中的錯誤信息 事件調度器運 ...
  • 第一步:添加 MariaDB yum 倉庫 首先在CentOS操作系統中/etc/yum.repos.d/目錄下添加 MariaDB 的YUM配置文件MariaDB.repo文件。 vi /etc/yum.repos.d/MariaDB.repo 在該文件中添加以下內容保存: 第二步:安裝 Mari ...
  • 公用表表達式 (CTE) 具有一個重要的優點,那就是能夠引用其自身,從而創建遞歸 CTE。遞歸 CTE 是一個重覆執行初始 CTE 以返回數據子集直到獲取完整結果集的公用表表達式。 當某個查詢引用遞歸 CTE 時,它即被稱為遞歸查詢。遞歸查詢通常用於返回分層數據,例如:顯示某個組織圖中的雇員或物料清 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...