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?
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.