Your SlideShare is downloading. ×
Flashback (Practical Test)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Flashback (Practical Test)

416
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
416
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Anar Godjaev FLASHBACK (Practical test) SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 184549376 bytes Fixed Size 1300928 bytes Variable Size 157820480 bytes Database Buffers 25165824 bytes Redo Buffers 262144 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter system set DB_FLASHBACK_RETENTION_TARGET=4320; System altered. SQL> alter system set DB_RECOVERY_FILE_DEST_SIZE=536870912; System altered. SQL> alter system set DB_RECOVERY_FILE_DEST='/home/oracle/flash'; System altered. SQL> alter database flashback on; Database altered.
  • 2. Anar Godjaev SQL> alter database open; Database altered. SQL> select flashback_on from v$database; FLASHBACK_ON -----------YES FLASHBACK (DROP TABLE) CMD > sqlplus hr/hr SQL> create table test_table( id number(2), name varchar2(30) ); Table created. SQL> insert into test_table values (1, 'Ben Rockwood'); 1 row created. SQL> insert into test_table values (2, 'Tamarah Rockwood'); 1 row created. SQL> insert into test_table values (3, 'Nova Rockwood'); 1 row created. SQL> insert into test_table values (4, 'Hunter Rockwood'); insert into test_table values (5, 'ddddter Rockwood'); 1 row created. SQL> select * from test_table;
  • 3. Anar Godjaev ID NAME ---------- -----------------------------1 Ben Rockwood 2 Tamarah Rockwood 3 Nova Rockwood 4 Hunter Rockwood SQL> drop table test_table; Table dropped. SQL> select * from test_table; select * from test_table * ERROR at line 1: ORA-00942: table or view does not exist SQL> select * from recyclebin; SQL> show recyclebin; SQL> flashback table test_table to before drop; Flashback complete. SQL> select * from test_table; ID NAME ---------- -----------------------------1 Ben Rockwood 2 Tamarah Rockwood 3 Nova Rockwood 4 Hunter Rockwood SQL> drop table test_table purge; Table dropped. SQL> select * from test_table;
  • 4. Anar Godjaev select * from test_table * ERROR at line 1: ORA-00942: table or view does not exist SQL> select * from recyclebin; SQL> show recyclebin; SQL> alter system set "_recyclebin"=FALSE; FLASHBACK (SCN) CMD > sqlplus hr/hr SQL> CREATE TABLE flashback_table_test ( id NUMBER(10) ); SQL> ALTER TABLE flashback_table_test ENABLE ROW MOVEMENT; SQL> SELECT current_scn FROM v$database; CURRENT_SCN ----------933716 SQL> INSERT INTO flashback_table_test (id) VALUES (1); SQL> INSERT INTO flashback_table_test (id) VALUES (2); SQL> COMMIT; SQL> SELECT current_scn FROM v$database; CURRENT_SCN ----------934423
  • 5. Anar Godjaev SQL> SELECT * FROM flashback_table_test; ID ----------1 2 SQL> INSERT INTO flashback_table_test (id) VALUES (3); SQL> INSERT INTO flashback_table_test (id) VALUES (4); SQL> COMMIT; SQL> SELECT current_scn FROM v$database; CURRENT_SCN ----------934474 SQL> SELECT * FROM flashback_table_test; ID ----------1 2 3 4 SQL> FLASHBACK TABLE flashback_table_test TO SCN 934423; SQL> SELECT COUNT(*) FROM flashback_table_test; COUNT(*) ---------2 SQL> FLASHBACK TABLE flashback_table_test TO SCN 934474;
  • 6. Anar Godjaev SQL> SELECT COUNT(*) FROM flashback_table_test; COUNT(*) ---------4 SQL> FLASHBACK TABLE flashback_table_test TO SCN 933716; SQL> SELECT COUNT(*) FROM flashback_table_test; COUNT(*) ---------4 FLASHBACK (TIME) CMD > sqlplus hr/hr SQL> CREATE TABLE t3 ENABLE ROW MOVEMENT AS SELECT owner, table_name, tablespace_name FROM all_tables WHERE 1=2; SQL> desc t SQL> SELECT table_name, row_movement FROM user_tables; SQL> SELECT current_scn, SYSTIMESTAMP FROM gv$database; CURRENT_SCN ----------SYSTIMESTAMP --------------------------------------------------------------------------935085
  • 7. Anar Godjaev 10-MAR-12 10.30.40.360096 AM +02:00 SQL> INSERT INTO t3 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'SYS'; SQL> COMMIT; SQL> SELECT current_scn, SYSTIMESTAMP FROM gv$database; CURRENT_SCN ----------SYSTIMESTAMP --------------------------------------------------------------------------935177 10-MAR-12 10.32.18.675106 AM +02:00 SQL> INSERT INTO t3 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'HR'; SQL> COMMIT; SQL> SELECT current_scn, SYSTIMESTAMP FROM gv$database; CURRENT_SCN ----------SYSTIMESTAMP --------------------------------------------------------------------------935196 10-MAR-12 10.32.57.849132 AM +02:00 SQL> INSERT INTO t3 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'CTXSYS'; SQL> COMMIT;
  • 8. Anar Godjaev SQL> SELECT current_scn, SYSTIMESTAMP FROM gv$database; CURRENT_SCN ----------SYSTIMESTAMP --------------------------------------------------------------------------935239 10-MAR-12 10.33.36.687213 AM +02:00 SQL> SELECT owner, COUNT(*) FROM t3 GROUP BY owner; OWNER COUNT(*) ------------------------------ ---------HR 10 CTXSYS 5 SYS 27 SQL> FLASHBACK TABLE t3 TO TIMESTAMP TO_TIMESTAMP('10/03/2012 10:40:00','dd/mm/yyyy hh24:mi:ss'); SQL> SELECT owner, COUNT(*) FROM t3 GROUP BY owner; SQL> FLASHBACK TABLE t3 TO TIMESTAMP TO_TIMESTAMP('07/02/2011 19:31:22','dd/mm/yyyy hh24:mi:ss'); SQL> SELECT owner, COUNT(*) FROM t3 GROUP BY owner; SQL> FLASHBACK TABLE t3 TO TIMESTAMP TO_TIMESTAMP('07/02/2011 19:33:55','dd/mm/yyyy hh24:mi:ss'); SQL> SELECT owner, COUNT(*) FROM t3 GROUP BY owner; FLASHBACK (POINT) CMD > sqlplus hr/hr SQL> CREATE TABLE t2 ENABLE ROW MOVEMENT AS SELECT owner, table_name, tablespace_name
  • 9. Anar Godjaev FROM all_tables WHERE 1=2; SQL> desc t2 SQL> SELECT table_name, row_movement FROM user_tables; SQL> CREATE RESTORE POINT zero; SQL> INSERT INTO t2 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'SYS'; SQL> COMMIT; SQL> CREATE RESTORE POINT one; SQL> INSERT INTO t2 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'WMSYS'; SQL> COMMIT; SQL> CREATE RESTORE POINT two; SQL> INSERT INTO t2 SELECT owner, table_name, tablespace_name FROM all_tables WHERE owner = 'CTXSYS'; SQL> COMMIT; SQL> SELECT owner, COUNT(*) FROM t2 GROUP BY owner;
  • 10. Anar Godjaev SQL> SELECT scn, time, name FROM gv$restore_point; SQL> FLASHBACK TABLE t2 TO RESTORE POINT two; SQL> SELECT owner, COUNT(*) FROM t2 GROUP BY owner; SQL> FLASHBACK TABLE t2 TO RESTORE POINT one; SQL> SELECT owner, COUNT(*) FROM t2 GROUP BY owner; SQL> FLASHBACK TABLE t2 TO RESTORE POINT zero; SQL> SELECT owner, COUNT(*) FROM t2 GROUP BY owner; FLASHBACK (DATABASE) CMD > sqlplus hr/hr SQL> create table test_table2( id number(2), name varchar2(30) ); Table created. SQL> insert into test_table values (1, 'Ben Rockwood'); 1 row created. SQL> insert into test_table values (2, 'Tamarah Rockwood'); 1 row created.
  • 11. Anar Godjaev SQL> insert into test_table values (3, 'Nova Rockwood'); 1 row created. SQL> insert into test_table values (4, 'Hunter Rockwood'); 1 row created. SQL> select * from test_table; ID NAME ---------- -----------------------------1 Ben Rockwood 2 Tamarah Rockwood 3 Nova Rockwood 4 Hunter Rockwood SQL> CONN sys/password AS SYSDBA; SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT EXCLUSIVE; SQL> FLASHBACK DATABASE TO TIMESTAMP SYSDATE-(1/24/12); // 5 minutes earlier to SQL> ALTER DATABASE OPEN RESETLOGS; SQL> CONN hr/hr SQL> select * from test_table; FLASHBACK DATABASE TO TIMESTAMP my_date; FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date; FLASHBACK DATABASE TO SCN my_scn; FLASHBACK DATABASE TO BEFORE SCN my_scn;