将多个大数据导入 AWS RDS Postgres 使其变慢

Importing multiple large data to AWS RDS Postgres making it slow

在我们当前的应用程序中,我们每天备份到我们的 s3 存储桶。这些备份是每天和每个 table 的 CSV 格式。

我们的要求是在某个日期范围内从 s3 导入数据,假设我们需要查看 2015 年 1 月 1 日至 2015 年 7 月 31 日的数据,我们将数据从 s3 下载到 ec2 实例并导入到新创建的postgres 数据库。

但是随着时间的推移,导入变得非常慢。以下是我在导入过程中执行的步骤:

  1. 使用 m3-XLarge 和 600GB space 以及一般 SSD 存储类型创建 RDS postgres-9.6 实例。
  2. 关闭副本和多 AZ 实例。
  3. 导入没有外键和索引的模式。
  4. 将 tables 设置为 UNLOGGED 并关闭 autovacuum。
  5. 使用 COPY 命令导入。

    psql -h <HOST_NAME> -d <database_name> -U <user_name> -c "\COPY TABLE_NAME FROM '<exact_path_of_the_file>' CSV DELIMITER ',' HEADER"

导入开始时,它很容易在 2 分钟内消耗 2GB 的文件。但是导入数据一个月后,导入变得很慢。对于导入相同大小的文件,时间增加到 30 分钟(我正在比较 2 个不同日期的相同 table 的文件大小)。

我试过将文件拆分成更小的块并进行导入,但导入时间没有任何改善。

我从 RDS 监控中观察到交换 space 从 0 增加到 50...不知道这是否正常。任何改进导入的输入都会有所帮助。

提前致谢。

[PS: 所有步骤都在shell命令中]

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html#USER_PIOPS

The ratio of the requested IOPS rate to the amount of storage allocated is important, and depends on your database engine. For example, for Oracle, the ratio should be between 1:1 and 50:1. You can start by provisioning an Oracle DB instance with 1,000 IOPS and 200 GiB storage (a ratio of 5:1). You can then scale up to 2,000 IOPS with 200 GiB of storage (a ratio of 10:1). You can scale up to 30,000 IOPS with 6 TiB (6144 GiB) of storage (a ratio of 5:1), and you can scale up further if necessary.

Postgres 有相同的比率 (1:50),而且 iops 不是字节 ps,它的操作,所以当你给 8K piops,它不是 8KB 或每秒 MB。我建议您将 piops 增加到 40K,导入数据然后再减少。