如何从S3导入数据文件到Postgresql RDS [英] how to import data files from s3 to postgresql rds
问题描述
我是AWS和Postgresql的新手。
I am very new to AWS, and Postgresql.
- 我已经创建了一个Postgresql数据库(在was上使用rds)
- 我已将多个文档上载到多个s3存储桶
- 我正在运行EC2(Amazon Linux 64位)
我尝试使用数据管道,但是Postgres似乎没有可用的(模板)。我无法弄清楚如何连接到RDS实例以及如何从postgres导入/导出数据。
I tried to use a data pipeline, but nothing seems to be available (template) for Postgres. I can't figure out how to connect to my RDS instance and import/export data from postgres.
我假设我可以使用EC2从我的S3存储桶中抓取,导入Postgres代替没有可用的数据管道模板。
I assumed that I could use EC2 to grab from my S3 bucket and import into Postgres in lieu of no data pipeline template being available. If it is possible I have no idea how.. Please advise if possible..
推荐答案
我希望AWS在RDS中扩展COPY命令就像在Redshift中所做的那样。但是到目前为止,他们还没有,我们必须自己做。
I wish AWS extends COPY command in RDS Postgresql as they did in Redshift. But for now they haven't and we have to do it by ourselves.
- 安装
awscli
在EC2盒上(可能默认情况下已安装) - 使用凭据配置
awscli
- 使用
aws s3 sync
或aws s3 cp
命令从s3下载到本地目录 - 使用psql命令将文件
\COPY
放入RDS(需要\
从客户端目录复制)
- Install
awscli
on your EC2 box (it might have been installed by default) - Configure your
awscli
with credentials - Use
aws s3 sync
oraws s3 cp
commmands to download from s3 to your local directory - Use psql command to
\COPY
the files into your RDS (requires\
to copy from client directory)
示例:
aws s3 cp s3://bucket/file.csv /mydirectory/file.csv
psql -h your_rds.amazonaws.com -U username -d dbname -c '\COPY table FROM ''file.csv'' CSV HEADER'
这篇关于如何从S3导入数据文件到Postgresql RDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!