Active Session History at work

本文介绍 Oracle Database 10g 中 Active Session History (ASH) 的使用技巧,包括如何快速定位 CPU 和等待事件的高消耗会话,以及追踪特定会话的 SQL 执行情况。

Performance Monitoring: Active Session History at work

Teaching an Oracle Database 10g Performance Tuning course this week, I introduced the 10g New Feature Active Session History (ASH) to the students. That was one major improvement – together with the Automatic Workload Repository (AWR) and the Automatic Database Diagnostic Monitor (ADDM) – of the 10g version. Way better than STATSPACK was before!

Imagine you are a DBA on a production system and get an emergency call like “The Database is dead slow!”. You are supposed to spot the cause as soon as possible. ASH kicks in here: We sample the Wait-Events of active sessions every second into the ASH-Buffer. It is accessed most comfortable with the Enterprise Manager GUI from the Performance Page (Button ASH Report there). Or with little effort from the command line like this:

-----------------------------------------
--
-- Top 10 CPU consumers in last 5 minutes
--
-----------------------------------------
SQL> select * from
(
select session_id, session_serial#, count(*)
from v$active_session_history
where session_state= 'ON CPU' and
 sample_time > sysdate - interval '5' minute
group by session_id, session_serial#
order by count(*) desc
)
where rownum <= 10;
--------------------------------------------
--
-- Top 10 waiting sessions in last 5 minutes
--
--------------------------------------------
SQL> select * from
(
select session_id, session_serial#,count(*)
from v$active_session_history
where session_state='WAITING'  and
 sample_time >  sysdate - interval '5' minute
group by session_id, session_serial#
order by count(*) desc
)
where rownum <= 10;

These 2 queries should spot the most incriminating sessions of the last 5 minutes. But who is that and what SQL was running?

--------------------
--
-- Who is that SID?
--
--------------------

set lines 200
col username for a10
col osuser for a10
col machine for a10
col program for a10
col resource_consumer_group for a10
col client_info for a10

SQL> select  serial#,
 username,
 osuser,
 machine,
 program,
 resource_consumer_group,
 client_info
from v$session where sid=&sid;

-------------------------
--
-- What did that SID do?
--
-------------------------

SQL> select distinct sql_id, session_serial# from v$active_session_history
where sample_time >  sysdate - interval '5' minute
and session_id=&sid;
----------------------------------------------
--
-- Retrieve the SQL from the Library Cache:
--
----------------------------------------------
col sql_text for a80
SQL> select sql_text from v$sql where sql_id='&sqlid';

You may spot the cause of the current performance problem in very short time with the shown technique. But beware: You need to purchase the Diagnostic Pack in order to be allowed to use AWR, ADDM and ASH

