閃迴歸檔(11G新功能)遠離ORA-01555錯誤

來源:互聯網
上載者:User

閃迴歸檔(11G新功能)遠離ORA-01555錯誤

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

T                            SCOTT                          FBA2                          SYS_FBA_HIST_78983                                  ENABLED

1.1.1.1.14 查看閃迴歸檔的基表

SQL> selecttable_name,tablespace_name from user_tables where table_name like '%FBA%';

TABLE_NAME                    TABLESPACE_NAME

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

SYS_FBA_DDL_COLMAP_78983(記錄DDL操作)      HIS_DATA_1

SYS_FBA_TCRV_78983(每一個事物、改變的資訊)          HIS_DATA_1

SYS_FBA_HIST_78983(記錄表實際改變的資料)

1.1.1.1.15 修改閃迴歸檔配額為200M

SQL> alterflashback archive fba1 modify tablespace his_data_1 quota 200M;

Flashback archive altered.

1.1.1.1.16 修改閃迴歸檔保留時間為1天

SQL> alterflashback archive fba1 modify retention1 day;

Flashback archive altered.

1.1.1.1.17 刪除閃迴歸檔

SQL> drop flashback archive fba1;

Flashback archive dropped.

1.1.1.1.18手動清除所有歸檔

SQL> alterflashback archive fba2 purge all;

Flashback archive altered.

1.1.1.1.19      手動清除某時間段閃迴歸檔

SQL> alterflashback archive fba2 purge before timestamp (systimestamp - interval '1' day);(清除一天前的,month,year);

Flashback archive altered.

1.1.1.1.20      手動清除基於SCN的歸檔。

SQL> alter flashback archive fba2 purgebefor scn 1111

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.