Skip to main content

Understanding the Oracle Database Technical Architecture in Detail continued...


<<Back to DB Administration Main Page

Understanding the Oracle Database Technical Architecture in Detail

A high level architecture of non multi tenant (classical) oracle  database is explained here
Detail explanation of Database Buffer Cache is presented here


Database Shared Pool in Details:

What is Shared Pool?
shared pool is nothing but a meta data cache. The shared pool is used for caching complex objects describing where the data is stored and how it relates to other data and how it can be retrieved. Its a  memory component located in oracle database SGA. The shared pool is basically the 2nd largest memory area in SGA after Database buffer Cache. You can configure the shared pool size using shared_pool_size initialization parameter

What is the Purpose of Shared Pool?
The purpose of shared pool is to cache various types of program data.
For Example
Parsed SQL (cursor)
Execution Plan of a SQL
optimizer stats
etc...etc..
 Because of the nature of data shared pool stores, it is involved in almost every operation that occurs in the database. Since every operation that occurs in the database access the shared pool, to speedup the shared pool access it is further divided into several sub components as shown below.
Library Cache
The library cache is a shared pool memory structure that stores executable SQL and PL/SQL code and control structures such as locks and library cache handles. In other words it is a library of ready-to-execute SQL statements. In a shared server architecture, the library cache also contains private SQL areas (otherwise private SQL areas resides in process's PGA itself).

Private SQL area
Each session issuing a SQL statement has a private SQL area in its PGA. Each user that submits the same statement has a private SQL area pointing to the same shared SQL area. Thus, many private SQL areas in separate PGAs can be associated with the same shared SQL area.

Shared SQL Areas
As the name suggest, whatever stored in this area is shared among many users/sessions.
Shared SQL Areas contains:
Parsed SQL (cursors)
Frequently used PL/SQL:  Executable representation of PL/SQL packages ,procedures and functions etc
Other Type of Objects: that is needed to parse and execute SQL statements including tables, ,indexes, types, methods classes etc.
Execution plan of SQLs
NOTE: Only one shared SQL area exists for a unique statement.


Data Dictionary CacheThe data dictionary cache stores various information like table definition, index information, referential integrity, user information and other metadata. Oracle database uses these metadata very frequently eg to parse a SQL statement.

NOTE: Oracle internally controls the size of Library and  dictionary cache. As the overall shared pool changes in size, so does the dictionary and library cache.

Server Result Cache
SQL result cache
Cache recently executed Query Results, which lets Oracle skip the subsequent execution part of the SQL  and returns the result directly from result cache improving the performance. Are you worried about the result cache returning incorrect data? Not at all. Oracle automatically invalidates data stored in the result cache if any of the underlying components are modified.

PL/SQL Function Result Cache
Function results can be cached and is system-wide available to all sessions. Changes to dependent objects automatically invalidate the cache


Reserved Pool:
Oracle usages Reserved Pool to allocate a large chunk (over 4 KB) of contiguous memory in the shared pool. For large allocations, Oracle Database attempts to allocate space in the shared pool in the following order:

  • From the unreserved part of the shared pool.
  • From the reserved pool.
  • From memory

Size of the reserved pool can be configured using SHARED_POOL_RESERVED_SIZE initialization parameter. The default value for the SHARED_POOL_RESERVED_SIZE parameter is 5% (controlled by hidden parameter _shared_pool_reserved_pct ) of the SHARED_POOL_SIZE parameter. The default minimum reserved pool allocation is 4,400 bytes ( controlled by hidden parameter _shared_pool_reserved_min_alloc)

Allocation and Reuse of Memory in the Shared Pool
  • The first thing you need to know is that Oracle requires contiguous space to satisfy each memory request. Memory is allocated in the form  of chunks. A request for 4k chunk can not be fulfilled by 3K chunk +1K chunk, but must be 4K chunk. Most memory allocation is done in 1K and 4K chunks, although there are many smaller unit of allocation is also used
  • The database allocates shared pool memory when a new SQL statement is parsed. The memory size depends on the complexity of the statement.
  • Oracle database follows the LRU algorithm to age out the item from shared pool to free up the space.

The database also removes a shared SQL area from the shared pool in the following circumstances:

  • If statistics are gathered for a table, table cluster, or index, then by default the database gradually removes all shared SQL areas that contain statements referencing the analyzed object after a period of time. 
  • If a schema object is referenced in a SQL statement, and if this object is later modified by a DDL statement
  • If you change the global database name, then the database removes all information from the shared pool.
  • You can use the ALTER SYSTEM FLUSH SHARED_POOL statement to manually remove all information in the shared pool.


Technical Implementation of Oracle Shared Pool

As we know Oracle requires a lot of different memory (chunk) sizes in the shared pool, Oracle uses the durations to "group" these different kinds of memory requests. Starting with Oracle 9.2 the shared pool can be divided into sub-pools and starting with Oracle 10g R2 each sub-pool may also be split-up into four durations (which has been reduced to 2 durations with Oracle 12c). The hidden parameter "_kghdsidx_count" (value of which is internally calculated by oracle depending CPU count and shared pool size) controls how much sub-pools should be created. Durations are created automatically if ASMM or AMM is used, which sets the hidden parameter  "_enable_shared_pool_durations" to TRUE.

Shared pool implementation with Oracle version >= 10.2 and <12
Shared pool implementation with Oracle version >= 12

COL KSPPINM FOR a40
COL KSPPSTVL FOR a20
COL KSPPDESC FOR a80
SET LINE 200

SELECT ksppinm, ksppstvl, ksppdesc
  FROM x$ksppi a, x$ksppsv b
 WHERE     a.indx = b.indx
       AND SUBSTR (ksppinm, 1, 1) = '_'
       AND a.ksppinm IN ('_kghdsidx_count', '_enable_shared_pool_durations');

Below is the output from 12.1.0.2
Using the below query you can confirm that the shared pool is divided into 2 sub pools

SQL> SELECT DECODE(kghlushrpool,0,'Java Pool',1,'Shared Pool') AS pool, kghluidx
num_subpool FROM x$kghlu;

POOL                              NUM_SUBPOOL
--------------------------------- -----------
Shared Pool                                 2
Shared Pool                                 1

By performing a heap dump of level 2 we can even verify that the Shared pool is divided into sub pool and duration is enabled. I have 2 sub pools with each with 2 durations (0,3) as you can see in the screenshot below 
SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_350055.trc
SQL> oradebug dump heapdump 2
Statement processed.
$ grep -i "sga heap" /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_350055.trc

If you will deep dive in the trace file of heap dump you will get to know where the shared pool memory is allocated how much and why. The lines that start with “Chunk” identify chunks of memory in the granule. Each chunk shows its starting address and size in bytes
For Example KGLH0 Kernel General Library Heap 0 storing environment, statistics and bind variables stored at address a700005e0 with size of 4096 bytes KQR (Kernal Query Rowcache) PO (Parent Object) stored in a size if 1072 bytes. SQLA (SQL Area) stored in 20480 bytes 5 x 4096 an so on....

Processing Oradebug command 'dump heapdump 2'
KGH Latch Directory Information
ldir state: 2  last allocated slot: 187
Slot [  1] Latch: 0x1444e05848  Index: 2  Flags:  3  State: 2  next:  (nil)
...............
HEAP DUMP heap name="sga heap"  desc=0x600013d0
 extent sz=0x4d3a8 alt=272 het=32767 rec=9 flg=130 opc=0
 parent=(nil) owner=(nil) nex=(nil) xsz=0x68018 heap=(nil)
 fl2=0x60, nex=(nil)
 pdb id=1
 ds for latch 1: 0x60064348                       0x60068c50
 ds for latch 2: 0x6006e098                       0x600729a0
 reserved granule count 0 (granule size 268435456)
******************************************************
HEAP DUMP heap name="sga heap(1,0)"  desc=0x60064348
 extent sz=0xfe0 alt=272 het=32767 rec=9 flg=130 opc=0
 parent=(nil) owner=(nil) nex=(nil) xsz=0x10000000 heap=(nil)
 fl2=0x20, nex=(nil), dsxvers=1, dsxflg=0x0
 dsx first ext=0x1450000000
 dsx empty ext bytes=0  subheap rc link=0x14500000b8,0x14500000b8
 pdb id=1
 latch set 1 of 2
 durations enabled for this heap
 reserved granules for root 0 (granule size 268435456)
EXTENT 0 addr=0xa70000000
  Chunk        a70000058 sz=      248    freeable  "KGLDA          "
  Chunk        a70000150 sz=      240    freeable  "KGLDA          "
  Chunk        a70000240 sz=      384    recrPT030 "KGLHD          "  latch=(nil)
  Chunk        a700003c0 sz=      544    recrPT021 "KGLHD          "  latch=(nil)
  Chunk        a700005e0 sz=     4096    recrUR021 "KGLH0^e329e33c "  latch=(nil)
     ds        53aeb0700 sz=     4096 ct=        1
  Chunk        a700015e0 sz=      144    free      "               "
  Chunk        a70001670 sz=     1072    recrUT005 "KQR PO         "  latch=0xb1eb13d8
  Chunk        a70001aa0 sz=     4096    recrPR007 "KGLH0^347a0496 "  latch=(nil)
     ds        5a75e91f0 sz=     4096 ct=        1
 ..................
  Chunk        a7001a678 sz=     1072    recrUR005 "KQR PO         "  latch=0xb1eb13d8
  Chunk        a7009b220 sz=      576    recrPT056 "KQR SO         "  latch=(nil)
.................
  Chunk        65cbc8730 sz=     4096    freeableU "SQLA^b6955f1c  "  ds=0x778fd78d8
  Chunk        65cbc9730 sz=     4096    recrUT011 "SQLA^18943aa4  "  latch=(nil)
     ds        59e334b58 sz=    20480 ct=        5

               652b00028 sz=     4096
               652b01028 sz=     4096
               652b02028 sz=     4096
               652b03028 sz=     4096
  Chunk        65cbca730 sz=      936    freeableU "KGLA^93fddbf6  "  ds=0x5a4415e08
  Chunk        65cbcaad8 sz=     3856    free      "               "

You can query V$SQL to find out which SQL is stored in a particular memory chunk using query below 
SQL > select child_number,child_address,sql_text from v$sql where hash_value =
to_number('18943aa4', 'XXXXXXXXXXXXXXXX');

You can even perform the level 2  granule dump and see how the shared pool is arranged in memory.
SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_267550.trc
SQL> oradebug dump dump_all_comp_granules 2
Statement processed.

$ grep -i "sga heap(" /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_267550.trc
Address 0xd0000000 to 0xe0000000 in sga heap(1,0) (idx=1, dur=1)
Address 0xc0000000 to 0xd0000000 in sga heap(1,0) (idx=1, dur=1)
Address 0xb0000000 to 0xc0000000 in sga heap(2,0) (idx=2, dur=1)
Address 0xa0000000 to 0xb0000000 in sga heap(2,0) (idx=2, dur=1)
..........................................................
Address 0x210000000 to 0x220000000 in sga heap(1,3) (idx=1, dur=4)
Address 0x200000000 to 0x210000000 in sga heap(2,0) (idx=2, dur=1)
Address 0x1f0000000 to 0x200000000 in sga heap(2,3) (idx=2, dur=4)
..........................................................

Orcale require shared pool latches to work with shared pool eg. to pin/unpin an object , allocate memory chunk etc etc.. Although the number of shared pool latches are hardcoded into oracle, the one actually used depends on the number of sub pools. There is always 1 shared pool latch for each sub pool.
  SQL>  SELECT child#, gets
    FROM v$latch_children
   WHERE name = 'shared pool'
ORDER BY child#;

    CHILD#       GETS
---------- ----------
         1 2805101061
         2 3892790786

         3        390
         4        390
         5        390
         6        390
         7        390

7 rows selected.
Since the shared pool in  my case is divided into 2 sub pools only 2 latches are active.

By now you would have probably understand why Oracle split-up the shared pool in this way. Basically there were two reasons

  • The first reason is scalability - Oracle has one shared pool latch per sub-pool which makes various operations like shared pool memory allocation or linked list modifications much more scalable reducing the shared pool latch contention. 
  • The second reason is to avoid memory fragmentation as a consequence ORA-04031 errors

Who is the top 10 Consumer of Shared Pool

SELECT *
  FROM (  SELECT con_id, name, bytes / POWER (1024, 2) MB
            FROM v$sgastat
           WHERE pool = 'shared pool'
        ORDER BY bytes DESC)
 WHERE ROWNUM < 11;

View Related to Shared Pool

v$db_object_cach view
v$librarycache;
v$rowcache
v$shared_pool_advice
V$SQL
v$SQL_AREA
v$OPEN_CURSORS
v$sgastat
v$sqlstat
V$SQL_SHARED_CURSOR
v$sgainfo
v$shared_pool_reserved;

init Parameters related to shared pool

session_cached_cursors
cursor_space_for_time
cursor_sharing

Comments

Popular posts from this blog

DataPump Import Of Object Types Fails With Errors ORA-39083 ORA-2304 Or ORA-39117 ORA-39779

<<Back to Oracle DATAPUMP Main Page ORA-39083: Object type TYPE:"TEST_QA01"."LOG_RECORD" failed to create with error: ORA-02304: invalid object identifier literal Import: Release 12.1.0.2.0 - Production on Tue May 29 07:59:12 2018 Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security, OLAP, Advanced Analytics and Real Application Testing options Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/********@TEST_QA parfile=import_TEST.par Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Pr

ORA-28374: typed master key not found in wallet

<<Back to Oracle DB Security Main Page ORA-46665: master keys not activated for all PDBs during REKEY SQL> ADMINISTER KEY MANAGEMENT SET KEY FORCE KEYSTORE IDENTIFIED BY xxxx WITH BACKUP CONTAINER = ALL ; ADMINISTER KEY MANAGEMENT SET KEY FORCE KEYSTORE IDENTIFIED BY xxxx WITH BACKUP CONTAINER = ALL * ERROR at line 1: ORA-46665: master keys not activated for all PDBs during REKEY I found following in the trace file REKEY: Create Key in PDB 3 resulted in error 46658 *** 2019-02-06T15:27:04.667485+01:00 (CDB$ROOT(1)) REKEY: Activation of Key AdnU5OzNP08Qv1mIyXhP/64AAAAAAAAAAAAAAAAAAAAAAAAAAAAA in PDB 3 resulted in error 28374 REKEY: Keystore needs to be restored from the REKEY backup.Aborting REKEY! Cause: All this hassle started because I accidently deleted the wallet and all wallet backup files too and also forgot the keystore password. There was no way to restore the wallet back. Fortunately in my case the PDB which had encrypted data was supposed to be deco

How to Find VIP of an Oracle RAC Cluster

<<Back to Oracle RAC Main Page How to Find Out VIP of an Oracle RAC Cluster Login clusterware owner (oracle) and execute the below command to find out the VIP hostname used in Oracle RAC $ olsnodes -i node1     node1-vip node2     node2-vip OR $ srvctl config nodeapps -viponly Network 1 exists Subnet IPv4: 10.0.0.0/255.255.0.0/bondeth0, static Subnet IPv6: Ping Targets: Network is enabled Network is individually enabled on nodes: Network is individually disabled on nodes: VIP exists: network number 1, hosting node node1 VIP Name: node1-vip VIP IPv4 Address: 10.0.0.1 VIP IPv6 Address: VIP is enabled. VIP is individually enabled on nodes: VIP is individually disabled on nodes: VIP exists: network number 1, hosting node node2 VIP Name: node2-vip VIP IPv4 Address: 10.0.0.2 VIP IPv6 Address: VIP is enabled. VIP is individually enabled on nodes: VIP is individually disabled on nodes:

How to Power On/off Oracle Exadata Machine

<<Back to Exadata Main Page How to Power On/off Oracle Exadata Machine Oracle Exadata machines can be powered on/off either by pressing the power button on front of the server or by logging in to the ILOM interface. Powering on servers using  button on front of the server The power on sequence is as follows. 1. Start Rack, including switches  Note:- Ensure the switches have had power applied for a few minutes to complete power on  configuration before starting Exadata Storage Servers 2.Start Exadata Storage Servers  Note:- Ensure all Exadata Storage Servers complete the boot process before starting the   database servers 3. Start Database Servers Powering On Servers Remotely using ILOM The ILOM can be accessed using the Web console, the command-line interface (CLI), IPMI, or SNMP. For example, to apply power to server dm01cel01 using IPMI, where dm01cel01-ilom is the host name of the ILOM for the server to be powered on, run the

How to Attach to a Datapump Job and Check Status of Export or Import

<<Back to Oracle DATAPUMP Main Page How to check the progress of  export or import Jobs You can attach to the export/import  job using ATTACH parameter of oracle datapump utility. Once you are attached to the job you check its status by typing STATUS command. Let us see how Step1>  Find the Export/Import Job Name You can find the datapump job information from  DBA_DATAPUMP_JOBS or  USER_DATAPUMP_JOBS view. SQL> SELECT OWNER_NAME,JOB_NAME,OPERATION,JOB_MODE,STATE from DBA_DATAPUMP_JOBS; OWNER_NAME JOB_NAME                       OPERATION            JOB_MODE   STATE ---------- ------------------------------ -------------------- ---------- ---------- SYSTEM     SYS_EXPORT_FULL_02             EXPORT               FULL       EXECUTING OR You can also find the job name for export/import in logfile in beginning itself. Step2>Attach to the Job and check status One you get the Export/Import Job Name attach the job and check its status. You can attach or det

How to Create Pfile from Spfile and Vice Versa

<<Back to DB Administration Main Page There are instances when a DBA need to start the database using pfile, for example to trouble an instance startup error or to validate init file post parameter changes etc. In such situations you can create a pfile from spfile and once you are done with your changes you can create spfile from updated/modified pfile to start the database. How to Create Pfile from Spfile As sysdba execute following command  SQL> create pfile='/tmp/initOrcl.ora' from spfile; How to Create SPfile from Pfile As sysdba execute following command  SQL> create spfile from  pfile='/tmp/initOrcl.ora'; You can also create the pfile directly from memory How to Create Pfile from Memory As sysdba execute following command  SQL> create  pfile='/tmp/initOrcl.ora' from memory;

How to export only data or only metadata using expdp

<<Back to Oracle DATAPUMP Main Page CONTENT parameter of expdp let you select whether you want to export only data or only metadata or both Default : ALL Syntax and Description CONTENT=[ALL | DATA_ONLY | METADATA_ONLY] DATA_ONLY exports only table row data; no database object definitions are exported. METADATA_ONLY exports only database object definitions; no table row data is exported. Exporting metadata only  $ cat exp_full_pdb01.par directory=dump dumpfile=EXP_PDB01_FULL%U.dmp logfile=EXP_PDB01_FULL.log full=y CONTENT=METADATA_ONLY $ expdp system@PDB01 parfile=exp_full_pdb01.par Exporting data only directory=dump dumpfile=EXP_PDB01_FULL%U.dmp logfile=EXP_PDB01_FULL.log full=y CONTENT=DATA_ONLY $ expdp system@PDB01 parfile=exp_full_pdb01.par

Step by Step How to Configure Software Keystore/ Oracle Wallet

<<Back to Oracle DB Security Main Page How to Configure a Software Keystore A software keystore is a container that stores the Transparent Data Encryption master encryption key. To configure a software Keystore follow the steps below. Step 1: Set the Keystore Location in the sqlnet.ora File You can store the software keystore (also known as wallet) in file system or in ASM Diskgroup. Does not matter where you want to store the keystore you have modify the sqlnet.ora and make an entry accordingly Make an entry as shown below in $ORACLE_HOME/network/admin/sqlnet.ora file Example1: If Storing the Wallet in ASM ENCRYPTION_WALLET_LOCATION=  (SOURCE=(METHOD=FILE)    (METHOD_DATA=     (DIRECTORY= +DG_TST_DATA/$ORACLE_SID/wallet )    )  )   Example2: If Storing the Wallet in File System ENCRYPTION_WALLET_LOCATION=  (SOURCE=(METHOD=FILE)    (METHOD_DATA=     (DIRECTORY= /u01/dbatst1/admin/wallet/$ORACLE_SID)    )  ) NOTE: Ensure that the path you entered in  DIREC

ORA-15040: diskgroup is incomplete

<<Back to Oracle ASM Main Page ORA-15040: diskgroup is incomplete SQL> startup ORA-00099: warning: no parameter file specified for ASM instance ASM instance started Total System Global Area 1140850688 bytes Fixed Size                  8629704 bytes Variable Size            1107055160 bytes ASM Cache                  25165824 bytes ORA-15110: no diskgroups mounted Reason: The reason of this error is simply the ASM is not able to find the some or all the disks. Solution: Investigate and make all the disks available to ASM to mount the disk group. Make sure the disks has proper permissions. If you are using AFD check following services are online oracleacfs oracleadvm oracleoks  oracleafd   Source of Problem : Issue started after restart of the server After restarting the server when I tried to start the ASM instance its started throwing error.  ORA-15110: no diskgroups mounted Investigation in my Case Step1> ASM Logfile Scanning  Looked i

ORA-28365: wallet is not open while starting the database

<<Back to DB Administration Main Page ORA-28365: wallet is not open Encountered while Starting the Database $ srvctl start instance -d CDB001 -i CDB0011 PRCR-1013 : Failed to start resource ora.cdb001.db PRCR-1064 : Failed to start resource ora.cdb001.db on node node1.oracle.com CRS-5017: The resource action "ora.cdb001.db start" encountered the following error: ORA-28365: wallet is not open . For details refer to "(:CLSN00107:)" in "/u01/app/oracle/diag/crs/node1.oracle.com/crs/trace/crsd_oraagent_oracle.trc". CRS-2674: Start of 'ora.cdb001.db' on 'node1.oracle.com' failed Solution : Start the instance in mount mode SQL> startup mount; ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size                  2926472 bytes Variable Size            1392511096 bytes Database Buffers          738197504 bytes Redo Buffers               13848576 bytes Database mounted. Check Wallet status set linesiz