less04 instance

43
4 Copyright © 2007, Oracle. All rights reserved. Managing the Oracle Instance

Upload: carlos-alberto-canon-romero

Post on 24-Oct-2014

59 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: Less04 Instance

4Copyright © 2007, Oracle. All rights reserved.

Managing the Oracle Instance

Page 2: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 2

Objectives

After completing this lesson, you should be able to:

• Start and stop the Oracle database and components

• Use Oracle Enterprise Manager

• Access a database with SQL*Plus

• Modify database initialization parameters

• Describe the stages of database startup

• Describe database shutdown options

• View the alert log

• Access dynamic performance views

Page 3: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 3

Management Framework

Oracle Database 11g management frameworkcomponents:• Database instance • Listener• Management interface:

– Database Control– Management agent (when using Grid Control)

ListenerDatabase Control

Management

agent

Management interface

or

Page 4: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 4

Starting and Stopping Database Control

$ emctl start dbconsoleOracle Enterprise Manager 11g Database Control Release 11.1.0.1.0Copyright (c) 1996, 2006 Oracle Corporation. All rights reserved.https://edrsr17p1.us.oracle.com:1158/em/console/aboutApplicationStarting Oracle Enterprise Manager 11g Database Control ............. started.------------------------------------------------------------------Logs are generated in directory /u01/app/oracle/product/11.1.0/db_1/ edrsr17p1.us.oracle_orcl/sysman/log

$ emctl stop dbconsoleOracle Enterprise Manager 11g Database Control Release 11.1.0.1.0Copyright (c) 1996, 2006 Oracle Corporation. All rights reserved.https://edrsr17p1.us.oracle.com:1158/em/console/aboutApplicationStopping Oracle Enterprise Manager 11g Database Control ... ... Stopped.

Page 5: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 5

Oracle Enterprise Manager

Page 6: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 6

Accessing Oracle Enterprise Manager

Page 7: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 7

Database Home Page

Property pages

Page 8: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 8

Other Oracle Tools

SQL*Plus provides an additional interface to your database so that you can:

• Perform database management operations

• Execute SQL commands to query, insert, update, and delete data in your database

SQL Developer:

• Is a graphical user interface for accessing your instance of Oracle Database

• Supports development in both SQL and PL/SQL

• Is available in the default installation of Oracle Database

Components> SQL*Plus

Init ParamsDB StartupDB ShutdownAlert LogPerf Views

Page 9: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 9

Using SQL*Plus

SQL*Plus is:

• A command-line tool

• Used interactively or in batch mode

$ sqlplus hr/hr SQL*Plus: Release 11.1.0.3.0 - Beta on Wed May 30 21:41:24 2007Copyright (c) 1982, 2006, Oracle. All rights reserved. Connected to:Oracle Database 11g Enterprise Edition Release 11.1.0.3.0 - BetaWith the Partitioning, OLAP and Data Mining options SQL> select last_name from employees; LAST_NAME-------------------------AbelAndeAtkinson…

Page 10: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 10

Calling SQL*Plus from a Shell Script

$ ./batch_sqlplus.sh SQL*Plus: Release 11.1.0.3.0 - Beta on Wed May 30 21:41:24 2007Copyright (c) 1982, 2006, Oracle. All rights reserved.

Connected to:Oracle Database 11g Enterprise Edition Release 11.1.0.3.0 - BetaWith the Partitioning, OLAP and Data Mining options SQL> COUNT(*)---------- 107SQL>107 rows updated.SQL>Commit complete.SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.3.0 - BetaWith the Partitioning, OLAP and Data Mining options[oracle@EDRSR9P1 oracle]$

# Name of this file: batch_sqlplus.sh# Count employees and give raise.sqlplus hr/hr <<EOFselect count(*) from employees;update employees set salary = salary*1.10;commit;quitEOFexit

Output

Page 11: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 11

Calling a SQL Script from SQL*Plus

$ sqlplus hr/hr @script.sql SQL*Plus: Release 11.1.0.3.0 - Beta on Wed May 30 21:41:24 2007

Copyright (c) 1982, 2006, Oracle. All rights reserved. Connected to:Oracle Database 11g Enterprise Edition Release 11.1.0.3.0 - BetaWith the Partitioning, OLAP and Data Mining options DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID------------- ------------------------------ ---------- ----------- 60 IT 103 1400 Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.3.0 - BetaWith the Partitioning, OLAP and Data Mining options

select * from departments where location_id = 1400;quit

script.sql

Output

Page 12: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 12

spfileorcl.ora

Initialization Parameter FilesComponentsSQL*Plus

> Init ParamsDB StartupDB ShutdownAlert LogPerf Views

Page 13: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 14

