19.2.5 限制生成的闪回数据量
启用闪回数据库可能对联机性能造成影响,因为启用了闪问数据库,那么会记录所有表空间的闪问数据,可以使用如下命令关闭部分表空间的闪回属性:
SQL> altertablespace <tablespace_name> flashback off;
可以在任何时候执行上面的命令,或者使用如下命令:
SOL> altertablespace <tabLespace_name> flashback on ;
该命令只有当数据阵处于加载模式时才能执行.
通过V$TABLESPACE 视图,可以查看闪回状态.
SQL> selectname,flashback_on from v$tablespace;
如果一个或多个表空间不生成闪回数据,那么在执行闪问操作之前必须使构成表空间的文件脱机. 然后闪回(包括隐式的恢复)可以正常进行。要记住RECOVER 将忽略脱机数据文件一一这与FLASHBACK是相同的。
19.3 FlashbackDrop
Flashback Drop(闪回删除)允许您将之前DROP的表(但不是TRUNCATE的表)恢复到刚好删除它之前的状态,同时还会恢复所有索引以及任何触发器和权限。唯一的主键和非空约束也会被恢复一但不包括外键约束.
USER_RECYCLEBIN 数据字典视图是用户的回收站, 用户通过查看回收站获取它们的新名称可以查询删除的对象。这里列出了己删除的所有对象,并将原始的表和索引名称映射到删除对象的系统生成的名称。
练习19-3
1. Connect to your database as user SYSTEM with SQL*Plus. |
2. Create a user for this exercise: |
SQL> create user dropper identified by dropper; 用户已创建。
SQL> grant create session, resource to dropper; 授权成功。
SQL> connect dropper/dropper; 已连接。 |
3. Create a table, with an index and a constraint, and insert a row: |
SQL> create table names (name varchar2(10)); 表已创建。
SQL> create index name_idx on names(name); 索引已创建。
SQL> alter table names add (constraint name_u unique(name)); 表已更改。
SQL> insert into names values ('John'); 已创建 1 行。
SQL> commit; 提交完成。 |
4. Confirm the contents of your schema: 确认模式的内容 |
SQL> select object_name,object_type from user_objects; SQL> select constraint_name,constraint_type,table_name from user_constraints; |
5. Drop the table: |
SQL> drop table names; |
6. Rerun the queries from Step 4. Note that the objects have been removed from USER_OBJECTS, but the constraint does still exist with a system-generated name.重新运行步骤(4)中的查询。注意, 已从USER OBJECTS 中删除了对象, 但是仍存在采用系统生成的名称的约束 |
SQL> select object_name,object_type from user_objects; SQL> select constraint_name,constraint_type,table_name from user_constraints; |
7. Query your recycle bin to see the mapping of the original name to the recycle bin names: (7) 查询回收站以查看原始的名称到回收站名称的映射: |
SQL> select object_name,original_name,type from user_recyclebin;
OBJECT_NAME ORIGINAL_NAME ------------------------------ -------------------------------- TYPE ------------------------- BIN$hEeY4LCsR3Cgm6K9NI4A7g==$0 NAME_IDX INDEX
BIN$8SdMhoYaRPS7HvzKCF6RNg==$0NAMES TABLE
SQL> select * from "BIN$8SdMhoYaRPS7HvzKCF6RNg==$0";
NAME ---------- John |
9. Recover the table with Flashback Drop:使用F1ashback Drop 恢复表: |
SQL> flashback table names to before drop; 闪回完成。
SQL> select * from names; NAME ---------- John |
10. Rerun the queries from Steps 4 and 7. Note that the index and the constraint have retained their recycle bin names重新运行步骤(4)和(7)中的查询.注意,索引和约束巳保留了它们的问收站名称. |
11. Rename the index and constraint to the original names. In the examples that follow, substitute your own recycle bin names: ( 11 )将索引和约束重命名回原先的名称.在后面的示例中,转换您自己的回收站名称: |
|
altertable NAMES addconstraintBIN$rigqwRLfTRO94/ns1/dIXw==$0unique (NAME); |
SQL> alter index "BIN$hEeY4LCsR3Cgm6K9NI4A7g==$0" rename to name_idx;
索引已更改。 SQL> alter table names rename constraint 2 "BIN$rigqwRLfTRO94/ns1/dIXw==$0" to name_u;
表已更改。 |
( 12) 通过重新运行步骤(10)中的查询来确认操作成功. Confirm the success of the operation by rerunning the queries from Step 10. |
SQL> select object_name,object_type from user_objects;
OBJECT_NAME --------------------------------------------------------------------------------
OBJECT_TYPE ------------------- NAMES TABLE
NAME_IDX INDEX
SQL> select constraint_name,constraint_type,table_name from user_constraints;
CONSTRAINT_NAME C TABLE_NAME ------------------------------ - ------------------------------ NAME_U U NAMES |
13.作为用户SYS连接数据库,并删除DROPPER 模式: Connect as user SYS, and drop the DROPPER schema |
SQL> conn / as sysdba SQL> drop user dropper cascade; |
14. Query the DBA_RECYCLEBIN view to demonstrate that all the objects owned by user DROPPER really are gone:查询DBA_RECYCLEBIN 视图来证实确实删除了用户DROPPER 拥行的所有对象: |
SQL> select count(*) from dba_recyclebin where owner='DROPPER';
COUNT(*) ---------- 0 |