在 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 支持可序列化隔离。其中一个命令是否打破隔离?
最佳答案
是的,可行,但如果生成临时表需要一段时间,您可能会在运行时看到其他查询的错误。您可以尝试在单独的事务中生成临时表(除非您担心更新源表,否则可能不需要事务)。然后快速轮换表名,这样争用的时间就会少得多:
-- 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;
关于sql - AWS Redshift 可以删除包含在事务中的表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42297723/