はじめに
19cにブロック・チェーン・テーブルがバック・ポートされたことを知りました。
Connor McDonaldさんのブログによると、利用可能になる条件はRU19.10 + 個別パッチ32431413の適用だそうです。あと、初期化パラメータcompatibleを19.10.0にする必要があるようです
環境
$ opatch lspatches
32431413;19.10 RU FOR ORACLE IS MISSING QCPLK.O WHICH GETS LINKED INTO LIBGENERIC19.A
32218454;Database Release Update : 19.10.0.0.210119 (32218454)
29585399;OCW RELEASE UPDATE 19.3.0.0.0 (29585399)
OPatch succeeded.
$ sql / as sysdba
SQL> show parameter compatible
NAME TYPE VALUE
----------------- ------- -------
compatible string 19.10.0
ブロック・チェーン・テーブルで遊ぶ
マニュアルの演習: ブロックチェーン表および行の管理をみていろいろ遊んでみます
作ってみる
## ユーザを作成
SQL> alter session set container=pdb01;
SQL> create user test identified by <Password> default tablespace users quota unlimited on users;
SQL> grant connect, resource to test;
SQL> exit;
$ sql test/<Password>@$(hostname -s)/<PDBServiceName>
SQL> show user
USER is "TEST"
## ブロック・チェーン・テーブル!
SQL> CREATE BLOCKCHAIN TABLE ledger_emp (employee_id NUMBER, salary NUMBER)
NO DROP UNTIL 31 DAYS IDLE
NO DELETE LOCKED
HASHING USING "SHA2_512" VERSION "v1";
Table created.
create blockchain tableのオプション句についてはここなどを参照
dropしてみる
SQL> drop table ledger_emp;
Table dropped.
え??DROPできる。。よく考えたら、データ入れてなかった。もう一度
SQL> CREATE BLOCKCHAIN TABLE ledger_emp (employee_id NUMBER, salary NUMBER)
NO DROP UNTIL 31 DAYS IDLE
NO DELETE LOCKED
HASHING USING "SHA2_512" VERSION "v1";
Table created.
SQL> insert into ledger_emp select level, 100*level from dual connect by level <=100;
100 rows created.
SQL> commit;
Commit complete.
もう一度DROP!今度は、エラーになってくれた。
SQL> drop table ledger_emp;
drop table ledger_emp
*
ERROR at line 1:
ORA-05723: drop blockchain table LEDGER_EMP not allowed
削除!
SQL> delete from ledger_emp;
delete from ledger_emp
*
ERROR at line 1:
ORA-05715: operation not allowed on the blockchain table
更新!
SQL> update ledger_emp set employee_id=100 where employee_id=1;
update ledger_emp set employee_id=100 where employee_id=1
*
ERROR at line 1:
ORA-05715: operation not allowed on the blockchain table
Truncate!
SQL> truncate table ledger_emp;
truncate table ledger_emp
*
ERROR at line 1:
ORA-05715: operation not allowed on the blockchain table
保存期間を減らす! おお、これもだめ
SQL> ALTER TABLE ledger_emp NO DROP UNTIL 1 DAYS IDLE;
ALTER TABLE ledger_emp NO DROP UNTIL 1 DAYS IDLE
*
ERROR at line 1:
ORA-05732: retention value cannot be lowered
保存期間を増やすのはOKらしい
SQL> ALTER TABLE ledger_emp NO DROP UNTIL 40 DAYS IDLE;
Table altered.
SYSでDROP! おお、SYSでもエラーになる
SQL> conn / as sysdba
Connected.
SQL> alter session set container=pdb01;
SQL> drop table test.ledger_emp;
drop table test.ledger_emp
*
ERROR at line 1:
ORA-05723: drop blockchain table LEDGER_EMP not allowed
SYSでユーザごとDROP!
SQL> drop user test cascade;
drop user test cascade
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-05723: drop blockchain table LEDGER_EMP not allowed
消えない・・・PDBドロップ!これはさすがに消えてくれた
SQL> alter pluggable database pdb01 close;
Pluggable database altered.
SQL> drop pluggable database pdb01 including datafiles;
Pluggable database dropped.