利用nid更改数据库的名称(OCM--->OCP)

转载请注明处出:http://blog.csdn.net/guoyjoe/article/details/19265523


1、运行nid,显示如下参数:
[oracle@mydb 2014_02_15]$ nid


DBNEWID: Release 11.2.0.3.0 - Production on Sun Feb 16 00:37:04 2014


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


Keyword     Description                    (Default)
----------------------------------------------------
TARGET      Username/Password              (NONE)
DBNAME      New database name              (NONE)
LOGFILE     Output Log                     (NONE)
REVERT      Revert failed change           NO
SETNAME     Set a new database name only   NO
APPEND      Append to output log           NO
HELP        Displays these messages        NO


2、查出原来的数据库名称为OCM
idle> SELECT NAME,DBID FROM V$DATABASE;


NAME            DBID
--------- ----------
OCM       2222218432


3、关闭数据库并启动到MOUNT
idle> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
idle> startup mount;
ORACLE instance started.


Total System Global Area 1006809088 bytes
Fixed Size                  2233520 bytes
Variable Size             478153552 bytes
Database Buffers          419430400 bytes
Redo Buffers              106991616 bytes
Database mounted.




4、在LINUX命令提示符中运行nid命令,修改数据库名称为OCP

idle> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@mydb ~]$ nid target=sys/oracle dbname=ocp


DBNEWID: Release 11.2.0.3.0 - Production on Sun Feb 16 00:40:33 2014


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


Connected to database OCM (DBID=2222218432)


Connected to server version 11.2.0


Control Files in database:
    /u01/app/oracle/oradata/ocm/control01.ctl
    /u01/app/oracle/oradata/ocm/control02.ctl


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


Proceeding with operation
Changing database ID from 2222218432 to 2735927810
Changing database name from OCM to OCP
    Control File /u01/app/oracle/oradata/ocm/control01.ctl - modified
    Control File /u01/app/oracle/oradata/ocm/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/ocm/system01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/sysaux01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/undotbs01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/users01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/example01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/tp1.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/tp2.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/tp3.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/ocm/temp01.db - dbid changed, wrote new name
    Control File /u01/app/oracle/oradata/ocm/control01.ctl - dbid changed, wrote new name
    Control File /u01/app/oracle/oradata/ocm/control02.ctl - dbid changed, wrote new name
    Instance shut down


Database name changed to OCP.
Modify parameter file and generate a new password file before restarting.
Database ID for database OCP changed to 2735927810.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


5、修改oracle用户环境变量(ORACLE_SID=ocp)
[oracle@mydb ~]$ pwd
/home/oracle
[oracle@mydb ~]$ vi .bash_profile


# .bash_profile


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi


# User specific environment and startup programs


PATH=$PATH:$HOME/bin


export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
export ORACLE_SID=ocp
export PATH=$ORACLE_HOME/bin:$PATH


".bash_profile" 17L, 316C written


[oracle@mydb ~]$ source .bash_profile
[oracle@mydb ~]$ echo $ORACLE_SID
ocp


6、重命名密码文件
[oracle@mydb dbs]$ mv orapwocm orapwocp




7、修改参数(重命令spfileocm.ora为spfileocp.ora以及修改参数内容)
[oracle@mydb flashback]$ cd $ORACLE_HOME/dbs
[oracle@mydb dbs]$ ll
total 23004
-rw-r----- 1 oracle oinstall 13272576 Nov 28 22:13 arch1_395_828309773.dbf
-rw-rw---- 1 oracle oinstall     1544 Nov 25 21:08 hc_abc.dat
-rw-rw---- 1 oracle oinstall     1544 Oct  8 21:41 hc_ocm.dat
-rw-r----- 1 oracle oinstall       24 Nov 17 15:03 lkMYDB_PRI
-rw-r----- 1 oracle oinstall       24 Oct  8 22:02 lkOCM
-rw-r----- 1 oracle oinstall       24 Jan 14 20:51 lkOCP
-rw-r----- 1 oracle oinstall     1536 Jan 16 20:39 orapwocm
-rw-r----- 1 oracle oinstall 10207232 Feb 16 00:21 snapcf_ocm.f
-rw-r----- 1 oracle oinstall     4608 Feb 16 00:02 spfileocm.ora
-rw-r----- 1 oracle oinstall     3584 Nov 30 20:54 spfile.ora
[oracle@mydb dbs]$ mv spfileocm.ora spfileocp.ora


[oracle@mydb ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.3.0 Production on Sun Feb 16 00:43:55 2014


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


Connected to an idle instance.


idle> create pfile='/tmp/pfile.ora' from spfile;


File created.


!vi /tmp/pfile.ora 
*.instance_name='ocp'
*.db_name='ocp'
*.db_unique_name='ocp'


idle> shutdown abort;
ORACLE instance shut down.
idle> startup nomount pfile='/tmp/pfile.ora';
ORACLE instance started.


Total System Global Area 1006809088 bytes
Fixed Size                  2233520 bytes
Variable Size             478153552 bytes
Database Buffers          419430400 bytes
Redo Buffers              106991616 bytes
idle> create spfile from pfile='/tmp/pfile.ora';


File created.


idle> shutdown abort;
ORACLE instance shut down.


8、用resetlogs打开数据库
idle> startup mount;
ORACLE instance started.


Total System Global Area 1006809088 bytes
Fixed Size                  2233520 bytes
Variable Size             478153552 bytes
Database Buffers          419430400 bytes
Redo Buffers              106991616 bytes
Database mounted.


idle> alter database open resetlogs;


Database altered.




9、检查数据库名
idle> SELECT NAME,DBID FROM V$DATABASE;


NAME            DBID
--------- ----------
OCP       2735927810


数据库名称由原来的OCM变为OCP.

你可能感兴趣的:(利用nid更改数据库的名称(OCM--->OCP))