318 lines
7.4 KiB
Plaintext
318 lines
7.4 KiB
Plaintext
|
|
alias adm_NIHILUS='rlwrap sqlplus adm/"secret"@bakura:1521/NIHILUS as sysdba'
|
||
|
|
|
||
|
|
|
||
|
|
create pluggable database NIHILUS admin user NIHILUS$OWNER identified by secret;
|
||
|
|
alter pluggable database NIHILUS open;
|
||
|
|
alter pluggable database NIHILUS save state;
|
||
|
|
|
||
|
|
|
||
|
|
alter session set container=NIHILUS;
|
||
|
|
|
||
|
|
create bigfile tablespace LIVE_TS datafile size 32M autoextend on next 32M;
|
||
|
|
create bigfile tablespace ARCHIVE_TS datafile size 32M autoextend on next 32M;
|
||
|
|
|
||
|
|
create user adm identified by "secret";
|
||
|
|
grant sysdba to adm;
|
||
|
|
|
||
|
|
|
||
|
|
create user usr identified by "secret";
|
||
|
|
grant CONNECT,RESOURCE to usr;
|
||
|
|
grant alter session to usr;
|
||
|
|
|
||
|
|
alter user usr default tablespace LIVE_TS;
|
||
|
|
|
||
|
|
alter user usr quota unlimited on LIVE_TS;
|
||
|
|
alter user usr quota unlimited on ARCHIVE_TS;
|
||
|
|
|
||
|
|
alias adm_NIHILUS='rlwrap sqlplus adm/"secret"@bakura:1521/NIHILUS as sysdba'
|
||
|
|
alias usr_NIHILUS='rlwrap sqlplus usr/"secret"@bakura:1521/NIHILUS'
|
||
|
|
|
||
|
|
|
||
|
|
create flashback archive default ARCHIVE_7_DAY
|
||
|
|
tablespace ARCHIVE_TS
|
||
|
|
quota 1G
|
||
|
|
retention 7 DAY;
|
||
|
|
|
||
|
|
grant flashback archive on ARCHIVE_7_DAY to usr;
|
||
|
|
grant flashback archive administer to usr;
|
||
|
|
grant execute on dbms_flashback_archive to usr;
|
||
|
|
|
||
|
|
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
SET LINESIZE 150
|
||
|
|
|
||
|
|
COLUMN owner_name FORMAT A20
|
||
|
|
COLUMN flashback_archive_name FORMAT A22
|
||
|
|
COLUMN create_time FORMAT A20
|
||
|
|
COLUMN last_purge_time FORMAT A20
|
||
|
|
|
||
|
|
SELECT owner_name,
|
||
|
|
flashback_archive_name,
|
||
|
|
flashback_archive#,
|
||
|
|
retention_in_days,
|
||
|
|
TO_CHAR(create_time, 'YYYY-MM-DD HH24:MI:SS') AS create_time,
|
||
|
|
TO_CHAR(last_purge_time, 'YYYY-MM-DD HH24:MI:SS') AS last_purge_time,
|
||
|
|
status
|
||
|
|
FROM dba_flashback_archive
|
||
|
|
ORDER BY owner_name, flashback_archive_name;
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
SET LINESIZE 150
|
||
|
|
|
||
|
|
COLUMN flashback_archive_name FORMAT A22
|
||
|
|
COLUMN tablespace_name FORMAT A20
|
||
|
|
COLUMN quota_in_mb FORMAT A11
|
||
|
|
|
||
|
|
SELECT flashback_archive_name,
|
||
|
|
flashback_archive#,
|
||
|
|
tablespace_name,
|
||
|
|
quota_in_mb
|
||
|
|
FROM dba_flashback_archive_ts
|
||
|
|
ORDER BY flashback_archive_name;
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
SET LINESIZE 150
|
||
|
|
|
||
|
|
COLUMN owner_name FORMAT A20
|
||
|
|
COLUMN table_name FORMAT A20
|
||
|
|
COLUMN flashback_archive_name FORMAT A22
|
||
|
|
COLUMN archive_table_name FORMAT A20
|
||
|
|
|
||
|
|
SELECT owner_name,
|
||
|
|
table_name,
|
||
|
|
flashback_archive_name,
|
||
|
|
archive_table_name,
|
||
|
|
status
|
||
|
|
FROM dba_flashback_archive_tables
|
||
|
|
ORDER BY owner_name, table_name;
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
-- Example 1
|
||
|
|
-------------
|
||
|
|
|
||
|
|
create table TAB1 (
|
||
|
|
ID number,
|
||
|
|
DESCRIPTION varchar2(50),
|
||
|
|
constraint TAB_1_PK primary key (id)
|
||
|
|
);
|
||
|
|
|
||
|
|
alter table TAB1 flashback archive ARCHIVE_7_DAY;
|
||
|
|
|
||
|
|
insert into TAB1 values (1, 'one');
|
||
|
|
commit;
|
||
|
|
|
||
|
|
update TAB1 set description = 'two' where id = 1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
update TAB1 set description = 'three' where id = 1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
SET LINESIZE 200
|
||
|
|
|
||
|
|
COLUMN versions_startscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_starttime FORMAT A32
|
||
|
|
COLUMN versions_endscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_endtime FORMAT A32
|
||
|
|
COLUMN versions_xid FORMAT A16
|
||
|
|
COLUMN versions_operation FORMAT A1
|
||
|
|
COLUMN description FORMAT A11
|
||
|
|
|
||
|
|
SELECT versions_startscn,
|
||
|
|
versions_starttime,
|
||
|
|
versions_endscn,
|
||
|
|
versions_endtime,
|
||
|
|
versions_xid,
|
||
|
|
versions_operation,
|
||
|
|
description
|
||
|
|
FROM tab1
|
||
|
|
VERSIONS BETWEEN TIMESTAMP SYSTIMESTAMP-(1/24) AND SYSTIMESTAMP
|
||
|
|
WHERE id = 1
|
||
|
|
ORDER BY versions_startscn;
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
create table TAB1 (d date);
|
||
|
|
alter table TAB1 flashback archive ARCHIVE_7_DAY;
|
||
|
|
|
||
|
|
insert into TAB1 values (sysdate);
|
||
|
|
commit;
|
||
|
|
|
||
|
|
-- infinite_update1.sql
|
||
|
|
begin
|
||
|
|
loop
|
||
|
|
update TAB1 set d=sysdate;
|
||
|
|
commit;
|
||
|
|
dbms_session.sleep(1);
|
||
|
|
end loop;
|
||
|
|
end;
|
||
|
|
/
|
||
|
|
|
||
|
|
|
||
|
|
alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
|
||
|
|
|
||
|
|
SET LINESIZE 200
|
||
|
|
|
||
|
|
COLUMN versions_startscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_starttime FORMAT A32
|
||
|
|
COLUMN versions_endscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_endtime FORMAT A32
|
||
|
|
COLUMN versions_xid FORMAT A16
|
||
|
|
COLUMN versions_operation FORMAT A1
|
||
|
|
COLUMN description FORMAT A25
|
||
|
|
|
||
|
|
SELECT
|
||
|
|
versions_startscn,
|
||
|
|
versions_starttime,
|
||
|
|
versions_endscn,
|
||
|
|
versions_endtime,
|
||
|
|
versions_xid,
|
||
|
|
versions_operation,
|
||
|
|
d
|
||
|
|
FROM
|
||
|
|
TAB1
|
||
|
|
VERSIONS BETWEEN TIMESTAMP TIMESTAMP'2023-06-17 17:20:10' and TIMESTAMP'2023-06-17 17:20:40'
|
||
|
|
ORDER BY versions_startscn;
|
||
|
|
|
||
|
|
|
||
|
|
SELECT * from TAB1
|
||
|
|
AS OF TIMESTAMP TIMESTAMP'2023-06-17 17:05:10';
|
||
|
|
|
||
|
|
|
||
|
|
SELECT * from TAB1
|
||
|
|
AS OF TIMESTAMP TIMESTAMP'2023-06-17 17:30:49';
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
EXEC DBMS_SYSTEM.set_ev(si=>163, se=>24797, ev=>10046, le=>8, nm=>'');
|
||
|
|
|
||
|
|
|
||
|
|
-- Example 2
|
||
|
|
-------------
|
||
|
|
|
||
|
|
alter table TAB2 no flashback archive;
|
||
|
|
drop table TAB2 purge;
|
||
|
|
|
||
|
|
|
||
|
|
create table TAB2 (
|
||
|
|
n1 number,
|
||
|
|
c1 varchar2(10),
|
||
|
|
d1 DATE
|
||
|
|
);
|
||
|
|
|
||
|
|
alter table TAB2 flashback archive ARCHIVE_7_DAY;
|
||
|
|
|
||
|
|
insert into TAB2 values(1,'One',TIMESTAMP'2023-01-01 00:00:00');
|
||
|
|
commit;
|
||
|
|
insert into TAB2 values(2,'Two',TIMESTAMP'2023-01-01 00:00:00');
|
||
|
|
commit;
|
||
|
|
insert into TAB2 values(3,'Three',TIMESTAMP'2023-01-01 00:00:00');
|
||
|
|
commit;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
|
||
|
|
|
||
|
|
SET LINESIZE 200
|
||
|
|
COLUMN versions_startscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_starttime FORMAT A32
|
||
|
|
COLUMN versions_endscn FORMAT 99999999999999999
|
||
|
|
COLUMN versions_endtime FORMAT A32
|
||
|
|
COLUMN versions_xid FORMAT A16
|
||
|
|
COLUMN versions_operation FORMAT A1
|
||
|
|
COLUMN description FORMAT A25
|
||
|
|
|
||
|
|
SELECT
|
||
|
|
versions_startscn,
|
||
|
|
versions_starttime,
|
||
|
|
versions_endscn,
|
||
|
|
versions_endtime,
|
||
|
|
versions_xid,
|
||
|
|
versions_operation,
|
||
|
|
T.*
|
||
|
|
FROM
|
||
|
|
TAB2 VERSIONS BETWEEN TIMESTAMP (systimestamp-3/24) and systimestamp T
|
||
|
|
where
|
||
|
|
N1=1
|
||
|
|
ORDER BY versions_startscn;
|
||
|
|
|
||
|
|
update TAB2 set d1=TIMESTAMP'2023-12-31 23:59:59' where n1=1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
|
||
|
|
select * from TAB2 as of timestamp TIMESTAMP'2023-06-18 08:47:20' where N1=1;
|
||
|
|
|
||
|
|
select * from TAB2 as of timestamp systimestamp where N1=1;
|
||
|
|
select * from TAB2 as of scn 4335762 where N1=1;
|
||
|
|
select * from TAB2 as of scn 4335824 where N1=1;
|
||
|
|
|
||
|
|
->
|
||
|
|
alter table TAB2 add C2 varchar2(3);
|
||
|
|
|
||
|
|
update TAB2 set C2='abc' where n1=1;
|
||
|
|
update TAB2 set C2='***' where n1=1;
|
||
|
|
commit;
|
||
|
|
update TAB2 set C2='def' where n1=1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
|
||
|
|
alter table TAB2 drop column C2;
|
||
|
|
alter table TAB2 rename column C1 to C3;
|
||
|
|
|
||
|
|
update TAB2 set d1=systimestamp where n1=1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
update TAB2 set d1=TIMESTAMP'1973-10-05 10:00:00',C3='birthday' where n1=1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
update TAB2 set d1=systimestamp,C3='right now' where n1=1;
|
||
|
|
commit;
|
||
|
|
|
||
|
|
|
||
|
|
4336404 18-JUN-23 03.14.59
|
||
|
|
select * from TAB2 as of timestamp TIMESTAMP'2023-06-18 03:15:00' where N1=1;
|
||
|
|
|
||
|
|
select * from TAB2 as of scn 4336403 where N1=1;
|
||
|
|
select * from TAB2 as of scn 4336404 where N1=1;
|
||
|
|
select * from TAB2 as of scn 4337054 where N1=1;
|
||
|
|
|
||
|
|
select * from TAB2 as of scn 4282896 where N1=1;
|
||
|
|
select * from TAB2 as of scn 4283027 where N1=1;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
-- cleanup
|
||
|
|
alter table TAB2 no flashback archive;
|
||
|
|
drop table TAB2 purge;
|
||
|
|
|
||
|
|
alter table TAB1 no flashback archive;
|
||
|
|
drop table TAB1 purge;
|
||
|
|
|
||
|
|
drop user USR cascade;
|
||
|
|
|
||
|
|
drop flashback archive ARCHIVE_7_DAY;
|
||
|
|
|
||
|
|
drop tablespace LIVE_TS including contents and datafiles;
|
||
|
|
drop tablespace ARCHIVE_TS including contents and datafiles;
|
||
|
|
|
||
|
|
|
||
|
|
-- cleanup
|
||
|
|
alter pluggable database NIHILUS close instances=ALL;
|
||
|
|
drop pluggable database NIHILUS including datafiles;
|