如何将数据从 S3 加载到 PostgreSQL RDS
How to load data from S3 to PostgreSQL RDS
我需要将数据从 S3 加载到 Postgres RDS(大约 50-100 GB)我没有使用 AWS Data Pipeline 的选项,我正在寻找类似于使用 COPY 命令加载的东西S3 中的数据导入 Amazon Redshift。
如有任何建议,我将不胜感激。
http://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html
Use the COPY command to load a table in parallel from data files on
Amazon S3. You can specify the files to be loaded by using an Amazon
S3 object prefix or by using a manifest file.
The syntax to specify the files to be loaded by using a prefix is as
follows:
copy <table_name> from 's3://<bucket_name>/<object_prefix>'
authorization;
更新
另一种选择是挂载 s3 并通过 COPY
命令使用指向 csv 的直接路径。我不确定它是否能有效地容纳 100GB,但值得一试。 Here is some list 的软件选项。
另一种选择是 "parsing" s3 file part by part to a file and COPY
from named pipe, described here
最明显的选择是将文件下载到本地存储并使用COPY
我根本不涉及
另外值得一提的是 s3_fdw (status unstable). Readme 非常简洁,但我假设您可以创建一个指向 s3 文件的外部 table。这本身意味着您可以将数据加载到其他关系...
最初,此答案试图使用 S3 到 Postgres RDS 功能。整个企业都失败了(见下文)。
我终于能够做到这一点的方法是:
- 设置一个安装了 psql 的 EC2 实例(见下面 post 的近尾)
- 复制相关 CSV 以从 S3 导入到本地实例
- 使用psql /copy 命令向上导入文件
这最后一部分真的非常重要。如果您使用 SQL COPY 命令,整个 RDS Postgres 角色结构会让您感到沮丧。它有一个不稳定的 SUPERRDSADMIN 角色,它根本不是很超级。但是,如果您使用 psql /copy 命令,您显然可以做任何事情。我已经确认是这种情况,并已成功开始上传。我会回来重新编辑此 post(时间允许)以添加上述的相关文档步骤。
Caveat Emptor: The post below was all the original work I had done trying to get this implemented. I don't want to bury the lead despite multiple efforts (including what can only be described as pathetic tech support from AWS) I don't believe that this feature is ready for prime time. Despite a very simple test environment, easy to replicate, AWS has not provided an effective way to not get the copy statement to crap out as follows:
The actual call to aws_s3.table_import_from_s3(...)
is reporting a permission problem between RDS and S3. From my research work with psql
this appears to be a C library, probably installed by AWS.
NOTICE: CURL error code: 28 when attempting to validate pre-signed URL, 1 attempt(s) remaining
NOTICE: HINT: make sure your instance is able to connect with S3.
现已添加 S3 到 Postgres RDS 功能
2019-04-24 AWS 发布了允许 Postgres RDS 直接从 S3 加载的功能。您可以阅读公告here, and see the documentation page here.
我正在与 OP 分享,因为这似乎是 AWS 支持的解决所提出问题的方法。
关键总结点:
- 需要 Postgres 11.1 或更高版本
- 需要访问
psql
并能够将其连接到 RDS 实例
- 需要安装
aws_s3
扩展 aws_commons
。
- 您可以通过指定凭据或将 IAM 角色分配给 RDS 来访问 S3 存储桶
- 它宣传支持所有与 postgres
COPY
命令相同的数据格式
- 它目前似乎一次只支持一个文件(即没有正则表达式)
说明相当详细,并提供了多种配置路径(AWS CLI 脚本、控制台说明等)。此外,使用 IAM 密钥而不是必须设置角色的选项很好。
我没有找到下载 psql
的方法,所以我不得不将完整的 postgres 安装到我的 mac,但这没什么大不了的用酿造:
brew install postgres
并且由于数据库服务未被激活,这是获取 psql 的最快方式。
Update: Decided that having psql on my mac was a security hole, port forwarding, etc. I found that there is a simple Postgres install available for AMI Linux 2 under the AMI Extras rubric. The install command is fairly simple on your ami instance type.
sudo amazon-linux-extras install postgresql10
psql
相当容易使用,但是,重要的是要记住任何对 psql
本身的指令都会被 \
转义。 psql
的文档可以在 here 中找到。建议在执行 AWS 推荐的脚本之前至少检查一次。
在某种程度上你 运行 严格的安全性并且可以访问你的 RDS 实例受到严重限制(我这样做)不要忘记从你的 AMI 实例打开端口 运行ning Postgres到您的 RDS 实例。
如果您喜欢 GUI,那么您可以尝试使用 PGAdmin4。根据文档,这是 AWS 推荐的连接到 RDS Postgres 实例的方式。我无法使任何 SSH 隧道功能正常工作(这就是为什么我最终做了用于 psql
的本地主机 SSH 映射)。我还发现它在其他方面有很多问题。阅读产品评论似乎版本 4 可能不是最稳定的版本。
我需要将数据从 S3 加载到 Postgres RDS(大约 50-100 GB)我没有使用 AWS Data Pipeline 的选项,我正在寻找类似于使用 COPY 命令加载的东西S3 中的数据导入 Amazon Redshift。
如有任何建议,我将不胜感激。
http://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html
Use the COPY command to load a table in parallel from data files on Amazon S3. You can specify the files to be loaded by using an Amazon S3 object prefix or by using a manifest file.
The syntax to specify the files to be loaded by using a prefix is as follows:
copy <table_name> from 's3://<bucket_name>/<object_prefix>' authorization;
更新
另一种选择是挂载 s3 并通过 COPY
命令使用指向 csv 的直接路径。我不确定它是否能有效地容纳 100GB,但值得一试。 Here is some list 的软件选项。
另一种选择是 "parsing" s3 file part by part COPY
from named pipe, described here
最明显的选择是将文件下载到本地存储并使用COPY
我根本不涉及
另外值得一提的是 s3_fdw (status unstable). Readme 非常简洁,但我假设您可以创建一个指向 s3 文件的外部 table。这本身意味着您可以将数据加载到其他关系...
最初,此答案试图使用 S3 到 Postgres RDS 功能。整个企业都失败了(见下文)。
我终于能够做到这一点的方法是:
- 设置一个安装了 psql 的 EC2 实例(见下面 post 的近尾)
- 复制相关 CSV 以从 S3 导入到本地实例
- 使用psql /copy 命令向上导入文件
这最后一部分真的非常重要。如果您使用 SQL COPY 命令,整个 RDS Postgres 角色结构会让您感到沮丧。它有一个不稳定的 SUPERRDSADMIN 角色,它根本不是很超级。但是,如果您使用 psql /copy 命令,您显然可以做任何事情。我已经确认是这种情况,并已成功开始上传。我会回来重新编辑此 post(时间允许)以添加上述的相关文档步骤。
Caveat Emptor: The post below was all the original work I had done trying to get this implemented. I don't want to bury the lead despite multiple efforts (including what can only be described as pathetic tech support from AWS) I don't believe that this feature is ready for prime time. Despite a very simple test environment, easy to replicate, AWS has not provided an effective way to not get the copy statement to crap out as follows:
The actual call to
aws_s3.table_import_from_s3(...)
is reporting a permission problem between RDS and S3. From my research work withpsql
this appears to be a C library, probably installed by AWS.NOTICE: CURL error code: 28 when attempting to validate pre-signed URL, 1 attempt(s) remaining NOTICE: HINT: make sure your instance is able to connect with S3.
现已添加 S3 到 Postgres RDS 功能
2019-04-24 AWS 发布了允许 Postgres RDS 直接从 S3 加载的功能。您可以阅读公告here, and see the documentation page here.
我正在与 OP 分享,因为这似乎是 AWS 支持的解决所提出问题的方法。
关键总结点:
- 需要 Postgres 11.1 或更高版本
- 需要访问
psql
并能够将其连接到 RDS 实例 - 需要安装
aws_s3
扩展aws_commons
。 - 您可以通过指定凭据或将 IAM 角色分配给 RDS 来访问 S3 存储桶
- 它宣传支持所有与 postgres
COPY
命令相同的数据格式 - 它目前似乎一次只支持一个文件(即没有正则表达式)
说明相当详细,并提供了多种配置路径(AWS CLI 脚本、控制台说明等)。此外,使用 IAM 密钥而不是必须设置角色的选项很好。
我没有找到下载 psql
的方法,所以我不得不将完整的 postgres 安装到我的 mac,但这没什么大不了的用酿造:
brew install postgres
并且由于数据库服务未被激活,这是获取 psql 的最快方式。
Update: Decided that having psql on my mac was a security hole, port forwarding, etc. I found that there is a simple Postgres install available for AMI Linux 2 under the AMI Extras rubric. The install command is fairly simple on your ami instance type.
sudo amazon-linux-extras install postgresql10
psql
相当容易使用,但是,重要的是要记住任何对 psql
本身的指令都会被 \
转义。 psql
的文档可以在 here 中找到。建议在执行 AWS 推荐的脚本之前至少检查一次。
在某种程度上你 运行 严格的安全性并且可以访问你的 RDS 实例受到严重限制(我这样做)不要忘记从你的 AMI 实例打开端口 运行ning Postgres到您的 RDS 实例。
如果您喜欢 GUI,那么您可以尝试使用 PGAdmin4。根据文档,这是 AWS 推荐的连接到 RDS Postgres 实例的方式。我无法使任何 SSH 隧道功能正常工作(这就是为什么我最终做了用于 psql
的本地主机 SSH 映射)。我还发现它在其他方面有很多问题。阅读产品评论似乎版本 4 可能不是最稳定的版本。