Arquivo mensal: outubro 2015

Oracle Database in Memory

Neste Post mostrarei como habitar o Database in Memory num banco de dados Oracle.

Oracle Database In-Memory é uma Option adicional para o banco de dados Oracle a partir da versão 12.1.0.2.

A área de In-Memory é um conjunto estático dentro do SGA, cujo tamanho é controlado pelo parâmetro de  inicialização INMEMORY_SIZE . O tamanho atual da área de In-Memory é visível na V$SGA.  O armazenamento de dados na memória principal de um servidor ao invés de disco permite que os bancos de dados in-memory tenham tempos de resposta mais rápidos para consultas, evitando a latência de I/O.

Abaixo veremos como configurar um banco de dados com IN-Memory:

1 – Verificar a versão do Oracle Database instalado

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

2 – Verificar o parâmetro inmemory

SQL> show parameter inmemory

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

OBS: quando o parâmetro inmemory_size esta igual a 0, significa que não há memória alocada para o parametro inmemory

3 – Configurando o parametro inmemory no banco de dados

SQL> ALTER SYSTEM SET inmemory_size = 200m;

System altered.

SQL>

OBS: Após a configuração do parametro inmemory, o banco de dados deve ser restartado.

4 – Verificar se o parametro inmemory está habilitado

SQL> show parameter inmemory

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

5 – Verificando a configuração da SGA, após a alteração do parâmetro INMEMORY

SQL> select name, value from v$sga;

NAME                       VALUE
——————–         ———-
Fixed Size                2929936
Variable Size        532679408
Database Buffers   88080384
Redo Buffers            5455872
In-Memory Area  209715200

6 – Verificando se a tabela ITEM_PEDIDO esta em Memória

SQL> conn ecommerce/ecommerce
Connected.

neste teste usarei uma tabela da aplicação chamada ITEM_PEDIDO

SQL> SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
WHERE table_name=’ITEM_PEDIDO’;

TABLE_NAME INMEMORY INMEMORY  INMEMORY_DISTRI  INMEMORY_COMPRESS  INMEMORY_DUPL
———–         ——–             ——–           —————               —————–                          ————-
ITEM_PEDIDO DISABLED

7 – Configurando a tabela ITEM_PEDIDO na memória

SQL> alter table ITEM_PEDIDO inmemory;

Table altered.

8 – Verificando se a tabela ITEM_PEDIDO em Memória

SQL> SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
WHERE table_name=’ITEM_PEDIDO’;

TABLE_NAME INMEMORY   INMEMORY   INMEMORY_DISTRI   INMEMORY_COMPRESS   INMEMORY_DUPL
———–          ——–         ——–                        —————                    —————–               ————-
ITEM_PEDIDO ENABLED NONE AUTO FOR QUERY LOW NO DUPLICATE

9 – Verificando a quantidade me memoria alocada pela tabela ITEM_PEDIDO

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

POOL           ALLOC_BYTES      USED_BYTES    POPULATE_STATUS
————————–    ———–                ———-                ————————–
1MB  POOL       166723584                   0                               DONE
64KB POOL        25165824                   0                                DONE

10 – Extraindo plano de execução da consulta da tabela em memória

SQL> set autotrace traceonly;
SQL> select CD_PRODUTO,count(*) from ecommerce.ITEM_PEDIDO group by CD_PRODUTO;
Execution Plan
———————————————————-
Plan hash value: 590499307

——————————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
——————————————————————————————-
| 0 | SELECT STATEMENT | | 4 | 8 | 60 (50)| 00:00:01 |
| 1 | HASH GROUP BY | | 4 | 8 | 60 (50)| 00:00:01 |
| 2 | TABLE ACCESS INMEMORY FULL| ITEM_PEDIDO | 1138K| 2222K| 33 (10)| 00:00:01 |
——————————————————————————————-

Statistics
———————————————————-
232 recursive calls
0 db block gets
3059 consistent gets
2830 physical reads
0 redo size
704 bytes sent via SQL*Net to client
551 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
17 sorts (memory)
0 sorts (disk)
4 rows processed

11 – Extraindo plano de execução da consulta da tabela em disco (Com In-Memory desabilitado)

SQL> set autotrace traceonly;
SQL> select CD_PRODUTO,count(*) from ecommerce.ITEM_PEDIDO group by CD_PRODUTO;

Execution Plan
———————————————————-
Plan hash value: 1581306332

—————————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————————-
| 0 | SELECT STATEMENT | | 4 | 8 | 805 (4)| 00:00:01 |
| 1 | HASH GROUP BY | | 4 | 8 | 805 (4)| 00:00:01 |
| 2 | INDEX FAST FULL SCAN| PK_ITEM_PEDIDO | 1138K| 2222K| 778 (1)| 00:00:01 |
—————————————————————————————-

Statistics
———————————————————-
35 recursive calls
0 db block gets
2931 consistent gets
2857 physical reads
0 redo size
704 bytes sent via SQL*Net to client
551 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
4 rows processed

Podemos constatar que o custo é menor quando a tabela consultada esta em memória

Fonte:
How to Verify / Enable In-Memory Database Configuration? (Doc ID 1929758.1)