OCA 01 - Exploring the Database Architecture

download OCA 01 - Exploring the Database Architecture

of 39

Transcript of OCA 01 - Exploring the Database Architecture

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    1/39

    01 - Exploring the Database

    Architecture

    By Muhammad Asghar Khan

    Reference:Apress RMAN Recipes for Oracle Database 11g by Darl Kuhn, Sam Alapati,

    and Arup Nanda

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    2/39

    Agenda

    http://asghars.blogspot.com

    Single-Instance Database Architecture Oracle Instance

    Oracle Database

    Distributed Systems Architectures

    Real Application Clusters

    Streams

    Data Guard

    1/1

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    3/39

    Single-Instance Database Architecture

    http://asghars.blogspot.com

    Oracle database consists of two entities: Oracle Instance

    A set of processes (Unix) or single threaded process

    (Windows) and shared memory area or System Global

    Area (SGA)

    Oracle Database

    A collection of physical OS files or disks in case of ASM

    or RAW partitions

    Database may be mounted & opened by many

    instances, while an instance may mount & open a

    single database in its entire lifetime

    1/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    4/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    Oracle Instance

    System/Shared Global Area

    SGA allocates & de-allocates space in units of granules (4MB,8MB or 16MB)

    SGA memory is declared by the SGA_TARGET initialization

    parameter

    SGA contains:

    Required

    Database Buffer Cache: Buffer Pools etc.

    Redo Log Buffer Cache: Redo entries

    Shared Pool: Library Cache, Dictionary Cache

    Fixed SGA: Bootstrap of SGA

    Optional

    Large Pool: Shared Server Session, RMAN backup/restore

    Java Pool: Java Code

    Streams Pool: Queue, Messages

    2/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    5/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    Database Buffer Cache

    The data blocks containing the data of interest are firstcopied into the database buffer cache

    Changes (INSERT,UPDATE, DELETE) are applied to copiesof the data blocks in the database buffer cache

    When querying data the rows of interest are copies intothe database buffer cache; the relevant rows are thentransferred into the sessions PGA for further processing

    Blocks containing data that is frequently accessed will

    be in the database buffer cache, therefore minimizingthe need for disk I/O

    A well-tuned database buffer cache can result in acache hit ratio well over 90 percent

    3/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    6/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    The buffer will become dirty when the block in it is updated,

    at which point the buffer will be clean again The write to the datafiles is done by the database writer

    background process

    The size of the database buffer cache is critical forperformance

    An undersized cache will result in excessive disk activity An oversized cache is not so bad but can cause problems;

    like startup of an instance may be slower or OS is having toswap pages of virtual memory

    Determining the optimal size of the database buffer cache is

    application specific and a matter of performance tuning Redo Log Buffer Cache

    Short-term staging area for change vectors before they arewritten to the redo log on disk

    4/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    7/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    A change vector is a modification applied to something

    Whenever a data block is changed, the change vectors applied tothe block are written out to the redo log, from where they can beextracted and applied to datafile backups if it is ever necessary torestore a datafile

    One write of the log buffer to disk may be a batch of many changevectors from many transactions

    The writes are done by the log writer background process (LGWR)

    Write occurs in real time, and while it is in progress, the sessionthat issued the COMMIT will hang

    It is a circular buffer

    The commit-complete message is not returned to the session until

    the data blocks in the cache have been changed (which meansthat the transaction has been completed) and the change vectorshave been written to the redo log on disk (and therefore thetransaction could be recovered if necessary)

    The size of log buffer cache is determined by the Oracle server andis based on the number of CPUs on the server node

    5/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    8/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    You cannot do DML faster than the LGWR can flush the

    change vectors to the online redo log files If redo generation is the limiting factor in a databases

    performance, the only option is to go to RAC

    Shared Pool Memory in the shared pool is allocated according to an LRU

    (least recently used) algorithm It is divided into dozens of substructures, all of which are

    managed internally by the Oracle server

    Four of the shared pool components are: Library Cache: Stores recently executed code, in its parsed form. In a

    well-designed application, it is possible that statements may be parsedonce and executed millions of times

    Data Dictionary Cache/Row Cache: Stores recently used objectdefinitions: descriptions of tables, indexes, users, and other metadatadefinitions

    6/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    9/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    PL/SQL Area: Stored PL/SQL objects are stored in PL/SQL area.

    Anonymous PL/SQL cannot be cached

    SQL Query and PL/SQL Function Result Cache: The result cache

    is a release 11g new feature. A result cache lets the Oracle

    server store the results of frequent queries or PL/SQL in

    memory. By default, use of the SQL query and PL/SQL functionresult cache is disabled

    Fixed SGA

    Contains a set of variables that point to other

    components of the SGA Acts like a bootstrap section of the SGA

    It is fixed for each release of Oracle and cant be altered

    7/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    10/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    Large Pool

    Major use of the large pool is by shared server processes

    Large pool may also be used by the Recovery Manager

    Java Pool

    Only required if your application is going to run Java-storedprocedures within the database

    It is used for the heap space needed to instantiate the Java

    objects

    Note that Java code is not cached in the Java pool: it iscached in the shared pool

    Optimal size of the Java pool is dependent on the Java

    application

    8/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    11/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    Streams Pool Used by Oracle Streams

    In streams, change vectors from the redo log are used

    to reconstruct the statements that were executed

    These statements are executed at the remote database Stream pool is used for these operations

    9/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    12/39

    Single-Instance Database Architecture(Oracle Instance Memory Structures)

    http://asghars.blogspot.com

    EXERCISE 1-1: Investigate the Memory Structures ofthe Instance

    1. Connect as user SYSTEM

    1. Show the sizes of the SGA components that can bedynamically resized

    10/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    13/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Processes User Processes

    Application program or Oracle tool creates a user process on

    the server

    Run the application or Oracle tool code

    Server Processes/ Foreground Processes

    Services an individual user process

    With each server process is associated a private non-shareable

    memory, called the program global area (PGA)

    Server process can be configured as dedicated or shared server

    In dedicated mode; listener spawn a new dedicated server

    process for each user process

    11/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    14/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    In shared mode; listener handover the connection to dispatcher

    which connects the user process to the shared server process

    Background Processes

    An Oracle instance can have many background processes

    Each Oracle background process is in charge of a separate task

    Some of the BG processes can be:

    Database Writer (DBWn)

    Log Writer (LGWR)

    Checkpoint (CKPT)

    System Monitor (SMON)

    Process Monitor (PMON)

    Manageability Monitor (MMON)

    Memory Manager (MMAN)

    Archiver (ARCn)

    Recoverer (RECO)

    12/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    15/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Database Writer (DBWn) DBWn writes dirty buffers from the database buffer cache to the

    datafiles

    It is possible for an instance to have several database writers (up to amaximum of twenty), which will be called DBW0, DBW1, and so on

    The default number is one database writer per eight CPUs

    No free buffers, too many dirty buffers, a three-second timeout, or a

    checkpoint will cause the DBW to write A free buffer is a buffer that is neither dirty (updated, and not yet

    written back to disk) nor pinned (a pinned buffer is one that is beingused by another session at that very moment)

    DBW does absolutely nothing when a transaction is committed,however; when a checkpoint occurs, all dirty buffers are written

    During a checkpoint, disk I/O rates will hit the roof, CPU usage may goto 100 percent, end user sessions will experience degradedperformance, therefore; it must be avoided

    Partial checkpoints occur only when a datafile or tablespace is takenoffline; when a tablespace is put into backup mode; when a tablespaceis made read only

    13/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    16/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Log Writer (LGWR) LGWR writes (flushes) the contents of the log buffer to the online log files When a session makes any change to blocks in the database buffer cache,

    before it applies the change to the block it writes out the change vectorthat it is about to apply to the log buffer

    When a session issues a COMMIT, the LGWR writes in real time: thesession hangs, while LGWR writes the buffer to disk

    It is impossible to do DML faster than LGWR can write the change vectorsto disk

    LGWR flush the log buffer to disk; on COMMIT, when the buffer is one-third full, just before DBWn writes

    As DBWn writes after three-second timeout, therefor, LGWR will alwayswrite before three-second timout

    It is necessary to know that it is perfectly possible for DBWn to write anuncommitted transaction to the datafiles, as long as the undo data isavailable

    Undo data also generates change vectors: as these will be in the redo logfiles before the datafiles are updated which can be used to roll back atransaction

    14/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    17/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Checkpoint (CKPT) Checkpoint instructs DBWn to write out dirty buffers at a constant

    rate, so that there is always a predictable gap between DBWn (whichwrites blocks on a lazy algorithm) and LGWR (which writes changevectors in near real time)

    This is also called incremental checkpoints

    The current checkpoint position, also known as the RBA (the redo byte

    address), is the point in the redo stream at which recovery must beginin the event of an instance crash

    CKPT continually updates the controlfile with the current checkpointposition

    System Monitor (SMON) SMON mounts a database by locating and validating the database

    controlfile It then opens a database by locating and validating all the datafiles

    and online log files

    Once the database is opened and in use, SMON is responsible forvarious housekeeping tasks, such as collating free space in datafiles

    15/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    18/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Process Monitor (PMON) If the session (user process) is terminated in a disorderly manner

    (perhaps because the users PC is rebooted), then the session will beleft in a state that must be cleared up

    If a session has terminated abnormally, PMON will destroy the serverprocess, return its PGA memory to the operating systems freememory pool, and roll back any incomplete transaction that may havebeen in progress

    Manageability Monitor (MMON) MMON regularly (by default, every hour) captures statistics

    (snapshots) from the SGA and writes them to the data dictionary (keptfor only eight days)

    Every time MMON takes a snapshot, it also launches the AutomaticDatabase Diagnostic Monitor (ADDM)

    The ADDM is a tool that analyses database activity using an expertsystem developed over many years by many DBAs

    16/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    19/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    MMON also continuously monitors the database and the instance to

    check whether any alerts should be raised Memory Manager (MMAN) It enables the automatic management of memory allocations

    The DBA need to set an overall target for memory usage, and MMANwill observe the demand for PGA memory and SGA memory, andallocate memory to sessions and to SGA structures as needed

    Archiver (ARCn) The process and purpose of launching ARCn to create archive log files

    There can be from one to thirty, named ARC0, ARC1, and so on

    In order to preserve a complete history of all changes applied to thedata, the online log files must be copied as they are filled and beforethey are reused, the ARCn is responsible for doing this

    Most production transactional databases will run in archive log mode,meaning that ARCn is started automatically and that LGWR is notpermitted to overwrite an online log file until ARCn has successfullyarchived it to an archive log file

    If archiving fails, the database will eventually hang

    17/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    20/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Recoverer (RECO)

    A distributed transaction is a transaction that involves updates

    to two or more databases

    Distributed transactions are designed by programmers and

    operate through database links

    Distributed transactions require a two-phase commit

    If anything goes wrong anywhere between the two phases,

    RECO takes action to cancel the commit and roll back the work

    in all databases

    EXERCISE 1-2: Investigate the Processes Running inYour Instance

    1. Determine what processes are running

    18/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    21/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    19/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    22/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    2. Demonstrate the launching of server processes as

    sessions are made

    1. Count the number of processes running that have the string

    oracle in their name; this will include all the session server

    processes (and possibly a few others)

    1. Launch a SQL*Plus session, and rerun the preceding

    command: use the host command to launch an

    operating shell from within the SQL*Plus session

    20/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    23/39

    Single-Instance Database Architecture(Oracle Instance - Processes)

    http://asghars.blogspot.com

    Observe how the number of processes changes from 81

    to 82 : the difference is the launching and terminating of

    the server process supporting the SQL*Plus session

    21/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    24/39

    Single-Instance Database Architecture(Oracle Database)

    http://asghars.blogspot.com

    Oracle Database

    As per the RDBMS standard the Oracle architectureguarantees abstraction of the logical from the physical

    The relationship between physical and logical structures ismaintained and documented in the data dictionary ,

    which contains metadata describing the whole database Physical Structure

    Physical structures are visible to the system administrators

    Data Files

    Control Files

    Online Redo Log Files Archive Log Files

    Parameter Files

    Trace Files

    22/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    25/39

    Single-Instance Database Architecture(Oracle Database)

    http://asghars.blogspot.com

    Alert Files

    Password Files

    Logical Structure

    Logical structures (segments) are visible to the

    programmers Tablespaces

    Segments

    Extents

    Blocks

    23/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    26/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    Data Files Datafiles are the repository for data Oracle database requires at least two data files

    At the operating system level, a datafile consists of a numberof operating system blocks

    Internally, datafiles are formatted into Oracle blocks

    The block size is a matter for tuning and can range (withlimits depending on the platform) from 2 KB up to 64 KB

    Many DBAs like to match the operating system block size tothe Oracle block size. For performance reasons, theoperating system blocks should never be larger than the

    Oracle blocks Within a block, there is a header section and a data area,

    and possibly some free space

    24/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    27/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    The header section contains information such as the row

    directory , which lists the location within the data area of

    the rows in the block (if the block is being used for a table

    segment) and also row locking information if there is a

    transaction working on the rows in the block

    Server processes read from the datafiles; DBWn writes todatafiles

    Control Files

    It contains pointers to the rest of the database:

    Locations of the online redo log files and of the datafiles, and of themore recent archive log files if the database is in archive log mode

    It also stores information required to maintain database integrity:

    various critical sequence numbers and timestamps

    25/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    28/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    Every database has one controlfile, but a good DBA will

    always create multiple copies of the controlfile so that if one

    copy is damaged, the database itself will survive

    All organizations should have a DBA standards handbook,

    which will state something like all production databases will

    have three copies of the controlfile Online Redo Log Files

    It stores a continuous chain in chronological order of every

    change vector applied to the database

    If a datafile is damaged, these change vectors can be appliedto datafile backups to redo the work, bringing them forward

    in time until the moment that the damage occurred

    26/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    29/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    Every database has at least two online redo log files,

    but as with the controlfile, a good DBA creates multiplecopies of each online redo log file

    The online redo log consists of groups of online redo logfiles, each file being known as a member

    An Oracle database requires at least two groups of atleast one member each to function

    The size and number of your log file groups are a matterof tuning

    Archive Log Files When an online redo log file fills, the ARCn process

    copies it out of the database to an archive redo log file

    27/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    30/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    Parameter Files

    When an Oracle instance is started, the SGA structuresbuild in memory and the background processes startaccording to settings in the parameter file

    This is the only file that needs to exist in order to start

    an instance There are several hundred parameters, but only one is

    required: the DB_NAME parameter

    Alert Log and Trace Files

    The alert log is a continuous stream of messagesregarding certain critical operations affecting theinstance and the database

    28/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    31/39

    Single-Instance Database Architecture(Oracle Database - Physical)

    http://asghars.blogspot.com

    Trace files are generated by background processes

    when they detect error conditions, and sometimes to

    report certain actions

    Password Files

    In this file you specify the names of database users whohave been granted the SYSDBA or SYSOPER privilages

    29/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    32/39

    Single-Instance Database Architecture(Oracle Database-Logical)

    http://asghars.blogspot.com

    Tablespaces

    Oracle abstracts the logical storage from the physical storage by means ofthe tablespace

    A tablespace is logically a collection of one or more segments, andphysically a collection of one or more datafiles

    Each database has five default tablespaces: system, sysaux, undo,temporary and default tablespace

    Segments Oracle uses the term segment to describe any structure that contains

    data like table

    Segment can be of type data, index or temporary

    Extents

    An extent is a series of blocks that are consecutively numbered within adatafile, and segments will grow by adding new extents to them

    These extents need not be adjacent to each other, or even in the samedatafile; they can come from any datafile that is part of the tablespacewithin which the segment resides

    30/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    33/39

    Single-Instance Database Architecture(Oracle Database-Logical)

    http://asghars.blogspot.com

    Blocks

    Oracle block is the smallest unit of space allocation in

    Oracle

    Internally, datafiles are formatted into Oracle blocks

    The block size is a matter for tuning and can range (withlimits depending on the platform) from 2 KB up to 64

    KB

    Many DBAs like to match the operating system block

    size to the Oracle block size. For performance reasons,the operating system blocks should never be larger than

    the Oracle blocks

    31/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    34/39

    Single-Instance Database Architecture(Oracle Database)

    http://asghars.blogspot.com

    EXERCISE 1-3: Investigate the Storage Structures in

    Your Database

    1. Create a table without nominating a tablespace

    2. Identify the tablespace in which the table resides,the size of the extent, the file number the extent is

    in, and which block of the file the extent starts at

    32/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    35/39

    Single-Instance Database Architecture(Oracle Database)

    http://asghars.blogspot.com

    3. Identify the file by name

    4. Work out precisely where in the file the extent is, interms of how many bytes into the file it begins

    33/33

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    36/39

    Distributed Systems Architectures

    http://asghars.blogspot.com

    In a distributed environment, there are variouspossibilities for grouping instances and databases:

    Real Application Clusters (RAC), where multipleinstances open one database

    Streams, where multiple Oracle servers propagatetransactions between each other

    Data Guard, where a primary database updates astandby database

    Real Application Clusters RAC database can be configured for 100 percent

    uptime

    1/4

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    37/39

    Distributed Systems Architectures

    http://asghars.blogspot.com

    Sessions against the failed instance can bereestablished against a surviving instance without theend user being aware of any disruption

    Streams

    There are various circumstances that make itdesirable to transfer data from one database toanother

    Streams can also be used for fault tolerance

    Data Guard A physical standby is byte-for-byte identical with the

    primary, for the purpose of zero data loss

    2/4

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    38/39

    Distributed Systems Architectures

    http://asghars.blogspot.com

    A logical standby contains the same data as the

    primary, but possibly with different data structures

    EXERCISE 1-4: Database Is Single Instance or Part of

    a Distributed System

    1. Determine if the instance is part of an RAC database

    2. Determine if the database is protected against dataloss by a standby database

    3/4

    4/4

  • 7/29/2019 OCA 01 - Exploring the Database Architecture

    39/39

    Distributed Systems Architectures

    htt // h bl t

    3. Determine if Streams has been configured in the

    database

    This return no rows, which shows Streams has neverbeen configured

    4/4