All technological notes.
Flashback Data ArchivesFlashback Data Archives
Flashback Data ArchivesArchive 不使用 undo, 而是使用 temporal table/tbsp
保留更长的
Flashback data archives:

Enable at the table level with specified retention period.
FDA have SQL-level access to the versions of database objects without getting a snapshot-too-old error.
You can use this technology for compliance, audit reports, data analysis, and decision-support systems.
flashback data archive consists of one or more tablespaces.flashback data archives.The database server will automatically purge all historical information on the day after the retention period expires.
Steps:
tablespace for your FDA.
base table and the expected DML and DDL activity.Create a flashback data archive with retention time, by default, with duplication and without compression.
FLASHBACK ARCHIVE ADMINISTER system privilege.retention periods are needed, different archives must be created.OPTIMIZE DATA clause, the flashback data archive is created with compression and deduplication.-- creat a flashback archive named fda1
-- point the fda1 to the tbsp fda_tbs1
-- define a retention as one year
-- use optimize data to enable efficient storage
CREATE FLASHBACK ARCHIVE fda1 TABLESPACE fda_tbs1
OPTIMIZE DATA QUOTA 10M RETENTION 1 YEAR;
FLASHBACK ARCHIVE object privilege.DDL statements are not allowed on that table.-- turn on flashback archive for the table to fda1
ALTER TABLE HR.EMPLOYEES FLASHBACK ARCHIVE fda1;

History data:
undo (and buffer cache) by the £dba background process at self-tuned intervals.
base table row that is updated is stored, no matter how many columns are updated. 更新的行都会存储retention policyStorage:
OPTIMIZE DATA clause:
OPTIMIZE DATA clause:
FDA history tables already compressed and deduplicated in releases prior to 12.1 are not changed. Their storage continues compressed and deduplicated.
To stop optimization on FDA history tables:
ALTER FLASHBACK ARCHIVE flal NO OPTIMIZE DATA;Partitions
Flashback queries to the archives skip unrelated partitions.
flashback archive partition is at least 1 day and 1 MB of data, partitioned on ENDSCN.process and slaves:
flashback archiver slaves can be called upon by the £bda process. 最多 10 个flashback archive process and slaves are too busy, archiving may be performed inline, which significantly affects the user’s response time.影响客户响应时间The user context of a transaction executed on a table with Temporal History is collected and retrievable.
GET SYS CONTEXT (USERENV) function:
DBMS_FLASHBACK_ARCHIVE.GET_SYS_CONTEXT function:
DBMS_FLASHBACK_ARCHIVE.SET_CONTEXT_LEVEL function:
value:
NONE, no user context is collected.TYPICAL: gets database user ID, global user ID, client identifier, service name, module name, or host name.ALLEach row of the user context can be read only by the DBA or the owner of the transaction.
EXEC DBMS_FLASHBACK_ARCHIVE.SET_ CONTEXT LEVEL ('TYPICAL')
/
SELECT
DBMS_FLASHBACK_ARCHIVE.GET_SYS_CONTEXT
(VERSIONS_XID, 'USERENV', 'SESSION USER'),
VERSIONS_XID,
VERSIONS_STARTTIME,
VERSIONS_ENDTIME,
employee_id,
salary
FROM hr.employees VERSIONS BETWEEN SCN MINVALUE
AND MAXVALUE ;
DDL commands supported by flashback data archives:
Temporal History technology automatically keeps track of the changes.Flashback query appropriately returns the row or rows with the corresponding schema.
Disassociate or associate procedures in the DBMS_FLASHBACK_ARCHIVE package:
Flashback Archive on specified tables and allow more complex DDL (upgrades, split tables, and so on).Enforce schema integrity during association. (Base table and history table must be the same schema.)

