如何分析 Oracle 存储过程的端到端性能
我想知道从外部进程访问数据库并说执行此操作到数据库返回到进程并说开始,我的存储过程需要多长时间才能执行。
有没有一种简单易行的方法来完成这项非常基本的任务?
当然,关于存储过程执行期间发生的情况以及执行每个任务(插入、plsql 字符串操作等)花费了多少存储过程时间的报告将是一个额外的好处,但我真的只想要一些简单且易于执行的东西使用。 (而且免费)
I want to know how long my stored procedure is taking to execute from the time an external process hits the database and says execute this to the time the database returns back to the process and says here ya go.
Is there a simple easy way to do this very basic task?
Of course a report of what is happening during the stored procedure execution and how much of the stored procedure's time is spent doing each task (inserts, plsql string manipulation etc.) would be a bonus, but I really just want something simple and easy to use. (And free)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 Oracle 11g,您应该查看分层分析器 DBMS_HPROF。这是一个工具,可以为您提供 PL/SQL 程序中所有节点的运行时间。顾名思义,它对于调查调用程序的程序特别有用。它还识别与函数调用不同的 SQL 语句的计时。 了解更多信息。
它是标准 11g 部署的一部分,因此是免费的。好吧,一旦您支付了许可证费用,它就是免费的:)
默认情况下,DBMS_HPROF 包的权限不会授予任何人。因此,您需要让具有 SYSDBA 访问权限的人来了解您的情况。分析还需要创建一些表。这些事情都不应该成为问题,但我知道有时它们确实是问题。
唉,你使用的是早期版本。这样你就只剩下了 DBMS_PROFILER,它从 9i 就已经存在了。这基本上对于单个程序来说效果很好。它的主要缺点是我们只能在具有 CREATE 权限的程序上使用它(即只能在我们的架构中的程序,除非我们具有 CREATE ANY PROCEDURE 权限,这通常意味着成为 DBA)。此外,为了分析嵌入式 SQL 语句,我们需要使用 DBMS_TRACE 包。 了解更多信息。
If you're using Oracle 11g you should have a look at the hierarchical profiler, DBMS_HPROF. This is a tool which will give you elapsed timings for all the nodes in a PL/SQL program. As the name suggests, it is especially useful for investigating programs which call programs which call programs. It also identifies timing for SQL statements distinct from function calls. Find out more.
It is part of the standard 11g deployment, and hence is free. Well, once you've paid for your license it's free :)
By default rights on the DBMS_HPROF package are not granted to any one. So, you'll need to get somebody with SYSDBA access to see you right. The analysis also requires the creation of some tables. Neither of these things should be an issue but I know sometimes they are.
Alas, you're on an earlier version. So that leaves you with just DBMS_PROFILER, which has been around since 9i. This basically works well for a single program. Its main drawback is that we can only use it on programs for which we have the CREATE privilege (i.e. just programs in our schema unless we have the CREATE ANY PROCEDURE privilge, which usually means being a DBA). Also, for profiling embedded SQL statements we need to use the DBMS_TRACE package. Find out more.
最简单、最便宜的选择
您可以将事件记录到“调试”表并检查日志之间的持续时间,例如。
在插入表 a 之前记录事件,并将时间戳 a 插入调试表。
将带有时间戳 b 的表插入调试表后记录事件。
如果您的存储过程超过 5 行,这会有点耗时,但它仍然会对您有所帮助。还要实现一个调试标志,因此当您需要记录时间戳时,请将过程顶部的标志设置为 true,然后重新编译它。执行存储过程时,它将记录所有事件,完成调试后,将标志设置为 false 并重新编译。
SIMPLEST,CHEAPEST OPTION
You could log events to a "debug" table and check the duration between the logs, like for ex.
Log event before insert into table a with time stamp a into debug table.
Log event after insert into table a with timestamp b into debug table.
It's a bit time consuming if you're stored procedure is anything more than 5 lines, but it will help you none the less. Also implement a debug flag, so when you need to log time stamps, set the flag at the top of the procedure to true, and then re-compile it. When executing the stored procedure, it will then go and log all your events, when done with debugging, set the flag to false and re-compile.
如果您希望将自己的延时写入 PL/SQL 程序,下面是我用于执行此操作的模板代码。此外,这不需要 DBA 的帮助。我的 DBA 通常不愿意让我有更多机会接触更多的东西。那,我讨厌等待他们真正给我访问权限。
If you are looking to write your own time lapse into your PL/SQL programs the below is my template code for doing this. Also, this requires no assistance from your DBA. My DBA's are often reluctant to give me more access to more things. That, and I hate waiting for them to actually give me access.