top of page

Will the Upgrade Make Any Query Slower? Testing 19c Production SQL on 23ai with SQL Performance Analyzer in Oracle Database@Azure

OmerNarman
Nov 27
8 min read

Upgrade projects usually test functions, not performance. The application team clicks through the screens, everything works, and the upgrade goes ahead. A week later one report that ran in two seconds takes two minutes, because the new optimizer picked a different plan. With hundreds of statements in a busy application, nobody can test every one by hand.


SQL Performance Analyzer (SPA) does it for you. It takes a set of real statements captured from production, runs each one on the upgraded test database, and compares the results statement by statement with the figures from production. You get a list of improved, unchanged and regressed statements before anything changes for users. This post tests an upgrade from 19c to 23ai, with the test database on Exadata Database Service in Oracle Database@Azure.



The Use Case

Production SALESPROD runs Oracle Database 19c on premises. It is going to be migrated and upgraded to Oracle Database 23ai on Exadata Database Service in Oracle Database@Azure. A test copy of production, already upgraded to 23ai, runs on the new Exadata VM cluster. The DBA team must show, before the cut-over, that no important statement gets slower, and fix any that do.


Environment used in this runbook


  • Production: SALESPROD, Oracle Database 19c (19.24), PDB SALESPDB, on premises

  • Test: SALESTST, Oracle Database 23ai, PDB SALESPDB, on Exadata Database Service in Oracle Database@Azure, restored from a recent production backup and upgraded with AutoUpgrade

  • Workload: order entry and daytime reports in the SALES schema

  • Licence: SQL Performance Analyzer is part of the Oracle Real Application Testing option, an extra-cost option; it is included in licence-included Exadata Database Service and must be licensed separately on premises and with Bring Your Own License; capturing a SQL tuning set from the cursor cache also uses the Tuning Pack



How SPA Works

  • A SQL tuning set holds the workload. It stores the statements with their binds, plans and execution statistics, captured from the cursor cache or AWR.

  • The tuning set travels. It is packed into a staging table, moved with Data Pump and unpacked on the test database.

  • Two trials are compared. The "before" trial uses the statistics captured on 19c; the "after" trial executes each statement on 23ai.

  • Each statement gets a verdict. SPA compares a metric such as buffer gets or elapsed time and marks each statement as improved, unchanged or regressed.



Step 1: Capture the Workload into a SQL Tuning Set

On production, create a SQL tuning set and fill it from the cursor cache over a business day. Polling the cursor cache every few minutes catches statements that stay in memory only briefly.


SQL

-- On SALESPROD, connected to SALESPDB as a DBA

BEGIN

DBMS_SQLTUNE.CREATE_SQLSET(

sqlset_name => 'SALES_UPG_STS',

description => 'Business day workload of the SALES schema for the 23ai upgrade');

DBMS_SQLTUNE.CAPTURE_CURSOR_CACHE_SQLSET(

sqlset_name => 'SALES_UPG_STS',

time_limit => 28800,

repeat_interval => 300,

basic_filter => q'[parsing_schema_name = 'SALES']');

END;

/

Expected output

PL/SQL procedure successfully completed.

What this does: It creates the tuning set SALES_UPG_STS and polls the cursor cache every 5 minutes for 8 hours, adding every statement parsed by the SALES schema together with its plan and statistics. The call runs for the whole capture period, so start it from a scheduler job or a session that will not be interrupted.



Step 2: Check What Was Captured

Look at the size of the tuning set and at its heaviest statements. These are the ones that matter most after the upgrade.


SQL

COLUMN sql_id FORMAT A13

SELECT sql_id, executions, buffer_gets,

ROUND(elapsed_time / NULLIF(executions, 0) / 1000, 1) AS ms_per_exec

FROM TABLE(DBMS_SQLTUNE.SELECT_SQLSET('SALES_UPG_STS'))

ORDER BY buffer_gets DESC

FETCH FIRST 4 ROWS ONLY;

SELECT statement_count FROM dba_sqlset WHERE name = 'SALES_UPG_STS';

Expected output

SQL_ID        EXECUTIONS BUFFER_GETS MS_PER_EXEC
------------- ---------- ----------- -----------
7mcd1x2b0rk5q      18432   412083321        92.4
2gt8v9wq4h1zd       1204   190227846       811.7
c5w0n3fj8yk2p     241860    88415203         1.9
9qpz6r4mx1d7b         96    61022417      2384.1

STATEMENT_COUNT
---------------
           1847

What to expect: 1,847 distinct statements, with the heaviest one running more than 18,000 times a day at about 92 milliseconds each. A tuning set of a few thousand statements is normal for one application schema and is a manageable size for SPA.



Step 3: Pack and Move the Tuning Set

Pack the tuning set into a staging table, export it with Data Pump, and copy the dump file to the test database. Object storage in Azure or OCI works well as the transfer point.


SQL

-- On SALESPROD

BEGIN

DBMS_SQLTUNE.CREATE_STGTAB_SQLSET(

table_name => 'STS_STAGE',

schema_name => 'DBA_TOOLS');

