27
MANAGING ORACLE DATABASE PROCESSES By Lecturer / Aisha Dawood 1

Managing Oracle Database Processes

  • Upload
    ronny

  • View
    54

  • Download
    0

Embed Size (px)

DESCRIPTION

Managing Oracle Database Processes. By Lecturer / Aisha Dawood. Managing Oracle Database Processes. Dedicated and Shared Server Processes Configuring Oracle Database for Shared Server Oracle Database Background Processes Managing Processes for Parallel SQL Execution - PowerPoint PPT Presentation

Citation preview

Page 1: Managing Oracle Database Processes

1

MANAGING ORACLE DATABASE PROCESSES

ByLecturer / Aisha Dawood

Page 2: Managing Oracle Database Processes

2

MANAGING ORACLE DATABASE PROCESSES Dedicated and Shared Server Processes Configuring Oracle Database for Shared Server Oracle Database Background Processes Managing Processes for Parallel SQL Execution Managing Processes for External Procedures Terminating Sessions Monitoring the Operation of Your Database

Page 3: Managing Oracle Database Processes

3

TERMINATING SESSIONS For example, you might want to perform an administrative operation and

need to terminate all non-administrative sessions. This section describes the various aspects of terminating sessions, and contains the following topics:

■ Identifying Which Session to Terminate ■ Terminating an Active Session ■ Terminating an Inactive Session

When a session is terminated, any active transactions of the session are rolled back, and resources held by the session (such as locks and memory areas) are immediately released and available to other sessions.

Example: You terminate a current session using the SQL statement ALTER

SYSTEM KILL SESSION. The following statement terminates the session whose system identifier is 7 and serial number is 15:

ALTER SYSTEM KILL SESSION '7,15';

Page 4: Managing Oracle Database Processes

4

TERMINATING SESSIONS Identifying Which Session to Terminate: To identify which session to terminate, specify the session index number

and serial number. To identify the system identifier (SID) and serial number of a session, query the V$SESSION dynamic performance view. For example, the following query identifies all sessions for the user jward:

A session is ACTIVE when it is making a SQL call to Oracle Database. A session is INACTIVE if it is not making a SQL call to the database.

Page 5: Managing Oracle Database Processes

5

TERMINATING SESSIONS Terminating an Active Session: If a user session is processing a transaction (ACTIVE status) when you

terminate the session, the transaction is rolled back and the user immediately receives the following message:

ORA-00028: your session has been killed

If, after receiving the ORA-00028 message, a user submits additional statements before reconnecting to the database, Oracle Database returns the following message:

ORA-01012: not logged on

Page 6: Managing Oracle Database Processes

6

TERMINATING SESSIONS Terminating an Active Session Scenario: An active session cannot be interrupted when it is performing network

I/O or rolling back a transaction. Such a session cannot be terminated until the operation completes.

In this case, the session holds all resources until it is terminated. Additionally, the session that issues the ALTER SYSTEM statement to terminate a session waits up to 60 seconds for the session to be terminated.

If the operation that cannot be interrupted continues past one minute, the issuer of the ALTER SYSTEM statement receives a message indicating that the session has been marked to be terminated.

A session marked to be terminated is indicated in V$SESSION with a status of KILLED and a server that is something other than PSEUDO.

Page 7: Managing Oracle Database Processes

7

TERMINATING SESSIONS Terminating an Inactive Session: If the session is not making a SQL call to Oracle Database (is

INACTIVE) when it is terminated, the ORA-00028 message is not returned immediately. The message is not returned until the user subsequently attempts to use the terminated session.

When an inactive session has been terminated, the STATUS of the session in the V$SESSION view is KILLED. The row for the terminated session is removed from V$SESSION after the user attempts to use the session again and receives the ORA-00028 message.

Page 8: Managing Oracle Database Processes

8

TERMINATING SESSIONS Terminating an Inactive Session: In the following example, an inactive session is terminated. First,

V$SESSION is queried to identify the SID and SERIAL# of the session, and then the session is terminated.

Page 9: Managing Oracle Database Processes

9

MONITORING THE OPERATION OF YOUR DATABASE

It is important that you monitor the operation of your database on a regular basis. Doing so not only informs you about errors that have not yet come to your attention but also gives you a better understanding of the normal operation of your database.

Being familiar with normal behavior in turn helps you recognize when something is wrong.

Page 10: Managing Oracle Database Processes

10

MONITORING THE OPERATION OF YOUR DATABASE

Server-Generated Alerts A server-generated alert is a notification from the Oracle Database server

of an impending problem. The notification may contain suggestions for correcting the problem. Notifications are also provided when the problem condition has been cleared.

