ORACLE 受限RESTRICT模式,只读READ ONLY模式,静默QUIESCE模式,延迟SUSPEND模式解释

一、受限RESTRICT模式
关于ORACLE RESTRICT模式,以及START OPEN RECOVER 




说明如下:
Restricting Access to an Instance at Startup
You can start an instance, and optionally mount and open a database, in restricted 
mode so that the instance is available onlyto administrative personnel (not general 
database users). Use this mode of instance startup when you must accomplish one of 
the following tasks:
■ Perform an export or import of data
■ Perform a data load (with SQL*Loader)
■ Temporarily prevent typical users from using data
■ Perform certain migration or upgrade operations
Typically, all users with the CREATE SESSIONsystem privilege can connect to an open 
database. Opening a database in restricted mode allows database access only to users 
with both the CREATE SESSIONand RESTRICTED SESSIONsystem privilege. Only 
database administrators should have the RESTRICTED SESSIONsystem privilege. 




关于如上文档,说明受限模式可以再你想做一些维护的时候,而不想其他非restrict权限用户登录的时候使用。
可以和STARTUP进行搭配启动实例
startup [nomount|mount|open} restrict;
而ORACLE RESTART也可以使用
srvctl start database -d db_unique_name-o restrict




同时在正常数据库使用期间也可以使用
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;
 
System altered
 
SQL> ALTER SYSTEM enable RESTRICTED SESSION;
 
System altered




来启用和禁用。但是注意经过测试,这个操作知识影响随后的会话。已经连接的会话不受影响,通过查看V$INSTANCE的
LOGINS字段可以查看其状态




二、只读READ ONLY模式


如下描述:
Opening a database in read-only mode enables you to query an open database while 
eliminating any potential for online data content changes. While opening a database in 
read-only mode guarantees that data file and redo log files are not written to, it does 
not restrict database recovery or operations that change the state of the database 
without generating redo. For example, you can take data files offline or bring them 
online since these operations do not affect data content.
可以看到实际上READ ONLY打开数据库后并不是限制所有的操作,而是关于修改数据和写入日志
文件的操作时不允许,相反的是允许的。V$DATABASE的OPEN_MODE字段显示其状态。
做测试如下:
1、增加表空间
SQL> create tablespace jjj datafile size 10m ;
create tablespace jjj datafile size 10m
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-16000: database open for read-only access




2、增加日志文件
SQL> alter database add logfile group 11;


Database altered.




3、OFFLINE数据文件


SQL> alter database datafile 8 offline;


Database altered.


SQL> alter database  datafile 8 online;


Database altered.


而关于使用READ ONLY 模式。文档只给出了
在MOUNT阶段下。使用如下命令打开数据库


alter database open read only;
alter database open read write;
意思是如果想改变模式,需要SHUTDOWN IMMEDIATE然后
startup mount 下修改


三、静默QUIESCE模式
如下描述:
   Occasionally you might want to put a database in a state that allows only DBA 
transactions, queries, fetches, or PL/SQL statements. Such a state is referred to as a 
quiesced state, in the sense that no ongoing non-DBA transactions, queries, fetches, or 
PL/SQL statements are running in the system. 
  In this discussion of quiesce database, a DBA is defined as user SYS or SYSTEM. 
Other users, including those with the DBA role, are not allowed to issue the 
ALTER SYSTEM QUIESCE DATABASE statement or proceed after the database is quiesced. 
  If a user issues a SQL query in an attempt to force an inactive session to
become active, the query will appear to be hung. When the database is later unquiesced,
the session is resumed, and the blocked action is processed.
  Once all non-DBA sessions become inactive, the ALTER SYSTEM QUIESCE RESTRICTED
statement completes, and the database is ina quiesced state. In an Oracle Real 
Application Clusters environment, this statement affects all instances, not just the one 
that issues the statement.
  The ALTER SYSTEM QUIESCE RESTRICTED statement may wait a long time for active 
sessions to become inactive. You can determine the sessions that are blocking the 
quiesce operation by querying the V$BLOCKING_QUIESCE view.
  select bl.sid, user, osuser, type, program
   from v$blocking_quiesce bl, v$session se
   where bl.sid = se.sid;
  当你需要做一些维护的时候,可能需要只有SYS或者SYSTEM用户登录,你可以使用这种模式.其他即使
