Oracle修改实例名及数据库名

注:生产环境中进行如下操作之前,务必备份数据库且确保备份完整可用。

一、测试环境信息

操作系统版本:
SQL> !uname -a
Linux db10g 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
数据库版本:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
当前实例名:
SQL> select instance from v$thread;
INSTANCE
--------------------------------------------------------------------------------
orcl
当前数据库名:
SQL> select name from v$database;
NAME
---------
ORCL
SQL> show parameter db_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      orcl

二、修改数据库实例(orcl-->orcl1)
修改实例名为orcl1:
1、干净的关闭数据库

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
2、查看spfileorcl.ora中的内容创建pfile initorcl.ora
oracle@db10g:orcl$cd $ORACLE_HOME/dbs 
oracle@db10g:orcl$pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
oracle@db10g:orcl$mv spfileorcl.ora spfileorcl.ora.bak
oracle@db10g:orcl$strings spfileorcl.ora.bak
oracle@db10g:orcl$ls
alert_orcl.log  hc_orcl.dat  initdw.ora  init.ora  initorcl.ora  lkORCL  orapworcl  snapcf_orcl.f  spfileorcl.ora.bak
oracle@db10g:orcl$cat initorcl.ora 
orcl.__db_cache_size=150994944
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=109051904
orcl.__streams_pool_size=8388608
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=283115520
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'
3、确认数据库使用pfile文件启动
SQL> startup
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  2095704 bytes
Variable Size             125830568 bytes
Database Buffers          150994944 bytes
Redo Buffers                6291456 bytes
Database mounted.
Database opened.
SQL> show parameter pfile
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
SQL> show parameter spfile
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
4、干净的关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
5、修改参数文件名为init_orcl1.ora
oracle@db10g:orcl$mv initorcl.ora initorcl1.ora 
6、修改oracle用户环境变量ORACLE_SID=orcl1
oracle@db10g:orcl1$pwd
/home/oracle
oracle@db10g:orcl$echo $ORACLE_SID
orcl
oracle@db10g:orcl$source .bash_profile 
oracle@db10g:orcl1$echo $ORACLE_SID
orcl1
7、创建新实例使用的密码文件orapworcl1
oracle@db10g:orcl1$orapwd file=orapworcl1 password=oracle entries=10
oracle@db10g:orcl1$ls
hc_orcl.dat  initdw.ora  init.ora  initorcl1.ora  lkORCL  orapworcl  orapworcl1  snapcf_orcl.f  spfileorcl.ora.bak
8、启动数据库验证当前实例名已经修改为orcl1
SQL> startup
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  2095704 bytes
Variable Size              88081832 bytes
Database Buffers          188743680 bytes
Redo Buffers                6291456 bytes
Database mounted.
Database opened.
SQL>  select instance from v$thread;
INSTANCE
--------------------------------------------------------------------------------
orcl1

SQL> select name from v$database;
NAME
---------
ORCL

SQL> show parameter instance_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
instance_name                        string      orcl1
SQL> show parameter db_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      orcl

三、修改数据库名为orcl1
1、切换归档日志,备份控制文件

SQL>  alter system switch logfile;
System altered.

SQL> alter database backup controlfile to trace resetlogs; 
Database altered.
备份控制文件生成的trace文件内容如下:
oracle@db10g:orcl1$pwd
/u01/app/oracle/admin/orcl/udump
oracle@db10g:orcl1$cat  orcl1_ora_7189.trc
/u01/app/oracle/admin/orcl/udump/orcl1_ora_7189.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1
System name:    Linux
Node name:      db10g
Release:        2.6.18-194.el5
Version:        #1 SMP Tue Mar 16 21:52:39 EDT 2010
Machine:        x86_64
Instance name: orcl1
Redo thread mounted by this instance: 1
Oracle process number: 15
Unix process pid: 7189, image: oracle@db10g (TNS V1-V3)

