Have you attempted any further upgrade (to v7 for example)? I have the same problem (I think I started on postgresql 10, upgraded to 12 and now trying to upgrade mattermost from 5.31.9). I don’t want to put too much effort into solving the problem as you did if there are still underlying issues that continue to wreak havor.