英文:
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_activity
的 backend_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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论