Session Control with Oracle Database Resource Manager

The Oracle Database Resource Manager (DBRM) provides a wealth of functionality to control what user workloads are able to consume server and database resources. I have recently used the DBRM to provide the following functionality to the application:

  • Provide the ability to limit the duration of reports that are run through the DBMS_SCHEDULER.
  • Provide the ability to cancel and/or limit the duration a query submitted from the application user interface can run.

The Oracle Database Resource Manager is often overlooked as an important tool to enable predictable and consistent performance for your database workloads. The Oracle DBRM provides the ability to create service levels across your database workloads – reducing the potential cost of poor Oracle database performance.

Reviewing the Oracle 11.2 documentation for the DBMS_RESOURCE_MANAGER package there exists the ability to switch the session to a built in CANCEL_SQL consumer group or KILL_SESSION consumer group.

To summarise the Oracle docs:

CANCEL_SQL – will cancel the current executing SQL for the session.
KILL_SESSION – will kill the session completely from the database.

Determining the appropriate built in consumer group to switch to will largely depend on the type of application you have and the ability to respond to any errors returned from the database session.

Download my FREE Oracle Technical Discovery
template form for easy issue reporting SOP

From the consumer group name it would seem fairly self-explanatory what they do however we discovered some interesting observations around the actual runtime behaviour of the DBRM when using this method to control query execution time.

DBRM Configuration

First up I will run through the setup in place to create the consumer group, resource plan, plan directives and user permissions to switch between consumer groups.

For this application we want to have all connections from a connection pool being set to use the consumer group that will have the query time limit. There are other connections to the same database user that we do not wish to restrict. The easiest way to accomplish this is to create a database service and configure the application connection pool to use the SERVICE_NAME instead of the SID.

  1. Edit the $ORACLE_HOME/network/admin/tnsnames.ora file to include an alias for the service name that will be configured:

  1. Create the database service:
  1. For single instance environments:

Login to SQL*Plus and create the service in the database:

  1. For RAC environments:

Login as the oracle database software owner:

  1. Create the consumer group, resource plan, plan directive and consumer group mapping:

We have set a limit of 30 seconds for a query that runs from a session connected via the DEV1_UI service (which in turn has the UI_MAX_QUERY_DURATION consumer group attached).

Sessions Controlled by CPU Time

The implementation of the SWITCH_TIME directive actually uses CPU time consumed by the session and not the elapsed time of the individual SQL statement. This is something to be aware of as you will not see the statement being cancelled even though it may have run longer than 30 seconds – or whatever time limit you have implemented.

Something else to keep in mind with this is that the call will be cancelled at the end of the current SQL operation. For example if you have a hash join operation in the SQL that is executing that runs for 10 minutes and the CPU time threshold is exceeded during this 10 minute window the query will not be cancelled until the end of the hash join operation.

We can easily expand on this functionality to limit the number of active sessions in a pool to control the workload on the database server through changing the ACTIVE_SESS_POOL_P1 resource plan directive. This allows us to control the number of active sessions on the database where its not possible to manage the number of connections through connection pool parameters.

Taking Control of Poor Performance

We have covered off one use of the Oracle DBRM. There are many other DBRM use cases to enable IT Managers to take control and manage poorly performing systems. With the consistent move to consolidation and Database as a Service deployment models fine grained resource management across the Oracle stack will become a necessity.

Download my FREE Oracle Technical Discovery
template form for easy issue reporting SOP

About the Author

Mark Burgess has been helping organisations obtain the maximum value from their data management platforms for over 20 years. Mark is passionate about enabling secure, fast and reliable access to organisations data assets.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Send this to a friend