Alerts are automatically generated when a problem occurs or when data does not match expected values for metrics, such as the following:

■ Physical Reads Per Second ■ User Commits Per Second ■ SQL Service Response Time

Page 11: Managing Oracle Database Processes

11

MONITORING THE OPERATION OF YOUR DATABASE

Server-generated alerts can be based on threshold levels or can issue simply because an event has occurred.

Threshold-based alerts can be triggered at both threshold warning and critical levels. The value of these levels can be customer-defined or internal values, and some alerts have default threshold levels which you can change if appropriate.

Page 12: Managing Oracle Database Processes

12

MONITORING THE OPERATION OF YOUR DATABASE

For example, by default a server-generated alert is generated for tablespace space usage when the percentage of space usage exceeds either the 85% warning or 97% critical threshold level.

Examples of alerts not based on threshold levels are: ■ Snapshot Too Old ■ Resumable Session Suspended ■ Recovery Area Space Usage

An alert message is sent to the predefined persistent queue ALERT_QUE owned by the user SYS. Oracle Enterprise Manager reads this queue and provides notifications about outstanding server alerts, and sometimes suggests actions for correcting the problem.

Page 13: Managing Oracle Database Processes

13

MONITORING THE OPERATION OF YOUR DATABASE

Using APIs to Administer Server-Generated Alerts You can view and change threshold settings for the server alert metrics

using the SET_THRESHOLD and GET_THRESHOLD procedures of the DBMS_SERVER_ALERTS PL/SQL package. The DBMS_AQ and DBMS_AQADM packages provide procedure for accessing and reading alert messages in the alert queue.

Page 14: Managing Oracle Database Processes

14

MONITORING THE OPERATION OF YOUR DATABASE

Setting Threshold Levels The following example shows how to set thresholds with the SET_THRESHOLD

procedure for CPU time for each user call for an instance:DBMS_SERVER_ALERT.SET_THRESHOLD(DBMS_SERVER_ALERT.CPU_TIME_PER_CALL, DBMS_SERVER_ALERT.OPERATOR_GE, '8000',DBMS_SERVER_ALERT.OPERATOR_GE, '10000', 1, 2, 'inst1',DBMS_SERVER_ALERT.OBJECT_TYPE_SERVICE, 'main.regress.rdbms.dev.us.oracle.com'); In this example, a warning alert is issued when CPU time exceeds 8000

microseconds for each user call and a critical alert is issued when CPU time exceeds 10,000 microseconds for each user call.

The observation period is set to 1 minute. This period specifies the number of minutes that the condition must deviate from the threshold value before the alert is issued.

The number of consecutive occurrences is set to 2. This number specifies how many times the metric value must violate the threshold values before the alert is generated.

Page 15: Managing Oracle Database Processes

15

MONITORING THE OPERATION OF YOUR DATABASE

Retrieving Threshold Information To retrieve threshold values, use the GET_THRESHOLD procedure. For

example:

Page 16: Managing Oracle Database Processes

16

MONITORING THE OPERATION OF YOUR DATABASE

You can also check specific threshold settings with the DBA_THRESHOLDS view. For example:

SELECT metrics_name, warning_value, critical_value, consecutive_occurrencesFROM DBA_THRESHOLDSWHERE metrics_name LIKE '%CPU Time%';

If you use your own tool rather than Enterprise Manager to display alerts return to the section “Additional APIs to Manage Server-Generated Alerts” in chapter 4.

Page 17: Managing Oracle Database Processes

17

MONITORING THE OPERATION OF YOUR DATABASE

Viewing Alert Data The following dictionary views provide information about server alerts:

■ DBA_THRESHOLDS lists the threshold settings defined for the instance.■ DBA_OUTSTANDING_ALERTS describes the outstanding alerts in the database.■ DBA_ALERT_HISTORY lists a history of alerts that have been cleared.■ V$ALERT_TYPES provides information such as group and type for each alert.■ V$METRICNAME contains the names, identifiers, and other information about the system metrics.■ V$METRIC and V$METRIC_HISTORY views contain system-level metric values in memory.

Page 18: Managing Oracle Database Processes

18

MONITORING THE OPERATION OF YOUR DATABASE

Monitoring the Database Using Trace Files and the Alert Log Each server and background process can write to an associated trace file.

When an internal error is detected by a process, it dumps information about the error to its trace file. Some of the information written to a trace file is intended for the database administrator, and other information is for Oracle Support Services. Trace file information is also used to tune applications and instances.

Page 19: Managing Oracle Database Processes

19

MONITORING THE OPERATION OF YOUR DATABASE

The alert log is a special trace file. The alert log of a database is a chronological log of messages and errors, and includes the following items:

