How to Find Slow SQL: Databases for Developers: Performance #9

Опубликовано: 13 Октябрь 2024
на канале: The Magic of SQL
16,785
373

In order to tune SQL, you need to know what the slow statement is. But often you're just told that "the database" is slow!

To find the slow components, you need a breakdown of how long each piece of code takes to execute. You can do this in Oracle Database using:

A SQL trace
The PL/SQL hierarchical profiler

This video shows you how to do these with Oracle SQL Developer.

The script to spool the trace file is:

-----
set serveroutput off
set pagesize 0
set echo off
set feedback off
set trimspool on
set heading off
set tab off
set long 1000000
spool c:\temp\student_trace.trc

select payload
from v$diag_trace_file_contents
where trace_filename = (
select substr (
value,
instr ( value, '/', -1 ) + 1
) filename
from v$diag_info
where name = 'Default Trace File'
)
order by line_number;

spool off

-----

Need help with SQL?

Ask us over on AskTOM: https://asktom.oracle.com

Twitter:   / chrisrsaxon  
Daily SQL Twitter tips:   / sqldaily  
All Things SQL blog: https://blogs.oracle.com/sql/
Test your SQL Skills on the Oracle Dev Gym: https://devgym.oracle.com/

============================
The Magic of SQL with Chris Saxon

Copyright © 2020 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.