Vous êtes sur la page 1sur 40

04 - Managing the Oracle Instance

By Muhammad Asghar Khan


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

1/1

Agenda

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


EXERCISE 4-3: Query Dynamic Performance Views
http://asghars.blogspot.com

Data Dictionary and Dynamic Performance Views

1/5

Components Required for Database Startup

The three components (database instance, database listener, and optionally Database Control) have their own command-line utilities that can be used for startup In single instance environment Oracle Corporations recommended sequence for starting a database is to start Database Control, then the database listener, and then the database Starting a Database Control

Database Control is a tool for managing only one database The configuration of Database Control will have been done at database creation time
http://asghars.blogspot.com

2/5

Components Required for Database Startup

To start Database Control, use the emctl utility. This will be located in the ORACLE_HOME/bin directory
emctl 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

http://asghars.blogspot.com

3/5

Components Required for Database Startup

To connect to Database Control, use any reasonably upto-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 The database listener is a process that monitors a port for database connection requests

Starting the Database Listener

http://asghars.blogspot.com

4/5

Components Required for Database Startup

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

http://asghars.blogspot.com

5/5

Components Required for Database Startup

http://asghars.blogspot.com

1/5

Connecting to Database

An instance may be started and stopped A database is mounted and opened, and then dismounted 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 against data dictionary which cannot be read until the database is open You must therefore connect with some form of external authentication: i.e by OS or external password file
8 http://asghars.blogspot.com

2/5

Connecting to Database

The syntax of the CONNECT command tells Oracle what 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 connect connect connect connect user/pass[@connect_alias] user/pass[@connect_alias] as sysdba user/pass[@connect_alias] as sysoper / as sysdba / as sysoper

http://asghars.blogspot.com

3/5

Connecting to Database

In these examples;

The connect_alias will be resolved to a connect string, this is necessary if the connection is to be made across a network 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/password combination The last two examples use operating system authentication; Oracle will go to the host operating system and check whether the operating system user running SQL*Plus is a member of the operating system group that owns the Oracle software
http://asghars.blogspot.com

10

4/5

Connecting to Database

Database Control will by default attempt to connect through a listener, but it can also use operating system authentication SYSOPER and SYSDBA are special privileges with special capabilities They can only be enabled when users are connecting with an external authentication method: either operating system or password file You may be wondering what Oracle user you are actually logging on as when you use operating system authentication
11 http://asghars.blogspot.com

5/5

Connecting to Database

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

12

http://asghars.blogspot.com

1/13

Database Startup

When you start up a database, you create an instance of 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
13 http://asghars.blogspot.com

2/13

Database Startup

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

SHUTDOWN NOMOUNT MOUNT OPEN

14

http://asghars.blogspot.com

3/13

Database Startup

SHUTDOWN State

When the database is SHUTDOWN, all files are closed and the instance does not exist 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 to a database

NOMOUNT State

15

http://asghars.blogspot.com

4/13

Database Startup

The startup process with NOMOUNT mode is described graphically in the figure Database is started in NOMOUNT state during:

Database Creation Re-creation of Control Files Backup & Recovery Scenarios

16

http://asghars.blogspot.com

5/13

Database Startup

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
http://asghars.blogspot.com

17

6/13

Database Startup

The startup process with MOUNT mode is described graphically in the figure

OPEN State

Opening database includes:

Opening data files Opening online redo log files


http://asghars.blogspot.com

18

7/13

Database Startup

In OPEN state all the data files and online redo log files are checked fro consistency, if required the SMON perform the instance recovery The overall startup process is described graphically

19

http://asghars.blogspot.com

8/13

Database Startup

Altering database states

Mount the database

Open the database

20

http://asghars.blogspot.com

9/13

Database Shutdown

Shutdown require either a SYSDBA or a SYSOPER connection Following are the different shutdown modes:

NORMAL TRANSACTIONAL IMMEDIATE ABORT In normal shutdown, no new connection is allowed and the database will wait for all currently connected users to disconnect
http://asghars.blogspot.com

NORMAL

21

10/13

Database Shutdown

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 connection and transcation is allowed, wait for all the transactions to complete It prevents clients from losing work

22

http://asghars.blogspot.com

11/13

Database Shutdown

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
http://asghars.blogspot.com

23

12/13

Database Shutdown

Next startup will require instance recovery

A shutdown abort will not damage the database, but some operations (such as backups) are not advisable after an abort

The normal, immediate, and transactional shutdown 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 to write all updated data from the database buffer cache down to the datafiles
http://asghars.blogspot.com

24

13/13

Database Shutdown

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 shutdown abort followed by a startup

25

http://asghars.blogspot.com

1/5

Setting Database Initialization Parameters

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 default values for the advanced parameters Only about thirty-three (the exact number may vary between versions) are basic which may need to be set
26 http://asghars.blogspot.com

2/5

Setting Database Initialization Parameters

Parameters that can be changed while the instance is running called dynamic parameters while static parameters are fixed at instance startup time To view the parameters and their current values
select 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

27

http://asghars.blogspot.com

3/5

Setting Database Initialization Parameters

The views can also be seen through Database Control. From the database home page, take the Server tab and the Initialization Parameters link

28

http://asghars.blogspot.com

4/5

Setting Database Initialization Parameters

To change a parameters with SQL*Plus, use the ALTER SYSTEM command


alter 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 spfile


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

29

http://asghars.blogspot.com

5/5

Setting Database Initialization Parameters

To view the basic parameters and their current values

30

http://asghars.blogspot.com

EXERCISE 4-1: Query and Set Initialization Parameters


1)

1/2

Run sqldeveloper Connect as user SYS, with the SYSDBA privilege Check whether basic parameters have all been set or are still on default

2) 3)

31

http://asghars.blogspot.com

EXERCISE 4-1: Query and Set Initialization Parameters


4)

2/2

All the basic parameters should be considered, investigated to see if the default is appropriate Change the PROCESSES parameter to 200. This is a static parameter. The next illustration shows how to do this by specifying a SCOPE and then bouncing the database

5)

32

http://asghars.blogspot.com

1/2

Using the Alert Log and Trace Files

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
33 http://asghars.blogspot.com

2/2

Using the Alert Log and Trace Files

These files will also be located in the BACKGROUND_DUMP_DEST directory

34

http://asghars.blogspot.com

1/1

EXERCISE 4-2: Use the Alert Log


1.

Find the value of the BACKGROUND_DUMP_DEST parameter

2.

Navigate and open the alert log

35

http://asghars.blogspot.com

1/4

Data Dictionary and Dynamic Performance Views


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, prefixed DBA_, ALL_, or USER_
36 http://asghars.blogspot.com

2/4

Data Dictionary and Dynamic Performance Views

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 (given permission) Any view prefixed DBA_ will have rows for every object in the database Some of those commonly used by DBAs are:

37

DBA_OBJECTS
http://asghars.blogspot.com

3/4

Data Dictionary and Dynamic Performance Views


DBA_DATA_FILES DBA_USERS DBA_TABLES DBA_ALERT_HISTORY

The dynamic performance views give access to a phenomenal amount of information about the instance, and (to a certain extent) about the database The dynamic performance views are created at startup, updated during the lifetime of the instance, and dropped at shutdown
38 http://asghars.blogspot.com

4/4

Data Dictionary and Dynamic Performance Views

Dynamic performance views are populated from the instance or the controlfile

39

http://asghars.blogspot.com

1/1

EXERCISE 4-3: Query Dynamic Performance Views


1.

Determine what datafile and tablespaces make up the database

2.

Determine the location of all the controlfile copies

40

http://asghars.blogspot.com

Vous aimerez peut-être aussi