ITPub博客

首页 > 数据库 > Oracle > [20240912]21c设置会话参数read-only.txt

[20240912]21c设置会话参数read-only.txt

原创 Oracle 作者:lfree 时间:2024-09-12 21:08:18 0 删除 编辑

[20240912]21c设置会话参数read-only.txt

--//21c支持设置会话参数read-only,简单测试如下:

1.环境:
SCOTT@book01p> @ver2
==============================
PORT_STRING                   : x86_64/Linux 2.4.xx
VERSION                       : 21.0.0.0.0
BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID                        : 0
PL/SQL procedure successfully completed.

2.测试:
SCOTT@book01p> create table deptx as select * from dept;
Table created.

SCOTT@book01p> create sequence seq1 cache 5;
Sequence created.

SCOTT@book01p> show parameter read_only
PARAMETER_NAME         TYPE     VALUE
---------------------- -------- -------
hybrid_read_only       boolean  FALSE
read_only              boolean  FALSE
read_only_open_delayed boolean  FALSE

SCOTT@book01p> alter session set read_only=true;
Session altered.

SCOTT@book01p> create index  pk_deptx on deptx(deptno);
create index  pk_deptx on deptx(deptno)
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SCOTT@book01p> create sequence seq2;
create sequence seq2
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SCOTT@book01p> delete from deptx;
delete from deptx
            *
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SCOTT@book01p> truncate table deptx;
truncate table deptx
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SCOTT@book01p> select seq1.nextval,dept.* from dept;
   NEXTVAL     DEPTNO DNAME                          LOC
---------- ---------- ------------------------------ -------------
         2         10 ACCOUNTING                     NEW YORK
         3         20 RESEARCH                       DALLAS
         4         30 SALES                          CHICAGO
         5         40 OPERATIONS                     BOSTON

SCOTT@book01p> select seq1.nextval,dept.* from dept;
   NEXTVAL     DEPTNO DNAME                          LOC
---------- ---------- ------------------------------ -------------
         6         10 ACCOUNTING                     NEW YORK
         7         20 RESEARCH                       DALLAS
         8         30 SALES                          CHICAGO
         9         40 OPERATIONS                     BOSTON
--//使用中涉及到的sequence没有问题.

SCOTT@book01p> select * from dept for update;
select * from dept for update
              *
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

--//可以设置登录触发器,设置一些用户只读查询:
create or replace trigger logon_trg
after logon on scott.schema
declare
begin
  execute immediate 'alter session set read_only=true';
end;
/


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3027614/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7970381