DBMS_SQLTUNE.PACK_STGTAB_SQLSET(

sqlset_name => 'SALES_UPG_STS',

staging_table_name => 'STS_STAGE',

staging_schema_owner => 'DBA_TOOLS');

END;

/

-- Then on the database server:

-- expdp dba_tools@salespdb tables=DBA_TOOLS.STS_STAGE directory=DP_DIR dumpfile=sts_stage.dmp

Expected output

PL/SQL procedure successfully completed.

What this does: It copies the tuning set, with its statements, binds, plans and statistics, into the table DBA_TOOLS.STS_STAGE, which an ordinary Data Pump export can carry. A staging table from 19c can be unpacked on 23ai; the other direction is not supported.



Step 4: Unpack the Tuning Set on the Test Database

On the 23ai test database, import the staging table and unpack it into a tuning set with the same name.


SQL

-- On SALESTST, after: impdp dba_tools@salespdb tables=DBA_TOOLS.STS_STAGE directory=DP_DIR dumpfile=sts_stage.dmp

BEGIN

DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET(

sqlset_name => 'SALES_UPG_STS',

sqlset_owner => '%',

replace => TRUE,

staging_table_name => 'STS_STAGE',

staging_schema_owner => 'DBA_TOOLS');

END;

/

SELECT name, statement_count FROM dba_sqlset WHERE name = 'SALES_UPG_STS';

Expected output

PL/SQL procedure successfully completed.

NAME                           STATEMENT_COUNT
------------------------------ ---------------
SALES_UPG_STS                             1847

What to expect: The same 1,847 statements now exist on the test database. The test data must be close to production in volume and distribution, which is why a restore of a recent production backup is the best basis; a small or synthetic copy would make every comparison meaningless.


Tip: Gather optimizer statistics on the test database the same way production does, with the same preferences, before running the trials. Comparing a 19c plan built on fresh statistics with a 23ai plan built on stale ones tests the statistics, not the upgrade.


Step 5: Create the Analysis Task and the "Before" Trial

Create an SPA task for the tuning set, then build the "before" trial from the statistics captured on 19c. Nothing is executed for this trial; SPA converts the captured figures.


SQL

VARIABLE tname VARCHAR2(64)

BEGIN

:tname := DBMS_SQLPA.CREATE_ANALYSIS_TASK(

sqlset_name => 'SALES_UPG_STS',

task_name => 'SALES_UPG_SPA');

DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(

task_name => 'SALES_UPG_SPA',

execution_type => 'CONVERT SQLSET',

execution_name => 'BEFORE_19C');

END;

/

PRINT tname

Expected output

PL/SQL procedure successfully completed.

TNAME
----------------------------------------------------------------
SALES_UPG_SPA

What this does: It creates the task SALES_UPG_SPA and the trial BEFORE_19C, which holds the production plans and statistics as they were measured on 19c. This is the baseline every 23ai execution is compared with.



Step 6: Run the "After" Trial on 23ai

Execute every statement of the tuning set on the 23ai test database. SPA runs each statement with its captured binds, records the plan and statistics, and discards the results. Data changing statements are executed only for their query part.


SQL

BEGIN

DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(

task_name => 'SALES_UPG_SPA',

execution_type => 'TEST EXECUTE',

execution_name => 'AFTER_23AI',

execution_params => DBMS_ADVISOR.ARGLIST('time_limit', '18000'));

END;

/

COLUMN execution_name FORMAT A12

COLUMN status FORMAT A10

SELECT execution_name, execution_type, status,

TO_CHAR(execution_start, 'YYYY-MM-DD HH24:MI') AS started

FROM dba_advisor_executions

WHERE task_name = 'SALES_UPG_SPA'

ORDER BY execution_start;

Expected output

PL/SQL procedure successfully completed.

EXECUTION_NA EXECUTION_TYPE                 STATUS     STARTED
------------ ------------------------------ ---------- ----------------
BEFORE_19C   CONVERT SQLSET                 COMPLETED  2026-11-27 09:12
AFTER_23AI   TEST EXECUTE                   COMPLETED  2026-11-27 09:14

What to expect: Both trials completed. The test execution ran each statement once, within the overall limit of five hours set by time_limit. On a test database, run it when nobody else uses the system, so the measurements are not disturbed.



Step 7: Compare the Trials

Compare the two trials on buffer gets, which is stable and independent of the hardware, and then look at the summary of improved and regressed statements.


SQL

BEGIN

DBMS_SQLPA.EXECUTE_ANALYSIS_TASK(

task_name => 'SALES_UPG_SPA',

execution_type => 'COMPARE PERFORMANCE',

execution_name => 'COMPARE_GETS',

execution_params => DBMS_ADVISOR.ARGLIST(

'comparison_metric', 'buffer_gets',

'execution_name1', 'BEFORE_19C',

'execution_name2', 'AFTER_23AI'));

END;

/

SET LONG 1000000 LONGCHUNKSIZE 1000000 LINESIZE 160 PAGESIZE 0

SELECT DBMS_SQLPA.REPORT_ANALYSIS_TASK(

task_name => 'SALES_UPG_SPA',

type => 'TEXT',

level => 'TYPICAL',

section => 'SUMMARY',

execution_name => 'COMPARE_GETS')

