修改ORACLES数据库名字 db name
时间:2010-12-05 来源:stonejia
  转自 http://space.itpub.net/?uid-24234775-action-viewspace-itemid-680943
  贾石林 博客 http://stonejia.itpub.net
  贾石林 空间 http://space.itpub.net/24234775
  
  数据库原名为ORCL,实例名为hyjt,我们在这里把数据库名ORCL改为跟实例名对应的hyjt
  
  查看原数据库名
  idle> select name from v$database;
  NAME
  ------------------------------
  ORCL
  
  修改数据库名需要把数据哭关闭并启动到mount状态
  idle> shutdown immediate
  Database closed.
  Database dismounted.
  ORACLE instance shut down.
  
  idle> startup mount
  ORACLE instance started.
  
  Total System Global Area 184549376 bytes
  Fixed Size 1218412 bytes
  Variable Size 62916756 bytes
  Database Buffers 117440512 bytes
  Redo Buffers 2973696 bytes
  Database mounted.
  
  显示nid命令帮助
  [oracle@rhel5 ~]$ nid -help
  
  DBNEWID: Release 10.2.0.1.0 - Production on Sun Dec 5 21:17:25 2010
  
  Copyright (c) 1982, 2005, Oracle. 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
  
  修改数据库名dbname
  [oracle@rhel5 ~]$ nid target=sys/oracle dbname=hyjt setname=y
  
  DBNEWID: Release 10.2.0.1.0 - Production on Sun Dec 5 21:18:23 2010
  Copyright (c) 1982, 2005, Oracle. All rights reserved.
  Connected to database ORCL (DBID=1264786455)
  Connected to server version 10.2.0
  Control Files in database:
  /u01/app/oracle/oradata/orcl/control01.ctl
  /u01/app/oracle/oradata/orcl/control02.ctl
  /u01/app/oracle/oradata/orcl/control03.ctl
  
  Change database name of database ORCL to HYJT? (Y/[N]) => y
  
  Proceeding with operation
  Changing database name from ORCL to HYJT
  Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
  Control File /u01/app/oracle/oradata/orcl/control02.ctl - modified
  Control File /u01/app/oracle/oradata/orcl/control03.ctl - modified
  Datafile /u01/app/oracle/oradata/orcl/system01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/undotbs01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/sysaux01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/users01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/stone01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/ts1.1 - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/big01.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/t4k.4 - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/tnolog.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/ts3.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/ts4.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/undo2.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/tm2.dbf - wrote new name
  Datafile /u01/app/oracle/oradata/orcl/temp01.dbf - wrote new name
  Control File /u01/app/oracle/oradata/orcl/control01.ctl - wrote new name
  Control File /u01/app/oracle/oradata/orcl/control02.ctl - wrote new name
  Control File /u01/app/oracle/oradata/orcl/control03.ctl - wrote new name
  Instance shut down
  
  Database name changed to HYJT.
  Modify parameter file and generate a new password file before restarting.
  Succesfully changed database name.
  DBNEWID - Completed succesfully.
  
  
  修改参数文件pfile里对应的db_name 参数值为新的dbname
  [oracle@rhel5 dbs]$ vi $ORACLE_HOME/dbs/inithyjt.ora
  修改db_name一行,值为‘hyjt’
  *.db_name='hyjt'
  
  重新登录sqlplus
  [oracle@rhel5 ~]$ sqlplus / as sysdba
  SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 5 21:26:37 2010
  Copyright (c) 1982, 2005, Oracle. All rights reserved.
  Connected to:
  Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
  With the Partitioning, OLAP and Data Mining options
  
  利用修改后的参数文件启动数据库
  idle> startup pfile=/u01/app/oracle/product/10.2/dbs/inithyjt.ora
  ORACLE instance started.
  
  Total System Global Area 184549376 bytes
  Fixed Size 1218412 bytes
  Variable Size 62916756 bytes
  Database Buffers 117440512 bytes
  Redo Buffers 2973696 bytes
  Database mounted.
  Database opened.
  
  查看数据库名字修改成功
  idle> select name from v$database;
  NAME
  ------------------------------
  HYJT
  
  创建spfile
  idle> create spfile from pfile;
  File created.
  
  查看spfile参数没有内容,这说明数据库目前是用pfile启动的。
  idle> show parameter spfile
  
  NAME TYPE VALUE
  ------------------------------------ ----------- ------------------------------
  spfile string
  
  重启数据库
  idle> startup force
  ORACLE instance started.
  
  Total System Global Area 184549376 bytes
  Fixed Size 1218412 bytes
  Variable Size 62916756 bytes
  Database Buffers 117440512 bytes
  Redo Buffers 2973696 bytes
  Database mounted.
  Database opened.
  
  检验spfile启动启动成功
  idle> show parameter spfile
  
  NAME TYPE VALUE
  ------------------------------------ ----------- ------------------------------
  spfile string /u01/app/oracle/product/10.2/d
  bs/spfilehyjt.ora
  数据库名字修改成功
  idle> select name from v$database;
  
  NAME
  ------------------------------
  HYJT










