Md Mominul Islam | Software and Data Enginnering | SQL Server, .NET, Power BI, Azure Blog

while(!(succeed=try()));

LinkedIn Portfolio Banner

Latest

Home Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Thursday, September 11, 2025

How to Identify & Fix CPU Bottlenecks in Oracle Database

 

How to Identify and Fix CPU Bottlenecks in Oracle Database

In Oracle Database management, CPU bottlenecks can severely impact performance, leading to slow query execution, delayed transactions, and degraded user experience. This comprehensive guide explores how to detect CPU saturation in Oracle Database, provides step-by-step strategies to mitigate it, and discusses real-world applications, pros, cons, and business usage.

Understanding CPU Bottlenecks in Oracle Database

A CPU bottleneck occurs when the database server's CPU resources are overwhelmed by the workload, causing delays in processing queries and transactions. Common causes include inefficient SQL queries, inadequate indexing, excessive parallel processing, or external system pressures. Identifying and resolving these bottlenecks is critical for maintaining optimal database performance.

Why Monitor CPU Usage?

  • Performance Optimization: Pinpointing high-CPU queries enables targeted optimization.

  • Capacity Planning: Understanding CPU usage aids in scaling resources effectively.

  • Troubleshooting: High CPU usage often signals underlying issues like poor query design.

  • Cost Efficiency: In cloud environments, optimizing CPU usage reduces operational costs.

Step-by-Step Guide to Detect CPU Saturation

Step 1: Monitor System-Level CPU Usage

Use operating system tools to assess overall CPU consumption on the database server.

  • Linux/Unix:

    • top: Displays real-time CPU usage by processes.

    • vmstat: Provides system-wide CPU statistics.

    • iostat: Checks for disk-related bottlenecks that may contribute to CPU load.

    top
    vmstat 1 5
    iostat -c 1 5

    Example Output (top):

    PID   USER      %CPU  COMMAND
    12345 oracle    95.2  oracleDB

    If Oracle processes consistently show high CPU usage (e.g., >90%), a bottleneck may exist.

  • Windows:

    • Use Task Manager or Performance Monitor to track CPU usage by Oracle processes.

Step 2: Query Oracle Dynamic Performance Views

Oracle provides dynamic performance views (V$ views) to monitor CPU usage at the database level.

  • V$SESSION: Displays session-level CPU usage.

  • V$SQL: Identifies high-CPU-consuming SQL statements.

  • V$ACTIVE_SESSION_HISTORY (ASH): Provides historical session activity for detailed analysis.

Example Query: Identify High-CPU Sessions

SELECT s.sid, s.serial#, s.username, s.program, 
       s.cpu_time_total/1000000 AS cpu_seconds
FROM v$session s
JOIN v$process p ON s.paddr = p.addr
WHERE s.status = 'ACTIVE'
ORDER BY cpu_seconds DESC;

Output:

SID  SERIAL#  USERNAME  PROGRAM           CPU_SECONDS
101  45678    APP_USER  sqlplus@db01      120.45
102  45679    APP_USER  jdbc@db01         95.32

This query highlights sessions consuming significant CPU time, helping identify problematic processes.

Example Query: High-CPU SQL Statements

SELECT sql_id, plan_hash_value, executions, 
       cpu_time_total/1000000 AS cpu_seconds, 
       sql_text
FROM v$sql
WHERE cpu_time_total > 1000000
ORDER BY cpu_time_total DESC;

Output:

SQL_ID        EXECUTIONS  CPU_SECONDS  SQL_TEXT
abc123xyz     9720        4427.3       BEGIN PKG_NEW_UPDATER.INS_OUTLET_DATA_SYNC(:v0, :v1, :v2, :v3, :v4); END;

This identifies SQL statements with high CPU consumption, like the one above, which may need optimization.

Step 3: Use Automatic Workload Repository (AWR) Reports

AWR reports provide a comprehensive view of database performance, including CPU usage.

  • Generate an AWR report:

    @?/rdbms/admin/awrrpt
  • Select the time range (e.g., 11:06–11:24 when CPU usage spiked).

  • Analyze sections like “Top Timed Events” and “SQL Ordered by CPU Time” to identify culprits.

Example AWR Snippet:

Top 5 Timed Foreground Events
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Event                Waits    Time(s)   Avg wait (ms)   % DB time
CPU time                     2,672                    85.2
db file sequential read  1,234    150       121          4.8

Here, CPU time dominates, indicating a potential bottleneck.

Step 4: Analyze Active Session History (ASH)

For granular insights, query V$ACTIVE_SESSION_HISTORY:

SELECT sql_id, user_id, module, 
       COUNT(*) AS cpu_secs
FROM v$active_session_history
WHERE event IS NULL
AND sample_time BETWEEN TO_DATE('2025-09-11 11:06:00', 'YYYY-MM-DD HH24:MI:SS')
AND TO_DATE('2025-09-11 11:24:00', 'YYYY-MM-DD HH24:MI:SS')
GROUP BY sql_id, user_id, module
ORDER BY cpu_secs DESC;

This query identifies which SQL statements or modules consumed CPU during a specific time frame.

Step 5: Use Oracle Enterprise Manager (OEM)

OEM provides a graphical interface for monitoring CPU usage:

  • Navigate to the Performance tab.

  • Check the “Host CPU Usage” and “Active Sessions” charts.

  • Drill down to identify high-CPU sessions or queries.

Strategies to Mitigate CPU Bottlenecks

Strategy 1: Optimize SQL Queries

