docker icon indicating copy to clipboard operation
docker copied to clipboard

How to migrate from mysql to postgres service?

Open iVegas opened this issue 1 year ago • 1 comments

Mattermost 11 will support only Postgres databases. This repo used MySQL database before Mattermost 10. Will there be any additional compose file provided for the example of the migration process?

iVegas avatar Dec 17 '24 10:12 iVegas

I ran through a similar process recently (native install+mysql -> docker install+postgres). Here are some notes from my process in case they help.

  • Copy production mysql data dir to staging server
  • On the staging server, start docker run -v ./mysql_data:/var/lib/mysql -d mysql:<version> --default-authentication-plugin=mysql_native_password
  • Create a throwaway blank staging MM https://docs.mattermost.com/install/install-docker.html
  • Mostly follow https://docs.mattermost.com/deploy/postgres-migration-assist-tool.html , but with the following tweaks
    • <address> in the following two steps found via docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <the_container>
    • MYSQL_DSN looked like: root:<password>@tcp(<address>:3306)/mattermost
    • POSTGRES_DSN looked like: postgres://mattermost:<password>@<address>:5432/mattermost?sslmode=disable
    • pgloader always crashed until I edited migration.load to reduce values to: workers = 2, rows per range = 4000, prefetch rows = 4000, batch rows = 1000
    • I executed pgloader via: docker run -it --rm --network=host -v $(pwd):/home/migration mattermost/mattermost-pgloader:latest pgloader migration.load > migration.log
    • After running pgloader, I had to ALTER USER mattermost RESET SEARCH_PATH; within docker exec -it mattermost-postgres-1 psql mattermost
  • Once this was all complete, set up production MM with volumes/app/mattermost/data from your existing files data and volumes/db/postgres/data copied from the corresponding folder on the staging server

alpha0010 avatar Jan 21 '25 19:01 alpha0010