Simplified Initialization Parameters

DB_CACHE_SIZEDB_FILE_MULTIBLOCK_READ_COUNTSHARED_POOL_SIZE…

Advanced

CONTROL_FILESDB_BLOCK_SIZEPROCESSESUNDO_MANAGEMENT…

Basic

Page 14: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 15

Initialization Parameters: Examples

Parameter Specifies

CONTROL_FILES One or more control file names

DB_FILES Maximum number of database files

PROCESSES Maximum number of OS user processes that can simultaneously connect

DB_BLOCK_SIZE Standard database block size used by all tablespaces

DB_CACHE_SIZE Size of the standard block buffer cache

Page 15: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 16

Initialization Parameters: Examples

Parameter Specifies

SGA_TARGET Total size of all SGA components

MEMORY_TARGET Oracle systemwide usable memory

SGA

Database buffercache

Redo log buffer

Java pool

Streams pool

Shared pool

Large pool

Shared SQL area

Library cache

Data dictionary cache

Other

I/O buffer

Response queue

Request queue

Free memory

Page 16: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 18

Initialization Parameters: Examples

Parameter Specifies

PGA_AGGREGATE_TARGET Amount of PGA memory allocated to all server processes

SHARED_POOL_SIZE Size of shared pool (in bytes)

UNDO_MANAGEMENT Undo space management mode to be used

Page 17: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 19

Using SQL*Plus to View Parameters

SQL> SELECT name , value FROM V$PARAMETER;NAME VALUE------------ ----------lock_name_space 2processes 150sessions 170timed_statistics TRUEtimed_os_statistics 0…

SQL>SHOW PARAMETER SHARED_POOL_SIZENAME TYPE VALUE------------------------------------ ----------- ---------------------shared_pool_size big integer 0

SQL> show parameter paraNAME TYPE VALUE------------------------------------ ----------- ---------------------fast_start_parallel_rollback string LOWparallel_adaptive_multi_user boolean TRUEparallel_automatic_tuning boolean FALSEparallel_execution_message_size integer 2148parallel_instance_group string…

Page 18: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 21

Changing Initialization Parameter Values

• Static parameters:– Can be changed only in the parameter file– Require restarting the instance before taking effect

• Dynamic parameters:– Can be changed while database is online– Can be altered at:

— Session level— System level

– Are valid for duration of session or based on SCOPE setting

– Are changed by using ALTER SESSION and ALTER SYSTEM commands

Page 19: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 23

Changing Parameter Values: Examples

SQL> ALTER SESSION SET NLS_DATE_FORMAT ='mon dd yyyy';

Session altered.

SQL> SELECT SYSDATE FROM dual;

SYSDATE-----------jun 12 2007

SQL> ALTER SYSTEM SET SEC_MAX_FAILED_LOGIN_ATTEMPTS=2 COMMENT='Reduce from 10 for tighter security.' SCOPE=SPFILE;

System altered.

Page 20: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 24

Database Startup and Shutdown

or

ComponentsSQL*PlusInit Params

> DB StartupDB Shutdown

Alert LogPerf Views

Page 21: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 25

Starting Up an Oracle Database Instance

Page 22: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 26

Starting Up an Oracle Database Instance: NOMOUNT

OPEN

MOUNT

NOMOUNT

SHUTDOWN

Instance started

STARTUP

Page 23: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 27

Starting Up an Oracle Database Instance:MOUNT

OPEN

MOUNT

NOMOUNT

SHUTDOWN

Control file opened for this instance

Instance started

STARTUP

Page 24: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 28

Starting Up an Oracle Database Instance: OPEN

OPEN

MOUNT

NOMOUNT

SHUTDOWN

All files opened as described by the control file for this instance

Control file opened for this instance

Instance started

STARTUP

Page 25: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 29

Startup Options: Examples

SQL> startup

SQL> alter database mount;

SQL> alter database open;

SQL> startup nomount

1

2

3

4

Page 26: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 30

Shutting Down an Oracle Database Instance

ComponentsSQL*PlusInit ParamsDB Startup

> DB ShutdownAlert LogPerf Views

Page 27: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 31

Shutdown Modes

A

No

No

No

No

T

No

No

Yes

Yes

I

No

No

No

Yes

Shutdown Mode

Allows new connections

Waits until current sessions end

Waits until current transactions end

Forces a checkpoint and closes files

N

No

Yes

Yes

Yes

Shutdown modes:

• A = ABORT• I = IMMEDIATE• T = TRANSACTIONAL• N = NORMAL

Page 28: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 32

Shutdown Options

During:

SHUTDOWN NORMAL

orSHUTDOWN

TRANSACTIONALor

SHUTDOWN IMMEDIATE

