r/PostgreSQL • u/Pupper_Hugger • Jun 15 '26
Help Me! Moving from Mysql to Postgresql. Where do We start?
Long Story Short: We're looking to move our production database (around 1.2G in size, seperated into 3 seperate database schema) from Mariadb (mariadb galera cluster) to another Relational database. We're looking at postgresql for now.
We're all quite familiar with mysql we've been using it for total combined experience of around 20+ years all between us. so I think it's safe to say that we're quite familiar with sql, mysql and their quirks.
We're planning to learn postgresql first and run it in staging and test environment before pulling the trigger. Anyone have good advice on where to start?
We're worried about index corruption like what happened to github, and any other administration and usage we need to learn about.
19
u/didamirda Jun 15 '26
Your database is very small, so it is very cheap to overscale PostgreSQL, which will make things work even if you do make some mistakes.
Everything else depends on
- do you want to use managed solution from someone else or set everything on your own (managed solutions for a small database are cheaper)
- the rest of you tech stack
- acceptable downtime
13
u/illuminanze Jun 15 '26
As someone who loves postgres and somewhat dislikes mysql/mariadb, why do you want to do this migration? What problem are you trying to solve? If the whole team knows mariadb, shouldn't you put that effort into the database you have?
3
u/SomeoneInQld Jun 15 '26
depends on how much 'standard' SQL you did versus customised 'mysql' Sql
generally it shouldn't be too hard.
1
u/TechnoEmpress Jun 15 '26
I'm not sure this is a great idea because your SQL would have to be "standard SQL", and you wouldn't be able to use any extensions or PostgreSQL dialect.
GitHub's MySQL cluster is a beast that operates on scales that are not yours. Look at their blog posts on the subject: https://github.blog/?s=mysql
All in all, good luck with the migration :)
1
u/jkh911208 Jun 15 '26
What problem do you have with current setup that you want to switch?
2
u/LevelSoft1165 Jun 16 '26
We did this migration a couple years ago, similar size database. Here is a few things I can tell you that I feel I would've loved to know:
Use pgLoader. It handles the schema conversion and data transfer and saves you a ton of headaches with type mapping differences.
Stuff that'll catch you off guard coming from MySQL:
For the index corruption, look into
amcheckbut honestly Postgres is solid on that front. Just don't turn off fsync and you'll be fine. The GitHub thing was a very specific situation.1
u/AutoModerator Jun 15 '26
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/gisborne Jun 15 '26
You are likely to find it useful to deploy a Foreign Data Wrappers connection between your new Postgres database and your old MySQL database.
This will let you treat the old database as part of the new one. This is useful in a variety of ways.
Since your data isn’t huge, it might be the easiest way to copy your data over.
You can move parts of your data over at a time, and use the FDW version of the rest of the data while you’re migrating.
You could set up triggers to sync changes in one place with changes in the other during the migration.
There’s probably other things.
1
u/lakeland_nz Jun 15 '26
I've bounced between them on various apps and for various reasons over the years. E.g. a manager decides we're all in on MySQL.
Generally they behave in similar ways. So these differences are deliberately oversized:
I find MySQL is a bit faster than Postgres on dumb queries. If your query doesn't match your data model, doesn't use the index correctly, etc. On such a tiny DB it should be irrelevant.
Postgres is much more inclined to do things like ACID. You need to be more careful to not run stupidly long transactions for example.
The sequences in Postgres vs auto-increment in MySQL is quite different.
Last migration I ran was the same way as you, MySQL to Postgres, with staging and dev run on Postgres for a few months before pulling the trigger. It was pretty painful due to some process decisions I made. I'd wanted to run it in dev/staging for a couple months to get very confident everything was perfect. However that meant when users reported a problem in prod, my dev and staging environments were not set up for a quick test/fix cycle. I wish I'd maintained the emergency path deliberately.
From a performance perspective, I benchmarked my app using playwright prior to the move, so I was able to validate swapping RDBMS had minimal user-visible impact to performance. Some tests ran slower, while other tests ran faster.
1
u/elevarq Jun 15 '26
Start with this configuration setting in your MySQL database: https://dev.mysql.com/doc/refman/8.4/en/sql-mode.html#sqlmode_ansi
1
u/Aromatic_Ad3754 Jun 15 '26
I think this is a good start if you already know SQL: https://wiki.postgresql.org/wiki/Don%27t_Do_This
1
u/ibraaaaaaaaaaaaaa Jun 18 '26 edited Jun 18 '26
Your data is very small that I would argue you should not even have indexes.
The github scale does not make any sense with your single AZ instance
If you have a server, ensure to have a stable server version compatible with both schemas, like dual insert in mysql and pg, and read from pg first and mysql as a fallback.
Once the server is stable, run some scripts loop throw mysql tables and sync data with pg.
the moment your server logs show that no traces going to mysql, then shut it down and delete backward compatible code.
1
u/g0pherman Jul 13 '26
Why do you want to migrate?
The database is small enough the process should be relatively quick but if you are not willing to have downtime you will probably have to go through a painful process of double writing.
0
u/chock-a-block Jun 15 '26 edited Aug 29 '26
Boat saffron imagine library boron doll
This post was anonymized with Redact