FROM dual;

Expected output

Projected Workload Change Impact:
-------------------------------------------
 Overall Impact      :  31.42%
 Improvement Impact  :  33.97%
 Regression Impact   :  -2.55%

SQL Statement Count
-------------------------------------------
SQL Category  SQL Count  Plan Change Count
Overall            1847                214
Improved            188                171
Regressed            11                 11
Unchanged          1648                 32

What to expect: The workload as a whole needs 31 percent fewer buffer gets on 23ai. 188 statements improved and 11 regressed, all 11 with a plan change. The overall result is good, but the 11 regressions decide whether users will complain, so look at them one by one in the next step.



Step 8: List the Regressed Statements

List the statements whose buffer gets per execution grew the most, from the statistics SPA stored for both trials, so the team can fix the important ones first.


SQL

COLUMN sql_id FORMAT A13

SELECT b.sql_id,

b.executions AS execs_19c,

ROUND(b.buffer_gets / NULLIF(b.executions, 0)) AS gets_19c,

ROUND(a.buffer_gets / NULLIF(a.executions, 0)) AS gets_23ai,

ROUND((a.buffer_gets / NULLIF(a.executions, 0)) /

NULLIF(b.buffer_gets / NULLIF(b.executions, 0), 0), 1) AS ratio

FROM dba_advisor_sqlstats b

JOIN dba_advisor_sqlstats a

ON a.task_name = b.task_name AND a.sql_id = b.sql_id

WHERE b.task_name = 'SALES_UPG_SPA'

AND b.execution_name = 'BEFORE_19C'

AND a.execution_name = 'AFTER_23AI'

AND a.buffer_gets / NULLIF(a.executions, 0) > 1.5 * b.buffer_gets / NULLIF(b.executions, 0)

ORDER BY (a.buffer_gets / NULLIF(a.executions, 0) - b.buffer_gets / NULLIF(b.executions, 0))

* b.executions DESC

FETCH FIRST 3 ROWS ONLY;

Expected output

SQL_ID         EXECS_19C   GETS_19C  GETS_23AI  RATIO
------------- ---------- ---------- ---------- ------
2gt8v9wq4h1zd       1204     158000     791200    5.0
4hx2k7m0qv9cn      38210       1840       5520    3.0
0ar5t1w8zp3kd         96      12400      19800    1.6

What to expect: The three regressions with the largest effect on the workload. The first is the 800-millisecond report from Step 2, with five times more buffer gets per execution on 23ai; the second is a statement of the order entry screen, small per execution but run 38,000 times a day. The full report with level => 'REGRESSED' and section => 'ALL' shows both plans of each statement side by side, which is the quickest way to see what the 23ai optimizer chose differently.



Step 9: Fix a Regression with the 19c Plan

For a regressed statement whose 19c plan was good, load that plan from the tuning set as a SQL plan baseline on the test database, then run the trial again for that statement to confirm.


SQL

SET SERVEROUTPUT ON

DECLARE

n PLS_INTEGER;

BEGIN

n := DBMS_SPM.LOAD_PLANS_FROM_SQLSET(

sqlset_name => 'SALES_UPG_STS',

basic_filter => q'[sql_id = '2gt8v9wq4h1zd']',

fixed => 'NO',

enabled => 'YES');

DBMS_OUTPUT.PUT_LINE(n || ' plan(s) loaded');

END;

/

COLUMN sql_handle FORMAT A20

COLUMN plan_name FORMAT A30

SELECT sql_handle, plan_name, enabled, accepted, origin

FROM dba_sql_plan_baselines

WHERE origin = 'MANUAL-LOAD-FROM-STS';

Expected output

1 plan(s) loaded

PL/SQL procedure successfully completed.

SQL_HANDLE           PLAN_NAME                      ENA ACC ORIGIN
-------------------- ------------------------------ --- --- -----------------------------
SQL_8e4d31c0a7f2b915 SQL_PLAN_8wm9jr2mz5f8p3c1a7b2d YES YES MANUAL-LOAD-FROM-STS

What this does: It gives the optimizer on 23ai the plan that worked on 19c, as an accepted baseline. After migrating production, export the baselines with DBMS_SPM pack and unpack procedures and import them there, or load them from the same tuning set on the new production. Rerun TEST EXECUTE and COMPARE PERFORMANCE for the task to confirm that the statement is no longer regressed, and keep the reports as evidence for the upgrade approval.



Summary

SQL Performance Analyzer turns "we hope the upgrade is fine" into a measured list. Capture a business day of SQL into a SQL tuning set on 19c, pack it, move it with Data Pump and unpack it on the 23ai test database in Oracle Database@Azure. Create an analysis task, build the 19c trial from the captured statistics, run the statements on 23ai, and compare the trials on buffer gets. Review the regressed statements in the report, fix the important ones with SQL plan baselines loaded from the tuning set, and run the comparison again. The Real Application Testing option is needed, and is included in licence-included Exadata Database Service.

Recent Posts

See All

Comments


bottom of page