Skip to content

Commit 8e35143

Browse files
committed
docs: fixes for PR #4573 - editorial and formatting updates
1 parent a6f3a11 commit 8e35143

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

articles/postgresql/troubleshoot/how-to-identify-slow-queries-elastic-clusters.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ ms.topic: troubleshooting-general
1212

1313
# Troubleshoot and identify slow-running queries in Azure Database for PostgreSQL Elastic Clusters
1414

15-
This article describes how to identify and diagnose the root cause of slow-running queries, which can consume CPU resources and lead to high CPU utilization.
15+
This article describes how to identify and diagnose the root cause of slow-running queries. These queries can consume CPU resources and lead to high CPU utilization.
1616

1717
## Identify the slow query
1818

19-
You can identify the slow query by using `pg_stat_statements`. The following query helps identify the top five slowest operations.
19+
Use `pg_stat_statements` to identify the slow query. The following query helps you find the top five slowest operations.
2020

2121
```sql
2222
SELECT userid::regrole, dbid, query, mean_exec_time
2323
FROM pg_stat_statements
2424
ORDER BY mean_exec_time DESC LIMIT 5;
2525
```
2626

27-
## Inspect current active/long-running queries
27+
## Inspect current active or long-running queries
2828

29-
The following query helps identify queries running for greater than 15 minutes.
29+
The following query helps you identify queries running for more than 15 minutes.
3030

3131
```sql
3232
SELECT
@@ -53,17 +53,17 @@ ORDER BY NOW() - query_start DESC;
5353

5454
:::image type="content" source="media/how-to-identify-slow-queries-elastic-clusters/long-running-queries.png" alt-text="Screenshot of long-running queries result." lightbox="media/how-to-identify-slow-queries-elastic-clusters/long-running-queries.png":::
5555

56-
This result shows there's one query on the server that has been running slow and taking longer execution times.
56+
This result shows there's one query on the server that runs slow and takes longer execution times.
5757

58-
The `global_pid` associated with the long-running query is the same, which means the same query is running the longest on all the worker nodes.
58+
The `global_pid` associated with the long-running query is the same, which means the same query runs the longest on all the worker nodes.
5959

6060
### Identify the tables and their distribution type in the query
6161

6262
1. The distributed tables
6363
1. The reference tables
6464
1. The colocation tables
6565

66-
If any tables are regular, make them either reference tables or colocation tables. You can find that information using the following query.
66+
If the query uses regular tables, change them to either reference tables or colocation tables. To find this information, use the following query.
6767

6868
```sql
6969
SELECT table_name,
@@ -77,8 +77,8 @@ ORDER BY table_name;
7777

7878
What to look for in the preceding query:
7979

80-
- distribution_type = reference → broadcast joins
81-
- Missing or wrong distribution_column
80+
- `distribution_type = reference` → broadcast joins
81+
- Missing or wrong `distribution_column`
8282

8383
### Solution
8484

@@ -90,7 +90,7 @@ SELECT create_reference_table('products');
9090

9191
## Detect non-colocated tables used in joins
9292

93-
One of the top causes for slow queries could be a non-colocated table. Here's a query to identify non-colocated tables.
93+
One of the top causes for slow queries is a non-colocated table. Here's a query to identify non-colocated tables.
9494

9595
```sql
9696
SELECT a.table_name AS table_a,
@@ -105,10 +105,10 @@ WHERE a.colocation_id <> b.colocation_id;
105105

106106
What to look for in the preceding query:
107107

108-
1. If your tables are listed here, you should consider colocating them. Colocating tables prevents:
109-
a. Data reshuffling across nodes
110-
b. Network overhead
111-
c. Temp file spills
108+
1. If your tables are listed, consider colocating them. Colocating tables prevents:
109+
- Data reshuffling across nodes
110+
- Network overhead
111+
- Temp file spills
112112

113113
You can also identify these symptoms by reviewing the execution plans of your query. Pay attention to these action types:
114114

@@ -118,8 +118,8 @@ You can also identify these symptoms by reviewing the execution plans of your qu
118118
### Solution
119119

120120
- Distribute tables on the join key.
121-
- Make sure the distributed table and reference table are joined correctly
122-
- Index the join keys
121+
- Make sure you join the distributed table and reference table correctly.
122+
- Index the join keys.
123123
- Fix colocation of the table by pointing the table to the right distribution key.
124124
- You might need to recombine the table and then distribute the table using a more appropriate distribution key.
125125

@@ -130,7 +130,7 @@ SELECT create_distributed_table('orders', 'customer_id');
130130

131131
## Check for skewness of data across shards and nodes
132132

133-
The following query identifies which shards/nodes contain long-running queries, and their shard sizes.
133+
The following query identifies which shards and nodes contain long-running queries, and their shard sizes.
134134

135135
```sql
136136
SELECT
@@ -148,21 +148,21 @@ JOIN citus_stat_activity ON citus_stat_activity.query LIKE '%' || cs.shardid ||
148148
ORDER BY duration DESC;
149149
```
150150

151-
The results show that the queries are accessing four specific shards in each of the worker nodes.
151+
The results show that the queries access four specific shards in each of the worker nodes.
152152

153-
If you see the majority of data on a subset of worker nodes, this indicates you should reconsider your distribution key selection.
153+
If you see the majority of data on a subset of worker nodes, reconsider your distribution key selection.
154154

155-
You can troubleshoot further by reviewing details of the distributed table by shards using the following query:
155+
To troubleshoot further, review details of the distributed table by shards using the following query:
156156

157157
```sql
158158
SELECT * FROM run_command_on_shards('orders', $$ SELECT json_build_object( 'shard_name', '%1$s', 'size', pg_size_pretty(pg_table_size('%1$s')) ); $$);
159159
```
160160

161161
### Solution
162162

163-
Based on the preceding output, if the data is skewed to a few shards, the distribution key is likely the cause. In this case, consider rearchitecting the distribution key.
163+
Based on the preceding output, if the data is skewed to a few shards, the distribution key is likely the cause. Consider rearchitecting the distribution key.
164164

165-
Here's a related talk on choosing the right shard key. [Efficiently distributing Postgres with Citus - How to choose the right shard key? | Citus Con 2022](https://www.youtube.com/watch?v=t0EXeWk3lAk)
165+
Here's a related talk on choosing the right shard key: [Efficiently distributing Postgres with Citus - How to choose the right shard key? | Citus Con 2022](https://www.youtube.com/watch?v=t0EXeWk3lAk).
166166

167167
## Diagnose lock contention
168168

@@ -249,8 +249,8 @@ SELECT * FROM run_command_on_all_nodes( $$ SELECT json_agg(t) FROM (
249249
) t $$ );
250250
```
251251

252-
> [!NOTE]
253-
> This might happen when your server is restarted or scaled. In those cases, wait for your system to stabilize.
252+
> [!NOTE]
253+
> This condition might happen when your server restarts or scales. In those cases, wait for your system to stabilize.
254254
255255
## Related content
256256

0 commit comments

Comments
 (0)