拥有DBA角色的用户也是受到限制的。它不仅会让新的非SYS和SYSTEM用户登录HANGH住,而且登录的会话
如果再想执行语句也会被HANG住。注意改变为静默模式需要等待当前所有的ACTIVE会话完成其操作,可能
需要较长的时间,次期间虽然静默模式并未完成,其效果已经产生新的登录和ACTIVE已有的会话是会HANG住的。
可以通过V$BLOCKING_QUIESCE来查看哪些会话堵塞了改变静默模式。同时RAC环境中他影响全部节点,而非本实例。
当然本操作也会由于事物而被堵塞,在一个事物未COMMIT或者ROLLBACK的时候其会话状态任然为NOACTIVE,
但是也会堵塞本操作。 V$INSTANCE ACTIVE_STATE可以查看其状态
  更改方法 
  ALTER SYSTEM QUIESCE RESTRICTED;
  ALTER SYSTEM UNQUIESCE;
  
可以简单的测试如下:
开启一个非SYSTEM,SYSDBA用户事物
SQL> delete test10;
 
93 rows deleted
而不提交,另外开启SYSDBA权限会话改变为静默模式
SQL> ALTER SYSTEM QUIESCE RESTRICTED;
....一直HANG主
等待事件为wait for possible quiesce finish


提交这个事物
commit;
改变模式成功,如果再想查询数据,则开始等待
select * from test
一直HANG
其等待事件为resmgr:become active 


四、延迟SUSPEND模式
描述如下:
  The ALTER SYSTEM SUSPEND statement halts all input and output (I/O) to data files (file 
header and file data) and control files. The suspended state lets you back up a 
database without I/O interference. When the database is suspended all preexisting 
I/O operations are allowed to complete and any new database accesses are placed in a 
queued state. 
   The suspend/resume feature is not a suitable substitute for normal shutdown 
operations, because copies of a suspended database can contain uncommitted updates.
SUSPEND模式会阻挡所有的I/O,所有的读写都会处于HANG的状态,而这种模式在移动文件的时候比较
有用,而他不能代替传统的SHUTDOWN操作或者备份操作,因为他包含UNCOMMIT的事物。RAC下影响全节点,
V$INSTANCE的DATABASE_STATUS可以查看其状态
其改变方式如下:


ALTER SYSTEM SUSPEND;
ALTER SYSTEM RESUME;


做一个测试
ALTER SYSTEM SUSPEND;

select * from test;
drop table test;
alter system switch logfile;
操作均被堵塞,其等待事件为:
 writes stopped by instance recovery or database suspension

在做一个测试在LINUX 使用这种方法移动数据文件。
先发起
SQL> ALTER SYSTEM SUSPEND;
然后建立一个目录
mkdir TESTXUEXI 
然后拷贝我的数据文件目录到这个目录
cp -R xuexi TESTXUEXI/
然后MV 以前的目录
mv xuexi xuexitest
然后建立一个连接
ln -s TESTXUEXI/xuexi/ xuexi
 xuexi -> TESTXUEXI/xuexi/
这样我们算完成了。可以恢复
ALTER SYSTEM RESUME;
这样我们继续查询我们的数据,但是实际底层的文件已经是用的复制的那一份。这种方法
可以再空间不够的时候使用,但是这和SHUTDOWN DATABASE再移动也没什么区别。

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

转载于:http://blog.itpub.net/7728585/viewspace-1270941/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RESTRICT 是一种数据库约束,用于确保在主表中删除或更新行时,如果关联表中存在相关行,则阻止删除或更新操作。当使用 RESTRICT 时,删除或更新操作将被拒绝,直到关联表中的相关行被删除或更新为止,以保持数据的完整性和一致性。 RESTRICT 可以应用于 FOREIGN KEY 约束和 CHECK 约束。在 FOREIGN KEY 约束中,RESTRICT 将阻止删除或更新主表中的行时,存在关联表中的相关行。在 CHECK 约束中,RESTRICT 将阻止更新主表中的行时,CHECK 约束条件不满足的情况。 下面是一个示例,展示 RESTRICT 约束的用法: ``` CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, order_date DATE, FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE RESTRICT ); ``` 在这个示例中,orders 表中的 customer_id 列是一个外键,引用了 customers 表中的 customer_id 列。ON DELETE RESTRICT 子句指定了在 customers 表中删除与 orders 表中的行相关联的 customer_id 时,如果存在关联表中的相关行,则阻止删除操作。 同样,在 UPDATE RESTRICT 子句中指定的情况下,如果 customers 表中的 customer_id 列被更新,orders 表中的相关行也会被阻止更新操作。 需要注意的是,RESTRICT 约束可能会导致操作无法完成,因此应该谨慎使用。如果需要删除或更新行,但又不能使用 RESTRICT 约束,可以考虑使用 CASCADE 约束或其他适当的约束。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值