PG::ConnectionBad causes site to temporarily crash

But they aren’t. There are settings that control, e.g., how much RAM the database can use that are embedded in app.yml. You can edit them by hand or re-run discourse-setup.