从 MySQL 迁移到 PostgreSQL

发布于 2024-07-04 08:17:52 字数 300 浏览 6 评论 0原文

我们目前正在将 MySQL 用于我们正在构建的产品,并且热衷于尽快迁移到 PostgreSQL,主要是出于许可原因。

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

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

We are currently using MySQL for a product we are building, and are keen to move to PostgreSQL as soon as possible, primarily for licensing reasons.

Has anyone else done such a move? Our database is the lifeblood of the application and will eventually be storing TBs of data, so I'm keen to hear about experiences of performance improvements/losses, major hurdles in converting SQL and stored procedures, etc.

Edit: Just to clarify to those who have asked why we don't like MySQL's licensing. We are developing a commercial product which (currently) depends on MySQL as a database back-end. Their license states we need to pay them a percentage of our list price per installation, and not a flat fee. As a startup, this is less than appealing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小忆控 2024-07-11 08:17:53

我们从 MySQL3 迁移到 PostgreSQL 8.2,然后是 8.3。 PostgreSQL 具有 SQL 的基础知识以及更多功能,因此如果您的 MYSQL 不使用花哨的 MySQL 内容,您会没事的。

根据我的经验,我们的 MySQL 数据库(版本 3)没有外键...PostgreSQL 允许您拥有它们,所以我们必须更改它...这是一件好事,我们发现了一些错误。

我们必须更改的另一件事是编码 (C#) 连接器与 MySQL 中的不同。 MySQL 比 PostgreSQL 更稳定。 我们对 PostgreSQL 仍然没有什么问题。

We did a move from a MySQL3 to PostgreSQL 8.2 then 8.3. PostgreSQL has the basic of SQL and a lot more so if your MYSQL do not use fancy MySQL stuff you will be OK.

From my experience, our MySQL database (version 3) doesn't have Foreign Key... PostgreSQL lets you have them, so we had to change that... and it was a good thing and we found some mistake.

The other thing that we had to change was the coding (C#) connector that wasn't the same in MySQL. The MySQL one was more stable than the PostgreSQL one. We still have few problems with the PostgreSQL one.

耶耶耶 2024-07-11 08:17:53

我也做了类似的转换,但出于不同的原因。 这是因为我们需要更好的 ACID 支持,并且能够让 Web 用户通过其他数据库工具看到相同的数据(两者都用一个 ID)。

以下是令我们困扰的事情:

  1. MySQL 不强制执行约束
    与 PostgreSQL 一样严格。
  2. 有不同的日期处理例程。 这些需要手动转换。
  3. 任何不需要 ACID 的代码
    合规性可能是一个问题。

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

提示:

  • contrib 中的自动化脚本
    目录是一个很好的起点
    为了您的转换,但需要
    平时要稍微触碰一下。
  • 我强烈推荐你
    使用可序列化隔离
    级别作为默认值。
  • pg_autodoc 工具很好用
    真正看到你的数据结构和
    帮助找到您的任何关系
    忘记定义和执行。

I have done a similar conversion, but for different reasons. It was because we needed better ACID support, and the ability to have web users see the same data they could via other DB tools (one ID for both).

Here are the things that bit us:

  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.

That said, once it was in place and tested, it was much nicer. With correct locking for safety reasons and heavy concurrent use, PostgreSQL performed better than MySQL. On the things where locking was not needed (read only) the performance was not quite as good, but it was still faster than the network card, so it was not an issue.

Tips:

  • 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.
深白境迁sunset 2024-07-11 08:17:52

Steve,我不得不迁移我的旧应用程序,即 PgSQL->MySQL。 我必须说,你应该认为自己很幸运;-)
常见的问题是:

  • SQL 实际上非常接近语言标准,因此您可能会受到 MySQL 方言的影响,您已经知道
  • MySQL 会悄悄地截断超过最大长度的 varchar,而 Pg 则抱怨 - 快速解决方法是将这些列设置为“文本”而不​​是“ varchar' 并使用触发器截断长行
  • 使用双引号而不是反向撇号
  • 使用 IS 和 IS NOT 运算符比较布尔字段,但是与 MySQL 兼容的 INT(1) 与 = 和 <> 仍然可能
  • 没有 REPLACE,请使用 DELETE/INSERT 组合
  • Pg 对于强制外键完整性非常严格,因此如果您将 PHP 与 PDO 一起使用,请不要忘记在引用上使用 ON DELETE CASCADE
  • ,请记住将参数传递给 lastInsertId( ) 方法 - 它应该是序列名称,通常是这样创建的: [tablename]_[primarykeyname]_seq

我希望至少有一点帮助。 祝您使用 Postgres 充满乐趣!

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

I hope that helps at least a bit. Have lots of fun playing with Postgres!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文