oracle19_Flashback Data Archive (FDA)

show CON_NAME
CREATE TABLESPACE fda_ts DATAFILE SIZE
1M AUTOEXTEND ON NEXT 1M;
ALTER USER lihao QUOTA UNLIMITED ON fda_ts;
Insert picture description here
创建闪回存档
show CON_NAME
CREATE FLASHBACK ARCHIVE DEFAULT fda_1year TABLESPACE fda_ts
QUOTA 10G RETENTION 1 YEAR;
GRANT FLASHBACK ARCHIVE ON fda_1year TO lihao;
GRANT FLASHBACK ARCHIVE ADMINISTER TO lihao;
GRANT EXECUTE ON DBMS_FLASHBACK_ARCHIVE TO lihao;
GRANT CREATE ANY CONTEXT TO lihao;
Insert picture description here
SELECT owner_name,
flashback_archive_name,
flashback_archive#,
retention_in_days,
TO_CHAR(create_time, ‘DD-MON-YYYY HH24:MI:SS’) AS create_time,
TO_CHAR(last_purge_time, ‘DD-MON-YYYY HH24:MI:SS’) AS last_purge_time,
status
FROM dba_flashback_archive
ORDER BY owner_name, flashback_archive_name;
Description
DBA_FLASHBACK_ARCHIVE Describes all available flashback archives in the database.
OWNER_NAME: the name of the creator of the
flashback archive FLASHBACK_ARCHIVE_NAME: the name of the flashback archive
FLASHBACK_ARCHIVE#: the number of the flashback archive
RETENTION_IN_DAYS: the maximum duration of data retention in the flashback archive (days)
CREATE_TIME: the creation time of the flashback archive
LAST_PURGE_TIME: The last time the system cleared the data in the
flashback archive STATUS: Indicates whether the flashback archive is the default flashback archive (DEFAULT) (NULL)
Insert picture description here
SELECT flashback_archive_name,
flashback_archive#,
tablespace_name,
quota_in_mb
FROM dba_flashback_archive_ts
ORDER BY flashback_archive_name;
Description of
DBA_FLASHBACK_ARCHIVE_name All table spaces in the flashback archive file available in the database.
FLASHBACK_ARCHIVE_NAME: The name of the flashback archive
FLASHBACK_ARCHIVE#: the number of the flashback archive
TABLESPACE_NAME: the name of the
table space in the flashback archive QUOTA_IN_MB: the maximum space available for the flashback archive in the table space (in MB); NULL means there is no quota limit to
Insert picture description here
create a table and put it Associated with FDA
CREATE TABLE tab1 (
id NUMBER,
description VARCHAR2(50),
CONSTRAINT tab_1_pk PRIMARY KEY (id)
) FLASHBACK ARCHIVE fda_1year;
Insert picture description here
SELECT owner_name,
table_name,
flashback_archive_name,
archive_table_name,
status
FROM table FROM dba_flashback_archive_tables_ORDER_ARCHIVE_DBA_ ORDER_ARCHIVE_DBA_ ORDER_ARCHIVE owner show
;
description
Information about all tables in the database that have Flashback Archive enabled.
TABLE_NAME: The name of the table that is enabled for Flashback Archive
OWNER_NAME: The name of the owner of the table that is enabled for Flashback Archive
FLASHBACK_ARCHIVE_NAME: The name of the Flashback Archive
ARCHIVE_TABLE_NAME: The name of the archive table that contains the historical data of the user table
STATUS: Whether the flashback archive status is enabled. The
Insert picture description here
DBMS_FLASHBACK_ARCHIVE package contains the process of performing various flashback tasks.
How much user context is saved according to the need. ALL-the entire SYS_CONTEXT
EXEC DBMS_FLASHBACK_ARCHIVE.set_context_level('ALL');
Insert picture description here
CREATE OR REPLACE CONTEXT test_context USING test_ctx_api ;
CREATE OR REPLACE PACKAGE test_ctx_api AS
PROCEDURE set_value (p_name IN VARCHAR2,
p_value IN VARCHAR2);
END test_ctx_api;
/
Insert picture description here
CREATE OR REPLACE PACKAGE BODY test_ctx_api AS

PROCEDURE set_value (p_name IN VARCHAR2,
p_value IN VARCHAR2) AS
BEGIN
DBMS_SESSION.set_context(‘test_context’, LOWER(p_name), p_value);
END;

END test_ctx_api;
/
Insert picture description here
EXEC DBMS_SESSION.set_identifier(‘Peter Pan’);
EXEC lihao.test_ctx_api.set_value(‘my_attribute’,‘First Action’);
INSERT INTO tab1 VALUES (1, ‘ONE’);
COMMIT;
Insert picture description here
EXEC DBMS_SESSION.set_identifier(‘Peter Parker’);
EXEC test_ctx_api.set_value(‘my_attribute’,‘Second Action’);

