restricted_session_quiesce_suspend
最近生產系統計劃使用HDS的VSP(Virtual Storage Platform)的shadowimage特性實現資料同步,其中涉及suspend操作,在這裡對相關特性進行測試比較.
資料庫或例項有一些特殊的狀態,可用於特殊的維護場景:
*可以限制非特權使用者登入(restricted session)
*暫停非SYS/SYSTEM使用者的操作(quiesce restricted/unquiesce)
*掛起系統(suspend/resume)
1,限制會話(restricted session)
僅允許有RESTRICTED SESSION許可權的使用者本地登入,不影響已登陸使用者操作.
1.1啟動例項
設定:
STARTUP [MOUNT|NOMOUNT|OPEN] RESTRICT
查詢狀態:
select logins from v$instance;
解除:
ALTER SYSTEM DISABLE RESTRICTED SESSION;
1.2已啟動例項
使用restricted session限制當前例項登入,不影響當前會話
設定:
alter system ENABLE RESTRICTED SESSION;
查詢狀態:
select logins from v$instance;
==>RESTRICTED
解除:
alter system DISABLE RESTRICTED SESSION;
測試:
1.2.1建立測試使用者
create user user_no_res identified by a;
grant create session to user_no_res;
create user user_with_res identified by a;
grant create session,restricted session to user_with_res;
create user user_sysdba identified by a;
grant create session,sysdba to user_sysdba;
1.2.2連線資料庫
--session 1:
sqlplus user_with_res/a
--session 2:
sqlplus user_no_res/a
--session 3:
sqlplus user_sysdba/a as sysdba
1.2.3 限制登入ENABLE RESTRICTED SESSION
--session 4:
sqlplus user_sysdba/a as sysdba
SQL> alter system ENABLE RESTRICTED SESSION;
System altered.
SQL> select logins from v$instance;
LOGINS
------------------------------
RESTRICTED
1.2.4連線資料庫
--session 1:
SQL> select sysdate from dual;
SYSDATE
------------------
23-DEC-13
SQL> exit
[oracle@rhel5 mah]$ sqlplus user_with_res/a
SQL>
--session 2:
SQL> select sysdate from dual;
SYSDATE
------------------
23-DEC-13
SQL> exit
[oracle@rhel5 mah]$ sqlplus user_no_res/a
ERROR:
ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege
Enter user-name:
--session 3:
SQL> select sysdate from dual;
SYSDATE
------------------
23-DEC-13
SQL> exit
[oracle@rhel5 mah]$ sqlplus user_sysdba/a as sysdba
SQL>
--session 5(remote):
D:\>sqlplus as sysdba
ERROR:
ORA-12526: TNS: 監聽程式: 所有適用例程都處於受限模式
請輸入使用者名稱:
1.2.5取消限制登入
--session 3:-->注意不是發起ENABLE RESTRICTED SESSION的session 4.
alter system DISABLE RESTRICTED SESSION;
SQL> select logins from v$instance;
LOGINS
------------------------------
ALLOWED
1.2.6連線資料庫
所有登入恢復正常(本地無RESTRICTED SESSION許可權的登入,遠端的登入).
測試結論:
*系統限制會話後,只允許有RESTRICTED SESSION許可權的使用者登入
*系統限制會話後,已存在所有的會話操作不受影響
*系統限制會話後,不允許遠端登陸,即使有RESTRICTED SESSION許可權
2,靜默狀態(quiesce)
在靜默狀態下,只有具有DBA許可權(這裡特指SYS和SYSTEM使用者,與DBA角色無關)的使用者能夠在資料庫中執行查詢/更新操作,執行PL/SQL程式,任何非DBA使用者都不能在資料庫中執行任何操作.
執行alter system quiesce restricted後,資料庫將等待所有正在執行的非DBA使用者會話主動終止/事務結束,同時不再允許開始任何新的非DBA使用者會話。當所有的非DBA使用者的活動會話都被成功暫停後,alter system quiesce restricted語句執行完畢,這是資料庫被認為處於靜默狀態。在靜默狀態中,即使某個非DBA使用者試圖執行一條SQL語句強行啟用某個會話,該SQL語句也會掛起。當資料庫從靜默狀態中恢復時,停止的會話將繼續執行,前面被掛起的SQL語句也會繼續執行。
設定:
alter system quiesce restricted;
查詢狀態:
select ACTIVE_STATE from v$instance;
==>NORMAL: Normal unquiesced state.
==>QUIESCING: Being quiesced, but some non-DBA sessions are still active.
==>QUIESCED: Quiesced; no non-DBA sessions are active or allowed.
解除:
alter system unquiesce;
2.1建立連線
--session 1:
[oracle@rhel5 mah]$ sqlplus mh/mh
SQL> show user
USER is "MH"
SQL> update emp set comm='';
14 rows updated.
--session 2:
[oracle@rhel5 mah]$ sqlplus mh/mh as sysdba
SQL> show user
USER is "SYS"
SQL> update emp set comm='' where empno=7900;
1 row updated.
--session 3:
[oracle@rhel5 mah]$ sqlplus / as sysdba
SQL> show user
USER is "SYS"
SQL> update emp set comm='' where empno=7902;
1 row updated.
2.2進入靜默
--session 4:
[oracle@rhel5 mah]$ sqlplus / as sysdba
SQL> show user
USER is "SYS"
SQL> alter system quiesce;
alter system quiesce
*
ERROR at line 1:
ORA-00905: missing keyword
SQL> alter system quiesce restricted;
-->掛起
--session 3:
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCING
2.3連線狀態
--session 1:
SQL> delete from test;
2 rows deleted.
SQL> rollback;
Rollback complete.
--session 3:
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCED
--session 1:
SQL> delete from test;
--掛起
--session 6:
[oracle@rhel5 mah]$ sqlplus mh/mh
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 23 15:43:11 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
--掛起
--session 2:
SQL> rollback;
Rollback complete.
SQL> update emp set comm='' where empno=7900;
1 row updated.SQL> rollback;
Rollback complete.
SQL> exit
[oracle@rhel5 mah]$ sqlplus mh/mh as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show user
USER is "SYS"
SQL> update emp set comm='' where empno=7902;
1 row updated.
--session 3:
SQL> rollback;
Rollback complete.
SQL> update emp set comm='' where empno=7902;
1 row updated.
SQL> exit
[oracle@rhel5 mah]$ sqlplus / as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show user
USER is "SYS"
SQL> update emp set comm='' where empno=7900;
1 row updated.
--session 5(遠端):
D:\>sqlplus as sysdba
連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>exit
D:\>sqlplus
SQL*Plus: Release 11.1.0.6.0 - Production on 星期四 12月 29 15:48:23 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
--掛起
2.4退出靜默
--session 3:-->不是發起quiesce的會話
SQL> alter system unquiesce;
System altered.
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
NORMAL
2.5連線狀態
被掛起的會話(非DBA使用者發起的連線,非DBA使用者新的事務)恢復.
2.6進入靜默,會話退出,系統狀態
--session 4:
SQL> alter system quiesce restricted;
-->掛起
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCED
SQL> exit
--session 3:
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCED
SQL> alter system unquiesce;
System altered.
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
NORMAL
SQL> select sid,serial# from v$session where sid=(select sid from v$mystat where rownum=1);
SID SERIAL#
---------- ----------
158 72
SQL> alter system quiesce restricted;
System altered.
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCED
--session 4:
[oracle@rhel5 mah]$ sqlplus / as sysdba
SQL> alter system kill session '158,72';
System altered.
SQL> select ACTIVE_STATE from v$instance;
ACTIVE_STATE
---------------------------
QUIESCED
測試結論:
*進入quiesce狀態過程中,非DBA使用者事務會阻塞系統進入靜默狀態
*進入quiesce狀態後,非DBA使用者的操作(查詢或新事務)會被掛起
*進入quiesce狀態後,SYSDBA許可權使用者可以發起新的事務
*進入quiesce狀態後,限制非DBA使用者登入
*執行alter system語句的會話被意外中止(exit或kill by other session),系統保持靜默狀態
3,掛起(suspend)
資料庫在掛起狀態,資料庫所有的物理檔案(控制檔案/資料檔案以及重做日誌檔案)的I/O操作都被暫停。
這樣能夠保證資料庫在沒有任何I/O操作的情況下進行物理備份。掛起的狀態與靜默狀態的區別是:它並不禁止非DBA使用者的資料庫操作,只是暫時停止所有使用者的I/O操作。
在RAC環境,一個例項的掛起會傳播到所有例項;掛起後新啟動的例項不受此影響.
主要用途:
當資料庫處於掛起狀態時,可以首先為資料庫建立磁碟映象,然後再從映象中分離出備份檔案,這樣就提供了一種進行資料庫備份和恢復的替代方法。在資料庫進入掛起狀態時,當前所有的I/O操作能夠繼續進行,但是所有新提交的I/O不會執行,而是被放入一個等待佇列中。一旦資料庫恢復到正常狀態,這些I/O操作將從佇列中取出並繼續執行。
設定:
alter system suspend;
查詢狀態:
select database_status from v$instance;
==>SUSPENDED
解除:
alter system resume;
測試:
3.1建立連線
--session 1:
sqlplus user_sysdba/a as sysdba
SQL> update emp set comm='';
14 rows updated.
3.2掛起系統
--session 2:
sqlplus user_sysdba/a as sysdba
SQL> alter system suspend;
System altered.
SQL> select database_status from v$instance;
DATABASE_STATUS
---------------------------------------------------
SUSPENDED
3.3對其他會話的影響
--session 1:
SQL> commit;
-->掛起
--session 3:
[oracle@rhel5 mah]$ sqlplus mh/mh as sysdba-->允許sysdba登入
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 23 14:16:31 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> exit
mah]$ sqlplus mh/mh-->不允許非sysdba登入
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 23 14:17:16 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
-->掛起
--session 4:
SQL> select sysdate from dual;
SYSDATE
------------------
23-DEC-13
SQL> create table t as select sysdate d from dual;
3.4停止掛起
--session 2:
SQL> alter system resume;
System altered.
SQL> select database_status from v$instance;
DATABASE_STATUS
-------------------
ACTIVE
3.5掛起的會話恢復
測試結論:
*系統掛起後,所有涉及物理IO(資料檔案,控制檔案,日誌)的操作會被掛起,比如commit操作
*系統掛起後,允許sysdba登入,不允許非sysdba登入
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-714173/,如需轉載,請註明出處,否則將追究法律責任。