Você está na página 1de 29

Managing Oracle Database Workloads with Services

Pete Dinin NEOOUG Training Seminar May 22, 2009

Overview
Definitions

and background Creating and managing database services Applications of database services

Definition Database Services


First

introduced in Oracle 8i. Services are logical abstractions for managing workloads. Services divide workloads into mutually disjoint groupings. Each service represents a workload with common attributes, service-level thresholds, and priorities.

Tnsnames Examples
Connect to Instance: TEST_INSTANCE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testhost)(PORT = 1521)) ) (CONNECT_DATA = (SID = test) ) ) Connect to Service: TEST_SERVICE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testhost)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = test_service) ) )

Service States

Within an instance, a service is binary:


Started Stopped (not started)

Within a clustered database, a service can be mapped to an instance in three ways:


Preferred CRS starts service on instance. Available CRS starts service on an available instance if it cannot run on an available instance. Not Used CRS does not use instance for service.

Listener Registration

Each instance of database service registers with listeners defined in local_listener and remote_listener init.ora parameters. When a connection request is processed by the listener, it knows where the service is running, and will pass the connection to the appropriate instance. If the listener does not know of any instances where the service is running, an error is returned.

Creating Services
Without

CRS

dbms_service.create_service service_names init.ora parameter


With

CRS

srvctl add service Grid Control Database > Maintenance > Cluster Managed Database Services dbms_service.modify_service for additional service parameters (failover properties)

Managing Services Single Instance

Starting & Stopping


dbms_service.start_service dbms_service.stop_service alter system set service_names='<list of all services to be running>';

Automatic startup
Set service_names init.ora parameter to list of all services to be started at instance startup. Create a startup trigger with logic to determine which services to start using dbms_service.start_service.

Managing Services - RAC

Starting and Stopping


srvctl start/stop service Grid Control Database > Maintenance > Cluster Managed Database Services

CRS can automatically start services after databases start. Modifying RAC services
srvctl modify service Grid Control Database > Maintenance > Cluster Managed Database Services dbms_service.modify_service can configure failover characteristics of a service

Default Services

SYS$USERS is the service assigned to a connection made without specifying a service name, such as bequeath or by instance name. SYS$BACKGROUND is assigned to database background processes. RAC Default Service (dbname.domain) is created for all RAC Databases, and runs on all running instances. Default services cannot be managed by the DBA.

Implementation Tips

Define a service for all applications. Do not include instance name in connect strings. If you must connect to a specific RAC instance, create a service for it. Avoid bequeath connections. With RAC, avoid connections using the dbname.domain default service, since manageability is limited. Maximum number of services varies by version
10gR1: 64 services (including defaults) 10gR2 and 11gR1: 118 services (including defaults)

Certain database features, such as DataPump and Streams, use services as well.

Applications of Services
The

following slides are examples of how Database Services can be used in the database infrastructure. Each example requires database services to have been configured to gain the most benefit.

Connection Control

Control access to the database at the service level. Some examples:


Stop a service used by an application middletier while upgrading an application. Stop ad-hoc query users from connecting during batch processing windows.

Normally a stop command only stops new connections. Using dbms_service.disconnect_session or srvctl stop service (with the -f flag), existing connections to that service can be killed as well.

SQL Tracing a Service


SQL Tracing can be enabled at the service level. Ideal if you have an application with connection pooling, where you do not know which session contains the code you want to trace. dbms_monitor.serv_mod_act_trace_enable ('service_name'); dbms_monitor.serv_mod_act_trace_disable ('service_name');

Performance Views by Service

Available for sql queries:


Service_name column in v$session Service-level performance views which contain the same data as the corresponding system and session views.
v$service_event v$service_wait_class v$service_stats

v$active_session_history contains a column service_hash, which can be joined to the name_hash column of dba_services to get the service_name.

Service-level views are also presented in Grid Control under Instance Performance > Top Consumers

System Utilization by App


When multiple applications share a database, what percentage of the workload belongs to each application? If each application has a service, you can use any service-level metric. Sample using DB CPU and ignoring SYS services:
service_name, TRUNC (RATIO_TO_REPORT (SUM (VALUE)) OVER (), 4) * 100 percentage gv$service_stats stat_name = 'DB CPU' AND service_name NOT LIKE 'SYS%' service_name 2 DESC;

SELECT FROM WHERE GROUP BY ORDER BY

This can be used for TCO calculations as well.

11g Scheduler
With

the 11g Oracle Scheduler, job classes can be defined for jobs. Job classes can be defined with a service name. This will cause the jobs in that job class to run on the specified database service.

Database Resource Manager


The

Database Resource Manager allows priority to be given to user processes based on consumer groups. Consumer groups can be defined based on various client attributes, including service name. This could allow certain services to have a higher priority in the database than others.

DataGuard

DataGuard enables failover to standby database. But how do clients find the new database location ? Primary Database Configuration
Local listener references local machine Remote listener references standby machine Service initially started

Standby Database Configuration


Local listener references standby machine Remote listener references primary machine Service initially stopped

Tnsnames entry for service references both listeners. Client-side load balancing (load_balance=yes) is optional, however is shown in the following example.

Moving an Application

An application needs to be moved from one shared database to another. Assumes that tnsnames or other centralized naming is used.
Move all underlying schemas and database objects to the new database. Create and start the service on new database. Edit the tnsnames entry for the service to direct to the new listener (if necessary).

There is no need to change any connection strings in the application tier. To avoid tnsnames changes altogether, the old listener redirect connections to the new database using techniques described for DataGuard.

RAC Parallel Slaves 11g


Parallel slaves are managed with parallel_instance_group and instance_group parameters. 11g Parallel slaves have service affinity. Parallel slaves will be spawned on instances where the parent sessions service is a preferred instance. Note that the parallel_instance_group and instance_group parameters are deprecated in 11g as well.
10g

Thank you.
Thank

you for your time and attention. If you have any additional questions, please feel free to contact me at pete@dinin.net

Você também pode gostar