oracle -arch-backup and recovery

Upload: alokmishra4533

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    1/59

    1

    ORACLE SYSTEM

    ADMINISTRATION

    TRAININGFOR

    LEVEL 2TECHNICAL SUPPORT

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    2/59

    2

    Course Overview

    The environment

    The architecture

    An Oracle Instance

    An Oracle Database

    How to startup and shutdown the instance Database creation

    Database access

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    3/59

    3

    Course Overview

    Archive and noarchivelog log mode

    Database Backup

    Database Recovery

    Import and export utilities

    Parallel server Questions and Answers

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    4/59

    4

    Environment Variables

    ORACLE_HOME

    ORACLE_SID

    ORACLE_BASE (OPTIONAL)

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    5/59

    5

    Product directory

    /oracle//product /rdbms

    /admin /sql scripts for data dictionary

    /bin

    /oracle, oracle0, exp , imp, svrmgrl, sqlplus

    /dbs /init.ora, config.ora

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    6/59

    6

    Architecture

    The three main components are:

    Background processes

    Memory structure

    Files

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    7/597

    Background Processes

    The required processes are:

    SMON

    PMON

    DBWR

    LGWR

    Other processes are CKPT, ARCH, RECO

    Generally, a server process is started for

    each user process (connection)

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    8/598

    Memory Structure

    This is known as the System Global Area or

    SGA

    large Pool

    The three main components are:

    Database Buffer cache

    Shared pool/shared SQL area

    Library Cache

    Dictionary Cache

    Redo Log buffer cache

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    9/599

    Files

    Parameter files (init.ora & config.ora)

    Controlfiles

    Datafiles

    Redo log files

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    10/5910

    Parameter Files

    The init.ora file

    The config.ora file

    They contain configuration information

    The default location for the init.ora is in the

    /oracle//product/dbs directory

    The config.ora file contains instance

    specific configuration

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    11/5911

    Controlfiles

    The control files contains information about

    the physical structure and status of the

    database

    It is a binary file and cannot be viewed

    using a text editor

    It is critical to the operation of the databaseand must be mirrored to prevent losses due

    to media failure

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    12/5912

    Data Files

    Datafiles are storage area for information

    Can be either a flat file or a raw partition

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    13/5913

    Redo Log Files

    The files contain records of transactions

    which modify the data in the database

    Each database must have at least two redo

    log groups and at least one member in each

    group

    Is often mirrored for safety reasons

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    14/59

    14

    An Oracle Instance

    An instance is made up of the SGA and the

    background processes

    An instance can be started without opening

    a database

    It is a framework under which the database

    operates

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    15/59

    15

    Starting An Instance

    Server manager is used to start an instance

    The command to start server manager is

    svrmgrl (server manager line mode)

    The user connects as internal before

    starting the instance if she was

    authenticated at the OS level.

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    16/59

    16

    Starting An Instance

    The instance is brought up using the startup

    command

    There are three stages in the startup process:

    startup nomount

    startup mount

    startup open

    startup force

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    17/59

    17

    Shutting Down An Instance

    This is accomplished through the shutdown

    command

    The shutdown command accepts threeparameters:

    shutdown normal

    immediate

    abort

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    18/59

    18

    Showing Server Processes

    Once an instance is started, use the ps -ef

    or ps -ax command to display all the

    background processes for that instance Each background process name shown in

    the ps output includes the instance name

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    19/59

    19

    Accessing An Instance

    Each person is given a login to the instance

    System administrator usually does connect

    internal or connect / as sysdba

    System/manager is the login and password

    used for system maintenance activities

    Having a login does not mean that the user

    has privileges to perform any operations in

    the database

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    20/59

    20

    An Oracle Database

    A database is composed of one or more

    control files, data files and redo log files

    Logically, a database is made up of one ormore tablespaces

    Typical tablespaces in a database are

    system, user, tool, rollback, temporary

    A database or a tablespace can be online or

    offline

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    21/59

    21

    Database Creation

    There is one database per instance but

    multiple instances can access the same

    physical database (Oracle Parallel Server) The database must have at least one control

    file, one data file and two redo log groups

    The init.ora file must be edited to includethe name of the database, the block size and

    other appropriate parameters

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    22/59

    22

    Creating A Database

    Create database command

    This command must be executed in the

    nomount stage

    A control file is created during this process

    and it needs to be mirrored

    When the database is first created, only the

    SYSTEM tablespace exists

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    23/59

    23

    Database File Synchronization

    An Oracle database cannot be opened

    unless all data, control and redo log files are

    synchronized Synchronization is based on the current

    redo log sequence number ? SCN numbers

    The exception is read-only tablespace

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    24/59

    24

    Database Access

    Connecting as internal or sysdba is required

    for structural changes

    Two logins (sys and system) are reservedfor system maintenance activities

    When creating a user, a profile indicating

    the resource assigned to the user must bespecified

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    25/59

    25

    Database Access

    There are two types of privileges: system

    and object

    System privileges allow users to performoperations that affect the structure of the

    database

    Object privileges allow users to performspecific actions on specific objects

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    26/59

    26

    Roles & Permissions

    To simplify the granting of privileges, roles

    are created

    A role can be assigned to multiple users

    System and object privileges can be granted

    to the role

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    27/59

    27

    Trace File and Alert File

    If an error occurs while the Oracle instance

    is running, messages are sent to the alert file

    If an internal error is detected by a server orbackground process, the information is sent

    to a trace file

    The BACKGROUND_DUMP_DESTparameter in the init.ora file indicates the

    location of both the alert and trace files

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    28/59

    28

    Transaction and Redo Log

    When data modification activities occur, the

    changes are first written to the redo log

    The changes are reflected in the data filesonly if the transaction has been committed

    A database must have at least two redo log

    groups

    Oracle writes to the redo log groups in a

    circular fashion

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    29/59

    29

    Noarchivelog Mode

    During the database creation process, the

    default mode is noarchivelog unless the

    archivelog parameter is explicitly specified This means that when Oracle has filled up

    all the redo log groups, it will reuse them by

    writing over existing information

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    30/59

    30

    Archivelog Mode

    In the archivelog mode, the redo log files

    are not reused until the ARCH process has

    made a copy of the content of file The archived log files will be used for

    recovery from media failure

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    31/59

    31

    Archivelog Mode

    The archivelog mode is enabled by issuing

    the alter database archivelog command

    Archiving redo logs can be automatic ormanual

    To start archiving the redo log manually,

    issue the alter system archive log start (thistell the ARCH process to begin archiving)

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    32/59

    32

    Archivelog Mode

    For automatic archiving, change the

    following init.ora parameters:

    LOG_ARCHIVE_START = true

    LOG_ARCHIVE_FORMAT = filename and

    extension

    LOG_ARCHIVE_DEST = directory path andfile prefix

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    33/59

    33

    Database Backup

    When developing a Backup strategy for a

    database, the following items need to be

    considered: the tolerance level for loss of data

    the amount of time available for backups

    the mode of the database

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    34/59

    34

    Database Backup

    In the noarchivelog mode, the database

    must be offline prior to taking backup (this

    is known as cold backups) In the archivelog mode, the database can be

    online during the backup (this is known as

    hot backups)

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    35/59

    35

    Database Backup

    The scope of a backup can be full or partial

    An offline (cold) backup is always a full

    database backup

    An online (hot) backup can be full or partial

    In a partial hot backup, only selected

    tablespaces are backed up or anything less

    than a full database backup

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    36/59

    36

    Offline (Cold) Backup

    Steps required are:

    Query the database to find out the data, control

    and redo log files to be backed up Shutdown the instance using shutdown normal

    or immediate

    Use operating system commands to make acopy of all the files

    The parameter files should also be backed up

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    37/59

    37

    Offline (Cold) Backup

    The main advantage of cold backups is ease

    of operation

    The main disadvantages are: Database unavailable during backup

    Possible loss of data

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    38/59

    38

    Online (Hot) Backup

    Steps required are:

    Query the database to find out the tablespaces

    to be backed up Tablespaces are put into the backup mode using

    the Alter tablespace begin

    backup; command

    Use operating system commands to make a

    copy of all the datafiles for each tablespace

    Take the tablespace out of the backup mode

    using the alter tablespace

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    39/59

    39

    Online (Hot) Backup

    Advantages of hot backups are:

    Prevent loss of data

    Database available during backup

    Allow more flexible recovery options

    The main disadvantage is that recovery

    from this type of backup may becomplicated

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    40/59

    40

    Control File Backup

    The command to back up the control file is:

    alter database backup controlfile to ;

    alter database backup controlfile to/db2/oracle/KENL/backup/control01.ctl

    The control file can be dumped in the text

    format as follow: alter database backup controlfile to trace;

    Recommended after any changes to the

    database structure

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    41/59

    41

    Backup of Read-Only Tablespace

    Data files related to the read-only

    tablespace need to be backed up only once

    The status of these tablespaces isunimportant

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    42/59

    42

    Database Recovery

    Recovery strategies depend on the cause of

    failure and the mode of the database

    For instance failure or crash recovery,Oracle will automatically perform instance

    recovery during the next startup -SMON

    For media failure, the affected files must berestored manually and the database needs to

    be recovered

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    43/59

    43

    Database Recovery

    For databases in noarchivelog mode,

    complete database recovery is the only

    option For databases in archivelog mode, both

    complete and incomplete recoveries are

    permitted

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    44/59

    44

    Recovery Process

    There are three phases in the recovery

    process:

    Identified what needs to be restored File restoration

    Application of redo and archive logs

    All transactions are applied to the databasethen uncommitted ones are rolled back to

    bring the database to a consistent state

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    45/59

    45

    Recovery Process

    Oracle will prompt the user to confirm

    before applying each archived log file

    This process can be automated by settingautorecovery on before recovering the

    database or enter AUTO at the prompt

    If the archived log files are not in thedefault location, specify the new location

    and filenames when prompted

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    46/59

    46

    Recovery from Cold Backups

    Steps required are:

    Replace all existing data, control and redo log

    files with those from the backup Replace the parameter files if necessary

    Start the instance

    The entire database will be brought back tothe time of the backup

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    47/59

    47

    Recovery from Hot Backups

    Recovery from a hot backup can be

    complete or incomplete

    Complete recovery is a recovery of thedatabase/tablespace/data file to the point of

    failure

    Incomplete recovery happens when thedatabase is not recovered to the point of

    failure

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    48/59

    48

    Complete Recovery

    Tablespaces and datafiles cannot be

    recovered to a point in time in the past

    while leaving the rest of the database in thecurrent time

    Tablespaces and data files must be taken

    offline before performing the recovery

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    49/59

    49

    Incomplete Recovery

    There are four types of incomplete

    recovery: time based, change based, cancel

    based and using a backup control file In order to perform incomplete recovery,

    the database has to be in archivelog mode

    The database must be opened with theresetlogs parameter

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    50/59

    50

    Point-In-Time Recovery

    This is done using the recover database

    command with the until clause

    The user can specify a particular time or aspecific SCN number

    The database must be opened with the

    resetlogs option and all previous backupsbecome invalid

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    51/59

    51

    Recovering Control File

    If there are good copies of the control file,

    shutdown the instance and copy the good

    one over the damaged one and restart theinstance

    Otherwise, recover the control file from the

    backup

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    52/59

    52

    Recreating the Control File

    Required if all the control files are damaged

    and there is no good backup or if the

    database name changes Use the create control file command

    The trace dump of the control file can be

    edited and used to create a new one alter database backup controlfile to trace;

    create a trace file in udump (location specified

    in your init.ora) destination

    R i R d O l

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    53/59

    53

    Recovering Read-Only

    Tablespace

    Read-only tablespaces are ignored during

    database recovery

    However, if the data files for this type oftablespace become damaged, replace them

    with those from the backup

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    54/59

    54

    Import and Export

    Import and export are utilities used to

    perform logical backup and recovery of the

    database or individual objects The information is written to operating

    system files

    export file has .dmp extention by default The export files can be used to move data

    between machines and versions of Oracle

    even with full exp, all the objects owned by

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    55/59

    55

    Export

    Scope of the export can be the whole

    database, the tables or objects, or objects

    belonged to a user or schema There are three types of export: complete,

    incremental and cumulative

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    56/59

    56

    Import

    The import utility can only import files

    created by the export utility

    There are three types of information thatcan be imported: table definition, table data

    and table constraints

    The order in which objects are imported isimportant (referential integrity)

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    57/59

    57

    Oracle Parallel Server

    The Oracle server can run in either the

    exclusive or shared (parallel) mode

    In the shared mode, one or more instancesof the server access a single physical

    database

    Each instance has its own SID, SGA,parameter file, background processes and

    redo log files

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    58/59

    58

    Oracle Parallel Server

    All instances share the same data files and

    control files

    Additional background processes, LCKn,are required to coordinate the locking of

    shared resources

  • 8/13/2019 Oracle -Arch-Backup and Recovery

    59/59

    Questions and Answers