Home > Database > Mysql Tutorial > body text

闪回归档(11G新功能)远离ORA-01555错误

WBOY
Release: 2016-06-07 16:00:21
Original
1260 people have browsed it

前面闪回都是基于undo来实现的闪回,由于我们的闪回都是不确定时间的,所以就会导致ORA-01555(快照太旧或者被覆盖)、ORA-01466

1.1.1.1  闪回归档

前面闪回都是基于undo来实现的闪回,由于我们的闪回都是不确定时间的,所以就会导致ORA-01555(快照太旧或者被覆盖)、ORA-01466(表定义被改)、ORA-08180(没有快照)等错误。

1.1.1.1.1      创建表空间,默认大小500M

SQL> CREATE TABLESPACEhis_data_1 datafile '+DATA' size 500m;

Tablespacecreated.

1.1.1.1.2      创建默认闪回归档,保存天数为7天

SQL> create flashback archivedefault fba1 tablespace his_data_1 retention 7 day;

Flashbackarchive created.

1.1.1.1.3      创建闪回归档,保存天数为30天,,配额为200M

SQL> create flashback archive fba2 tablespace his_data_1 QUOTA 200mRETENTION 30 day;

Flashbackarchive created.

1.1.1.1.4      为用户授权

SQL> grant flashback archive onfba1 to scott;

Grantsucceeded.

SQL> grant flashback archiveon fba2 to scott;

Grantsucceeded.

1.1.1.1.5      创建表,并开启闪回归档

SQL> create tableempsal_his(empno number,ename varchar2(10),sal number) flashback archive;(默认为fba1)

Tablecreated.

SQL> create table t(id int)flashback archive fba2;

Tablecreated.

1.1.1.1.6      向表内插入数据,并查看ALERT日志

17:07:57 SQL> insert intoscott.t select object_id from dba_objects;

75465rows created.

17:09:12 SQL> commit;

Commitcomplete

[Oracle@oracle trace]$ tail -falert_oracle007.log

Thread1 advanced to log sequence 63 (LGWR switch)

Current log# 3 seq# 63 mem# 0:/u01/app/oracle/oradata/oracle007/redo03.log

ThuMay 07 17:12:06 2015

ArchivedLog entry 60 added for thread 1 sequence 62 ID 0x958cb7c1 dest 1:

ThuMay 07 16:46:52 2015

Starting background process FBDA

Thu May 07 16:46:52 2015

FBDA started with pid=27, OS id=35751

1.1.1.1.7      重建UNDO表空间

17:11:59 SQL> create undo tablespaceundotbs2 datafile '+DATA' size 100m;

Tablespacecreated.

1.1.1.1.8      更改系统undo表空间

17:14:59 SQL> alter system setundo_tablespace='undotbs2';

Systemaltered.

1.1.1.1.9      删除系统undo表空间及数据库文件(原来)

17:56:27 SQL> drop tablespace undotbs1including contents and datafiles;

Tablespacedropped.

1.1.1.1.10 查看某个时间点表的内容

查看刚创建表没有添加内容时表里的内容

SQL> select id from t as of timestampto_timestamp('2015-5-7 17:05:57 ','YYYY-MM-DD hh24:mi:ss');

norows selected

向表内增加一条数据

SQL> insert into t values(1);

1row created.

SQL> commit;

Commitcomplete.

查看在增加数据之前表里行的条数

SQL> select count(id) from t asof timestamp to_timestamp('2015-5-7 18:07:04','YYYY-MM-DD hh24:mi:ss');

COUNT(ID)

----------

75465

查看在增加数据之后表里行的条数

SQL> select count(id) from t;

COUNT(ID)

----------

75466

norows selected

1.1.1.1.11 查看闪回归档表空间大小及配额

SQL> select flashback_archive_name,tablespace_name,quota_in_mb fromdba_flashback_archive_ts;

FLASHBACK_ARCHIVE_NAME        TABLESPACE_NAME                QUOTA_IN_MB

------------------------------------------------------------ ------------------------------

FBA1                          HIS_DATA_1

FBA2                          HIS_DATA_1                    200

1.1.1.1.12 查看闪回归档日期及保存时间及默认闪回归档

SQL> selectflashback_archive_name,to_char(CREATE_TIME,'dd-mm_yyyy')created,retention_in_days,statusfrom dba_flashback_archive;

FLASHBACK_ARCHIVE_NAME        CREATED    RETENTION_IN_DAYS STATUS

---------------------------------------- ----------------- -------

FBA1                          07-05_2015                7 DEFAULT

FBA2                          07-05_2015                30

1.1.1.1.13 查看闪回归档的表信息,

SQL> select * from dba_flashback_archive_tables;

TABLE_NAME                    OWNER_NAME                    FLASHBACK_ARCHIVE_NAME        ARCHIVE_TABLE_NAME                                  STATUS

------------------------------------------------------------ ------------------------------ ------------------------------------------------------------------

EMPSAL_HIS                    SCOTT                          FBA1                          SYS_FBA_HIST_78982(后面的数字对应的是dba_object里object_id,这个表对应的是装历史数据库块的)                                ENABLED

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!