Oracle 11g支援修改資料庫使用者名稱

bfc99發表於2014-03-27

以下轉自:http://ylw6006.blog.51cto.com/470441/799261 作者:ylw6006

Oracle 11g修改資料庫使用者名稱

2012-03-07 13:29:52
版權宣告:原創作品,謝絕轉載!否則將追究法律責任。

 最近翻看某blog,發現原來oracle 11g提供了使用者重新命名的新特性,在10g環境下,如果想對使用者重新命名,一般來說是先建立一個新的使用者並授權,然後將原使用者下的所有物件匯入,然後刪除舊的使用者!下面來在11g rac環境下介紹下這個新特性!

參考:http://www.orafan.net/blog/315.html,感謝作者分享!

一:建立一個測試使用者xxx,並寫入測試資料,由spfile檔案生成pfile檔案,關閉rac資料庫


  1. [oracle@node1 ~]$ sqlplus sys/Ab123456@rac5 as sysdba  

  2. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 19:42:12 2012  

  3. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  4. Connected to:  

  5. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  

  6. With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,  

  7. Data Mining andReal Application Testing options  

  8. SQL> createuser xxx identified by 123456 default tablespace users;  

  9. User created.  

  10. SQL> grant resource,connectto xxx;  

  11. Grant succeeded.  

  12. SQL> createtable xxx.test asselect * from dba_objects;  

  13. Table created.  

  14. SQL> alteruser xxx rename to yyy;  

  15. alteruser xxx rename to yyy  

  16.               *  

  17. ERROR at line 1:  

  18. ORA-00922: missing or invalid option

  19. SQL> alteruser xxx rename to yyy identified by 123456;  

  20. alteruser xxx rename to yyy identified by 123456  

  21.               *  

  22. ERROR at line 1:  

  23. ORA-00922: missing or invalid option

  24. SQL> create pfile from spfile;  

  25. File created.  

  26. [oracle@node1 ~]$ srvctl stop database -d rac -o immediate  

  27. [oracle@node1 ~]$ srvctl status database -d rac  

  28. Instance node1 isnot running on node node1  

  29. Instance node2 isnot running on node node2

二:修改pfile檔案,新增隱含引數 *._enable_rename_user='TRUE',將資料庫以restrict方式啟動


  1. [oracle@node1 ~]$ cd /u01/app/oracle/product/11.2.0/db1/dbs/  

  2. [oracle@node1 dbs]$ ls  

  3. hc_node1.dat  initnode1.ora  init.ora  orapwnode1  

  4. [oracle@node1 dbs]$ tail -1 initnode1.ora  

  5. *._enable_rename_user='TRUE'

  6. [oracle@node1 dbs]$ sqlplus /nolog  

  7. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 19:51:41 2012  

  8. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  9. SQL> conn /as sysdba  

  10. Connected to an idle instance.  

  11. SQL> startup restrict pfile=$ORACLE_HOME/dbs/initnode1.ora  

  12. ORACLE instance started.  

  13. Total System Global Area 1235959808 bytes  

  14. Fixed Size                  2227904 bytes  

  15. Variable Size             805306688 bytes  

  16. Database Buffers          419430400 bytes  

  17. Redo Buffers                8994816 bytes  

  18. Database mounted.  

  19. Database opened.  

  20. SQL> select open_mode,namefrom v$database;  

  21. OPEN_MODE            NAME

  22. -------------------- ---------------

  23. READ WRITE           RAC  

  24. SQL> show parameter spfile;  

  25. NAME                                 TYPE        VALUE  

  26. ------------------------------------ ----------- ------------------------------

  27. spfile                               string

三:修改xxx使用者名稱為yyy


  1. SQL> alter user xxx rename to yyy;  

  2. alter user xxx rename to yyy  

  3.                           *  

  4. ERROR at line 1:  

  5. ORA-02000: missing IDENTIFIED keyword  

  6. SQL> alter user xxx rename to yyy identified by 123456;  

  7. User altered.  

  8. SQL> select count(*) from yyy.test;  

  9.  COUNT(*)  

  10. ----------  

  11.     74556

四:使用spfile啟動rac


  1. SQL> shutdown immediate;  

  2. Database closed.  

  3. Database dismounted.  

  4. ORACLE instance shut down.  

  5. [oracle@node1 dbs]$ srvctl start database -d rac  

  6. [oracle@node1 dbs]$ srvctl status database -d rac  

  7. Instance node1 is running on node node1  

  8. Instance node2 is running on node node2

五:連線測試,由此可見,對使用者的rename操作,可以繼承原有的許可權


  1. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 20:00:52 2012  

  2. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  3. Connected to:  

  4. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  

  5. With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,  

  6. Data Mining andReal Application Testing options  

  7. SQL> select * from tab;  

  8. TNAME                          TABTYPE  CLUSTERID  

  9. ------------------------------ ------- ----------

  10. TEST                           TABLE

  11. [oracle@node1 ~]$ sqlplus xxx/123456@rac5  

  12. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 20:01:22 2012  

  13. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  14. ERROR:  

  15. ORA-01017: invalid username/password; logon denied

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22207394/viewspace-1130420/,如需轉載,請註明出處,否則將追究法律責任。

相關文章