Oracle可以使用alter tablespace/table xxx read only设置表空间/单个表的只读属性,并使用alter tablespace/table xxx read write解除只读属性。
环境:Oracle 12c
测试过程:
1. 设置表空间的只读属性
sql> create table t1(id int) tablespace tbs1;
Table created.
sql> insert into t1 values(111);
1 row created.
sql> alter tablespace tbs1 read only;
Tablespace altered.
sql> select * from t1;
ID
----------
111
sql> insert into t1 values(111);
insert into t1 values(111)
*
ERROR at line 1:
ORA-00372: file 13 cannot be modified at this time
ORA-01110: data file 13: '/home/oracle/app/oracle/oradata/orcl/tbs01.dbf'
2. 解除表空间只读属性
sql> alter tablespace tbs1 read write;
Tablespace altered.
sql> insert into t1 values(112);
1 row created.
3. 设置单个表的只读属性
sql> alter table t1 read only;
Table altered.
sql> insert into t1 values(113);
insert into t1 values(113)
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "SYS"."T1"
4. 解除单个表的只读属性
sql> alter table t1 read write;
Table altered.
sql> insert into t1 values(114); 1 row created.
环境:Oracle 12c
测试过程:
1. 设置表空间的只读属性
sql> create table t1(id int) tablespace tbs1;
Table created.
sql> insert into t1 values(111);
1 row created.
sql> alter tablespace tbs1 read only;
Tablespace altered.
sql> select * from t1;
ID
----------
111
sql> insert into t1 values(111);
insert into t1 values(111)
*
ERROR at line 1:
ORA-00372: file 13 cannot be modified at this time
ORA-01110: data file 13: '/home/oracle/app/oracle/oradata/orcl/tbs01.dbf'
2. 解除表空间只读属性
sql> alter tablespace tbs1 read write;
Tablespace altered.
sql> insert into t1 values(112);
1 row created.
3. 设置单个表的只读属性
sql> alter table t1 read only;
Table altered.
sql> insert into t1 values(113);
insert into t1 values(113)
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "SYS"."T1"
4. 解除单个表的只读属性
sql> alter table t1 read write;
Table altered.
sql> insert into t1 values(114); 1 row created.