修改数据库名(db_name)及实例名(Instance_name or Service_name)

Posted 锦心绣口,珠烁晶莹

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改数据库名(db_name)及实例名(Instance_name or Service_name)相关的知识,希望对你有一定的参考价值。

操作系统版本:rhel6.5 (Red Hat Enterprise Linux Server release 6.5 (Santiago))

数据库版本:12.1.0.2.0

实验目的:

假设原来的数据库名为scp,要改成etdb,原实例名(service_name,instance_name)scp,要改成etdb.

当前数据库的db_name和instance_name:

SQL> select dbid,name from v$database;

      DBID NAME
---------- ---------
3247610670 SCP

SQL> show parameter name;

NAME                               TYPE           VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name              string
db_file_name_convert                string
db_name                          string           scp
db_unique_name                      string           scp
global_names                       boolean          FALSE
instance_name                      string           scp
lock_name_space                   string
log_file_name_convert                string
pdb_file_name_convert                string
processor_group_name                 string
service_names                      string           scp

 

使用oracle自带的nid工具修改数据库的db_name:

SQL> shutdown immediate;       --先停止数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL
> startup mount; --nid需要在mount状态下才能做 ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size 2926472 bytes Variable Size 1325402232 bytes Database Buffers 805306368 bytes Redo Buffers 13848576 bytes Database mounted. SQL> ! nid target=sys/hzsunssytem dbname=etdb --nid是操作系统下执行的命令 DBNEWID: Release 12.1.0.2.0 - Production on Wed May 25 19:25:52 2016 Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. Connected to database SCP (DBID=3247610670) Connected to server version 12.1.0 Control Files in database: /home/OracleData/scp/control01.ctl /home/OracleArch/fast_recovery_area/scp/control02.ctl Change database ID and database name SCP to ETDB? (Y/[N]) => Y --需要确认 Proceeding with operation Changing database ID from 3247610670 to 637227457 Changing database name from SCP to ETDB Control File /home/OracleData/scp/control01.ctl - modified Control File /home/OracleArch/fast_recovery_area/scp/control02.ctl - modified Datafile /home/OracleData/scp/system01.db - dbid changed, wrote new name Datafile /home/OracleData/scp/sysaux01.db - dbid changed, wrote new name Datafile /home/OracleData/scp/undotbs01.db - dbid changed, wrote new name Datafile /home/OracleData/scp/users01.db - dbid changed, wrote new name Datafile /home/OracleData/scp/temp01.db - dbid changed, wrote new name Control File /home/OracleData/scp/control01.ctl - dbid changed, wrote new name Control File /home/OracleArch/fast_recovery_area/scp/control02.ctl - dbid changed, wrote new name Instance shut down --此时数据库实例已经关闭 Database name changed to ETDB. Modify parameter file and generate a new password file before restarting. Database ID for database ETDB changed to 637227457. 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. SQL> conn / as sysdba; Connected to an idle instance. --连接到空闲实例 SQL> SQL> SQL> startup mount; --启动数据库到mount状态 ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size 2926472 bytes Variable Size 1325402232 bytes Database Buffers 805306368 bytes Redo Buffers 13848576 bytes ORA-01103: database name ETDB in control file is not SCP--提示控制文件中的数据库名与实际的数据库名不匹配 SQL> alter system set db_name=etdb scope=spfile; System altered. SQL> shutdown immediate; ORA-01507: database not mounted ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 2147483648 bytes Fixed Size 2926472 bytes Variable Size 1325402232 bytes Database Buffers 805306368 bytes Redo Buffers 13848576 bytes Database mounted. SQL> select dbid,name from v$database; DBID NAME ---------- --------- 637227457 ETDB SQL> alter database open resetlogs; Database altered.

 修改数据库的 instance_name:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[[email protected] ~]$ sed -i s/"ORACLE_SID=scp"/"ORACLE_SID=etdb"/g  ~/.bash_profile 
[[email protected] ~]$ source ~/.bash_profile 
[[email protected] ~]$ env | grep ORACLE_SID
ORACLE_SID=etdb
[[email protected] ~]$ mv $ORACLE_HOME/dbs/spfilescp.ora $ORACLE_HOME/dbs/spfileetdb.ora
[[email protected] ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 25 23:49:44 2016

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 2147483648 bytes
Fixed Size            2926472 bytes
Variable Size         1325402232 bytes
Database Buffers      805306368 bytes
Redo Buffers           13848576 bytes
Database mounted.
Database opened.
SQL> show parameter name;

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name             string
db_file_name_convert             string
db_name                  string     ETDB
db_unique_name                 string     ETDB
global_names                 boolean     FALSE
instance_name                 string     etdb
lock_name_space              string
log_file_name_convert             string
pdb_file_name_convert             string
processor_group_name             string
service_names                 string     ETDB

SQL> alter system register;    --向listener注册

System altered.

SQL> host lsnrctl reload;

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 25-MAY-2016 23:52:04

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg1)(PORT=1521)))
The command completed successfully

SQL> host lsnrctl status;

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 25-MAY-2016 23:52:10

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                25-MAY-2016 23:14:06
Uptime                    0 days 0 hr. 38 min. 4 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/dg1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dg1.zytk.com)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "ETDB" has 1 instance(s).
  Instance "etdb", status READY, has 1 handler(s) for this service...
Service "scpXDB" has 1 instance(s).
  Instance "etdb", status READY, has 1 handler(s) for this service...
The command completed successfully

 最后修改一下密码文件:

[[email protected] ~]$ orapwd file=$ORACLE_HOME/dbs/orapwetdb password=‘[email protected]#‘ entries=3

 如果listener.ora、 tnsnames.ora文件中含有原来的 SERVICE_NAME 名称的话,用编辑器做相应的修改。

以上是关于修改数据库名(db_name)及实例名(Instance_name or Service_name)的主要内容,如果未能解决你的问题,请参考以下文章

Oracle 数据库名实例名Oracle_SID

数据库名实例名数据库域名全局数据库名服务名

全局数据库名称.数据库名称.SID是什么关系?

Oracle 服务名/实例名,Service_name 和Sid的区别

创建Oracle数据库数据库名与实例名与SID之间的关系(图文详解)

Oracle修改(db_name,db_unique_name, servie_names,db_domain)方法