UPDATE tab1 SET description = ‘TWO’
WHERE id = 1;
COMMIT;
Insert picture description here
EXEC DBMS_SESSION.set_identifier(‘Peter Rabbit’);
EXEC test_ctx_api.set_value(‘my_attribute’,‘Third Action’);
UPDATE tab1 SET description = ‘THREE’
WHERE id = 1;
COMMIT;
Insert picture description here
SELECT versions_startscn,–versions_starttime,
versions_endscn,–versions_endtime,
versions_xid,
versions_operation,
description,
DBMS_FLASHBACK_ARCHIVE.get_sys_context(versions_xid, ‘USERENV’,‘SESSION_USER’) AS session_user,
DBMS_FLASHBACK_ARCHIVE.get_sys_context(versions_xid, ‘USERENV’,‘CLIENT_IDENTIFIER’) AS client_identifier,
DBMS_FLASHBACK_ARCHIVE.get_sys_context(versions_xid, ‘test_context’,‘my_attribute’) AS my_attribute
FROM tab1
VERSIONS BETWEEN TIMESTAMP SYSTIMESTAMP-(3/17/21) AND SYSTIMESTAMP
WHERE id = 1
ORDER BY versions_startscn;
Insert picture description here
ALTER TABLE lihao.tab1 NO FLASHBACK ARCHIVE;
DROP TABLE lihao.tab1 PURGE;
Insert picture description here
CREATE TABLE app_tab1 AS
SELECT level AS id,
'Description for ’ || level AS description
FROM dual
CONNECT BY level <= 5;
Insert picture description here
Insert picture description here
ALTER TABLE app_tab1 ADD CONSTRAINT app_tab1_pk PRIMARY KEY (id);
Insert picture description here
CREATE TABLE app_tab2 AS
SELECT level AS id,
'Description for ’ || level AS description
FROM dual
CONNECT BY level <= 5;
ALTER TABLE app_tab2 ADD CONSTRAINT app_tab2_pk PRIMARY KEY (id);
Insert picture description here
Insert picture description here
create a new application
DBMS_FLASHBACK_ARCHIVE package contains the process of performing various tasks Flashback Data Archive (FDA) enabled table from its underlying FDA to disassociate or re-associate it
register_application: This process uses the application name and (optional) flashback data archive, and registers the application for database hardening.
flashback_archive_name: The name of the flashback data archive, which stores the historical data of the security table for a given application. If no flashback data archive is specified, the default flashback data archive
BEGIN
DBMS_FLASHBACK_ARCHIVE.register_application(
application_name =>'MY_APP',
flashback_archive_name =>'FDA_1YEAR');
END;
/
Insert picture description here
SELECT a.appname,
b.faname
FROM sys_fba_app a
JOIN sys_fba_fa b ON a.fa# = b.fa#;
Insert picture description here
ADD_TABLE_TO_APPLICATION Add a table to the application add_table_to_application
: add a table as a security table to the application
application_name: the name of the application
table_name:表的名称
BEGIN
DBMS_FLASHBACK_ARCHIVE.add_table_to_application (
application_name => ‘MY_APP’,
table_name => ‘APP_TAB1’,
schema_name => ‘LIHAO’);

DBMS_FLASHBACK_ARCHIVE.add_table_to_application (
application_name => ‘MY_APP’,
table_name => ‘APP_TAB2’,
schema_name => ‘LIHAO’);
END;
/
Insert picture description here
SELECT a.appname,
c.owner AS table_owner,
c.object_name As table_name
FROM sys_fba_app a
JOIN sys_fba_app_tables b ON a.app# = b.app#
JOIN dba_objects c ON b.obj# = c.object_id
ORDER BY 1,2,3;
Insert picture description here
未启用该应用程序,因此这些表当前未与FDA关联
SELECT owner_name,
table_name,
flashback_archive_name,
archive_table_name,
status
FROM dba_flashback_archive_tables
WHERE table_name LIKE ‘APP_TAB%’
ORDER BY owner_name, table_name;
Insert picture description here
BEGIN
DBMS_FLASHBACK_ARCHIVE.enable_application(
application_name => ‘MY_APP’);
END;
/
Insert picture description here
SELECT owner_name,
table_name,
flashback_archive_name,
archive_table_name,
status
FROM dba_flashback_archive_tables
WHERE table_name LIKE ‘APP_TAB%’
ORDER BY owner_name, table_name;
Insert picture description here
DISABLE_APPLICATION禁用该应用程序中所有表的FDA
BEGIN
DBMS_FLASHBACK_ARCHIVE.disable_application(
application_name => ‘MY_APP’);
END;
/
Insert picture description here
SELECT owner_name,
table_name,
flashback_archive_name,
archive_table_name,
status
FROM dba_flashback_archive_tables
WHERE table_name LIKE ‘APP_TAB%’
ORDER BY owner_name, table_name;
Insert picture description here
DROP_APPLICATION删除应用程序
BEGIN
DBMS_FLASHBACK_ARCHIVE.remove_table_from_application(
application_name => ‘MY_APP’,
table_name => ‘APP_TAB1’,
schema_name => ‘LIHAO’);

DBMS_FLASHBACK_ARCHIVE.remove_table_from_application(
application_name => ‘MY_APP’,
table_name => ‘APP_TAB2’,
schema_name => ‘LIHAO’);

DBMS_FLASHBACK_ARCHIVE.drop_application(
application_name => ‘MY_APP’);
END;
/
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_39568073/article/details/114969265
FDA