Monday 25 November 2019

Flashback Concepts1

 flashback query
 flashback transaction query

Flashback query:

If we delete any data we use flashback query and check which data will delete from this scn or timestamp and we will insert which data will deleted by flashback query.
C:\Users\svss3>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Apr 25 15:54:35 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> connect /as sysdba
Connected.
SQL> select flashback_on from v$database;
FLASHBACK_ON
YES

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     9
Next log sequence to archive   11
Current log sequence           11

SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SYSTEM01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\UNDOTBS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SYSAUX01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\USERS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\EXAMPLE01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\TEST.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SVSS.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SVSS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\RMAN.DBF
9 rows selected.

SQL> create tablespace flash datafile 'e:\oracle\product\10.2.0\oradata\agile2\f
lash.dbf' size 5m;
Tablespace created.

SQL> select name from v$datafile;
NAME
-------------------------------------------------------------------------------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SYSTEM01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\UNDOTBS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SYSAUX01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\USERS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\EXAMPLE01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\TEST.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SVSS.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\SVSS01.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\RMAN.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\AGILE2\FLASH.DBF
10 rows selected.

SQL> select username from dba_users;
USERNAME
------------------------------
MGMT_VIEW
SYS
SYSTEM
DBSNMP
SYSMAN
SCOTT
RMAN
SVSS
RMAN1
FLASH
OUTLN

USERNAME
------------------------------
MDSYS
ORDSYS
EXFSYS
DMSYS
WMSYS
CTXSYS
ANONYMOUS
XDB
ORDPLUGINS
SI_INFORMTN_SCHEMA
OLAPSYS

USERNAME
------------------------------
TSMSYS
BI
PM
MDDATA
IX
SH
DIP
OE
HR

31 rows selected.

SQL> alter user flash default tablespace flash;
User altered.

SQL> connect flash/flash
Connected.

SQL> select * from tab;
no rows selected

SQL> create table flash (id number(23));
Table created.

SQL> insert into flash values(12);
1 row created.

SQL> commit;
Commit complete.

SQL> insert into flash values(22);
1 row created.

SQL> commit;
Commit complete.

SQL> connect /as sysdba
Connected.


SQL> connect flash/flash
Connected.

SQL> select * from flash;
        ID
----------
        22
        23
        22
        23
        22
        23
        22
        23

8 rows selected.

SQL> connect /as sysdba
Connected.

SQL> select current_scn from v$Database;
CURRENT_SCN
-----------
    1625644

SQL> commit;
Commit complete.
QL> connect flash/flash
Connected.
SQL> delete flash
  8 rows deleted.

SQL> commit;
Commit complete.

SQL> connect flash/flash
Connected.

SQL> select * from flash;
no rows selected

SQL> select * from flash as of scn 1625644;

        ID
----------
        22
        23
        22
        23
        22
        23
        22
        23

8 rows selected.

SQL> insert into flash (select * from flash as of scn 1625644);

8 rows created.
SQL> commit;
Commit complete.
 SQL> select * from flash;

        ID
----------
        22
        23
        22
        23
        22
        23
        22
        23

8 rows selected.

Flashback transaction query
  By using this flashback transaction query we will check user which operation (dml) done on this table or particular schema.
SQL> connect /as sysdba
Connected.

SQL> select current_Scn from v$database;
CURRENT_SCN
-----------
    1626271

SQL> connect flash/flash
Connected.

SQL> insert into flash values (45);
1 row created.

SQL> commit;
Commit complete.

SQL> update flash
  2  set id=46
  3  where id=22;
4 rows updated.

SQL> commit;
Commit complete.

SQL> delete flash
  2  where id =45;
1 row deleted.

SQL> commit;
Commit complete

SQL> connect /as sysdba
Connected.

SQL> connect flash/flash
Connected.

SQL> desc flashback_transaction_query;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 XID                                                RAW(8)
 START_SCN                                          NUMBER
 START_TIMESTAMP                                    DATE
 COMMIT_SCN                                         NUMBER
 COMMIT_TIMESTAMP                                   DATE
 LOGON_USER                                         VARCHAR2(30)
 UNDO_CHANGE#                                       NUMBER
 OPERATION                                          VARCHAR2(32)
 TABLE_NAME                                         VARCHAR2(256)
 TABLE_OWNER                                        VARCHAR2(32)
 ROW_ID                                             VARCHAR2(19)
 UNDO_SQL                                           VARCHAR2(4000)

SQL> select operation,undo_sql,table_name from flashback_transaction_query where table_name='FLASH';

select operation,undo_sql,table_name from flashback_transaction_query where table_name='FLASH'
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> CONNECT /AS SYSDBA
Connected.

SQL> select operation,undo_sql,table_name from flashback_transaction_query where table_name='FLASH';

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAAAAAAAAAAA';
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAG';
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAF';
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAE';

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAD';
FLASH

UPDATE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
update "FLASH"."FLASH" set "ID" = '21' where ROWID = 'AAAM82AAKAAAAAMAAN';
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '21' where ROWID = 'AAAM82AAKAAAAAMAAM';
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
UPDATE
update "FLASH"."FLASH" set "ID" = '21' where ROWID = 'AAAM82AAKAAAAAMAAL';
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '21' where ROWID = 'AAAM82AAKAAAAAMAAK';
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAA';
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH

DELETE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('45');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('35');
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

DELETE
insert into "FLASH"."FLASH"("ID") values ('35');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('35');

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('35');
FLASH

DELETE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
insert into "FLASH"."FLASH"("ID") values ('12');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('12');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('12');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('12');
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

UPDATE
update "FLASH"."FLASH" set "ID" = '25' where ROWID = 'AAAM82AAKAAAAAMAAN';
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '25' where ROWID = 'AAAM82AAKAAAAAMAAM';

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '25' where ROWID = 'AAAM82AAKAAAAAMAAL';
FLASH

UPDATE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
update "FLASH"."FLASH" set "ID" = '25' where ROWID = 'AAAM82AAKAAAAAMAAK';
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

DELETE
insert into "FLASH"."FLASH"("ID") values ('25');
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '12' where ROWID = 'AAAM82AAKAAAAAQAAA';

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAC';
FLASH

INSERT

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAA';
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '22' where ROWID = 'AAAM82AAKAAAAANAAG';
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
UPDATE
update "FLASH"."FLASH" set "ID" = '22' where ROWID = 'AAAM82AAKAAAAANAAE';
FLASH

UPDATE
update "FLASH"."FLASH" set "ID" = '22' where ROWID = 'AAAM82AAKAAAAANAAC';
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

UPDATE
update "FLASH"."FLASH" set "ID" = '22' where ROWID = 'AAAM82AAKAAAAANAAA';
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH

DELETE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('22');

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

DELETE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAAAAAAAAAAA';
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAAAAAAAAAAA';
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAKAAAAAQAAB';

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
FLASH

INSERT
delete from "FLASH"."FLASH" where ROWID = 'AAAM82AAAAAAAAAAAA';
FLASH

DELETE

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH


OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

DELETE
insert into "FLASH"."FLASH"("ID") values ('23');
FLASH

OPERATION
--------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------


58 rows selected.



No comments:

Post a Comment