Immutable Tables in Oracle Database 19c and 21c
An immutable table is a tamper-proof, insert-only table with an associated table-level and row-level retention period.
oracle 21cconfigurationintermediate
by OracleDba
38 views
An immutable table is a tamper-proof, insert-only table with an associated table-level and row-level retention period.
12345678910
conn / as sysdba
# 19c
alter system set compatible='19.11.0' scope=spfile;
# 21c
alter system set compatible='21.0.0' scope=spfile;
shutdown immediate;
startup;123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
NO DROP [ UNTIL number DAYS IDLE ]
NO DELETE { [ LOCKED ] | (UNTIL number DAYS AFTER INSERT [ LOCKED ]) }
--drop table it_t1 purge;
create immutable table it_t1 (
id number,
fruit varchar2(20),
quantity number,
created_date date,
constraint it_t1_pk primary key (id)
)
no drop until 0 days idle
no delete until 16 days after insert;
set linesize 120 pagesize 50
column column_name format a30
column data_type format a27
column hidden_column format a13
select internal_column_id,
column_name,
data_type,
data_length,
hidden_column
FROM user_tab_cols
WHERE table_name = 'IT_T1'
ORDER BY internal_column_id;
INTERNAL_COLUMN_ID COLUMN_NAME DATA_TYPE DATA_LENGTH HIDDEN_COLUMN
------------------ ------------------------------ --------------------------- ----------- -------------
1 ID NUMBER 22 NO
2 FRUIT VARCHAR2 25 NO
3 QUANTITY NUMBER 22 NO
4 CREATED_DATE DATE 7 NO
5 ORABCTAB_INST_ID$ NUMBER 22 YES
6 ORABCTAB_CHAIN_ID$ NUMBER 22 YES
7 ORABCTAB_SEQ_NUM$ NUMBER 22 YES
8 ORABCTAB_CREATION_TIME$ TIMESTAMP(6) WITH TIME ZONE 13 YES
9 ORABCTAB_USER_NUMBER$ NUMBER 22 YES
10 ORABCTAB_HASH$ RAW 2000 YES
11 ORABCTAB_SIGNATURE$ RAW 2000 YES
12 ORABCTAB_SIGNATURE_ALG$ NUMBER 22 YES
13 ORABCTAB_SIGNATURE_CERT$ RAW 16 YES
14 ORABCTAB_SPARE$ RAW 2000 YES
14 rows selected.
SQL>
column row_retention format a13
column row_retention_locked format a20
column table_inactivity_retention format a26
SELECT row_retention,
row_retention_locked,
table_inactivity_retention
FROM user_immutable_tables
WHERE table_name = 'IT_T1';
ROW_RETENTION ROW_RETENTION_LOCKED TABLE_INACTIVITY_RETENTION
------------- -------------------- --------------------------
16 NO 0
SQL>12345678910111213141516171819202122232425262728293031323334
alter table it_t1 no drop until 100 days idle;
Error report -
ORA-05732: retention value cannot be lowered
SQL>
alter table it_t1 no drop;
Error starting at line : 1 in command -
alter table it_t1 no drop
Error report -
ORA-00600: internal error code, arguments: [atbbctable_1], [0], [], [], [], [], [], [], [], [], [], []
-- Increase to 32 days.
alter table it_t1 no delete until 32 days after insert;
Table IT_T1 altered.
SQL>
-- Decrease to 16 days (fail).
alter table it_t1 no delete until 16 days after insert;
Error report -
ORA-05732: retention value cannot be lowered
SQL>
alter table it_t1 no delete;
Error report -
ORA-00600: internal error code, arguments: [atbbctable_1], [0], [], [], [], [], [], [], [], [], [], []123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
-- INSERT
insert into it_t1 (id, fruit, quantity, created_date ) values (1, 'apple', 20, sysdate);
1 row inserted.
SQL> commit;
Commit complete.
SQL>
-- UPDATE
update it_t1 set quantity = 10 where id = 1;
Error report -
SQL Error: ORA-05715: operation not allowed on the blockchain or immutable table
SQL>
-- DELETE
delete from it_t1 where id = 1;
Error report -
SQL Error: ORA-05715: operation not allowed on the blockchain or immutable table
SQL>
truncate table it_t1;
Error report -
ORA-05715: operation not allowed on the blockchain or immutable table
SQL>
-- Extend column.
alter table it_t1 modify (fruit varchar2(25));
Table IT_T1 altered.
SQL>
-- Add column
alter table it_t1 add (additional_info varchar2(50));
Error report -
ORA-05715: operation not allowed on the blockchain or immutable table
SQL>
-- Drop column.
alter table it_t1 drop column quantity;
Error report -
ORA-05715: operation not allowed on the blockchain or immutable table
SQL>12345678910111213141516171819202122232425262728293031323334353637
set serveroutput on
declare
l_rows number;
begin
dbms_immutable_table.delete_expired_rows(
schema_name => 'testuser1',
table_name => 'it_t1',
before_timestamp => null,
number_of_rows_deleted => l_rows);
dbms_output.put_line('Rows Deleted=' || l_rows);
end;
/
Rows Deleted=0
PL/SQL procedure successfully completed.
SQL>
set serveroutput on
declare
l_rows number;
begin
dbms_immutable_table.delete_expired_rows(
schema_name => 'testuser1',
table_name => 'it_t1',
before_timestamp => systimestamp - 60,
number_of_rows_deleted => l_rows);
dbms_output.put_line('Rows Deleted=' || l_rows);
end;
/
Rows Deleted=0
PL/SQL procedure successfully completed.
SQL>Please to add comments
No comments yet. Be the first to comment!