0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Active Data Guard スタンバイ・インスタンスで Result Cache を試す(Oracle Database 21c)

Last updated at Posted at 2022-10-11

Oracle Database 19c の動作

Oracle Database 19c までは、Active Data Guard スタンバイ・インスタンスでは Result Cache は利用できませんでした。
以下は Oracle Database 19c 上で DBMS_RESULT_CACHE.STATUS を確認した結果です。初期化パラメーター上は有効になっていますが、DBMS_RESULT_CACHE.STATUSは DISABLED を返します。

SQL> SELECT DATABASE_ROLE FROM V$DATABASE;

DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> SELECT DBMS_RESULT_CACHE.STATUS FROM DUAL;

STATUS
--------------------------------------------------------------------------------
DISABLED

Oracle Database 21c の動作

Oracle Database 21c の Active Data Guard スタンバイ・インスタンスの標準状態では以下の動作になります。

SQL> SHOW PARAMETER result_cache
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
client_result_cache_lag              big integer 3000
client_result_cache_size             big integer 0
result_cache_execution_threshold     integer     2
result_cache_max_result              integer     5
result_cache_max_size                big integer 8M
result_cache_max_temp_result         integer     5
result_cache_max_temp_size           big integer 80M
result_cache_mode                    string      MANUAL
result_cache_remote_expiration       integer     0

SQL> SELECT DBMS_RESULT_CACHE.STATUS FROM DUAL;

STATUS
--------------------------------------------------------------------------------
ENABLED

SQL> SELECT /*+ RESULT_CACHE */ COUNT(*) FROM scott.data1;

  COUNT(*)
----------
      9999

実行計画
----------------------------------------------------------
Plan hash value: 1629554946

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

統計
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         30  consistent gets
          0  physical reads
          0  redo size
        592  bytes sent via SQL*Net to client
         52  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

DBMS_RESULT_CACHE.STATUS は ENABLED を返しますが、実際には Result Cache は利用されていません。
Oracle Database 21c ではプライマリ・インスタンスで ALTER TABLE RESULT_CACHE(STANDBY ENABLE) 文を実行することでスタンバイ・インスタンス上でも Result Cache を利用できるようになります。ALTER TABLE 文はテーブル属性を変更するため、スタンバイ・インスタンス上では実行できません。

SQL> ALTER TABLE scott.data1 RESULT_CACHE(STANDBY ENABLE);

表が変更されました。

属性を変更したので、スタンバイ・インスタンス上で Result Cache用のヒントを指定した SELECT 文を実行します。

SQL> SELECT /*+ RESULT_CACHE */ COUNT(*) FROM scott.data1;

  COUNT(*)
----------
      9999

実行計画
----------------------------------------------------------
Plan hash value: 1629554946

------------------------------------------------------------------------------------------
| Id  | Operation           | Name                       | Rows  | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |                            |     1 |     2   (0)| 00:00:01 |
|   1 |  RESULT CACHE       | 5q305cgq00cphbc310f47u9gj1 |     1 |            |          |
|   2 |   SORT AGGREGATE    |                            |     1 |            |          |
|   3 |    TABLE ACCESS FULL| DATA1                      |     1 |     2   (0)| 00:00:01 |
------------------------------------------------------------------------------------------

Result Cache Information (identified by operation id):
------------------------------------------------------

   1 - column-count=1; dependencies=(SCOTT.DATA1); attributes=(single-row); name="SELECT /*+ RESULT_
CACHE */ COUNT(*) FROM scott.data1"

統計
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          0  consistent gets
          0  physical reads
          0  redo size
        592  bytes sent via SQL*Net to client
         52  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

Result Cache を利用していることが確認できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?