错误日志信息如下: [Conversations Error] Loading GitHub account information... [Conversations Information] Need to get an auth token. [HttpClientFactoryProvider Information] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] Status Code: 200, Reason Phrase: OK [Conversations Information] Response Content: HasToken: True, ChatEnabled: True, ExpiresAt: 1753071148, RefreshIn: 1500, SKU: free_educational_quota, CopilotExclusion: False, ChatQuota: '', CompletionsQuota: '', LimitedUserResetDate: '', CanSignupForLimited: '' [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [PersistedCopilotSessionRepository Information] Persisted sessions are stored under C:\Users\Realian\Desktop\LDY_Proj\.vs\TestArcMapAddin2\copilot-chat\990ec542\sessions Logging to: C:\Users\Realian\AppData\Local\Temp\VSGitHubCopilotLogs\20250721_034226.315_VSGitHubCopilot.chat.log [Conversations Information] Copilot chat version 17.14.794-rc+55eeaed228.RR (17.14.794.21998). VS: VisualStudio.17.Release/17.14.7+36221.1. Session: 3b081a6b-8f5f-4a41-86cb-05e694d30729. [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] [Conversations] Active solution path changed to C:\Users\Realian\Desktop\LDY_Proj\TestArcMapAddin2.sln [Conversations Information] [Conversations] Out-of-process service (PID: 6484) finished initializing. [Conversations Information] [CopilotAgents] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] [ChunkIndex] Index db path: C:\Users\Realian\Desktop\LDY_Proj\.vs\TestArcMapAddin2\CopilotIndices\17.14.794.21998\CodeChunks.db [Conversations Information] [GetQuota] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] [CopilotClient] Copilot Internal User response: Conversations.Abstractions.Auth.CopilotUserData [Conversations Information] [CopilotModels] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [CopilotClientManager Information] LSP: Activated (56456672) [CopilotClientManager Information] LSP: Debug Server: http://localhost:8180 [CopilotClientManager Information] LSP: Process 14728 [CopilotClientManager Information] Initial auth status: OK [CopilotClientManager Information] CopilotClientManager: model list fetched as of 2025/7/21 11:42:33. [CopilotSessionProvider Information] Begin sending message (ConversationId:0d34d6aa-3ad8-4ba8-9374-f3bc254ad7e2, CorrelationId:650a04d1-42ff-4f39-a5be-c94d216bc588, MessageId: c1c6518f-4b68-4947-97de-c11710ac3814) [CopilotSessionProvider Information] Request content: "请给MainProcessingTabsForm.cs中的btnGrasslandCreateBasemapLinkPrice按钮写一个草地的核算价格表生成功能,这部分的功能逻辑和ForestBasemapPriceAssociationForm.cs的一摸一样,只不过从林地换成了草地,请你先认真读取ForestBasemapPriceAssociationForm.cs中的逻辑代码和功能,理解后仿照它来写即可,只是有一些细节需要变化。首先同样是导入数据,需要浏览按钮让用户选择两条路径,第一个变为“草地基准地价定级数据”,第二个则是“草原资源地类图斑数据”。第一个路径下有若干个文件夹,每个的名称均以一个6位数的行政区代码开头加行政区名称加“草地定级和基准地价数据成果”组成,而第二个路径下同样也有若干个文件夹,每个文件夹名称相似,例如有一个文件夹名为“广东省肇庆市德庆县(441226)全民所有自然资源资产清查2023年度工作底图成果_草原”,在该路径下有若干这样的广东省县级行政区的数据,每个文件夹的名字中只有行政区名称以及括号中的6位数行政区代码不同,其他内容一样。而在配对遍历的时候,第一个路径下是:不同行政区的文件夹里打开名为“1-矢量数据”的文件夹,里面名字由6位数对应行政区代码加上“CDDJHJZDJDY”组成的Shp数据即为目标要导入的数据。而在第二个路径下打开行政区代码匹配的文件夹后,打开“空间数据”文件夹,再打开“清查范围数据”文件夹,随后名称为(6位数对应行政区代码)加上“CYZY_DLTB”的Shp数据即为目标数据(注意六位数行政区代码被包含在括号里。后续的导入地价映射表和数据处理生成价格核算表的处理和ForestBasemapPriceAssociationForm.cs完全一样,不过生成的shp属性表中,“二级地类代码”(EJDLDM)和“二级地类名称”(EJDLMC)字段从第8个字段和9个字段的排序变为第7个字段和第8个字段,原先的第7个字段“林地级别”(LDJB)字段名称更改为“草地级别”,字段代码更改为“CDJB”,同时排序更改为第9个字段,除此之外赋值和空间分析的逻辑与ForestBasemapPriceAssociationForm.cs一致,原先的第10个字段“县级林地平均价”(XJLDPJJ)字段名称更改为“县级草地平均价“,字段代码更改为“XJCDPJJ”,赋值逻辑也和ForestBasemapPriceAssociationForm.cs一样,其余字段都和ForestBasemapPriceAssociationForm.cs一致,所有字段类型长度精度都不变。最后输出结果时文件结构都不用改变,只是命名时将所有的“LDHSJG”改为“CDHSJG”即可。" [Conversations Information] [CopilotCompletions] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] [ChunkIndex] Found 40 total results for 4 queries from local index. [Conversations Information] [CopilotEmbeddings] Environment variable COPILOT_USE_DEFAULTPROXY found: False [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Information] Copilot auth status: OK. Copilot badge status: Active [Conversations Error] [CopilotClient] Unknown exception: Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. Path: $.explanation | LineNumber: 0 | BytePositionInLine: 205. [Conversations Error] [Conversations] Unhandled exception in AskInConversationAsync: System.Exception: Error occurred while invoking intent 'Generic'. Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. Path: $.explanation | LineNumber: 0 | BytePositionInLine: 205. at Conversations.Kernel.ConversationBase.AskAsync(ConversationRequest requestContext, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service.Kernel\ConversationBase.cs:line 95 at Conversations.Kernel.ConversationBase.AskAsync(ConversationRequest requestContext, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service.Kernel\ConversationBase.cs:line 141 at Microsoft.VisualStudio.Conversations.Service.ServiceTarget.AskInConversationAsync(CopilotSessionId sessionId, CopilotRequest request, ActiveInteractions activeInteractions, IReadOnlyList`1 history, CopilotRequestOptions requestOptions, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service\ServiceTarget.cs:line 192 [CopilotSessionProvider Error] Unhandled exception invoking responder GitHub Copilot: StreamJsonRpc.RemoteInvocationException: Error occurred while invoking intent 'Generic'. Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. Path: $.explanation | LineNumber: 0 | BytePositionInLine: 205. 在 StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.VisualStudio.Copilot.ResponderBroker.<SendRequestHelperAsync>d__9.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.Copilot.ResponderBroker.<SendDirectRequestAsync>d__3.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) 在 Microsoft.VisualStudio.Copilot.Core.Agents.CopilotAgentModeResponder.<RespondInternalAsync>d__7.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.VisualStudio.Copilot.Core.Agents.CopilotAgentModeResponder.<RespondInternalAsync>d__7.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) 在 Microsoft.VisualStudio.Copilot.CopilotDefaultOrchestrator.<SendRequestToResponderAsync>d__22.MoveNext() RPC server exception: System.Exception: Error occurred while invoking intent 'Generic'. Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. Path: $.explanation | LineNumber: 0 | BytePositionInLine: 205. at Conversations.Kernel.ConversationBase.AskAsync(ConversationRequest requestContext, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service.Kernel\ConversationBase.cs:line 95 at Conversations.Kernel.ConversationBase.AskAsync(ConversationRequest requestContext, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service.Kernel\ConversationBase.cs:line 141 at Microsoft.VisualStudio.Conversations.Service.ServiceTarget.AskInConversationAsync(CopilotSessionId sessionId, CopilotRequest request, ActiveInteractions activeInteractions, IReadOnlyList`1 history, CopilotRequestOptions requestOptions, CancellationToken cancellation) in D:\a\_work\1\s\src\Copilot.Service\ServiceTarget.cs:line 192 at Microsoft.VisualStudio.Conversations.Service.CopilotServiceContainer.AskInConversationAsync(CopilotSessionId sessionId, CopilotRequest request, ActiveInteractions activeResponse, IReadOnlyList`1 history, CopilotRequestOptions requestOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Copilot.Service\CopilotServiceContainer.cs:line 508
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值