我想使用AWS Data Pipeline将数据从Postgres RDS传输到AWS S3。有人知道这是怎么做的吗?
更确切地说,我想使用数据管道将Postgres表导出到AWS S3。我使用数据管道的原因是我想自动执行此过程,并且此导出将每周运行一次。
任何其他建议也将起作用。
postgresql amazon-s3 amazon-web-services amazon-rds amazon-data-pipeline
如果我的表是 schema_one.table_five 并且我的文件名是 file_to_import.csv.gz,那么我给 copy_expert() cmd 提供什么参数以便将文件内容复制到表中?
这是我正在尝试的:
this_copy = '''COPY schema_one.table_five FROM STDIN with CSV'''
this_file = "file_to_import.csv.gz"
con = psycopg2.connect(dbname=dbname, host=host, port=port, user=user, password=password)
cur = con.cursor()
cur.copy_expert(this_copy, this_file)
Run Code Online (Sandbox Code Playgroud)
这会产生一个错误:
cur.copy_expert(this_copy, this_file)
TypeError: file must be a readable file-like object for COPY FROM; a writable file-like object for COPY TO.
Run Code Online (Sandbox Code Playgroud)
那么我如何告诉命令首先解压缩文件,然后指定一个分隔符(在本例中为“|”),以便可以对其进行处理。
次要问题。如果我的文件位于名为“files_to_import”的目录中,即 /home/dir1/dir2/files_to_import/file_to_import.csv.gz,有没有一种方法可以指定目录并在该目录中的所有文件中复制 pgm (同桌)?它们都是 .csv.gz 文件。
添加了 12-30-16 0940 MST -- 回应评论:试图使 COPY 语句正确,但所有这些错误 ---
this_file = "staging.tbl_testcopy.csv.gz"
this_copy_01 = '''COPY staging.tbl_testcopy_tmp FROM STDIN'''
this_copy_02 = '''COPY …Run Code Online (Sandbox Code Playgroud)