Consistent database(clean database)

On the way down:

• Uncommitted changes rolledback, forIMMEDIATE

• Database buffer cache written todata files

• Resources released

On the way up:

• No instance recovery

Page 29: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 33

Shutdown Options: Examples

SQL> shutdown

SQL> shutdown immediate

SQL> shutdown abort

SQL> shutdown transactional

Page 30: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 34

Shutdown Options

During:

SHUTDOWN ABORTor

Instance failureor

STARTUP FORCE

Inconsistent database(dirty database)

On the way down:

• Modified buffersnot written to data files

• Uncommitted changes not rolled back

On the way up:

• Online redo log files used to reapply changes

• Undo segments used to roll back uncommitted changes

• Resources released

Page 31: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 35

Using SQL*Plus to Start Up and Shut Down

[oracle@EDRSR9P1 oracle]$ sqlplus dba1/oracle as sysdba SQL> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SQL> startupORACLE instance started. Total System Global Area 285212672 bytesFixed Size 1218472 bytesVariable Size 250177624 bytesDatabase Buffers 33554432 bytesRedo Buffers 262144 bytesDatabase mounted.Database opened.SQL>

Page 32: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 36

Blackout Administration

Page 33: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 38

Viewing the Alert Log

Database Home page > Related Links region >Alert Log Content

ComponentsSQL*PlusInit ParamsDB StartupDB Shutdown

> Alert LogPerf Views

Page 34: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 40

Viewing the Alert History

Page 35: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 41

Using Trace Files

• Each server and background process can write to an associated trace file.

• Error information is written to the corresponding trace file.

• Automatic diagnostic repository (ADR) – Is a systemwide central tracing and logging repository– Stores database diagnostic data such as:

— Traces— Alert log— Health monitor reports

Page 36: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 43

Dynamic Performance Views

Provide access to information about changing states of the instance memory structures

Session data

Wait events

Memory allocations

Running SQL

UNDO usage

Open cursors

Redo log usage

…and so on

Oracle instance

ComponentsSQL*PlusInit ParamsDB StartupDB ShutdownAlert Log

> Perf Views

Page 37: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 44

Dynamic Performance Views:Usage Examples

SQL> SELECT sql_text, executions FROM v$sql WHERE cpu_time > 200000;

SQL> SELECT * FROM v$session WHERE machine = 'EDRSR9P1' and logon_time > SYSDATE - 1;

SQL> SELECT sid, ctime FROM v$lock WHERE block > 0;

a

b

c

Page 38: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 45

Dynamic Performance Views: Considerations

• These views are owned by the SYS user.

• Different views are available at different times:– The instance has been started.– The database is mounted.– The database is open.

• You can query V$FIXED_TABLE to see all the view names.

• These views are often referred to as “v-dollar views.”

• Read consistency is not guaranteed on these views because the data is dynamic.

Page 39: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 46

Data Dictionary: Overview

SELECT * FROM dictionary;

Tables

Indexes

Views

Users

Schemas

Procedures

…and so on

Schema Constraints

IndexesViewsSequencesTemp Tables

> Data Dict

Page 40: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 47

Data Dictionary Views

ALL_ views

DBA_ views

N/A

Subset of

Is usually the same as ALL_ except for the missing OWNER column (Some views have abbreviated names as PUBLIC synonyms.)

Everything that the user owns

EveryoneUSER_

Includes user’s own objects

Everything that the user has privileges to see

EveryoneALL_

May have additional columns meant for DBA use only

EverythingDBADBA_

NotesContentsWho CanQuery

Page 41: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 49

Data Dictionary: Usage Examples

SELECT USERNAME, ACCOUNT_STATUS FROMdba_users WHERE ACCOUNT_STATUS = 'OPEN';

SELECT table_name, tablespace_name FROM user_tables;

SELECT sequence_name, min_value, max_value, increment_by FROM all_sequences WHERE sequence_owner IN ('MDSYS','XDB');

a

b

c

DESCRIBE dba_indexes;d

Page 42: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 50

Summary

In this lesson, you should have learned how to:

• Start and stop the Oracle database and components

• Use Enterprise Manager and describe its high-level functionality

• Access a database with SQL*Plus

• Modify database initialization parameters

• Describe the stages of database startup

• Describe database shutdown options

• View the alert log

• Access dynamic performance views

Page 43: Less04 Instance

Copyright © 2007, Oracle. All rights reserved.4 - 51

Practice 4 Overview: Managing the Oracle Instance

This practice covers the following topics:

• Navigating in Enterprise Manager

• Viewing and modifying initialization parameters

• Stopping and starting the database instance

• Viewing the alert log

• Connecting to the database by using SQL*Plus