Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle 11g rename. Guaranteed to be atomic?

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

drop table new;
rename old to new;

"old" tables hold very valuable information.

As I see it, if the rename command is guaranteed to be atomic, then I´d have one problem solved.

Is it atomic? If not, is there a way to do a "safe" rename ?

Thanks in advance

like image 913
Tom Avatar asked Dec 14 '22 01:12

Tom


1 Answers

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.

like image 111
APC Avatar answered Jan 10 '23 15:01

APC