Oracle 11g rename. Guaranteed to be atomic?

前端 未结 5 1769
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 13:00

I have some (5) rename statements in a plsql script

drop table new;
rename old to new;

\"old\" tables hold very valuable information.

5条回答
  •  抹茶落季
    2021-01-13 13:33

    RENAME is a DDL command. So it is a single discrete transaction, if that's what you mean by atomic in this context. Consequently it is about as safe as anything could be. I can't imagine how a renaming would cause you to lose your data. But if you're feeling paranoid, just remember that's why Nature gave us backup and recovery.

    edit

    The way to be sure you don't lose data if the DROP succeeds and the RENAME fails is to deploy RENAME twice:

    SQL>  rename old_table to something_else;
    SQL>  rename new_table to old_table;
    SQL>  drop table something_else;
    

    That way you have your data online. This also minimises the downtime.

提交回复
热议问题