oracle 更改 db_name 的方法

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

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

下面演示:

C:\Documents and Settings\andyleng>set ORACLE_SID=haha

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:07:00 2011

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             234882472 bytes
Database Buffers          536870912 bytes
Redo Buffers                5259264 bytes
Database mounted.
Database opened.
SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      haha
db_unique_name                       string      haha
global_names                         boolean     FALSE
instance_name                        string      haha
lock_name_space                      string
log_file_name_convert                string
service_names                        string      haha
SQL> create pfile from spfile;

File created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

C:\Documents and Settings\andyleng>

 

C:\Documents and Settings\andyleng>set ORACLE_SID=haha

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:08:40 2011

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             234882472 bytes
Database Buffers          536870912 bytes
Redo Buffers                5259264 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

C:\Documents and Settings\andyleng>nid target=sys/oracle@haha dbname=test

DBNEWID: Release 11.2.0.1.0 - Production on Wed Nov 2 18:11:10 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to database HAHA (DBID=3533083211)

Connected to server version 11.2.0

Control Files in database:
    D:\ORACLE\ORADATA\TEST\CONTROL01.CTL
    D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL

Change database ID and database name HAHA to TEST? (Y/[N]) => y

Proceeding with operation
Changing database ID from 3533083211 to 2064306111
Changing database name from HAHA to TEST
    Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - modified
    Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - modified
    Datafile D:\ORACLE\ORADATA\TEST\SYSTEM01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\SYSAUX01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\UNDOTBS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\USERS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\ATG_TBS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\ATG_LOBTBS01.DB - dbid changed, wrote new na
me
    Datafile D:\ORACLE\ORADATA\TEST\TEMP01.DB - dbid changed, wrote new name
    Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - dbid changed, wrote new
name
    Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - dbid changed
, wrote new name
    Instance shut down

Database name changed to TEST.
Modify parameter file and generate a new password file before restarting.
Database ID for database TEST changed to 2064306111.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


C:\Documents and Settings\andyleng>ORADIM -del -sid haha
Instance deleted.

C:\Documents and Settings\andyleng>oradim -new -sid test
Instance created.

C:\Documents and Settings\andyleng>set ORACLE_SID=test

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:12:50 2011

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             427820456 bytes
Database Buffers          343932928 bytes
Redo Buffers                5259264 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SQL> create spfile from pfile;

File created.

SQL> alter database open resetlogs;

Database altered.

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      test
db_unique_name                       string      test
global_names                         boolean     FALSE
instance_name                        string      test
lock_name_space                      string
log_file_name_convert                string
service_names                        string      test
SQL>


 

你可能感兴趣的:(oracle 更改 db_name 的方法)