List of causes for PG::InvalidChangeOfResultFields exceptions

24 views
Skip to first unread message

mic...@knotch.com

unread,
Dec 3, 2018, 3:34:16 PM12/3/18
to ruby-pg
I am curious as to what exactly would cause this exception to be raised. We're using a read-only replica and run pretty long running aggregation queries off this replica. These queries are executed via Ruby PG using streaming mode. Occasionally, this exception is raised by our aggregation service but it seems to happen randomly and we haven't been able to reproduce it in a controlled setting.

Any insight into how or why this exception would be raised will be very helpful. Thanks! 

Robert Klemme

unread,
Dec 10, 2018, 3:07:39 PM12/10/18
to rub...@googlegroups.com
On Mon, Dec 3, 2018 at 9:34 PM <mic...@knotch.com> wrote:
>
> I am curious as to what exactly would cause this exception to be raised. We're using a read-only replica and run pretty long running aggregation queries off this replica. These queries are executed via Ruby PG using streaming mode. Occasionally, this exception is raised by our aggregation service but it seems to happen randomly and we haven't been able to reproduce it in a controlled setting.
>
> Any insight into how or why this exception would be raised will be very helpful. Thanks!

This is really just a guess: maybe there is a memory constraint (e.g.
either physical mem lacking, PG's buffer cache not large enough, not
enough work memory configured) so the query cannot be completed
properly. That would explain the randomness (e.g. via parallel
activity that eats memory).

Cheers

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Michael Coyne

unread,
Dec 10, 2018, 5:49:37 PM12/10/18
to rub...@googlegroups.com
Thanks for the insight! Very confused by this error overall and any
additional information is helpful and appreciated.

One thing I forgot to mention is that we're using this code in a
multi-threaded process. Is there any chance that could also explain it
and maybe somehow the streams are getting mixed up?
> --
> You received this message because you are subscribed to a topic in the Google Groups "ruby-pg" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-pg/nWONqbd-G_U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ruby-pg+u...@googlegroups.com.
> To post to this group, send email to rub...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-pg/CAM9pMnN%2BP53v%3DwKx2JfFsj99U60EgWouvqzE00oKKnDt1adpxg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Michael Coyne
Staff Software Engineer and Team Lead

52 Walker St, New York, NY, 10013
mic...@knotch.com
knotch.com | @knotchinc

Lars Kanis

unread,
Dec 11, 2018, 4:42:39 AM12/11/18
to mic...@knotch.com, ruby-pg
If I remember right, this error happens when prepared statements are outdated. ActiveRecord makes use of prepared statements by default. If you do database migrations, while long running processes are active, these processes will receive this error, when they execute the next query using a now outdated prepared statement.

This can be avoided by disabling prepared statements, leading to somewhat lower performance or by flushing all prepared statements in long running processes, whenever the schema changes.

--
Kind Regards,
Lars
Reply all
Reply to author
Forward
0 new messages