Skip to content

Commit 430fde6

Browse files
committed
slow query logging parameters and sample queries
1 parent 9aa6bb7 commit 430fde6

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

articles/mysql/concepts-server-logs.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ Other parameters you can adjust include:
3737
- **log_throttle_queries_not_using_indexes**: This parameter limits the number of non-index queries that can be written to the slow query log. This parameter takes effect when log_queries_not_using_indexes is set to ON.
3838
- **log_output**: if "File", allows the slow query log to be written to both the local server storage and to Azure Monitor Diagnostic Logs. If "None", the slow query log will only be written to Azure Monitor Diagnostics Logs.
3939

40-
> [!Note]
41-
> For `sql_text`, log will be truncated if it exceeds 2048 characters.
40+
> [!IMPORTANT]
41+
> If your tables are not indexed, setting the `log_queries_not_using_indexes` and `log_throttle_queries_not_using_indexes` parameters to ON may affect MySQL performance since all queries running against these non-indexed tables will be written to the slow query log.<br><br>
42+
> If you plan on logging slow queries for an extended period of time, it is recommended to set `log_output` to "None". If set to "File", these logs are written to the local server storage and can affect MySQL performance.
4243
4344
See the MySQL [slow query log documentation](https://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html) for full descriptions of the slow query log parameters.
4445

@@ -78,5 +79,63 @@ The following table describes what's in each log. Depending on the output method
7879
| `thread_id_s` | Thread ID |
7980
| `\_ResourceId` | Resource URI |
8081

82+
> [!Note]
83+
> For `sql_text`, log will be truncated if it exceeds 2048 characters.
84+
85+
## Analyze logs in Azure Monitor Logs
86+
87+
Once your slow query logs are piped to Azure Monitor Logs through Diagnostic Logs, you can perform further analysis of your slow queries. Below are some sample queries to help you get started. Make sure to update the below with your server name.
88+
89+
- Queries longer than 10 seconds on a particular server
90+
91+
```Kusto
92+
AzureDiagnostics
93+
| where LogicalServerName_s == '<your server name>'
94+
| where Category == 'MySqlSlowLogs'
95+
| project TimeGenerated, LogicalServerName_s, event_class_s, start_time_t , query_time_d, sql_text_s
96+
| where query_time_d > 10
97+
```
98+
99+
- List top 5 longest queries on a particular server
100+
101+
```Kusto
102+
AzureDiagnostics
103+
| where LogicalServerName_s == '<your server name>'
104+
| where Category == 'MySqlSlowLogs'
105+
| project TimeGenerated, LogicalServerName_s, event_class_s, start_time_t , query_time_d, sql_text_s
106+
| order by query_time_d desc
107+
| take 5
108+
```
109+
110+
- Summarize slow queries by minimum, maximum, average, and standard deviation query time on a particular server
111+
112+
```Kusto
113+
AzureDiagnostics
114+
| where LogicalServerName_s == '<your server name>'
115+
| where Category == 'MySqlSlowLogs'
116+
| project TimeGenerated, LogicalServerName_s, event_class_s, start_time_t , query_time_d, sql_text_s
117+
| summarize count(), min(query_time_d), max(query_time_d), avg(query_time_d), stdev(query_time_d), percentile(query_time_d, 95) by LogicalServerName_s
118+
```
119+
120+
- Graph the slow query distribution on a particular server
121+
122+
```Kusto
123+
AzureDiagnostics
124+
| where LogicalServerName_s == '<your server name>'
125+
| where Category == 'MySqlSlowLogs'
126+
| project TimeGenerated, LogicalServerName_s, event_class_s, start_time_t , query_time_d, sql_text_s
127+
| summarize count() by LogicalServerName_s, bin(TimeGenerated, 5m)
128+
| render timechart
129+
```
130+
131+
- Display queries longer than 10 seconds across all MySQL servers with Diagnostic Logs enabled
132+
133+
```Kusto
134+
AzureDiagnostics
135+
| where Category == 'MySqlSlowLogs'
136+
| project TimeGenerated, LogicalServerName_s, event_class_s, start_time_t , query_time_d, sql_text_s
137+
| where query_time_d > 10
138+
```
139+
81140
## Next Steps
82141
- [How to configure and access server logs from the Azure CLI](howto-configure-server-logs-in-cli.md).

0 commit comments

Comments
 (0)