OCA 04 - Managing the Oracle Instance

download OCA 04 - Managing the Oracle Instance

of 40

Transcript of OCA 04 - Managing the Oracle Instance

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    1/40

    04 - Managing the Oracle Instance

    By Muhammad Asghar Khan

    Reference: OCA Oracle Database 11g - Admin I Exam Guide by John Watson

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    2/40

    Agenda

    http://asghars.blogspot.com

    Components Required for Database Startup

    Starting a Database Control Starting the Database Listener

    Connecting to Database

    Database Startup Database Shutdown

    Setting Database Initialization Parameters

    EXERCISE 4-1: Query and Set Initialization Parameters

    Using the Alert Log and Trace Files EXERCISE 4-2: Use the Alert Log

    Data Dictionary and Dynamic Performance Views

    EXERCISE 4-3: Query Dynamic Performance Views

    1/1

    2

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    3/40

    Components Required for Database Startup

    http://asghars.blogspot.com

    The three components (database instance, databaselistener, and optionally Database Control) have theirown command-line utilities that can be used for startup

    In single instance environment Oracle Corporations

    recommended sequence for starting a database is tostart Database Control, then the database listener, andthen the database

    Starting a Database Control

    Database Control is a tool for managing only onedatabase

    The configuration of Database Control will have beendone at database creation time

    1/5

    3

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    4/40

    Components Required for Database Startup

    http://asghars.blogspot.com

    To start Database Control, use the emctl utility. This willbe located in the ORACLE_HOME/bin directoryemctl start|status|stop dbconsole

    For any of these commands to work, three environment

    variables must be set: PATH, ORACLE_HOME, and

    ORACLE_SID

    Figure shows the startup of Database Control

    2/5

    4

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    5/40

    Components Required for Database Startup

    http://asghars.blogspot.com

    To connect to Database Control, use any reasonably up-to-date browser with URL https://hostname:port/em

    The port number can be find by using the emctl status

    dbconsole command or alternatively, you can look in the

    file ORACLE_HOME/install/portlist.ini

    To see the Database Control logon window the database

    listener and instance must be running

    Starting the Database Listener

    The database listener is a process that monitors a port fordatabase connection requests

    3/5

    5

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    6/40

    Components Required for Database Startup

    http://asghars.blogspot.com

    There are three ways to start the database listener: With the lsnrctl utility

    With Database Control

    As a Windows service (Windows only)

    The lsnrctl utility is in the ORACLE_HOME/bin directory.The key commands are:lsnrctl start|status [listener]

    Where listener is the name of listener

    Figure on next slide shows the startup of default listener

    4/5

    6

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    7/40

    Components Required for Database Startup

    http://asghars.blogspot.com

    5/5

    7

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    8/40

    Connecting to Database

    http://asghars.blogspot.com

    An instance may be started and stopped

    A database is mounted and opened, and thendismounted and closed

    This can be done from either SQL*Plus or through

    Database Control Ordinary users cannot start up or shut down a database

    This is because ordinary users are authenticated againstdata dictionary which cannot be read until the database

    is open

    You must therefore connect with some form of externalauthentication: i.e by OS or external password file

    1/5

    8

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    9/40

    Connecting to Database

    http://asghars.blogspot.com

    The syntax of the CONNECT command tells Oraclewhat type of authentication you wish to use: the

    default of data dictionary authentication, password

    file authentication, or operating system

    authentication

    These are the possibilities:connect user/pass[@connect_alias]

    connect user/pass[@connect_alias] as sysdba

    connect user/pass[@connect_alias] as sysoper

    connect / as sysdba

    connect / as sysoper

    2/5

    9

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    10/40

    Connecting to Database

    http://asghars.blogspot.com

    In these examples;

    The connect_alias will be resolved to a connect string, thisis necessary if the connection is to be made across anetwork

    The first example is normal, data dictionary,

    authentication The second two examples instruct Oracle to go to the

    external password file to validate the username/passwordcombination

    The last two examples use operating system

    authentication; Oracle will go to the host operatingsystem and check whether the operating system userrunning SQL*Plus is a member of the operating systemgroup that owns the Oracle software

    3/5

    10

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    11/40

    Connecting to Database

    http://asghars.blogspot.com

    Database Control will by default attempt to connectthrough a listener, but it can also use operating systemauthentication

    SYSOPER and SYSDBA are special privileges with

    special capabilities They can only be enabled when users are connecting

    with an external authentication method: eitheroperating system or password file

    You may be wondering what Oracle user you areactually logging on as when you use operating systemauthentication

    4/5

    11

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    12/40

    Connecting to Database

    http://asghars.blogspot.com

    Issue the show user command The SYSDBA privilege logs you on to the instance as user

    SYS

    The SYSOPER privilege connects you as a user PUBLIC

    5/5

    12

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    13/40

    Database Startup

    http://asghars.blogspot.com

    When you start up a database, you create an instanceof that database and you determine the state of the

    database

    When you issue a startup command, Oracle will

    attempt to locate a parameter file

    There are three default filenames. On Unix they are:

    $ORACLE_HOME/dbs/spfileSID.ora

    $ORACLE_HOME/dbs/spfile.ora

    $ORACLE_HOME/dbs/initSID.ora

    Oracle will work its way down the list, using the first file

    it finds and ignoring the rest. If none of them exist, the

    instance will not start

    1/13

    13

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    14/40

    Database Startup

    http://asghars.blogspot.com

    The startup process is staged: whenever you issue astartup command, it will go through these stages:

    SHUTDOWN

    NOMOUNT

    MOUNT

    OPEN

    2/13

    14

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    15/40

    Database Startup

    http://asghars.blogspot.com

    SHUTDOWN State When the database is SHUTDOWN, all files are closed

    and the instance does not exist

    NOMOUNT State

    In NOMOUNT mode, the instance has been built in

    memory (the SGA has been created and the

    background processes started, according to the

    parameter file), but no connection has been made toa database

    3/13

    15

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    16/40

    Database Startup

    http://asghars.blogspot.com

    The startup process with NOMOUNT mode isdescribed graphically in the figure

    Database is started in NOMOUNT

    state during:

    Database Creation

    Re-creation of Control Files

    Backup & Recovery Scenarios

    4/13

    16

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    17/40

    Database Startup

    http://asghars.blogspot.com

    MOUNT State Mounting a database includes :

    Associating database with instance

    Instance locates and reads the control file using

    control_files parameter Obtaining names & statuses of data and online redo log

    fiels by reading the control file

    Database is started in MOUNT state during:

    Renaming data files

    Enabling & disabling online redo log file archiving

    Performing database recovery

    5/13

    17

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    18/40

    Database Startup

    http://asghars.blogspot.com

    The startup process with MOUNT mode is describedgraphically in the figure

    OPEN State

    Opening database includes: Opening data files

    Opening online redo log files

    6/13

    18

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    19/40

    Database Startup

    http://asghars.blogspot.com

    In OPEN state all the data files and online redo logfiles are checked fro consistency, if required the

    SMON perform the instance recovery

    The overall startup process is described graphically

    7/13

    19

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    20/40

    Database Startup

    http://asghars.blogspot.com

    Altering database states Mount the database

    Open the database

    8/13

    20

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    21/40

    Database Shutdown

    http://asghars.blogspot.com

    Shutdown require either a SYSDBA or a SYSOPERconnection

    Following are the different shutdown modes:

    NORMAL

    TRANSACTIONAL IMMEDIATE

    ABORT

    NORMAL

    In normal shutdown, no new connection is allowed andthe database will wait for all currently connected users todisconnect

    9/13

    21

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    22/40

    Database Shutdown

    http://asghars.blogspot.com

    Typically, a normal shutdown is useless: there is always

    someone logged on, even if it is only Database Control

    itself

    TRANSACTIONAL

    In transactional shutdown mode no new connectionand transcation is allowed, wait for all the

    transactions to complete

    It prevents clients from losing work

    10/13

    22

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    23/40

    Database Shutdown

    http://asghars.blogspot.com

    IMMEDIATE In immediate shutdown mode no new connection

    and transaction is allowed, any uncommited

    transactions are rolledback and disconnects all

    connected users Next startup will not require instance recovery

    ABORT In abort mode no new connection and transaction is

    allowed, uncommited transactions are not rollback

    and all connected users are implicitly disconnected

    11/13

    23

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    24/40

    Database Shutdown

    http://asghars.blogspot.com

    Next startup will require instance recovery

    A shutdown abort will not damage the database, butsome operations (such as backups) are not advisable afteran abort

    The normal, immediate, and transactionalshutdown modes are usually referred to as clean,consistent, or orderly shutdowns

    In clean shutdowns:

    PMON will roll back any incomplete transactions

    Then a checkpoint is issued, which forces the DBWn towrite all updated data from the database buffer cachedown to the datafiles

    12/13

    24

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    25/40

    Database Shutdown

    http://asghars.blogspot.com

    LGWR also flushes any change vectors still in memory

    to the log files

    The abort mode, sometimes referred to as a

    disorderly shutdown, leaves the database in an

    inconsistent state

    Which must be repaired by instance recovery

    There is a startup command startup force that can

    save time. It is two commands in one: a shutdownabort followed by a startup

    13/13

    25

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    26/40

    Setting Database Initialization Parameters

    http://asghars.blogspot.com

    The parameters used to build the instance initially

    come from either the parameter file (pfile or spfile) or

    from defaults

    Every parameter has a default, except for the DB_NAME

    parameter; this must always be specified These parameters are divided into basic and

    advanced

    Most database instances will run well with defaultvalues for the advanced parameters

    Only about thirty-three (the exact number may vary

    between versions) are basic which may need to be set

    1/5

    26

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    27/40

    Setting Database Initialization Parameters

    http://asghars.blogspot.com

    Parameters that can be changed while the instanceis running called dynamic parameters while static

    parameters are fixed at instance startup time

    To view the parameters and their current valuesselect name,value from v$parameter order by name;

    select name,value from v$spparameter order by name;

    V$PARAMETER shows the parameter values

    currently in effect in the running instance while

    V$SPPARAMETER shows the values in spfile on disk

    2/5

    27

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    28/40

    Setting Database Initialization Parameters

    http://asghars.blogspot.com

    The views can also be seen through DatabaseControl. From the database home page, take the

    Server tab and the Initialization Parameters link

    3/5

    28

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    29/40

    Setting Database Initialization Parameters

    http://asghars.blogspot.com

    To change a parameters with SQL*Plus, use theALTER SYSTEM commandalter system set parameter_name=value scope=memory|spfile|both;

    Note; If the instance is started with a pfile, then

    SCOPE=SPFILE will fail To create spfile from pfile

    create spfile='spfilename' from pfile='pfilename';

    To create pfile from spfilecreate pfile [='pfilename'] from spfile [=' spfilename'] ;

    4/5

    29

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    30/40

    Setting Database Initialization Parameters

    http://asghars.blogspot.com

    To view the basic parameters and their currentvalues

    5/5

    30

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    31/40

    EXERCISE 4-1: Query and Set Initialization

    Parameters

    http://asghars.blogspot.com

    1)

    Run sqldeveloper

    2) Connect as user SYS, with the SYSDBA privilege

    3) Check whether basic parameters have all been setor are still on default

    1/2

    31

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    32/40

    EXERCISE 4-1: Query and Set Initialization

    Parameters

    http://asghars.blogspot.com

    4)

    All the basic parameters should be considered,investigated to see if the default is appropriate

    5) Change the PROCESSES parameter to 200. This is a

    static parameter. The next illustration shows how

    to do this by specifying a SCOPE and thenbouncing the database

    2/2

    32

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    33/40

    Using the Alert Log and Trace Files

    http://asghars.blogspot.com

    The alert log (alert_ SID.log) is a continuous record of

    critical operations applied to the instance and the

    database

    Alert log location is determined by the instance

    parameter BACKGROUND_DUMP_DEST For many DBAs, the first thing they do when they are

    asked to look at a database for the first time is locate

    the alert log and scan through it, just to get an idea of

    what has been going on

    The trace files are generated by the various background

    processes, usually when they hit an error

    1/2

    33

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    34/40

    Using the Alert Log and Trace Files

    http://asghars.blogspot.com

    These files will also be located in theBACKGROUND_DUMP_DEST directory

    2/2

    34

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    35/40

    EXERCISE 4-2: Use the Alert Log

    http://asghars.blogspot.com

    1.

    Find the value of the BACKGROUND_DUMP_DESTparameter

    2. Navigate and open the alert log

    1/1

    35

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    36/40

    Data Dictionary and Dynamic Performance Views

    http://asghars.blogspot.com

    The data dictionary is metadata: data about data User definitions, security information, integrity

    constraints, and (from release 10 g onward)

    performance monitoring information are all part of

    the data dictionary

    It is stored in the SYSTEM and SYSAUX tablespaces

    To query the dictionary, Oracle provides a set of

    views. The views come in three forms, prefixedDBA_, ALL_, or USER_

    1/4

    36

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    37/40

    Data Dictionary and Dynamic Performance Views

    http://asghars.blogspot.com

    Any view prefixed USER_ will be populated with

    rows describing objects owned by the user querying

    the view

    Any view prefixed ALL_ will be populated with rows

    describing objects to which you have access (givenpermission)

    Any view prefixed DBA_ will have rows for every

    object in the database Some of those commonly used by DBAs are:

    DBA_OBJECTS

    2/4

    37

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    38/40

    Data Dictionary and Dynamic Performance Views

    http://asghars.blogspot.com

    DBA_DATA_FILES

    DBA_USERS

    DBA_TABLES

    DBA_ALERT_HISTORY

    The dynamic performance views give access to aphenomenal amount of information about theinstance, and (to a certain extent) about thedatabase

    The dynamic performance views are created atstartup, updated during the lifetime of the instance,and dropped at shutdown

    3/4

    38

    4/4

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    39/40

    Data Dictionary and Dynamic Performance Views

    http://asghars.blogspot.com

    Dynamic performance views are populated from

    the instance or the controlfile

    4/4

    39

    1/1

  • 7/29/2019 OCA 04 - Managing the Oracle Instance

    40/40

    EXERCISE 4-3: Query Dynamic Performance Views

    htt // h bl t

    1. Determine what datafile and tablespaces make up

    the database

    2. Determine the location of all the controlfile copies

    1/1

    40