gpt4 book ai didi

mysql - 有没有办法从 Amazon Redshift 进行 SQL 转储

转载 作者:IT老高 更新时间:2023-10-29 00:19:13 25 4
gpt4 key购买 nike

有没有办法从 Amazon Redshift 进行 SQL 转储?

你能使用 SQL workbench/J 客户端吗?

最佳答案

pg_dump 模式在过去可能不起作用,但现在可以。

pg_dump -Cs -h my.redshift.server.com -p 5439 database_name > database_name.sql

CAVEAT EMPTOR: pg_dump 仍然会生成一些 postgres 特定的语法,并且还会忽略 Redshift SORTKEYDISTSTYLE表的定义。

另一个不错的选择是 use the published AWS admin script views用于生成您的 DDL。它处理 SORTKEY/DISTSTYLE,但我发现它在捕获所有 FOREIGN KEY 时存在错误,并且不处理表权限/所有者。您的里程可能会有所不同。

要获取数据本身的转储,您仍然需要使用 UNLOAD command不幸的是在每张 table 上。

这是一种生成它的方法。请注意,如果目标表的列顺序与源表的列顺序不同,select * 语法将失败:

select
ist.table_schema,
ist.table_name,
'unload (''select col1,col2,etc from "' || ist.table_schema || '"."' || ist.table_name || '"'')
to ''s3://SOME/FOLDER/STRUCTURE/' || ist.table_schema || '.' || ist.table_name || '__''
credentials ''aws_access_key_id=KEY;aws_secret_access_key=SECRET''
delimiter as '',''
gzip
escape
addquotes
null as ''''
--encrypted
--parallel off
--allowoverwrite
;'
from information_schema.tables ist
where ist.table_schema not in ('pg_catalog')
order by ist.table_schema, ist.table_name
;

关于mysql - 有没有办法从 Amazon Redshift 进行 SQL 转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15440794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com