I recently looked at a blog and found that Oracle 11g provided the new feature of user rename. In a 10g environment, if you want to rename a user, you should first create a new user and authorize it, import all objects under the original user and delete the old user! Next we will introduce this new feature in the 11g rac environment!
1. Create a test user xxx and write the test data. The spfile file generates the pfile file to close the rac database.
- [oracle@node1 ~]$ sqlplus sys/Ab123456@rac5 as sysdba
- SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 19:42:12 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
- Data Mining and Real Application Testing options
-
- SQL> create user xxx identified by 123456 default tablespace users;
- User created.
-
- SQL> grant resource,connect to xxx;
- Grant succeeded.
-
- SQL> create table xxx.test as select * from dba_objects;
- Table created.
-
- SQL> alter user xxx rename to yyy;
- alter user xxx rename to yyy
- *
- ERROR at line 1:
- ORA-00922: missing or invalid option
-
- SQL> alter user xxx rename to yyy identified by 123456;
- alter user xxx rename to yyy identified by 123456
- *
- ERROR at line 1:
- ORA-00922: missing or invalid option
-
- SQL> create pfile from spfile;
- File created.
-
- [oracle@node1 ~]$ srvctl stop database -d rac -o immediate
- [oracle@node1 ~]$ srvctl status database -d rac
- Instance node1 is not running on node node1
- Instance node2 is not running on node node2
2. Modify the pfile file and add the implicit parameter *. _ enable_rename_user = 'true' to start the database in restrict mode.
- [oracle@node1 ~]$ cd /u01/app/oracle/product/11.2.0/db1/dbs/
- [oracle@node1 dbs]$ ls
- hc_node1.dat initnode1.ora init.ora orapwnode1
-
- [oracle@node1 dbs]$ tail -1 initnode1.ora
- *._enable_rename_user='TRUE'
-
- [oracle@node1 dbs]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 19:51:41 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> startup restrict pfile=$ORACLE_HOME/dbs/initnode1.ora
- ORACLE instance started.
-
- Total System Global Area 1235959808 bytes
- Fixed Size 2227904 bytes
- Variable Size 805306688 bytes
- Database Buffers 419430400 bytes
- Redo Buffers 8994816 bytes
- Database mounted.
- Database opened.
- SQL> select open_mode,name from v$database;
-
- OPEN_MODE NAME
- -------------------- ---------------
- READ WRITE RAC
-
- SQL> show parameter spfile;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string
3. Change xxx user name to yyy
- SQL> alter user xxx rename to yyy;
- alter user xxx rename to yyy
- *
- ERROR at line 1:
- ORA-02000: missing IDENTIFIED keyword
-
- SQL> alter user xxx rename to yyy identified by 123456;
- User altered.
-
- SQL> select count(*) from yyy.test;
-
- COUNT(*)
- ----------
- 74556
4. Use spfile to start rac
- SQL> shutdown immediate;
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
-
- [oracle@node1 dbs]$ srvctl start database -d rac
- [oracle@node1 dbs]$ srvctl status database -d rac
- Instance node1 is running on node node1
- Instance node2 is running on node node2
V. connection test. Therefore, the user's rename operation can inherit the original permissions.
- SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 20:00:52 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
- Data Mining and Real Application Testing options
-
- SQL> select * from tab;
-
- TNAME TABTYPE CLUSTERID
- ------------------------------ ------- ----------
- TEST TABLE
-
- [oracle@node1 ~]$ sqlplus xxx/123456@rac5
- SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 6 20:01:22 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
- ERROR:
- ORA-01017: invalid username/password; logon denied