Inefficient queries are a common cause of CPU saturation.

  • Use EXPLAIN PLAN:

    EXPLAIN PLAN FOR
    SELECT * FROM orders WHERE order_date > '2025-01-01';
    SELECT * FROM TABLE(dbms_xplan.display);

    Output:

    ---------------------------------------------
    | Id  | Operation         | Name  | Rows  |
    ---------------------------------------------
    |   0 | SELECT STATEMENT  |       | 10000 |
    |   1 | TABLE ACCESS FULL | ORDERS| 10000 |
    ---------------------------------------------

    A full table scan indicates a missing index. Create an index:

    CREATE INDEX idx_orders_date ON orders(order_date);
  • Rewrite Queries: Simplify complex joins or subqueries.

  • Use Hints: Guide the optimizer, e.g., /*+ INDEX(orders idx_orders_date) */.

Pros:

  • Immediate performance gains.

  • Reduces CPU load without hardware changes.

Cons:

  • Requires SQL expertise.

  • Over-indexing can slow DML operations.

Strategy 2: Manage Parallel Processing

Excessive parallelism can overload CPUs.

  • Check parallelism settings:

    SELECT name, value FROM v$parameter WHERE name LIKE '%parallel%';
  • Reduce parallelism for specific queries:

    ALTER SESSION SET parallel_max_servers = 4;

Pros:

  • Balances CPU usage across sessions.

  • Prevents resource contention.

Cons:

  • May increase query execution time.

  • Requires testing to find optimal settings.

Strategy 3: Implement Resource Manager

Oracle Resource Manager allocates CPU resources to sessions or consumer groups.

  • Create a resource plan:

    BEGIN
      DBMS_RESOURCE_MANAGER.CREATE_SIMPLE_PLAN(
        SIMPLE_PLAN => 'DAYTIME_PLAN',
        CONSUMER_GROUP1 => 'HIGH_PRIORITY',
        GROUP1_CPU => 80,
        CONSUMER_GROUP2 => 'LOW_PRIORITY',
        GROUP2_CPU => 20);
    END;
    /

Pros:

  • Prioritizes critical workloads.

  • Prevents CPU monopolization.

Cons:

  • Complex setup and maintenance.

  • May require frequent adjustments.

Strategy 4: Tune Database Configuration

Adjust parameters to optimize CPU usage:

  • CURSOR_SHARING: Set to FORCE to reduce parse CPU overhead.

    ALTER SYSTEM SET cursor_sharing = 'FORCE';
  • OPTIMIZER_MODE: Use ALL_ROWS for OLAP systems to optimize throughput.

    ALTER SYSTEM SET optimizer_mode = 'ALL_ROWS';

Pros:

  • Systemic improvements.

  • Reduces CPU usage globally.

Cons:

  • May affect specific workloads negatively.

  • Requires thorough testing.

Strategy 5: Scale Hardware or Cloud Resources

If optimization isn’t enough, consider:

  • Upgrading CPU cores or server capacity.

  • In cloud environments, scaling up instances (e.g., AWS RDS, Oracle Cloud).

Pros:

  • Handles increased workloads.

  • Quick to implement in cloud setups.

Cons:

  • High cost.

  • Temporary solution if underlying issues persist.

Real-Life Example

Scenario: A retail company’s Oracle Database experienced slow order processing during peak hours (10 AM–2 PM), with CPU usage hitting 95%. Users reported delays in order confirmations.

Steps Taken:

  1. Diagnosis:

    • Ran top and confirmed Oracle processes consumed 90%+ CPU.

    • Queried V$SQL and identified a high-CPU query:

      SELECT * FROM order_history WHERE order_date > SYSDATE - 30;
    • Generated an AWR report showing CPU time as the top event.

  2. Mitigation:

    • Used EXPLAIN PLAN and found a full table scan on order_history.

    • Created an index:

      CREATE INDEX idx_order_history_date ON order_history(order_date);
    • Reduced parallelism:

      ALTER TABLE order_history PARALLEL 2;
    • Implemented Resource Manager to prioritize order processing sessions.

  3. Outcome:

    • CPU usage dropped to 60%.

    • Order processing time reduced from 10 seconds to 2 seconds.

Business Impact:

  • Improved customer satisfaction due to faster order confirmations.

  • Reduced operational complaints, enhancing employee productivity.

Usage in Business

  • E-commerce: Ensures fast transaction processing during sales events.

  • Finance: Supports real-time trading systems with low latency.

  • Healthcare: Maintains quick access to patient data for critical care.

  • Logistics: Optimizes supply chain queries for timely deliveries.

Pros and Cons of CPU Bottleneck Management

Pros:

  • Enhances application responsiveness.

  • Supports scalability for growing businesses.

  • Reduces costs in cloud environments by optimizing resource usage.

Cons:

  • Requires specialized DBA skills.

  • Optimization may introduce trade-offs (e.g., indexing slows DML).

  • Hardware upgrades are expensive and not always feasible.

Conclusion

Detecting and mitigating CPU bottlenecks in Oracle Database involves systematic monitoring, precise diagnostics, and targeted optimizations. By leveraging tools like V$ views, AWR reports, and OEM, DBAs can identify high-CPU queries and sessions. Strategies like query optimization, Resource Manager, and hardware scaling ensure efficient performance. In business contexts, these practices translate to improved user experiences, cost savings, and operational reliability. Regular monitoring and proactive tuning are key to maintaining a robust Oracle Database environment.

References:

  • Oracle Database Performance Tuning Guide

  • UMA Technology: How To Check CPU Usage In Oracle Database

  • Stack Overflow: Detect What Causing Oracle's Server CPU Usage 100%

No comments:

Post a Comment

Thanks for your valuable comment...........
Md. Mominul Islam

Post Bottom Ad

Responsive Ads Here