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

來源:互聯網
上載者:User

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

一:建立一個測試使用者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.  
  5. Connected to:  
  6. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  
  7. With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,  
  8. Data Mining and Real Application Testing options  
  9.  
  10. SQL> create user xxx identified by 123456 default tablespace users;  
  11. User created.  
  12.  
  13. SQL> grant resource,connect to xxx;  
  14. Grant succeeded.  
  15.  
  16. SQL> create table xxx.test as select * from dba_objects;  
  17. Table created.  
  18.  
  19. SQL> alter user xxx rename to yyy;  
  20. alter user xxx rename to yyy  
  21.                *  
  22. ERROR at line 1:  
  23. ORA-00922: missing or invalid option 
  24.  
  25. SQL> alter user xxx rename to yyy identified by 123456;  
  26. alter user xxx rename to yyy identified by 123456  
  27.                *  
  28. ERROR at line 1:  
  29. ORA-00922: missing or invalid option 
  30.  
  31. SQL> create pfile from spfile;  
  32. File created.  
  33.  
  34. [oracle@node1 ~]$ srvctl stop database -d rac -o immediate  
  35. [oracle@node1 ~]$ srvctl status database -d rac  
  36. Instance node1 is not running on node node1  
  37. Instance node2 is not 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.  
  5. [oracle@node1 dbs]$ tail -1 initnode1.ora   
  6. *._enable_rename_user='TRUE' 
  7.  
  8. [oracle@node1 dbs]$ sqlplus /nolog  
  9. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 19:51:41 2012  
  10. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  11.  
  12. SQL> conn /as sysdba  
  13. Connected to an idle instance.  
  14. SQL> startup restrict pfile=$ORACLE_HOME/dbs/initnode1.ora  
  15. ORACLE instance started.  
  16.  
  17. Total System Global Area 1235959808 bytes  
  18. Fixed Size                  2227904 bytes  
  19. Variable Size             805306688 bytes  
  20. Database Buffers          419430400 bytes  
  21. Redo Buffers                8994816 bytes  
  22. Database mounted.  
  23. Database opened.  
  24. SQL> select open_mode,name from v$database;  
  25.  
  26. OPEN_MODE            NAME 
  27. -------------------- ---------------  
  28. READ WRITE           RAC  
  29.  
  30. SQL> show parameter spfile;  
  31.  
  32. NAME                                 TYPE        VALUE  
  33. ------------------------------------ ----------- ------------------------------  
  34. 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.  
  7. SQL> alter user xxx rename to yyy identified by 123456;  
  8. User altered.  
  9.  
  10. SQL> select count(*) from yyy.test;  
  11.  
  12.   COUNT(*)  
  13. ----------  
  14.      74556 

四:使用spfile啟動rac

 
  1. SQL> shutdown immediate;  
  2. Database closed.  
  3. Database dismounted.  
  4. ORACLE instance shut down.  
  5.  
  6. [oracle@node1 dbs]$ srvctl start database -d rac   
  7. [oracle@node1 dbs]$ srvctl status database -d rac   
  8. Instance node1 is running on node node1  
  9. 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.  
  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 and Real Application Testing options  
  8.  
  9. SQL> select * from tab;  
  10.  
  11. TNAME                          TABTYPE  CLUSTERID  
  12. ------------------------------ ------- ----------  
  13. TEST                           TABLE 
  14.  
  15. [oracle@node1 ~]$ sqlplus xxx/123456@rac5  
  16. SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 20:01:22 2012  
  17. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  18.  
  19. ERROR:  
  20. ORA-01017: invalid username/password; logon denied 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.