AWS Redshift 可以删除包含在事务中的表吗?

Posted

技术标签:

【中文标题】AWS Redshift 可以删除包含在事务中的表吗?【英文标题】:Can AWS Redshift drop a table that is wrapped in transaction? 【发布时间】:2017-02-17 12:15:20 【问题描述】:

在 ETL 期间,我们执行以下操作:

    begin transaction;

    drop table if exists target_tmp;
    create table target_tmp like target;

    insert into target_tmp select * from source_a inner join source_b on ...;
    analyze table target_tmp;

    drop table target;
    alter table target_tmp rename to target;

    commit;

SQL 命令由 AWS Data Pipeline 执行,如果这很重要的话。

但是,管道有时会失败并出现以下错误:

    ERROR: table 111566 dropped by concurrent transaction

Redshift 支持可序列化的隔离。其中一个命令会破坏隔离吗?

【问题讨论】:

【参考方案1】:

是的,但如果生成临时表需要一段时间,您可能会在运行时看到其他查询的错误。您可以尝试在单独的事务中生成临时表(除非您担心源表的更新,否则可能不需要事务)。然后快速轮换表名,这样竞争的时间就会少得多:

-- generate target_tmp first then
begin;
alter table target rename to target_old;
alter table target_tmp rename to target;
commit;
drop table target_old;

【讨论】:

谢谢,我听从了你的建议,已经有一段时间没有看到错误了。我仍然不确定我遇到的行为是否是错误。 因为只有当前会话会到达 target_old 表。如果 drop table 命令是在 commit 命令之后还是之前,了解它的重要性是非常有趣的? 这很棒。在计划作业的事务完成之前,我快速查看无法获取数据,此过程解决了问题。 两件事:我做了drop table if exists target_old;,如果生成target_tmp 失败,alter table rename 也应该失败,这将中止事务,这是我认为的预期结果。

以上是关于AWS Redshift 可以删除包含在事务中的表吗?的主要内容,如果未能解决你的问题,请参考以下文章

是否有任何适用于 AWS Redshift 的开源调度工具?

AWS Glue to Redshift:是否可以替换,更新或删除数据?

将 AWS Redshift 中的数据操作到计划中

AWS Glue to Redshift:是不是可以替换、更新或删除数据?

删除 Redshift 中的循环

控制台中的 Redshift Vacuum 进度