日期:2014-05-16  浏览次数:20513 次

模拟工业场景:数据库的用户被删除掉了,表空间,数据文件都在的 能否恢复?

    环境:

  

SQL> select * from v$version where rownum=1;

BANNER
----------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

SQL> !uname -a
Linux think-V30SA 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux

    我打算用闪回数据库来恢复,关于开启闪回数据库请参见:闪回如何开启及注意事项


    模拟的实验过程如下:

SQL> show user
USER is "SYS"
SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES

SQL> create user u1 identified by u1 default tablespace users quota 10m on users; --20:56分创建u1用户

User created.

SQL> grant connect,create any table to u1;

Grant succeeded.

SQL> conn u1/u1
Connected.
SQL> create table test (i int); 

Table created.

SQL> insert into test values(1);

1 row created.

SQL> insert into test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test;

	 I
----------
	 1
	 2

SQL> conn / as sysdba
Connected.
SQL> drop user u1 cascade; --21:09分把u1及其关联对象删除。

User dropped.

SQL> shutdown immediate
SQL> startup mount
SQL> flashback database to timestamp sysdate-9/1440;

Flashback complete.

SQL> alter database open resetlogs;

Database altered.

SQL> select * from u1.test;

	 I
----------
	 1
	 2

    小结:

            整个模拟实验的关键在于创建u1和删除u1之间的时间差,flashback database指定的timestamp要落在这个之间,否则实验会失败。