基于某些特定的需要我们需要改数据库名,下面是实验:

version:

Linux chartis 2.6.32-200.13.1.el5uek #1 SMP Wed Jul 27 21:02:33 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 7 16:23:04 2013

改名前:

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      gun2
db_unique_name                       string      gun2
global_names                         boolean     FALSE
instance_name                        string      gun2
lock_name_space                      string
log_file_name_convert                string
service_names                        string      gun2

这个实验需要把这里的gun2改为gun,其中包括instance_name和db_name.

1,备份controlfile,提取创建controlfile的语句

SQL> alter database backup controlfile to trace;

Database altered.

SQL>
select c.value || '/' || d.instance_name || '_ora_' ||
to_char(a.spid,'fm99999') || '.trc'
from v$process a, v$session b, v$parameter c, v$instance d
where a.addr = b.paddr
and b.audsid = userenv('sessionid')
  6  and c.name = 'user_dump_dest';

C.VALUE||'/'||D.INSTANCE_NAME||'_ORA_'||TO_CHAR(A.SPID,'FM99999')||'.TRC'
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/gun2/gun2/trace/gun2_ora_6805.trc

创建控制文件的语句(当然要做一些修改,粗体部分要特别注意):

CREATE CONTROLFILE set DATABASE "GUN" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/gun/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/u01/app/oracle/oradata/gun/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u01/app/oracle/oradata/gun/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/gun/system01.dbf',
  '/u01/app/oracle/oradata/gun/sysaux01.dbf',
  '/u01/app/oracle/oradata/gun/undotbs01.dbf',
  '/u01/app/oracle/oradata/gun/users01.dbf',
  '/u01/app/oracle/oradata/gun/ogg01.dbf',
  '/u01/app/oracle/oradata/gun/mysys01.dbf',
  '/u01/app/oracle/oradata/gun/mdu01.dbf'
CHARACTER SET ZHS16GBK
;

2,创建pfile文件并修改pfile

SQL> create pfile from spfile;

File created.

[oracle@chartis dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@chartis dbs]$ mv initgun2.ora initgun.ora

修改initgun.ora

将所有的gun2改为gun,并创建audit_file_dest,control_files参数指定的目录(不创建目录startup nomount时会报错)。

3,修改.bash_profile中的ORACLE_SID

ORACLE_SID=gun    -----到这里,控制实例名的参数已经改完

4,拷贝原数据库/u01/app/oracle/oradata/gun2/中的datafile,redo log到/u01/app/oracle/oradata/gun/目录

注意不包括controlfile并且这里是关闭数据库的后复制。

拷贝之前要关闭原数据库

SQL>shutdown immediate

5,创建控制文件

[oracle@chartis ~]$ source .bash_profile
[oracle@chartis ~]$ env|grep ORA
ORACLE_SID=gun
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

SQL> startup nomount
ORACLE instance started.

Total System Global Area  730714112 bytes
Fixed Size                  2216944 bytes
Variable Size             566234128 bytes
Database Buffers          159383552 bytes
Redo Buffers                2879488 bytes

 

SQL>CREATE CONTROLFILE set DATABASE "GUN" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/gun/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/u01/app/oracle/oradata/gun/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u01/app/oracle/oradata/gun/redo03.log'  SIZE 50M BLOCKSIZE 512
DATAFILE
  '/u01/app/oracle/oradata/gun/system01.dbf',
  '/u01/app/oracle/oradata/gun/sysaux01.dbf',
  '/u01/app/oracle/oradata/gun/undotbs01.dbf',
  '/u01/app/oracle/oradata/gun/users01.dbf',
  '/u01/app/oracle/oradata/gun/ogg01.dbf',
  '/u01/app/oracle/oradata/gun/mysys01.dbf',
  '/u01/app/oracle/oradata/gun/mdu01.dbf'
CHARACTER SET ZHS16GBK
;

Control file created.

SQL> alter database open resetlogs;

Database altered.

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      gun
db_unique_name                       string      gun
global_names                         boolean     FALSE
instance_name                        string      gun
lock_name_space                      string
log_file_name_convert                string
service_names                        string      gun

全部已经改好了。

可进一步参考:http://blog.itpub.net/post/29894/481048