When rebuild, Discourse removes PostGreSQL 10 and reinstalls version 9.5

Can you please share the first few lines of you app.yml?

The ones under templates.