Oracle 更改 db_name 的方法


运行下面的命令,即可更改db_name 从haha 更改为test

>nid target=sys/gaokai@haha dbname=test

下面演示:

  1. C:\Documents and Settings\andyleng>set Oracle_SID=haha  
  2.   
  3. C:\Documents and Settings\andyleng>sqlplus /nolog  
  4.   
  5. SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:07:00 2011  
  6.   
  7. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  8.   
  9. SQL> conn /as sysdba  
  10. Connected to an idle instance.  
  11. SQL> startup  
  12. ORACLE instance started.  
  13.   
  14. Total System Global Area  778387456 bytes  
  15. Fixed Size                  1374808 bytes  
  16. Variable Size             234882472 bytes  
  17. Database Buffers          536870912 bytes  
  18. Redo Buffers                5259264 bytes  
  19. Database mounted.  
  20. Database opened.  
  21. SQL> show parameter name  
  22.   
  23. NAME                                 TYPE        VALUE  
  24. ------------------------------------ ----------- ------------------------------   
  25. db_file_name_convert                 string  
  26. db_name                              string      haha  
  27. db_unique_name                       string      haha  
  28. global_names                         boolean     FALSE  
  29. instance_name                        string      haha  
  30. lock_name_space                      string  
  31. log_file_name_convert                string  
  32. service_names                        string      haha  
  33. SQL> create pfile from spfile;  
  34.   
  35. File created.  
  36.   
  37. SQL> shutdown immediate;  
  38. Database closed.  
  39. Database dismounted.  
  40. ORACLE instance shut down.  
  41. SQL> exit  
  42. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr  
  43. oduction  
  44. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  45.   
  46. C:\Documents and Settings\andyleng>   
 
  1. C:\Documents and Settings\andyleng>set ORACLE_SID=haha  
  2.   
  3. C:\Documents and Settings\andyleng>sqlplus /nolog  
  4.   
  5. SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:08:40 2011  
  6.   
  7. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  8.   
  9. SQL> conn /as sysdba  
  10. Connected to an idle instance.  
  11. SQL> startup mount;  
  12. ORACLE instance started.  
  13.   
  14. Total System Global Area  778387456 bytes  
  15. Fixed Size                  1374808 bytes  
  16. Variable Size             234882472 bytes  
  17. Database Buffers          536870912 bytes  
  18. Redo Buffers                5259264 bytes  
  19. Database mounted.  
  20. SQL> exit  
  21. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr  
  22. oduction  
  23. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  24.   
  25. C:\Documents and Settings\andyleng>nid target=sys/oracle@haha dbname=test  
  26.   
  27. DBNEWID: Release 11.2.0.1.0 - Production on Wed Nov 2 18:11:10 2011  
  28.   
  29. Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.  
  30.   
  31. Connected to database HAHA (DBID=3533083211)  
  32.   
  33. Connected to server version 11.2.0  
  34.   
  35. Control Files in database:  
  36.     D:\ORACLE\ORADATA\TEST\CONTROL01.CTL  
  37.     D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL  
  38.   
  39. Change database ID and database name HAHA to TEST? (Y/[N]) => y  
  40.   
  41. Proceeding with operation  
  42. Changing database ID from 3533083211 to 2064306111  
  43. Changing database name from HAHA to TEST  
  44.     Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - modified  
  45.     Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - modified  
  46.     Datafile D:\ORACLE\ORADATA\TEST\SYSTEM01.DB - dbid changed, wrote new name  
  47.     Datafile D:\ORACLE\ORADATA\TEST\SYSAUX01.DB - dbid changed, wrote new name  
  48.     Datafile D:\ORACLE\ORADATA\TEST\UNDOTBS01.DB - dbid changed, wrote new name  
  49.     Datafile D:\ORACLE\ORADATA\TEST\USERS01.DB - dbid changed, wrote new name  
  50.     Datafile D:\ORACLE\ORADATA\TEST\ATG_TBS01.DB - dbid changed, wrote new name  
  51.     Datafile D:\ORACLE\ORADATA\TEST\ATG_LOBTBS01.DB - dbid changed, wrote new na  
  52. me  
  53.     Datafile D:\ORACLE\ORADATA\TEST\TEMP01.DB - dbid changed, wrote new name  
  54.     Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - dbid changed, wrote new  
  55. name  
  56.     Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - dbid changed  
  57. , wrote new name  
  58.     Instance shut down  
  59.   
  60. Database name changed to TEST.  
  61. Modify parameter file and generate a new password file before restarting.  
  62. Database ID for database TEST changed to 2064306111.  
  63. All previous backups and archived redo logs for this database are unusable.  
  64. Database is not aware of previous backups and archived logs in Recovery Area.  
  65. Database has been shutdown, open database with RESETLOGS option.  
  66. Succesfully changed database name and ID.  
  67. DBNEWID - Completed succesfully.  
  68.   
  69.   
  70. C:\Documents and Settings\andyleng>ORADIM -del -sid haha  
  71. Instance deleted.  
  72.   
  73. C:\Documents and Settings\andyleng>oradim -new -sid test  
  74. Instance created.  
  75.   
  76. C:\Documents and Settings\andyleng>set ORACLE_SID=test  
  77.   
  78. C:\Documents and Settings\andyleng>sqlplus /nolog  
  79.   
  80. SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:12:50 2011  
  81.   
  82. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  83.   
  84. SQL> conn /as sysdba  
  85. Connected to an idle instance.  
  86. SQL> startup  
  87. ORACLE instance started.  
  88.   
  89. Total System Global Area  778387456 bytes  
  90. Fixed Size                  1374808 bytes  
  91. Variable Size             427820456 bytes  
  92. Database Buffers          343932928 bytes  
  93. Redo Buffers                5259264 bytes  
  94. Database mounted.  
  95. ORA-01589: must use RESETLOGS or NORESETLOGS option for database open  
  96.   
  97.   
  98. SQL> create spfile from pfile;  
  99.   
  100. File created.  
  101.   
  102. SQL> alter database open resetlogs;  
  103.   
  104. Database altered.  
  105.   
  106. SQL> show parameter name  
  107.   
  108. NAME                                 TYPE        VALUE  
  109. ------------------------------------ ----------- ------------------------------   
  110. db_file_name_convert                 string  
  111. db_name                              string      test  
  112. db_unique_name                       string      test  
  113. global_names                         boolean     FALSE  
  114. instance_name                        string      test  
  115. lock_name_space                      string  
  116. log_file_name_convert                string  
  117. service_names                        string      test  
  118. SQL>  

相关内容