共用方式為


PGSQLPgStatActivitySessions 資料表的查詢

如需在 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