4

We have a certain SQL_ID that has performance issues (ex. cd123812jedjdu). This was shown from the AWR report to be called from PKG1. However, PKG1 calls so many packages inside, like below:

PKG1.MAIN
-> PKG1.PROC1
-> -> PKG2.PROC1
-> -> PKG2.PROC2
-> -> PKG2.PROC3
-> PKG1.PROC2
-> -> PKG3.PROC1
-> -> PKG3.PROC2
-> -> PKG3.PROC3
-> PKG1.PROC3
-> -> PKG4.PROC1
-> -> PKG4.PROC2
-> -> PKG4.PROC3
-> PKG1.PROC4
-> -> PKG5.PROC1
-> -> PKG5.PROC2
-> -> PKG5.PROC3

After hours of tracing, I found out it was being called from PKG4.PROC3. Is there any way I can find out the actual PL/SQL package that calls the SQL_ID, perhaps using the v$ views?

Note: I know the SQL_TEXT can be queries from v$ views, but there are multiple similar queries with the same SQL_TEXT.

3 Answers 3

5

You don't need to use PL/Scope, the information you need is already stored in v$sql when the query is hard parsed (of course, if you have the same query appearing in multiple pieces of code, only the one that it was hard parsed from will appear, unless there are sufficient differences to trigger an additional child cursor).

The column you care about is program_id it matches up to dba_objects.object_id. It will also tell you the line number the SQL appears in under program_line#.

Here's a quick LiveSQL demo. The columns have existed since at least Oracle 10.2.

1
  • 1
    It may or may not be on v$sql...good add though. Commented Mar 16, 2021 at 9:43
4

Yes or maybe.

It depends on your version of Oracle, and if you've compiled your PL/SQL with PL/Scope.

In version 12cR2 and higher, there's a new view, ALL_STATEMENTS. It tracks the SQL being used in your PL/SQL, and includes the SQLIDs.

I talk about taking advantage of this information in SQL Developer here.

enter image description here

0

You can join from a SQL_ID in the SGA to the originating package name and code line as shown in the DBA AWR SQL Performance Summary and DBA SGA SQL Performance Summary blitz reports (Excel columns F+G):

select
(select so.name from sys.obj$ so where gsa.program_id=so.obj#) code,
case when gsa.program_line#>0 then gsa.program_line# end code_line#,
gsa.sql_id,
...
from
gv$sqlarea gsa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.