[RESTRICT]受限模式是只数据库只对部分具有特定权限的用户开发,通常是数据库管理员在进行备份恢复时采取的模式。(DBA在进行备份恢复可以有两种方式:将数据库变为mount模式,但是mount模式下可执行的操作有限;使用RESTRICT模式open数据库,这样除了部分授权用户可以连接数据库,其他用户都不能连接数据库了。)
如果数据库已经是open状态了,则可以使用alter命令将其调整为restrict模式:
SQL>>
Database altered. SQL>>
System altered. /*=====演示RESTRICT模式下用户连接的状况=======*/ [oracle@localhostdbs]$ lsnrctl start
LSNRCTL for Linux:Version 11.2.0.1.0 - Production on 09-SEP-2014 04:47:47
Copyright (c) 1991, 2009,Oracle. All rights reserved.
TNS-01106: Listener usinglistener name LISTENER has already been started
# 启动litsner
[oracle@localhost ~]$sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 04:48:29 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved. SQL> conn / assysdba
Connected to an> SQL> startup
ORACLE instance started.
Total System GlobalArea 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL> create usermickey>
User created.
-- 创建一个普通用户 SQL> grantconnect, resource to mickey;
Grant succeeded.
--为该用户授权 [oracle@localhost ~]$sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 04:54:24 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved. SQL> connmickey/123
Connected.
--用户mickey已经可以连接到数据库了
SQL> select *from dual;
D
-
X
--mickey可以正常使用数据库
SQL> quit
Disconnected from OracleDatabase 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning,OLAP, Data Mining and Real Application Testing options
-- mickey用户退出数据库
SQL>>
-- 切换成SYSDBA用户,alter数据库的模式为RESTRICT。
System altered. [oracle@localhost ~]$sqlplus mickey/123
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 04:58:11 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved.
ERROR:
ORA-01035: ORACLE onlyavailable to users with RESTRICTED SESSION privilege
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 04:59:54 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning,OLAP, Data Mining and Real Application Testing options
# system这个用户可以正常连接,该用户有比较高的权限。
/*============演示在restrict模式下如何踢除某些用户==============*/
如上所示,system用户在restrict模式下还可以连接数据库,但是管理员不希望这个用户连接,那么可以将其踢除出去: SQL> descv$session;
Name Null? Type
------------------------------------------------- ----------------------------
SADDR RAW(4)
SID NUMBER
SERIAL# NUMBER
...
CREATOR_ADDR RAW(4)
CREATOR_SERIAL# NUMBER
ECID VARCHAR2(64) SQL> selectsaddr, sid, serial# from v$session; SQL> select sid,serial#, username, saddr from v$session;
[oracle@localhost ~]$sqlplus mickey/123
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 05:17:29 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved.
Connected to:
Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning,OLAP, Data Mining and Real Application Testing options SQL> createtable tastbl(id integer);
create table tastbl(idinteger)
*
ERROR at line 1:
ORA-00604: error occurredat recursive SQL level 1
ORA-16000: database openfor read-only access
--普通用户不能创建表,因为是只读模式 SQL> select *from dual;
D
-
X
--但是可以进行查询操作
关闭数据库和启动数据库的过程是对应的: 一. Close a Database
1.将SGA中的数据分别写入到datafiles和redo log files中;
2.关闭联机数据文件和redolog file(离线的数据文件和tablespace不受影响)
3.普通用户无法再访问数据库了,但好似controlfiles仍然是open状态,管理员还能继续使用。 二. Unmounta Database
1.断开数据库和实例的联系;
2.实例仍然驻留在内存中;
3.当数据库unmounted了之后,control files将关闭 三. ShutDown an Instance
1.关闭进程
2.从内存中释放SGA占据的空间
3.终止后台进程
IMMEDIATE是最为常用的关闭方式,因为NORMAL 和 TRANSACTION这两种方式都要等用户把活干完才能关,这样不但浪费时间,而且如果用户一直不结束任务,数据库就一直无法关闭。 ===============演示NORMAL关闭过程======================== [oracle@localhost ~]$sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Wed Aug 27 19:44:25 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved. SQL> conn / assysdba
Connected to an idleinstance. SQL> startup
ORACLE instance started.
Total System GlobalArea 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 318769536 bytes
Database Buffers 96468992 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened. ===========开启另一个终端登录数据库=============== [oracle@localhost ~]$sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Wed Aug 27 19:47:19 2014
Copyright (c) 1982, 2009,Oracle. All rights reserved. SQL> conn mickey
Enter password:
Connected. ===================切回SYS用户======================= SQL> select sid,serial#, username from v$session;