Skip to content

Commit ff84e1d

Browse files
author
xiongcc
committed
add my opinion
1 parent e773105 commit ff84e1d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

How to decide when a query is too slow and needs optimization.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@
2424
3. DDL 应谨慎操作 — 确保它们不会导致大量写入 (如果会,则应分批处理),并使用较低的 `lock_timeout` 和重试机制,以避免形成阻塞链。
2525
4. 不要允许长时间运行的事务。确保 xmin 视界在推进,autovacuum 可以及时删除死元组 — 避免事务持续时间过长 (>1-2 小时)。
2626
5. 即使是快的查询 (<100 毫秒),如果 pg_stat_statements.calls 和 pg_stat_statements.total_exec_time 较高,也需要进行优化。
27+
28+
## 我见
29+
30+
- 10 ms or less – good performance
31+
- 10-100 ms – optimization is recommended
32+
- more than 100 ms – poor performance, optimization is needed
33+
34+
![img](https://postgres.ai/assets/blog/20210909-slow-sql.png)
35+
36+
另外,在 pb 中,可以跟直观地看到 TPS/QPS,详见:https://postgres.ai/blog/20210909-what-is-a-slow-sql-query
37+
38+
~~~bash
39+
stats: 318 xacts/s, 443 queries/s, in 59883 B/s, out 122544 B/s, xact 1076 us, query 454 us, wait 548 us
40+
~~~
41+

0 commit comments

Comments
 (0)