且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何轻松地从MySQL迁移到PostgreSQL?

更新时间:2022-10-20 13:16:16

尽管SQL是标准,但如果没有每个服务器软件都实现扩展功能,它的功能还不够强大.从MySQL到PostgreSQL的转换并不简单,除非您的模式很简单.自动化的翻译脚本只会让您受益匪浅.

***的方法是手动翻译模式,然后为数据本身编写自己的传输脚本.您还应该编写验证脚本,以确保架构和数据正确传递.

这不是解决方案.如果您的数据库足以迁移,那么花时间在自己身上也很重要.最后,与自动迁移脚本相比,您花费的时间至少要花更多的时间来解决怪异和细微的混乱.但是,自己动手,就有机会利用MySQL中没有的PostgreSQL功能,并有机会进行第二次改进. >

咬住子弹然后做.

I'd like to migrate an existing MySQL database (around 40tables, 400mb data) to Postgres before it gets bigger. I searched the web and tried some migration-scripts (some of them can be found here). None of them works seamlessly - if it would be just a few glitches I had to fix manually, it wouldn't be a problem, but the resulting dumps don't look like valid PostgreSQL at all.

Did anybody succeed in migrating a production table without using a full workday - is there an easy solution to that problem?

Note: I also would consider commercial products (as long as pricing is still feasible).

In spite of SQL being a standard, it's not full featured enough to do without each server software implementing extensions. The translation from MySQL to PostgreSQL is not simple, unless your schema is trivial. Automated translation scripts will only get you so far.

The very best approach would be to hand translate the schema, and then write your own transfer scripts for the data itself. You should also write verification scripts to make sure the schema and data come over correctly.

This isn't a cop-out answer. If your database is important enough to migrate then it's important enough to spend some time on yourself. In the end you would spend at least as much time figuring out the quirks and subtle messes than an automated migration script would cause as in the time to migrate the data yourself. But doing it yourself you have the chance to take advantage of features in PostgreSQL that aren't present in MySQL, as well as the chance to make the kinds of improvements that only come from having the chance to do something a second time.

Bite the bullet and do it.