Pg gem is often used in a multi-threaded environment and you're using simple PG::Connection#exec calls, so that I doubt, that this is a pg issue. Anyhow the heap memory gets corrupted somehow and libpq stumbles about it.
What is your operating system and what does PG.threadsafe? return?
@Eduard Bondarenko : I don't know much about delayed_job, but I assume that it forks its workers. If so, are you closing database connections and re-establishing them after the fork? Forked processes inherit the file descriptors of their parents, so as @Chris Bandy suggested above, you might have to ensure your workers get their own database connections by forcing a disconnect before they fork.
Most systems that fork have some kind of lifecycle management like an before_fork hook, so I'd start there.