I fixed an issue on my rails project locally (with postgres config) while adding in database.yml this statement:
test:
prepared_statements: false
turning off prepared statements decreases performance because postgresql has to replan every query before executing so i do not suggest to turn it off for production servers - especially as rails is notorious for doing many small queries when you don't take really good care about eager loading everything. I suggest indead figuring out how to do restarts in live after each deployment without affecting the availability of your service. I am not a rails guru but i know that it's doable (our company does it exactly like that). Here is a bit more insight into why this is happening https://github.com/rails/rails/issues/12330