有关在 Azure 门户中使用这些查询的信息,请参阅 Log Analytics 教程。 有关 REST API,请参阅查询。
最长会话数
搜索最长会话,而不考虑状态。
PGSQLPgStatActivitySessions
| where UserId != 10 //exclude azure managed user
| where BackendType =='client backend'
| where isnotempty(DatabaseId) and DatabaseName !in('azure_sys','azure_maintenance')
| extend ConnectionDurationSec = datetime_diff('second',CollectionTime,BackendStartTime)
| summarize maxConnectionDurationSeconds=max(ConnectionDurationSec),arg_max(LastSampledTime=TimeGenerated,lastState=State) by ProcessId,BackendStartTime,DatabaseName,UserId,ApplicationName,ClientIpAddress
| order by maxConnectionDurationSeconds desc
| take 100
最长事务数
搜索具有最长执行时间的会话和 TransactionId。
PGSQLPgStatActivitySessions
| where UserId != 10 and State !='idle' //exclude azure managed user and idle sessions
| where BackendType =='client backend'
| where isnotempty(DatabaseId) and DatabaseName !in('azure_sys','azure_maintenance')
| extend TransactionDurationMs = datetime_diff('millisecond',CollectionTime,TransactionStartTime)
| summarize MaxTransactionDurationMs=max(TransactionDurationMs),arg_max(LastSampledTime=TimeGenerated,lastState=State) by ProcessId,BackendStartTime,TransactionId,DatabaseName,UserId,ApplicationName,ClientIpAddress
| order by MaxTransactionDurationMs desc
| take 100
具有长查询的会话
使用提升的查询执行时间搜索会话。
PGSQLPgStatActivitySessions
| where UserId != 10 and State !='idle' //exclude azure managed user and idle sessions
| where BackendType =='client backend'
| where isnotempty(DatabaseId) and DatabaseName !in('azure_sys','azure_maintenance')
| extend QueryExecDurationMs = datetime_diff('millisecond',CollectionTime,QueryStartTime)
| summarize MaxQueryExecDurationMs=max(QueryExecDurationMs),arg_max(LastSampledTime=TimeGenerated,lastState=State) by ProcessId,BackendStartTime,DatabaseName,UserId,ApplicationName,ClientIpAddress
| order by MaxQueryExecDurationMs desc
| take 100