2
In the routine I’m developing, I do a simple SELECT in the bank, only in a table:
Model.select("id").where(:tipo => 2).find_each do |registro|
puts registro.id
end
But this select returns around 160,000 records. Then the system gives the error:
pid 258 SIGKILL (Signal 9)
If I comment on this line and follow my code, everything runs normally. I already researched it and started using the function find_each
in place of each
, but the error continued. If I limit the query, it also works normally.
As I understand it, the error is only due to the volume of data that is larger than the memory can support. Analyzing http://guides.rubyonrails.org/active_record_querying.html#retrieving-Multiple-Objects-in-batches and https://www.webascender.com/blog/rails-tips-speeding-activerecord-queries/, I observed that the find_each
improves this situation, but it did not help. How do I solve this?
Go to the command line in your Rails project folder and type
rails console
. It will open a terminal similar to theirb
. There you spinModel.select("id").where(:tipo => 2)
and see the SQL query being generated. Edit the question by entering this query.– vinibrsl
How much memory do you have? Which S.O ?
– Alex Takitani