← Performance
Oracle · Performance

How to generate CPU load in Oracle for testing

PL/SQL loop that generates CPU load in an Oracle session, useful for testing resource manager, load balancing, or ASH sampling.

Tested on11g12c18c19c21c23ai26ai

Anonymous PL/SQL loop that burns CPU by repeatedly calling DBMS_RANDOM. Useful for testing Resource Manager consumer group behaviour, cluster load balancing, or generating an ASH signal you can trace end-to-end.

Do NOT run in production. It will pin a CPU core until it finishes (~a minute of CPU-bound work, longer on slow instances). Run on a dev instance and be ready to cancel from another session.

DECLARE
  l_result NUMBER;
BEGIN
  FOR i IN 1 .. 999999999 LOOP
    l_result := (i / DBMS_RANDOM.VALUE + i * DBMS_RANDOM.VALUE) / DBMS_RANDOM.VALUE;
  END LOOP;
END;
/
performancetestingcpuplsql