Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"table definition changed" despite restore point creation after table create/alter

Tags:

oracle

FLASHBACK TABLE to a restore point fails when that restore point was created immediately after a table change. The below code only works if there is a sleep between certain steps.

SQL> DROP TABLE TEST_TABLE;

Table dropped.

SQL> CREATE TABLE TEST_TABLE AS SELECT 1 A FROM DUAL;

Table created.

SQL> ALTER TABLE TEST_TABLE ENABLE ROW MOVEMENT;

Table altered.

SQL> --Sleep required here to prevent error on flashback.
SQL> DROP RESTORE POINT TEST_RESTORE_POINT;

Restore point dropped.

SQL> CREATE RESTORE POINT TEST_RESTORE_POINT;

Restore point created.

SQL> FLASHBACK TABLE TEST_TABLE TO RESTORE POINT TEST_RESTORE_POINT;
FLASHBACK TABLE TEST_TABLE TO RESTORE POINT TEST_RESTORE_POINT
                *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed

Why is a delay required and is there a way to eliminate it?

like image 713
Josh Doebbert Avatar asked Dec 02 '15 15:12

Josh Doebbert


People also ask

Should I use ALTER TABLE rebuild in SQL Server?

Especially, note the CPU time in both cases. ALTER TABLE REBUILD was introduced in SQL Server 2008 (if I am not wrong) and still not known to many, so consider using it in case you have to rebuild a heap, rather than using the old technique. Shall you have a HEAP? Why not a clustered index?

What is the difference between delete table and ALTER TABLE?

The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints in a table. The DROP TABLE command deletes a table in the database. Note: Be careful before deleting a table. Deleting a table results in loss of all information stored in the table!

What does the ALTER TABLE command do in MySQL?

The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints in a table.

How to create a restore point before making changes to database?

If you create a restore point before making the changes, simply return to the restored point. In order to create a restore point, the flashback feature of our database must be open. We can use the following query to check flashback status.


1 Answers

This oddity might be caused by SMON process which is responsible to keep track between SCNs and timestamps which flashback query relies upon. There is a mapping table SYS.SMON_SCN_TIME where every 5 minutes a new record is inserted SMON.

Internally during the FLASHBACK TABLE executes a command INSERT /*+ APPEND */ into SYS_TEMP_FBT SELECT /*+ FBTSCAN FULL(S) PARALLEL(S, DEFAULT) */ :1, :2, :3, rowid, SYS_FBT_INSDEL FROM "<schema>."TEST_TABLE" as of SCN :4 S (notice a table SYS_TEMP_FBT is created in the same schema) which uses this mapping.

Up to Oracle 10.2 you needed to wait up to whole 5 minutes to succeed with FLASHBACK query on a new/altered object. In 11.1 the TIM_SCN_MAP column was introduced to make the mapping more fine grained. Maximum of 100 mappings is stored in one value which makes roughly 3 seconds precision in timestamp to SCN mapping.

I tried many things but I don't think you can do anything about it but wait around 3 seconds to avoid the error because this is handled asynchronously by background process without any user control.

like image 129
Husqvik Avatar answered Oct 18 '22 19:10

Husqvik