【问题标题】:moving heroku db to RDS将heroku db移动到RDS
【发布时间】:2019-10-10 01:47:04
【问题描述】:

我正在尝试将我们在 heroku 公共空间中的 postgres db(版本 9.6.15)移动到 AWS RDS。 db 约为 2.2tb,位于 heroku 高级 7 层。

由于我发现从 heroku 进行实时复制几乎是不可能的,因为它们限制了设置复制的功能(根据我的理解),我希望看看我能以多快的速度转储数据并将其加载到RDS。

我正在寻找优化 pg_dumps 的方法,到目前为止我所做的是从 AWS 中的 ec2 实例 (m5.2xlarge) 运行它,以查看 pg_dumps 的运行速度。

在 ec2 上运行它时,我只能达到 10mb/秒,这非常慢,因为从这个意义上说,它需要大约 84 小时才能运行。

我这样运行pg_dumps

sudo pg_dump postgres://user:pass@url:5432/db \
--jobs=24 \
--format=directory \
--file=/monodb/pgdump2 \
--verbose

我还能做些什么来加快导出速度,或者这只是对 heroku 出口带宽的限制?

【问题讨论】:

  • 您是否尝试过从其他位置执行 pg_dump,即在本地启动它只是为了测量下载速度? 10mb/sec 是物理备份的硬限制 (devcenter.heroku.com/articles/…),因为 pg_dump 速率不应受到任何限制,除了数据库实例本身的能力。
  • 是的...我已经从 AWS 上的 VM 和 GCP 上尝试过...当我查看时,两者似乎都以相同的下载速率在 iftop 上运行,开始时大约为 ~3Gb以 2 秒的速率,然后在 pg_dump 的过程中以 2 秒的速率缓慢下降到 ~500Mb。
  • 如果限制是从 Heroku 的出口,那么您可能无能为力 - 您验证了吗?您能否测试来自同一网络内的转储以查看其性能是否更好?
  • 你关心速度吗?如果没有,您可以查看 aws 数据库迁移服务
  • 不幸的是,AWS DMS 在这里无法工作,Heroku 不允许某些权限允许这种情况发生

标签: amazon-web-services heroku


【解决方案1】:

1.将您的架构与数据分开转储

原因会随着您的阅读而更加清楚,但简单地说,单独转储架构允许我们同时进行多个并发转储和恢复操作。

2。在开始恢复之前禁用外键

Postgres 转储通常是一系列插入语句。如果您要插入的表有外键,那么每次插入都必须评估键的规则。


create table if not exists dropped_foreign_keys (
       seq bigserial primary key,

       sql text

);

do $$ declare t record;

begin

   for t in select conrelid::regclass::varchar table_name, conname constraint_name,

           pg_catalog.pg_get_constraintdef(r.oid, true) constraint_definition

           from pg_catalog.pg_constraint r

           where r.contype = ‘f’

           — current schema only:

           and r.connamespace = (select n.oid from pg_namespace n where n.nspname = current_schema())

       loop

       insert into dropped_foreign_keys (sql) values (

           format(‘alter table %s add constraint %s %s’,

               quote_ident(t.table_name), quote_ident(t.constraint_name), t.constraint_definition));

       execute format(‘alter table %s drop constraint %s’, quote_ident(t.table_name), quote_ident(t.constraint_name));

   end loop;

end $$;

完成数据恢复后,您可以通过运行以下命令重新启用外键:

do $$ declare t record;

begin

   — order by seq for easier troubleshooting when data does not satisfy FKs

   for t in select * from dropped_foreign_keys order by seq loop

       execute t.sql;

       delete from dropped_foreign_keys where seq = t.seq;

   end loop;

end $$;

3。您可以使用当前标志为 pg_dump 设置不同的标志,例如:

–data-only – This is the flag to dump only the data from the tables and not the schema information.

–no-synchronized-snapshots – Prior to Postgres 9.2 this a requirement for running jobs in parallel

–schema=public – Instructs pg_dump to only dump the public schemas, for most cases this is all you need.

4.自己转储大表并将小表组合在一起

这样做可以让您同时运行多个转储和恢复。您可以使用 pg_dump 中的 –table 标志指定要组合在一起的表。

Reference link for more detail

【讨论】:

  • 我认为您不能更改 Heroku 中的 postgres.conf 文件...对吗?
猜你喜欢
  • 1970-01-01
  • 2012-04-01
  • 2018-01-27
  • 2013-07-04
  • 2013-02-01
  • 1970-01-01
  • 2014-10-27
  • 1970-01-01
相关资源
最近更新 更多