When rebuild, Discourse removes PostGreSQL 10 and reinstalls version 9.5

So you changed that to 9.5 over 2 years ago and forgot about it.

Well, just in time, the upgrade to PostgreSQL 12 is coming very soon. Meta is already running on it.