Cherry-pick #e2a4b7a that resolves postgres fail

https://github.com/rails/rails/commit/e2a4b7a506e36839771284942829cbbe8d
40b377