■ All internal errors (ORA-600), block corruption errors (ORA-1578), and deadlock errors (ORA-60) that occur

■ Administrative operations, such as CREATE, ALTER, and DROP statements and STARTUP, SHUTDOWN, and ARCHIVELOG statements

■ Messages and errors relating to the functions of shared server and dispatcher processes

■ Errors occurring during the automatic refresh of a materialized view ■ The values of all initialization parameters that had nondefault values at

the time the database and instance start

Page 20: Managing Oracle Database Processes

20

MONITORING THE OPERATION OF YOUR DATABASE

Initialization parameters controlling the location and size of trace files are: ■ BACKGROUND_DUMP_DEST ■ USER_DUMP_DEST ■ MAX_DUMP_FILE_SIZE Using the Trace Files Check the alert log and other trace files of an instance periodically to learn

whether the background processes have encountered errors. For example, when the log writer process (LGWR) cannot write to a member of a log group, an error message indicating the nature of the problem is written to the LGWR trace file and the database alert log. Such an error message means that a media or I/O problem has occurred and should be corrected immediately.

Specifying the Location of Trace Files All trace files for background processes and the alert log are written to the

directory specified by the initialization parameter BACKGROUND_DUMP_DEST. All trace files for server processes are written to the directory specified by the initialization parameter USER_DUMP_DEST. The names of trace files are operating system specific, but each file usually includes the name of the process writing the file (such as LGWR and RECO).

Page 21: Managing Oracle Database Processes

21

MONITORING THE OPERATION OF YOUR DATABASE

Controlling the Size of Trace Files You can control the maximum size of all trace files (excluding the alert

log) using the initialization parameter MAX_DUMP_FILE_SIZE, which limits the file to the specified number of operating system blocks.

To control the size of an alert log, you must manually delete the file when you no longer need it. Otherwise the database continues to append to the file.

You can safely delete the alert log while the instance is running, although you should consider making an archived copy of it first. This archived copy could prove valuable if you should have a future problem that requires investigating the history of an instance.

Page 22: Managing Oracle Database Processes

22

MONITORING THE OPERATION OF YOUR DATABASE

Controlling When Oracle Database Writes to Trace Files Background processes always write to a trace file when appropriate. In

the case of the ARCn background process, it is possible, through an initialization parameter, to control the amount and type of trace information that is produced.

Trace files are written on behalf of server processes whenever internal errors occur. Additionally, setting the initialization parameter SQL_TRACE = TRUE causes the SQL trace facility to generate performance statistics for the processing of all SQL statements for an instance and write them to the USER_DUMP_DEST directory.

by using the SQL statement ALTER SESSION SET SQL_TRACE. This example enables the SQL trace facility for a specific session:

ALTER SESSION SET SQL_TRACE TRUE;

Page 23: Managing Oracle Database Processes

23

MONITORING THE OPERATION OF YOUR DATABASE

Monitoring Locks Locks are mechanisms that prevent destructive interaction between

transactions accessing the same resource.

A deadlock can occur when two or more users are waiting for data locked by each other. Deadlocks prevent some transactions from continuing to work. Oracle Database automatically detects deadlock situations and resolves them by rolling back one of the statements involved in the deadlock

Oracle provides some scripts and views that enable you to monitor locks. The utllockt.sql script displays, in a tree fashion, the sessions in the system that are waiting for locks and the locks that they are waiting for. The location of this script file is operating system dependent.

A second script, catblock.sql, creates the lock views that utllockt.sql needs, so you must run it before running utllockt.sql.

Page 24: Managing Oracle Database Processes

24

MONITORING THE OPERATION OF YOUR DATABASE

The following views can help you to monitor locks:

Page 25: Managing Oracle Database Processes

25

MONITORING THE OPERATION OF YOUR DATABASE

Monitoring Wait Events Wait events are statistics that are incremented by a server process to

indicate that it had to wait for an event to complete before being able to continue processing.

A session could wait for a variety of reasons including waiting for more input, waiting for the operating system to complete a service such as a disk write, or it could wait for a lock or latch.

Page 26: Managing Oracle Database Processes

26

MONITORING THE OPERATION OF YOUR DATABASE

Process and Session Views some of the data dictionary views that you can use to monitor an Oracle

Database instance.

Page 27: Managing Oracle Database Processes

27

MONITORING THE OPERATION OF YOUR DATABASE

Monitoring Wait Events Wait events are statistics that are incremented by a server process to

indicate that it had to wait for an event to complete before being able to continue processing.

A session could wait for a variety of reasons including waiting for more input, waiting for the operating system to complete a service such as a disk write, or it could wait for a lock or latch.