|
1 | 1 | ---
|
2 | 2 | title: Query Store scenarios - Azure Database for PostgreSQL - Flex Server
|
3 | 3 | description: This article describes some scenarios for Query Store in Azure Database for PostgreSQL - Flex Server.
|
4 |
| -author: ssen-msft |
5 |
| -ms.author: ssen |
| 4 | +author: markingmyname |
| 5 | +ms.author: maghan |
| 6 | +ms.date: 11/30/2023 |
6 | 7 | ms.service: postgresql
|
7 | 8 | ms.subservice: flexible-server
|
8 | 9 | ms.topic: conceptual
|
9 |
| -ms.date: 7/1/2023 |
10 | 10 | ---
|
| 11 | + |
11 | 12 | # Usage scenarios for Query Store - Flexible Server
|
12 | 13 |
|
13 | 14 | [!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
|
14 | 15 |
|
15 |
| -You can use Query Store in a wide variety of scenarios in which tracking and maintaining predictable workload performance is critical. Consider the following examples: |
16 |
| -- Identifying and tuning top expensive queries |
17 |
| -- A/B testing |
18 |
| -- Keeping performance stable during upgrades |
19 |
| -- Identifying and improving ad hoc workloads |
| 16 | +You can use Query Store in a wide variety of scenarios in which tracking and maintaining predictable workload performance is critical. Consider the following examples: |
| 17 | +- Identifying and tuning top expensive queries |
| 18 | +- A/B testing |
| 19 | +- Keeping performance stable during upgrades |
| 20 | +- Identifying and improving improvised workloads |
| 21 | + |
| 22 | +## Identify and tune expensive queries |
| 23 | + |
| 24 | +### Identify longest running queries |
20 | 25 |
|
21 |
| -## Identify and tune expensive queries |
| 26 | +Use Query Store views on the azure_sys database of your server to quickly identify the longest running queries. These queries typically tend to consume the most resources. Optimizing your longest running queries can improve performance by freeing up resources used by other queries running on your system. |
22 | 27 |
|
23 |
| -### Identify longest running queries |
24 |
| -Use Query Store views on the azure_sys database of your server to quickly identify the longest running queries. These queries typically tend to consume the most resources. Optimizing your longest running queries can improve performance by freeing up resources used by other queries running on your system. |
| 28 | +### Target queries with performance deltas |
25 | 29 |
|
26 |
| -### Target queries with performance deltas |
27 | 30 | Query Store slices the performance data into time windows, so you can track a query's performance over time. This helps you identify exactly which queries are contributing to an increase in overall time spent. As a result you can do targeted troubleshooting of your workload.
|
28 | 31 |
|
29 |
| -### Tuning expensive queries |
30 |
| -When you identify a query with suboptimal performance, the action you take depends on the nature of the problem: |
| 32 | +### Tune expensive queries |
| 33 | + |
| 34 | +When you identify a query with suboptimal performance, the action you take depends on the nature of the problem: |
31 | 35 | - Make sure that the statistics are up-to-date for the underlying tables used by the query.
|
32 |
| -- Consider rewriting expensive queries. For example, take advantage of query parameterization and reduce the use of dynamic SQL. Implement optimal logic when reading data like applying data filtering on database side, not on application side. |
33 |
| - |
34 |
| - |
35 |
| -## A/B testing |
36 |
| -Use Query Store to compare workload performance before and after an application change you plan to introduce or before and after migration. Example scenarios for using Query Store to assess the impact of changes to workload performance: |
37 |
| -- Migration between PostgreSQL versions. |
38 |
| -- Rolling out a new version of an application. |
39 |
| -- Adding additional resources to the server. |
40 |
| -- Creating missing indexes on tables referenced by expensive queries. |
41 |
| -- Migration from Single Server to Flex Server. |
42 |
| - |
43 |
| -In any of these scenarios, apply the following workflow: |
44 |
| -1. Run your workload with Query Store before the planned change to generate a performance baseline. |
45 |
| -2. Apply application change(s) at the controlled moment in time. |
46 |
| -3. Continue running the workload long enough to generate performance image of the system after the change. |
47 |
| -4. Compare results from before and after the change. |
48 |
| -5. Decide whether to keep the change or rollback. |
49 |
| - |
50 |
| - |
51 |
| -## Identify and improve ad hoc workloads |
52 |
| -Some workloads do not have dominant queries that you can tune to improve overall application performance. Those workloads are typically characterized with a relatively large number of unique queries, each of them consuming a portion of system resources. Each unique query is executed infrequently, so individually their runtime consumption is not critical. On the other hand, given that the application is generating new queries all the time, a significant portion of system resources is spent on query compilation, which is not optimal. Usually, this situation happens if your application generates queries (instead of using stored procedures or parameterized queries) or if it relies on object-relational mapping frameworks that generate queries by default. |
53 |
| - |
54 |
| -If you are in control of the application code, you may consider rewriting the data access layer to use stored procedures or parameterized queries. However, this situation can be also be improved without application changes by forcing query parameterization for the entire database (all queries) or for the individual query templates with the same query hash. |
55 |
| - |
56 |
| -## Next steps |
57 |
| -- Learn more about the [best practices for using Query Store](concepts-query-store-best-practices.md) |
| 36 | +- Consider rewriting expensive queries. For example, take advantage of query parameterization and reduce the use of dynamic SQL. Implement optimal logic when reading data like applying data filtering on database side, not on application side. |
| 37 | + |
| 38 | +## A/B testing |
| 39 | + |
| 40 | +Use Query Store to compare workload performance before and after an application change you plan to introduce or before and after migration. Example scenarios for using Query Store to assess the impact of changes to workload performance: |
| 41 | +- Migration between PostgreSQL versions. |
| 42 | +- Rolling out a new version of an application. |
| 43 | +- Adding additional resources to the server. |
| 44 | +- Creating missing indexes on tables referenced by expensive queries. |
| 45 | +- Migration from Single Server to Flex Server. |
| 46 | + |
| 47 | +In any of these scenarios, apply the following workflow: |
| 48 | +1. Run your workload with Query Store before the planned change to generate a performance baseline. |
| 49 | +1. Apply application change(s) at the controlled moment in time. |
| 50 | +1. Continue running the workload long enough to generate performance image of the system after the change. |
| 51 | +1. Compare results from before and after the change. |
| 52 | +1. Decide whether to keep the change or rollback. |
| 53 | + |
| 54 | +## Identify and improve improvised workloads |
| 55 | + |
| 56 | +Some workloads don't have dominant queries that you can tune to improve overall application performance. Those workloads are typically characterized with a relatively large number of unique queries, each of them consuming a portion of system resources. Each unique query is executed infrequently, so individually their runtime consumption isn't critical. On the other hand, given that the application is generating new queries all the time, a significant portion of system resources is spent on query compilation, which isn't optimal. Usually, this situation happens if your application generates queries (instead of using stored procedures or parameterized queries) or if it relies on object-relational mapping frameworks that generate queries by default. |
| 57 | + |
| 58 | +If you are in control of the application code, you might consider rewriting the data access layer to use stored procedures or parameterized queries. However, this situation can be also be improved without application changes by forcing query parameterization for the entire database (all queries) or for the individual query templates with the same query hash. |
| 59 | + |
| 60 | +## Next step |
| 61 | + |
| 62 | +> [!div class="nextstepaction"] |
| 63 | +> [best practices for using Query Store](concepts-query-store-best-practices.md) |
0 commit comments