English 中文(简体)
从MySQL迁移到PostgreSQL[关闭]
原标题:
  • 时间:2008-08-20 10:40:38
  •  标签:

我们目前正在使用MySQL作为我们正在构建的产品,并渴望尽快迁移到PostgreSQL,主要是出于许可的原因。

有其他人做过这样的举动吗?我们的数据库是应用程序的生命线,最终将存储TB的数据,所以我很想了解性能改进/损失的经验,转换SQL和存储过程的主要障碍,等等。

编辑:只是想向那些问我们为什么不喜欢MySQL的许可证的人澄清一下。我们正在开发一种商业产品,该产品(目前)依赖MySQL作为数据库后端。他们的许可证规定,每次安装我们需要向他们支付标价的一定比例,而不是固定费用。作为一家初创公司,这并不吸引人。

问题回答

Steve, I had to migrate my old application the way around, that is PgSQL->MySQL. I must say, you should consider yourself lucky ;-) Common gotchas are:

  • SQL is actually pretty close to language standard, so you may suffer from MySQL s dialect you already know
  • MySQL quietly truncates varchars that exceed max length, whereas Pg complains - quick workaround is to have these columns as text instead of varchar and use triggers to truncate long lines
  • double quotes are used instead of reverse apostrophes
  • boolean fields are compared using IS and IS NOT operators, however MySQL-compatible INT(1) with = and <> is still possible
  • there is no REPLACE, use DELETE/INSERT combo
  • Pg is pretty strict on enforcing foreign keys integrity, so don t forget to use ON DELETE CASCADE on references
  • if you use PHP with PDO, remember to pass a parameter to lastInsertId() method - it should be sequence name, which is created usually this way: [tablename]_[primarykeyname]_seq

我希望这至少能有所帮助。和Postgres玩得很开心!

我也做过类似的转换,但原因不同。这是因为我们需要更好的ACID支持,以及让web用户通过其他DB工具看到相同数据的能力(两者都有一个ID)。

以下是咬我们的东西:

  1. MySQL does not enforce constraints as strictly as PostgreSQL.
  2. There are different date handling routines. These will need to be manually converted.
  3. Any code that does not expect ACID compliance may be an issue.

也就是说,一旦它就位并经过测试,它就好多了。由于安全原因的正确锁定和大量并发使用,PostgreSQL的性能优于MySQL。在不需要锁定的东西上(只读),性能不是很好,但它仍然比网卡快,所以这不是问题。

提示:

  • The automated scripts in the contrib directory are a good starting point for your conversion, but will need to be touched a little usually.
  • I would highly recommend that you use the serializable isolation level as a default.
  • The pg_autodoc tool is good to really see your data structures and help find any relationships you forgot to define and enforce.

我们从MySQL3迁移到了PostgreSQL 8.2,然后是8.3。PostgreSQL有SQL的基本知识,还有更多,所以如果你的MYSQL不使用花哨的MYSQL,你就可以了。

根据我的经验,我们的MySQL数据库(版本3)没有外键。。。PostgreSQL让你拥有它们,所以我们不得不改变这一点。。。这是一件好事,我们发现了一些错误。

我们必须改变的另一件事是编码(C#)连接器,这在MySQL中是不一样的。MySQL版本比PostgreSQL版本更稳定。我们对PostgreSQL仍然有一些问题。





相关问题
热门标签