Thanks @it33, but that doesn't much help. I was able to make some progress with the following command:
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 the error
pg_dump: [archiver (db)] connection to database "mattermost_production" failed: FATAL: Peer authentication failed for user "gitlab_mattermost"
See my standalone post: https://forum.mattermost.org/t/how-do-i-back-up-the-database/1748/3
Tried some more stuff, I found the pg_hba.conf, and it looks like there's a peer map, whatever that means. I think that's what's causing the error but I don't know what to do.
--
OMG! I got it. Here's what I did:
sudo -u mattermost -i bash
/opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > mattermost_production_backup
And now I have a backup! Jeez, that was overly difficult.