So beheben Sie einen HTTP 502-Fehler?

At this scale I recommend dedicated PG resources, any reason you are not running your database on a dedicated instance or managed PG?