Okay, I think I'm on to something here. I've got this:
sudo /opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > mattermost_production_backup
But that returns
pg_dump: [archiver (db)] connection to database "mattermost_production" failed: FATAL: Peer authentication failed for user "gitlab_mattermost"
Hmm.