如何驗證/啟用記憶體資料庫配置? (文件 ID 2178918.1)

mosdoc發表於2016-12-04

適用於:

Oracle Database - Enterprise Edition - 版本 12.1.0.2 和更高版本
本文件所含資訊適用於所有平臺

目標

如何驗證/啟用記憶體資料庫配置? 

解決方案

檢查資料庫的版本是 12.1.0.2:

SQL> Select * from v$version;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production              0
PL/SQL Release 12.1.0.2.0 - Production                                                    0
CORE    12.1.0.2.0      Production                                                                0
TNS for Linux: Version 12.1.0.2.0 - Production                                            0
NLSRTL Version 12.1.0.2.0 - Production                                                    0

inmemory_size 的設定應大於0

在設定 inmemory_size 引數之前先檢查:

SQL> show parameter inmemory

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
inmemory_clause_default              string
inmemory_force                       string      DEFAULT
inmemory_max_populate_servers        integer     0
inmemory_query                       string      ENABLE
inmemory_size                        big integer 0
inmemory_trickle_repopulate_servers_ integer     1
percent
optimizer_inmemory_aware             boolean     TRUE

SQL> select name, value from v$sga;

NAME                      VALUE
-------------------- ----------
Fixed Size              2927336
Variable Size         201327896
Database Buffers      402653184
Redo Buffers            5459968

配置資料庫引數:

SQL> ALTER SYSTEM SET inmemory_size = 200m scope=spfile;

System altered.

設定 inmemory_size 引數後(需要重新啟動資料庫讓引數生效)

SQL> show parameter inmemory

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
inmemory_clause_default              string
inmemory_force                       string      DEFAULT
inmemory_max_populate_servers        integer     2
inmemory_query                       string      ENABLE
inmemory_size                        big integer 200M
inmemory_trickle_repopulate_servers_ integer     1
percent
optimizer_inmemory_aware             boolean     TRUE

SQL> select name, value from v$sga;

NAME                      VALUE
-------------------- ----------
Fixed Size              2927336
Variable Size         264242456
Database Buffers      130023424
Redo Buffers            5459968
In-Memory Area        209715200

5 rows selected.

 

使用 SH 使用者進行測試

SQL> conn sh/oracle

Connected.

放置表到記憶體之前先檢查:

SQL> SELECT table_name,
       inmemory,
       inmemory_priority,
       inmemory_distribute,
       inmemory_compression,
       inmemory_duplicate
FROM   user_tables
WHERE table_name='CUSTOMERS';

TABLE_NAME                     INMEMORY INMEMORY INMEMORY_DISTRI INMEMORY_COMPRESS INMEMORY_DUPL
------------------------------ -------- -------- --------------- ----------------- -------------
CUSTOMERS                      DISABLED

1 row selected.

SQL> select pool, alloc_bytes, used_bytes, populate_status from v$inmemory_area;

POOL                       ALLOC_BYTES USED_BYTES POPULATE_STATUS
-------------------------- ----------- ---------- --------------------------
1MB POOL                             0          0 OUT OF MEMORY
64KB POOL                            0          0 OUT OF MEMORY

SQL> select owner, segment_name, populate_status from v$im_segments;

no rows selected

 

放置表到記憶體的命令:

SQL> alter table CUSTOMERS inmemory;

Table altered.

 

放置表到記憶體以後,檢查:

SQL> SELECT cust_valid, Count(*)
FROM customers
GROUP BY cust_valid;  2    3

C   COUNT(*)
- ----------
I      44879
A      10621

2 rows selected.

SQL> SELECT table_name,

       inmemory,
       inmemory_priority,
       inmemory_distribute,
       inmemory_compression,
       inmemory_duplicate
FROM   user_tables
WHERE table_name='CUSTOMERS';

TABLE_NAME                     INMEMORY INMEMORY INMEMORY_DISTRI INMEMORY_COMPRESS INMEMORY_DUPL
------------------------------ -------- -------- --------------- ----------------- -------------
CUSTOMERS                      ENABLED  NONE     AUTO            FOR QUERY LOW     NO DUPLICATE

1 row selected.

SQL> select owner, segment_name, populate_status from v$im_segments;

OWNER                     SEGMENT_NAME              POPULATE_
------------------------- ------------------------- ---------
SH                        CUSTOMERS                 COMPLETED

1 row selected.

SQL> select pool, alloc_bytes, used_bytes, populate_status from v$inmemory_area;

POOL                       ALLOC_BYTES USED_BYTES POPULATE_STATUS
-------------------------- ----------- ---------- --------------------------
1MB POOL                     166723584    4194304 DONE
64KB POOL                     25165824     131072 DONE

2 rows selected. 

驗證使用的執行計劃:

SQL> set autotrace traceonly;

SQL> SELECT cust_valid, Count(*)
FROM customers
GROUP BY cust_valid;

2 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1577413243

-----------------------------------------------------------------------------------------
| Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |           |     2 |     4 |    28  (11)| 00:00:01 |
|   1 |  HASH GROUP BY              |           |     2 |     4 |    28  (11)| 00:00:01 |
|   2 |   TABLE ACCESS INMEMORY FULL| CUSTOMERS | 55500 |   108K|    26   (4)| 00:00:01 |
-----------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
        249  recursive calls
          0  db block gets
        273  consistent gets
          5  physical reads
          0  redo size
        676  bytes sent via SQL*Net to client
        552  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         17  sorts (memory)
          0  sorts (disk)
          2  rows processed

 

功能使用情況的統計資料將在資料庫建立的7天后生成,否則將只返回2行。雖然解釋計劃可能會顯示’IN MEMORY FULL’,最終的執行可能會也可能不會使用 IN-Memory。如果表沒有被生成到列儲存裡(沒有足夠的空間,第一次訪問等),此時將會使用 Buffer Cache。可以使用 SQL Monitor 或日誌跟蹤來實際確認它的使用情況。

select name, detected_usages
from dba_feature_usage_statistics u1
where version=(select max(version)
from dba_feature_usage_statistics u2
where u2.name=u1.name and u1.name like 'In-%')

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31393455/viewspace-2129698/,如需轉載,請註明出處,否則將追究法律責任。

相關文章