这个查询生成三个查询进程是正常的吗?

huangapple go评论58阅读模式
英文:

Is it normal for a query to spawn three query processes?

问题

我有一个Rails应用程序,正在尝试解决一些数据库性能问题,我刚刚注意到,当我从Rails控制台进行查询时:

MyModel.where("field ILIKE '%hello%'")

当我查看PostgreSQL中的活动查询时:

SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE state != 'idle' AND query NOT ILIKE '%pg_stat_activity%';

我看到:

 28877 | 00:00:00.868747 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
 28960 | 00:00:00.868757 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
 28961 | 00:00:00.868759 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
(3 rows)

我非常担心一个命令会生成3个进程?这正常吗?

英文:

I have a rails application and am trying to troubleshoot some database performance issues, and I just noticed, when I make a query from the rails console:

MyModel.where("field ILIKE '%hello%'")

when I look at postgres for active queries:

SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE state != 'idle' AND query NOT ILIKE '%pg_stat_activity%';

I am seeing:

 28877 | 00:00:00.868747 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
 28960 | 00:00:00.868757 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
 28961 | 00:00:00.868759 | me | SELECT "shares".* FROM "shares" WHERE (message ilike '%hello%')
(3 rows)

I was very concerned that one command is spawning 3 processes??? Is this normal?

答案1

得分: 0

查看 pg_stat_activitybackend_type 列,你可能会看到其中两个进程是并行工作者。你正在看到并行查询正在执行。

英文:

Look at the backend_type column of pg_stat_activity, and you will probably see that two of these processes are parallel workers. You are seeing parallel query in action.

huangapple
  • 本文由 发表于 2023年6月22日 03:01:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定