*** ACTION NAME:() 2016-05-24 11:20:52.560
*** MODULE NAME:(sqlplus@db10g (TNS V1-V3)) 2016-05-24 11:20:52.560
*** SERVICE NAME:(SYS$USERS) 2016-05-24 11:20:52.560
*** SESSION ID:(159.3) 2016-05-24 11:20:52.560
DBRM(kskinitrm) cpu_count (fudge enabled): old(0) -> new(1)
kwqmnich: current time::  3: 20: 52
kwqmnich: instance no 0 check_only flag 1 
kwqmnich: initialized job cache structure 
*** 2016-05-24 11:26:40.398
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="orcl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=2
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/product/11.2.0/db_1/dbs/arch'
-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/orcl/system01.dbf',
  '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
  '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
  '/u01/app/oracle/oradata/orcl/users01.dbf',
  '/u01/app/oracle/oradata/orcl/ds3.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_716804664.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_881599865.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'
     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
--

2、参考备份控制文件生成的trace,编辑新文件cff.sql
内容如下(注意是set --- new_db_name):
oracle@db10g:orcl1$pwd
/home/oracle
oracle@db10g:orcl1$vi cff.sql
STARTUP NOMOUNT
CREATE CONTROLFILE set DATABASE "ORCL1" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/orcl/system01.dbf',
  '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
  '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
  '/u01/app/oracle/oradata/orcl/users01.dbf',
  '/u01/app/oracle/oradata/orcl/ds3.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_716804664.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_1_881599865.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'
     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
~
~
"cff.sql" [New] 37L, 1633C written   
3、干净的关闭数据库         
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.          
4、rename控制文件                                                                                                  
oracle@db10g:orcl1$cd /u01/app/oracle/oradata/orcl
oracle@db10g:orcl1$ls
control01.ctl  control02.ctl  control03.ctl  ds3.dbf  redo01.log  redo02.log  redo03.log  sysaux01.dbf  system01.dbf  temp01.dbf  undotbs01.dbf  users01.dbf
oracle@db10g:orcl1$mv control01.ctl control01.ctl.bak
oracle@db10g:orcl1$mv control02.ctl control02.ctl.bak
oracle@db10g:orcl1$mv control03.ctl control03.ctl.bak
5、修改参数文件中的db_name为新数据库名orcl1
oracle@db10g:orcl1$pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
oracle@db10g:orcl1$cat initorcl1.ora 
orcl.__db_cache_size=150994944
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=109051904
orcl.__streams_pool_size=8388608
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl1'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=283115520
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'
6、使用cff.sql创建新的控制文件
SQL> @cff.sql
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  2095704 bytes
Variable Size              88081832 bytes
Database Buffers          188743680 bytes
Redo Buffers                6291456 bytes
Control file created.

ORA-00279: change 1068936 generated at 05/24/2016 11:34:50 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_41_881599865.dbf
ORA-00280: change 1068936 for thread 1 is in sequence #41

ORA-00308: cannot open archived log '--'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log 'ALTER'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '--'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '--'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '--'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log 'ALTER'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log 'SIZE'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '--'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log
'/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_41_881599865.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL>  recover database using backup controlfile until cancel;
ORA-00279: change 1068936 generated at 05/24/2016 11:34:50 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_41_881599865.dbf
ORA-00280: change 1068936 for thread 1 is in sequence #41

Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.

7、resetlogs启动数据库
SQL> alter database open resetlogs; 
Database altered.
8、创建临时表空间(添加临时表空间数据文件)
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
DS3
6 rows selected.

SQL>  select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
no rows selected
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' SIZE 5m  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
Tablespace altered.
SQL> select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
TABLESPACE_NAME       FILE_NAME                              FILE_SIZE AUT
------------------------------------------------------------------------------
TEMP            /u01/app/oracle/oradata/orcl/temp01.dbf         5 YES
9、确认db_name已经修改
SQL> show parameter instance_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
instance_name                        string      orcl1
SQL> show parameter db_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------

db_name                              string      orcl1

SQL> show parameter service_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      orcl1

SQL> show parameter global_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
global_names                         boolean     FALSE
10、如果使用global_name,修改如下
alter database rename global_name to .

SQL> alter database rename global_name to orcl1;
Database altered.
SQL> show parameter global
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
global_context_pool_size             string
global_names                         boolean     FALSE

11、检查alert日志,干净的停库,备份数据库。


参考文档:How to Rename Database/Change DB_NAME or ORACLE_SID/Instance Name (文档 ID 15390.1)

你可能感兴趣的:(Oracle)