演習: 自動インメモリーの構成および監視

この演習では、自動インメモリーを構成した後、ユーザーの介入なしにインメモリー・オブジェクトが自動的かつ動的にIM列ストアに移入され、場合によってはIM列ストアから自動的に削除される様子を監視する方法を示します。

  1. 新しい演習を開始する前に、演習の環境の推奨事項を参照してください。
  2. 演習を開始する前に、/home/oracle/labs/M104783GC10/AutoIM_setup.shを実行します。このシェル・スクリプトでは、IM列ストアを110Mに構成し、PDB20HRスキーマにNO INMEMORY表を作成し、最後にHRの表に行を挿入します。
    $ cd /home/oracle/labs/M104783GC10
    $ /home/oracle/labs/M104783GC10/AutoIM_setup.sh
    SQL*Plus: Release 20.0.0.0.0 - Production on Tue Mar 10 10:38:54 2020
    Version 20.2.0.0.0
    
    Copyright (c) 1982, 2020, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL> SHUTDOWN ABORT
    ORACLE instance shut down.
    SQL> STARTUP MOUNT
    ORACLE instance started.
    
    Total System Global Area  851440264 bytes
    Fixed Size                  9573000 bytes
    Variable Size             339738624 bytes
    Database Buffers          377487360 bytes
    Redo Buffers                7200768 bytes
    In-Memory Area            117440512 bytes
    Database mounted.
    SQL> ALTER SYSTEM SET sga_target=812M SCOPE=spfile;
    
    System altered.
    
    SQL> ALTER SYSTEM SET inmemory_size=110M SCOPE=SPFILE;
    
    System altered.
    
    SQL> ALTER SYSTEM SET query_rewrite_integrity=stale_tolerated SCOPE=SPFILE;
    
    System altered.
    
    SQL> SET ECHO OFF
    
    System altered.
    
    SQL> ALTER SYSTEM SET INMEMORY_AUTOMATIC_LEVEL=LOW SCOPE=SPFILE;
    
    System altered.
    
    SQL> shutdown immediate
    ORA-01109: database not open
    
    
    Database dismounted.
    ORACLE instance shut down.
    SQL> STARTUP
    ORACLE instance started.
    
    Total System Global Area  851440264 bytes
    Fixed Size                  9573000 bytes
    Variable Size             339738624 bytes
    Database Buffers          377487360 bytes
    Redo Buffers                7200768 bytes
    In-Memory Area            117440512 bytes
    Database mounted.
    Database opened.
    SQL> ALTER PLUGGABLE DATABASE pdb20 OPEN;
    
    Pluggable database altered.
    
    SQL> CONNECT sys/password@PDB20 AS SYSDBA
    Connected.
    SQL> ALTER SYSTEM SET INMEMORY_AUTOMATIC_LEVEL=LOW SCOPE=SPFILE;
    
    System altered.
    
    SQL> ALTER SYSTEM SET query_rewrite_integrity=stale_tolerated SCOPE=SPFILE;
    
    System altered.
    
    SQL> shutdown immediate
    Pluggable Database closed.
    SQL> STARTUP
    Pluggable Database opened.
    SQL> exit
    Disconnected from Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL*Plus: Release 20.0.0.0.0 - Production on Tue Mar 10 10:41:05 2020
    Version 20.2.0.0.0
    
    Copyright (c) 1982, 2020, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL> ALTER SYSTEM SET db_create_file_dest='/home/oracle/labs';
    
    System altered.
    
    SQL>
    SQL> DROP TABLESPACE imtbs INCLUDING CONTENTS AND DATAFILES cascade constraints;
    
    Tablespace dropped.
    
    SQL> CREATE TABLESPACE imtbs DATAFILE '/home/oracle/labs/imtbs1.dbf' SIZE 10G;
    
    Tablespace created.
    
    SQL> EXIT
    Disconnected from Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL*Plus: Release 20.0.0.0.0 - Production on Tue Mar 10 10:44:02 2020
    Version 20.2.0.0.0
    
    Copyright (c) 1982, 2020, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    
    specify password for HR as parameter 1:
    
    specify default tablespeace for HR as parameter 2:
    
    specify temporary tablespace for HR as parameter 3:
    
    specify log path as parameter 4:
    
    PL/SQL procedure successfully completed.
    
    User created.
    
    User altered.
    
    User altered.
    
    Grant succeeded.
    
    Grant succeeded.
    
    Session altered.
    
    Session altered.
    
    Session altered.
    
    ******  Creating REGIONS table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    ******  Creating COUNTRIES table ....
    
    Table created.
    
    Table altered.
    
    ******  Creating LOCATIONS table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    Sequence created.
    
    ******  Creating DEPARTMENTS table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    Sequence created.
    
    ******  Creating JOBS table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    ******  Creating EMPLOYEES table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    Table altered.
    
    Sequence created.
    
    ******  Creating JOB_HISTORY table ....
    
    Table created.
    
    Index created.
    
    Table altered.
    
    ******  Creating EMP_DETAILS_VIEW view ...
    
    View created.
    
    Commit complete.
    
    Session altered.
    
    ******  Populating REGIONS table ....
    
    1 row created.
    
    1 row created.
    
    1 row created.
    
    1 row created.
    
    ******  Populating COUNTIRES table ....
    
    1 row created.
    ...
    ******  Populating LOCATIONS table ....
    
    1 row created.
    ...
    
    ******  Populating DEPARTMENTS table ....
    
    Table altered.
    
    ...
    1 row created.
    
    ******  Populating JOBS table ....
    
    1 row created.
    ...
    
    ******  Populating EMPLOYEES table ....
    
    1 row created.
    ...
    
    ******  Populating JOB_HISTORY table ....
    
    1 row created.
    ...
    
    Table altered.
    
    Commit complete.
    
    Index created.
    
    ...
    
    Commit complete.
    
    Procedure created.
    
    Trigger created.
    
    Trigger altered.
    
    Procedure created.
    
    Trigger created.
    
    Commit complete.
    
    Comment created.
    
    ...
    
    Commit complete.
    
    PL/SQL procedure successfully completed.
    
    SQL> Disconnected from Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL*Plus: Release 20.0.0.0.0 - Production on Tue Mar 10 10:44:22 2020
    Version 20.2.0.0.0
    
    Copyright (c) 1982, 2020, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    
    SQL> DROP TABLE hr.emp CASCADE CONSTRAINTS;
    DROP TABLE hr.emp CASCADE CONSTRAINTS
                  *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    
    SQL> CREATE TABLE hr.emp INMEMORY AS SELECT * FROM hr.employees ;
    
    Table created.
    
    SQL> INSERT INTO hr.emp SELECT * FROM hr.emp;
    
    107 rows created.
    
    SQL> /
    
    214 rows created.
    
    SQL> /
    
    428 rows created.
    
    SQL> /
    
    856 rows created.
    
    SQL> /
    
    1712 rows created.
    
    SQL> /
    
    3424 rows created.
    
    SQL> /
    
    6848 rows created.
    
    SQL> /
    
    13696 rows created.
    
    SQL> /
    
    27392 rows created.
    
    SQL> /
    
    54784 rows created.
    
    SQL> /
    
    109568 rows created.
    
    SQL> /
    
    219136 rows created.
    
    SQL> /
    
    438272 rows created.
    
    SQL> /
    
    876544 rows created.
    
    SQL> /
    
    1753088 rows created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> EXIT
    Disconnected from Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    $
  3. データ・ディクショナリを問い合せて、HRの表がINMEMORYとして指定されているかどうかを確認します。
    $ sqlplus sys@PDB20 AS SYSDBA
    
    Enter password: password
    
    Connected to:
    Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
    Version 20.2.0.0.0
    SQL> COL table_name FORMAT A18
    SQL> SELECT table_name, inmemory, inmemory_compression 
    FROM   dba_tables WHERE  owner='HR';
    
    TABLE_NAME         INMEMORY INMEMORY_COMPRESS
    ------------------ -------- -----------------
    REGIONS            DISABLED
    LOCATIONS          DISABLED
    DEPARTMENTS        DISABLED
    JOBS               DISABLED
    EMPLOYEES          DISABLED
    JOB_HISTORY        DISABLED
    EMP                ENABLED  FOR QUERY LOW
    COUNTRIES          DISABLED
    
    8 rows selected.
    
    SQL>
  4. INMEMORYおよびMEMCOMPRESS FOR CAPACITY LOW属性をHR.JOB_HISTORY表に適用します。
    SQL> ALTER TABLE hr.job_history INMEMORY MEMCOMPRESS FOR CAPACITY LOW;
    
    Table altered.
    
    SQL> SELECT table_name, inmemory, inmemory_compression 
    FROM   dba_tables WHERE  owner='HR';
    
    TABLE_NAME         INMEMORY INMEMORY_COMPRESS
    ------------------ -------- -----------------
    REGIONS            DISABLED
    LOCATIONS          DISABLED
    DEPARTMENTS        DISABLED
    JOBS               DISABLED
    EMPLOYEES          DISABLED
    JOB_HISTORY        ENABLED  FOR CAPACITY LOW
    EMP                ENABLED  FOR QUERY LOW
    COUNTRIES          DISABLED
    
    8 rows selected.
    
    SQL> 
  5. CDBルートに接続し、INMEMORY_AUTOMATIC_LEVELHIGHに設定して、データベース・インスタンスを再起動します。
    SQL> CONNECT / AS SYSDBA
    Connected.
    SQL> ALTER SYSTEM SET INMEMORY_AUTOMATIC_LEVEL=HIGH SCOPE=SPFILE;
    
    System altered.
    
    SQL> SHUTDOWN IMMEDIATE
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> STARTUP
    ORACLE instance started.
    
    Total System Global Area  851442944 bytes
    Fixed Size                  9571584 bytes
    Variable Size             440401920 bytes
    Database Buffers          276824064 bytes
    Redo Buffers                7204864 bytes
    In-Memory Area            117440512 bytes
    Database mounted.
    Database opened.
    SQL>
  6. データ・ディクショナリを問い合せて、HRの表がINMEMORYとして指定されているかどうかを確認します。
    SQL> CONNECT sys@PDB20 AS SYSDBA
    Enter password: password
    Connected.
    SQL> SELECT table_name, inmemory, inmemory_compression 
    FROM   dba_tables WHERE  owner='HR';
    
    TABLE_NAME         INMEMORY INMEMORY_COMPRESS
    ------------------ -------- -----------------
    REGIONS            DISABLED
    LOCATIONS          DISABLED
    DEPARTMENTS        DISABLED
    JOBS               DISABLED
    EMPLOYEES          DISABLED
    JOB_HISTORY        ENABLED  FOR CAPACITY LOW
    EMP                ENABLED  FOR QUERY LOW
    COUNTRIES          DISABLED
    
    8 rows selected.
    
    SQL>

    すでに手動でINMEMORYに設定されている表を除き、HRの表がINMEMORYに対して有効になっていないのはなぜですか。PDBのINMEMORY_AUTOMATIC_LEVELを表示します。

    SQL> SHOW PARAMETER INMEMORY_AUTOMATIC_LEVEL
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- -------------
    inmemory_automatic_level             string      LOW
    SQL> SELECT ispdb_modifiable FROM v$parameter WHERE name='inmemory_automatic_level';
    
    ISPDB
    -----
    TRUE
    
    SQL>
  7. PDBレベルでINMEMORY_AUTOMATIC_LEVELHIGHに設定し、PDB20を再起動します。
    SQL> ALTER SYSTEM SET INMEMORY_AUTOMATIC_LEVEL=HIGH SCOPE=SPFILE;
    
    System altered.
    
    SQL> SHUTDOWN IMMEDIATE
    Pluggable Database closed.
    SQL> STARTUP
    Pluggable Database opened.
    SQL>
  8. 1分待って、HRの表にINMEMORY属性が自動的に割り当てられることを確認します。
    SQL> SELECT table_name, inmemory, inmemory_compression 
    FROM   dba_tables WHERE owner='HR';
    
    TABLE_NAME         INMEMORY INMEMORY_COMPRESS
    ------------------ -------- -----------------
    REGIONS            ENABLED  AUTO
    LOCATIONS          ENABLED  AUTO
    DEPARTMENTS        ENABLED  AUTO
    JOBS               ENABLED  AUTO
    EMPLOYEES          ENABLED  AUTO
    JOB_HISTORY        ENABLED  FOR CAPACITY LOW
    EMP                ENABLED  FOR QUERY LOW
    COUNTRIES          DISABLED
    
    8 rows selected.
    
    SQL>

    INMEMORYとして手動で指定されたHR.JOB_HISTORYおよびHR.JOB_EMPが、以前の設定を保持していることに注目します。

    HR.COUNTRIESが自動的に有効にならないのはなぜですか。

    SQL> ALTER TABLE hr.countries INMEMORY;
     ALTER TABLE hr.countries INMEMORY
    *
    ERROR at line 1:
    ORA-64358: in-memory column store feature not supported for IOTs
    
    
    SQL>
  9. /home/oracle/labs/M104783GC10/AutoIM_scan.sql SQLスクリプトを実行して、HR表をIM列ストアに移入します。
    SQL> @/home/oracle/labs/M104783GC10/AutoIM_scan.sql
    SQL> SELECT /*+ FULL(hr.employees) NO_PARALLEL(hr.employees) */ count(*) FROM hr.employees;
    
      COUNT(*)
    ----------
           107
    
    SQL> SELECT /*+ FULL(hr.departments) NO_PARALLEL(hr.departments) */ count(*) FROM hr.departments;
    
      COUNT(*)
    ----------
            27
    
    SQL> SELECT /*+ FULL(hr.locations) NO_PARALLEL(hr.locations) */ count(*) FROM hr.locations;
    
      COUNT(*)
    ----------
            23
    
    SQL> SELECT /*+ FULL(hr.jobs) NO_PARALLEL(hr.jobs) */ count(*) FROM hr.jobs;
    
      COUNT(*)
    ----------
            19
    
    SQL> SELECT /*+ FULL(hr.regions) NO_PARALLEL(hr.regions) */ count(*) FROM hr.regions;
    
      COUNT(*)
    ----------
             4
    
    SQL> SELECT /*+ FULL(hr.emp) NO_PARALLEL(hr.emp) */ count(*) FROM hr.emp;
    
      COUNT(*)
    ----------
       3506176
    
    SQL>
  10. IM列ストアへのHRの表の移入ステータスを表示します。
    SQL> COL segment_name FORMAT A12
    SQL> SELECT segment_name, inmemory_size, bytes_not_populated, inmemory_compression FROM v$im_segments;
    
    SEGMENT_NAME INMEMORY_SIZE BYTES_NOT_POPULATED INMEMORY_COMPRESS
    ------------ ------------- ------------------- -----------------
    EMP               44433408                   0 FOR QUERY LOW
    
    SQL>

    ENABLED AUTOの表がIM列ストアに移入されないのはなぜですか。IM列ストアのコールド・データおよびホット・データを識別してIM列ストアに移入できるセグメントを検討するには、内部統計がまだ不十分です。

  11. /home/oracle/labs/M104783GC10/AutoIM_scan_AUTO.sql SQLスクリプトを実行してHR.EMPLOYEES表にさらに行を挿入し、HR.EMPLOYEES表を問い合せると、場合によってはIM列ストアに表が自動的に移入されます。
    SQL> @/home/oracle/labs/M104783GC10/AutoIM_scan_AUTO.sql
    SQL> set echo on
    SQL> begin
      2  for i in (select constraint_name, table_name from dba_constraints where table_name='EMPLOYEES') LOOP
      3  execute immediate 'alter table hr.employees drop constraint '||i.constraint_name||' CASCADE';
      4  end loop;
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    
    SQL> drop index hr.EMP_EMP_ID_PK;
    drop index hr.EMP_EMP_ID_PK
                  *
    ERROR at line 1:
    ORA-01418: specified index does not exist
    
    
    SQL>
    SQL> INSERT INTO hr.employees SELECT * FROM hr.employees;
    
    107 rows created.
    
    SQL> /
    
    214 rows created.
    
    SQL> /
    
    428 rows created.
    
    SQL> /
    
    856 rows created.
    
    SQL> /
    
    1712 rows created.
    
    SQL> /
    
    3424 rows created.
    
    SQL> /
    
    6848 rows created.
    
    SQL> /
    
    13696 rows created.
    
    SQL> /
    
    27392 rows created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> /
    
    Commit complete.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL>
  12. IM列ストアへのHRの表の移入ステータスを表示します。EMPLOYEES表の移入が開始されるまで数分間待つ必要がある場合があります。
    SQL> SELECT segment_name, inmemory_size, bytes_not_populated, inmemory_compression FROM v$im_segments;
    
    SEGMENT_NAME INMEMORY_SIZE BYTES_NOT_POPULATED INMEMORY_COMPRESS
    ------------ ------------- ------------------- -----------------
    EMP               44433408                   0 FOR QUERY LOW
    EMPLOYEES          1310720                   0 AUTO
    
    SQL> EXIT
    $

    INMEMORY_COMPRESS値がAUTOに設定され、HR.EMPLOYEES表が移入されていることに注目します。圧縮では、内部統計に基づいて自動インメモリー管理が使用されました。しばらくすると、内部統計に従ってHR.EMPが削除される場合があります。HR.EMP表を再度問合せると、統計により、HR.EMPがIM列ストアに再度移入されるようにHR.EMPLOYEESが削除されることになる場合があります。