ORACLE 11.2 性能调优之04 ( FBDA-闪回数据归档 )
Posted 轻飘飘D
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ORACLE 11.2 性能调优之04 ( FBDA-闪回数据归档 )相关的知识,希望对你有一定的参考价值。
1.创建FBDA管理员用户账号(后续用此用户管理)
CREATE USER FBDA_ADMIN IDENTIFIED BY "123456" DEFAULT TABLESPACE MY_UD TEMPORARY TABLESPACE TEMP_GP;
GRANT DBA to FBDA_ADMIN;
grant connect,resource,unlimited tablespace to FBDA_ADMIN;
GRANT FLASHBACK ARCHIVE ADMINISTER TO FBDA_ADMIN;
2.授予其它用户(XAG)合适的闪回权限--SYS 登录
GRANT FLASHBACK ANY TABLE TO XAG;
GRANT EXECUTE ON DBMS_FLASHBACK TO XAG;
3.为闪回数据归档创建表空间
create tablespace flash_tbs1 datafile
‘/u02/oradata/DB112/flash_tbs1_1.dbf‘ size 8M AUTOEXTEND ON NEXT 8M MAXSIZE UNLIMITED,
‘/u02/oradata/DB112/flash_tbs1_2.dbf‘ size 8M AUTOEXTEND ON NEXT 8M MAXSIZE UNLIMITED
segment space management auto;
4.创建闪回数据归档(FBDA_ADMIN登录)
-- 创建一个闪回数据归档保留2天有价值的历史
create flashback archive fbda_2day tablespace flash_tbs1 quota 512M retention 2 day;
--注意:这里只给分配了1024M的空间,如果想让空间不受限的话,执行下面的语句即可:
--create flashback archive fbda_2day tablespace flash_tbs1 retention 2 day;
GRANT FLASHBACK ARCHIVE ON fbda_2day TO xag;
-- 创建一个闪回数据归档保留1整月有价值的历史
create flashback archive fbda_1month tablespace flash_tbs1 quota 1024M retention 1 month;
GRANT FLASHBACK ARCHIVE ON fbda_1month TO xag;
-- 创建一个闪回数据归档保留1整年有价值的历史
create flashback archive fbda_1year tablespace flash_tbs1 quota 2048M retention 1 year;
GRANT FLASHBACK ARCHIVE ON fbda_1year TO xag;
5.更改闪回数据归档
#sys login
SQL> alter flashback archive fbda_1month set default;
/*
SQL> alter flashback archive fbda_1month add tablespace example; --添加表空间
SQL> alter flashback archive fbda_1month remove tablespace example; --删除表空间
SQL> alter flashback archive fbda_1month modify tablespace flash_tbs1 quota 2048M;? -添加配额
SQL> alter flashback archive fbda_1month modify retention 2 month; --修改保留年限
SQL> alter flashback archive fbda_1month purge all;? --清除所有
SQL> alter flashback archive fbda_1month purge before timestamp(systimestamp-interval ‘2‘ day); -清除2天前的
SQL> alter flashback archive fbda_1month purge before scn 123344; --指定scn清除
*/
6.启用和禁用闪回数据归档
#1、在建表的同时就启用表的闪回日志(xag)
create table t1(id int,name varchar2(10)) flashback archive fbda_2day;
#2、也可以在建表后,再启用表的闪回日志
--SQL> alter table t2 flashback archive;? --为表启用闪回数据归档,没指定表示使用数据库默认的
--SQL> alter table t3 flashback archive flash1; --为表启用闪回数据归档,指定在特定的闪回数据归档中存储表的变化
3、查看表的数据归档
SQL> select t.TABLE_NAME,t.FLASHBACK_ARCHIVE_NAME,t.ARCHIVE_TABLE_NAME,t.STATUS from dba_flashback_archive_tables t;
---------------------------------------------------------------------------------------------------
1 T1 FBDA_2DAY SYS_FBA_HIST_87401 ENABLED
???
4、在使用闪回数据归档前,必须设置默认闪回数据归档
SQL> select flashback_archive_name,status from dba_flashback_archive;
FLASHBACK_ARCHIVE_NAME???? STATUS
---------------------------------------
FBDA_2DAY
FBDA_1MONTH DEFAULT
FBDA_1YEAR
5、禁用闪回数据归档
--SQL> alter table t2 no flashback archive;
7.闪回数据归档的限制
在使用闪回归档的过程中有某些限制。对于已经启用闪回的表,不能使用DDL命令drop column(11r2可以drop column),
但可以add column命令。删除属于一个启用了闪回数据归档的表列的唯一方法是首先关闭闪回归档功能。但是,这样会删除所有闪回归档数据。
1、ALTER TABLE:
Drops, renames, or modifies a column (11GR2是可以的)
Performs partition or subpartition operations
Converts a LONG column to a LOB column
Includes an UPGRADE TABLE clause, with or without an INCLUDING DATA clause
2、 DROP TABLE
3、TRUNCATE TABLE (11GR2是可以的)
4、RENAME TABLE (11GR2也是可以的)
8.监控认回数据归档
1、查哪些表已经启用了闪回数据归档
SQL> select t.TABLE_NAME,t.OWNER_NAME,t.FLASHBACK_ARCHIVE_NAME,t.ARCHIVE_TABLE_NAME,t.STATUS from dba_flashback_archive_tables t;
---------------------------------------------------------------------------------------------------
1 T1 XAG FBDA_2DAY SYS_FBA_HIST_87401 ENABLED
2、查数据库中所有的闪回数据归档
SQL> select flashback_archive_name,tablespace_name,quota_in_mb from dba_flashback_archive_ts;
FLASHBACK_ARCHIVE_NAME??TABLESPACE_NAME ?QUOTA_IN_MB???????????????? ???????
----------------------------------------------------------------------------------------------
1 FBDA_2DAY FLASH_TBS1 512
2 FBDA_1MONTH FLASH_TBS1 1024
3 FBDA_1YEAR FLASH_TBS1 2048
9.使用闪回数据归档:例子
SQL> create table mytest(id int,name varchar2(10));
SQL> alter table mytest flashback archive FBDA_2DAY;
SQL>
begin
for i in 1..100 loop
insert into mytest values(i,‘shiyu‘||i);
commit;
end loop;
end;
/?
SQL> select count(*) from mytest;
? COUNT(*)
----------
?????? 100
SQL> select t.TABLE_NAME,t.OWNER_NAME,t.FLASHBACK_ARCHIVE_NAME,t.ARCHIVE_TABLE_NAME,t.STATUS from dba_flashback_archive_tables t;
---------- ----- ---------- -------------------- --------
1 T1 XAG FBDA_2DAY SYS_FBA_HIST_87401 ENABLED
2 MYTEST XAG FBDA_2DAY SYS_FBA_HIST_87402 ENABLED
SQL> select count(*) from SYS_FBA_HIST_87402;
? COUNT(*)
----------
? 0
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
??? 1004353
SQL> delete from mytest;
100 rows deleted.
SQL> commit;
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
??? 1004379
SQL> select count(*) from mytest as of scn 1004353;
? COUNT(*)
----------
?????? 100
SQL> select count(*) from mytest as of scn 1004379;
? COUNT(*)
----------
? 0
SQL> select count(*) from SYS_FBA_HIST_87402;
? COUNT(*)
----------
?????? 200
七、删除闪回归档数据
SQL>? drop flashback archive FBDA_2DAY;
SQL> select flashback_archive_name,status from dba_flashback_archive;
FLASHBACK_ARCHIVE_NAME???? STATUS
---------------------------------------
FBDA_1MONTH DEFAULT
FBDA_1YEAR
以上是关于ORACLE 11.2 性能调优之04 ( FBDA-闪回数据归档 )的主要内容,如果未能解决你的问题,请参考以下文章