10g flashback
TRANSCRIPT
-
8/22/2019 10g Flashback
1/9
PURPOSE=======This bulletin illustrates the new recyclebin functionality providedwith the 10gdatabase
SCOPE & APPLICATION===================Can be used by Oracle Support Analyst and DBA
ABOUT 10g RECYCLEBIN====================
In order to have FLASHBACK DROP functionality a recyclebin is providedto every oracle user.
SQL> desc recyclebinName Null? Type----------------------------------------- -------- ------------OBJECT_NAME NOT NULL VARCHAR2(30)
ORIGINAL_NAME VARCHAR2(32)OPERATION VARCHAR2(9)TYPE VARCHAR2(25)TS_NAME VARCHAR2(30)CREATETIME VARCHAR2(19)DROPTIME VARCHAR2(19)DROPSCN NUMBERPARTITION_NAME VARCHAR2(32)CAN_UNDROP VARCHAR2(3)CAN_PURGE VARCHAR2(3)RELATED NOT NULL NUMBERBASE_OBJECT NOT NULL NUMBERPURGE_OBJECT NOT NULL NUMBERSPACE NUMBER
The recyclebin is a public synonym and it is based on the viewuser_recyclebin which in turn is based on sys.recyclebin$ table.
Related recyclebin objects:
SQL> SELECT SUBSTR(object_name,1,50),object_type,ownerFROM dba_objects WHERE object_name LIKE '%RECYCLEBIN%';/SUBSTR(OBJECT_NAME,1,50) OBJECT_TYPEOWNER--------------------------- -----------------------------
RECYCLEBIN$ TABLESYSRECYCLEBIN$_OBJ INDEXSYSRECYCLEBIN$_TS INDEXSYSRECYCLEBIN$_OWNER INDEXSYSUSER_RECYCLEBIN VIEWSYS
-
8/22/2019 10g Flashback
2/9
USER_RECYCLEBIN SYNONYMPUBLICRECYCLEBIN SYNONYMPUBLICDBA_RECYCLEBIN VIEWSYSDBA_RECYCLEBIN SYNONYMPUBLIC
9 rows selected.
THE RECYCLE BIN===============The Recycle Bin is a virtual container where all dropped objectsreside. Underneath the covers, the objects are occupying the same spaceas when they were created. If table EMP was created in the USERStablespace, the dropped table EMP remains in the USERS tablespace.Dropped tables and any associated objects such as indexes,constraints,nested tables, and other dependant objects are not moved, they aresimply renamed with a prefix of BIN$$. You can continue to access the
data in a dropped table or even use Flashback Query against it. Eachuser has the same rights and privileges on Recycle Bin objects beforeit was dropped. You can view your dropped tables by querying the newRECYCLEBIN view. Objects in the Recycle Bin will remain in the databaseuntil the owner of the dropped objects decides to permanently removethem using the new PURGE command. The Recycle Bin objects are countedagainst a user's quota. But Flashback Drop is a non-intrusive feature.Objects in the Recycle Bin will be automatically purged by the spacereclamation process ifo A user creates a new table or adds data that causes their quotato be exceeded.o The tablespace needs to extend its file size to accommodatecreate/insert operations.
There is no issues with DROPping the table, behaviour wise. It is thesame as in 8i / 9i. The space is not released immediately and isaccounted for within the same tablespace / schema after the drop.
When we drop a tablespace or a user there is NO recycling of theobjects.
EXAMPLE=======
SQL> SELECT * FROM v$version;BANNER
----------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64biPL/SQL Release 10.1.0.2.0 - ProductionCORE 10.1.0.2.0 ProductionTNS for Solaris: Version 10.1.0.2.0 - ProductionNLSRTL Version 10.1.0.2.0 - Production
SQL> sho userUSER is "BH"
-
8/22/2019 10g Flashback
3/9
SQL> SELECT object_name,original_name,operation,type,dropscn,droptime2 FROM user_recyclebin3 /
no rows selected
SQL> CREATE TABLE t1(a NUMBER);Table created.
SQL> DROP TABLE t1;Table dropped.
SQL> SELECT object_name,original_name,operation,type,dropscn,droptime2 FROM user_recyclebin3 /
OBJECT_NAME ORIGINAL_NAMEOPERATION TYPE DROPSCN DROPTIME------------------------------ ----------------------------------------- ------------------------- ---------- -------------------BIN$1Unhj5+DSHDgNAgAIKds8A==$0 T1 DROPTABLE 8.1832E+12 2004-03-10:11:03:49
SQL> sho userUSER is "SYS"
SQL> SELECT owner,original_name,operation,type2 FROM dba_recyclebin3 /
OWNER ORIGINAL_NAMEOPERATION TYPE------------------------------ ----------------------------------------- ------BH T1 DROPTABLE
Once a table is dropped it is not available. We cannot accessthat table (or the BIN$$ table) till that is recovered(flashback). Wecan also create a new table with the same name at this point.
Dropped tables are viewable (with the BIN$$ name) underuser_tables and we can see them using the new columnuser_tables.dropped = 'YES'
From BH user:SQL> SELECT table_name,tablespace_name
FROM user_tablesWHERE dropped='YES'
4 /TABLE_NAME TABLESPACE_NAME------------------------------ ---------------BIN$1UtrT/b1ScbgNAgAIKds8A==$0 USERS
PURGING=======
-
8/22/2019 10g Flashback
4/9
In order to completely remove the table from the DB and torelease the spacethe new PURGE command is used.
From BH user:SQL> PURGE TABLE t1;Table purged.
OR
SQL> PURGE TABLE "BIN$1UtrT/b1ScbgNAgAIKds8A==$0";Table purged.
From SYSDBA user:SQL> SELECT owner,original_name,operation,type2 FROM dba_recyclebin3 /
no rows selected
From BH user:
SQL> SHOW recyclebinSQL>
There are various ways to PURGE objects:
PURGE TABLE t1;PURGE INDEX ind1;PURGE recyclebin; (Purge all objects in Recyclebin)PURGE dba_recyclebin; (Purge all objects / only SYSDBA can)PURGE TABLESPACE users; (Purge all objects of the tablespace)PURGE TABLESPACE users USER bh; (Purge all objects of the tablspacebelonging to BH)
For an object, the owner or a user with SYSDBA privilege or auser with DROP ANY... system privilege for the type of object to bepurged can PURGE it.
For more information on the PURGE command refer to the 10g SQLReference
DISABLING RECYCLEBIN====================We can DROP and PURGE a table with a single command
From BH user:SQL> DROP TABLE t1 PURGE;Table dropped.
SQL> SELECT *2 FROM recyclebin3 /
no rows selected
There is no need to PURGE.
-
8/22/2019 10g Flashback
5/9
In case we want to disable the behavior of recycling, there is anunderscore parameter "_recyclebin" which defaults to TRUE. We candisable recyclebin by setting it to FALSE.
From SYSDBA user:SQL> SELECT a.ksppinm, b.ksppstvl, b.ksppstdfFROM x$ksppi a, x$ksppcv bWHERE a.indx = b.indxAND a.ksppinm like '%recycle%'ORDER BY a.ksppinm/
Parameter ValueDefault?---------------------------- ------------------------------------------------_recyclebin TRUETRUE
From BH user:SQL> CREATE TABLE t1(a NUMBER);
Table created.
SQL> DROP TABLE t1;Table dropped.
SQL> SELECT original_nameFROM user_recyclebin;ORIGINAL_NAME--------------T1
From SYSDBA user:SQL> ALTER SYSTEM SET "_recyclebin"=FALSE SCOPE = BOTH;System altered.
SQL> SELECT a.ksppinm, b.ksppstvl, b.ksppstdfFROM x$ksppi a, x$ksppcv bWHERE a.indx = b.indxAND a.ksppinm like '%recycle%'ORDER BY a.ksppinm/
Parameter ValueDefault?---------------------------- ------------------------------------------------_recyclebin FALSETRUE
From BH user:SQL> CREATE TABLE t1(a NUMBER);Table created.
SQL> DROP TABLE t1;Table dropped.
SQL> SELECT original_nameFROM user_recyclebin;
-
8/22/2019 10g Flashback
6/9
no rows selected
There is no need to PURGE.As with anyother underscore parameter, setting this parameter is notrecommendedunless advised by oracle support services.
Flashback Version Query
Using undo data stored in the database, one can now view the changes toone or more rows along with all the metadata of the changes. Flashbackversion query allows the versions of a specific row to be trackedduring a window of time using the VERSIONS BETWEEN clauses:
CREATE TABLE flashback_version_query (id NUMBER(10), descriptionVARCHAR2(50));
INSERT INTO flashback_version_query (id, description) VALUES (1,'Kunal');
COMMIT;
SELECT current_scn, TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROMv$database;
CURRENT_SCN TO_CHAR(SYSTIMESTAM
---------- -------------------
725202 2004-03-29 14:59:08
UPDATE flashback_version_query SET description = 'John' WHERE id = 1;
COMMIT;
UPDATE flashback_version_query SET description = 'Mathew' WHERE id = 1;
COMMIT;
SELECT current_scn, TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROMv$database;
-
8/22/2019 10g Flashback
7/9
CURRENT_SCN TO_CHAR(SYSTIMESTAM
----------- -------------------
725219 2004-03-29 14:59:36
COLUMN versions_startscn FORMAT 99999999999999999
COLUMN versions_starttime FORMAT A24
COLUMN versions_endscn FORMAT 99999999999999999
COLUMN versions_endtime FORMAT A24
COLUMN versions_xid FORMAT A16
COLUMN versions_operation FORMAT A1
COLUMN description FORMAT A11
SET LINESIZE 200
SELECT versions_startscn, versions_starttime,
versions_endscn, versions_endtime,
versions_xid, versions_operation,
description
FROM flashback_version_query
VERSIONS BETWEEN TIMESTAMP TO_TIMESTAMP('2004-04-27 15:13:57', 'YYYY-MM-DD HH24:MI:SS')
AND TO_TIMESTAMP('2004-04-27 15:14:52', 'YYYY-MM-DD HH24:MI:SS')
WHERE id = 1;
VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME
VERSIONS_XID V DESCRIPTION
------------------ ------------------------ ------------------------------------------ ---------------- - -----------
8183217632829 27-APR-04 03.14.44 PM 0006001000000250 U Mathew
8183217632826 27-APR-04 03.14.44 PM 8183217632829 27-APR-04 03.14.44 PM0002000D00001347 U John
-
8/22/2019 10g Flashback
8/9
8183217632826 27-APR-04 03.14.44 PM Kunal
SELECT versions_startscn, versions_starttime,
versions_endscn, versions_endtime,
versions_xid, versions_operation,
description
FROM flashback_version_query
VERSIONS BETWEEN SCN 8183217632826 AND 8183217632829
WHERE id = 1;
VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIMEVERSIONS_XID V DESCRIPTION
------------------ ------------------------ ------------------------------------------ ---------------- - -----------
8183217632829 27-APR-04 03.14.44 PM 0006001000000250 U Mathew
8183217632826 27-APR-04 03.14.44 PM 8183217632829 27-APR-04 03.14.44 PM0002000D00001347 U John
8183217632826 27-APR-04 03.14.44 PM Kunal
The available pseudo columns are:
* VERSIONS_STARTSCN or VERSIONS_STARTTIME - Starting SCN and TIMESTAMPwhen row took on this value. The value of NULL is returned if the rowwas created before the lower bound SCN or TIMESTAMP.
* VERSIONS_ENDSCN or VERSIONS_ENDTIME - Ending SCN and TIMESTAMP whenrow last contained this value. The value of NULL is returned if thevalue of the row is still current at the upper bound SCN ot TIMESTAMP.
* VERSIONS_XID - ID of the transaction that created the row in it'scurrent state.
* VERSIONS_OPERATION - Operation performed by the transaction((I)nsert, (U)pdate or (D)elete)
-
8/22/2019 10g Flashback
9/9
Flashback Transaction Query
Flashback transaction query can be used to get extra information aboutthe transactions listed by flashback version queries. The VERSIONS_XIDcolumn values from a flashback version query can be used to query theFLASHBACK_TRANSACTION_QUERY view like:
SQL> SELECT xid, operation, start_scn,commit_scn, logon_user, undo_sql
FROM flashback_transaction_query
WHERE xid = HEXTORAW('0006001000000250'); 2 3
XID OPERATION START_SCN COMMIT_SCN
---------------- -------------------------------- ---------- ----------
LOGON_USER
------------------------------
UNDO_SQL
--------------------------------------------------------------------------------
0006001000000250 UPDATE 8.1832E+12 8.1832E+12
KUNAL
update "KUNAL"."FLASHBACK_VERSION_QUERY" set "DESCRIPTION" = 'John'where ROWID
= 'AAAOBfAAIAAAAnaAAA';
0006001000000250 BEGIN 8.1832E+12 8.1832E+12
KUNAL