- If you have the
FLASHBACK ARCHIVE ADMINISTERprivilege, you can disassociate thearchivefrom thebase tablewith theDTSASSOCTATE_FBAprocedure.- Make the necessary changes to the
base table.- Make the necessary changes to the corresponding
archive.- Then associate the
tablewith thearchivewithin the same schema with theRESASSOCIATE_FBAprocedure.
Temporal Historyvalidates that the schemas are the same upon association.
history tables.ORA-55610 when used on a table enabled for FDA.
Distinguish active from nonactive rows:
Temporal validity:Temporal History: System-managed transaction time in a separate tablespaceTemporal validity:
User-managed effective date in the same table
Temporal validity dates or time stamps are different from the dates or time stamps annotated when the fact was recorded in the database.标记的时间不同于录入时间.Temporal History / flashback data archive attributes:
Example

- employee 400 was hired on March 22
- the row was entered in the HR.EMP table on March 23.
- 22-MAR-12 is the
valid time temporaldate- 23-MAR-12 is the
transaction time temporaldate
valid time temporal implicit filter on the valid-time dimension, queries can show rows that are currently valid or that will be valid in the future. 用来过滤时间有效的数据
valid-time temporal and transaction time temporal date.valid-time dimension:
PERIOD FOR clause
Note: A check constraint is automatically added to ensure that the end time is later than the start time. 一个约束会自动生成
Example
-- Explicitly define the two date-time columns
CREATE TABLE emp
(
empno number, salary number, deptid number,
name VARCHAR2 (100),
user_time_start DATE, user_time_end DATE, -- Explicitly define
PERIOD FOR user_time (user_time_start, user_time_end)
);
-- automatic valid-time columns
CREATE TABLE emp2
(
empno number, salary number, deptid number,
name VARCHAR2 (100),
PERIOD FOR user_time -- automatic define
-- name of the valid-time dimension is user_time
-- USER_TIME is used as the prefix for the two date columns automatically created: USER_TIME_START and USER_TIME_END.
);
-- insert
INSERT INTO emp2
(empno, salary, deptid, name, user_time_start, user_time_end)
VALUES (1,1000,20, 'John', SYSDATE, NULL);
-- query
select EMPNO, user_time_start, user_time_end from emp2;
-- EMPNO USER_TIME_START USER_TIME_END
-- 1 17-AUG-12 09.58.03.000000 AM +00:00
To filter on valid-time columns:
SELECT statement with the PERIOD FOR clauseDBMS_FLASHBACK_ARCHIVE procedure.Example:
Scenario:
transaction date.PERIOD FOR clause.select * from hr.emp as of PERIOD FOR user_time
to_date('01-DEC-1992', 'dd-mon-yyyy') ;
即使用 period for 自动筛选在某个时间点上时间有效的记录.

VERSIONS PERIOD FOR BETWEEN clause:select * from hr.emp VERSIONS PERIOD FOR user_time
BETWEEN to_date('31-DEC-2011', 'dd-mon-yyyy')
AND to_date('31-DEC-2012', 'dd-mon-yyyy');
The query displays all employees whose
VALID_TIME_STARTis less than or equal to ‘31-DEC-2011’andVALID_TIME_ENDgreater than or equal to ‘31-DEC-2012”.

bi-temporal queries:
valid-time and transaction-time dimensionsQueries
select * from hr.emp
as of period for user time to_date('31-DEC-1992', 'dd-mon-yyyy"')
as of timestamp to_date ('30-mar-2012', 'dd-mon-yyyy');
DBMS_FLASHBACK_ARCHIVEUsers can modify visibility within a session by using the new DBMS_FLASHBACK_ARCHIVE package.
SELECT and DML statements.DDLs will default to getting full visibility to the table data.
ALTER TABLE MOVE operations will have full visibility of the table data.Example:
-- Set the visibility to data to the full table level, the default temporal table visibility.
DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME ('ALL')
-- Set the visibility to data valid as of the given time.
-- showing only rows overlapping the given date.
DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME(
'ASOF',
(to_timestamp ('29-SEP-10 05.44.01 PM'))
);
-- Set the visibility to data currently valid within the valid time period at the session level.
DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME ('CURRENT')