Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
For information on using these queries in the Azure portal, see Log Analytics tutorial. For the REST API, see Query.
Longest sessions
Search for longest sessions regardless of state.
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
Longest transactions
Search sessions and TransactionIds with longest execution time.
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
Sessions with long queries
Search for sessions with elevated query execution time.
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