# \[solved\] How do you restore the mattermost database?

**URL:** https://forum.mattermost.com/t/solved-how-do-you-restore-the-mattermost-database/6673
**Category:** Troubleshooting
**Created:** [February 12, 2019, 5:01pm UTC](https://forum.mattermost.com/t/solved-how-do-you-restore-the-mattermost-database/6673 "2019-02-12T17:01:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![edomingox](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@edomingox](https://forum.mattermost.com/u/edomingox)
#### Post date: [February 12, 2019, 5:01pm UTC](https://forum.mattermost.com/t/solved-how-do-you-restore-the-mattermost-database/6673/1 "2019-02-12T17:01:33Z")

</div>

I was looking at the migration documents [Redirect](https://docs.mattermost.com/administration/migrating.html#migrating-the-mattermost-server).

In particular, step 4. And step 4 says:  
Backup the database from the SOURCE Mattermost server and restore it in place of the database to which the DESTINATION server is connected.

And I’m like, duh. But what are the commands to do it?

I searched around and found the commands to export the database, but trying to restore it, not so lucky. There is this command:  
`sudo -u mattermost /opt/gitlab/embedded/bin/psql -U gitlab_mattermost -h /var/opt/gitlab/postgresql -d mattermost_production -f ./mattermost_production`  
But all I get is a bunch of relation exists errors. Is that normal?

---

<div class="post-metadata">

### Author: ![edomingox](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@edomingox](https://forum.mattermost.com/u/edomingox)
#### Post date: [February 12, 2019, 5:40pm UTC](https://forum.mattermost.com/t/solved-how-do-you-restore-the-mattermost-database/6673/2 "2019-02-12T17:40:33Z")

</div>

I figured it out. I have to remove the old database and create a new one.

sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql/ -d gitlabhq\_production  
drop database mattermost\_production  
;  
create database mattermost\_production  
;  
\q

Once that is done, the restore command works with no errors.
