修改數據庫名(db_name)及實例名(Instance_name or Service_name)

操做系統版本:rhel6.5 (Red Hat Enterprise Linux Server release 6.5 (Santiago))sql

數據庫版本:12.1.0.2.0數據庫

實驗目的:bash

假設原來的數據庫名爲scp,要改爲etdb,原實例名(service_name,instance_name)scp,要改爲etdb.oracle

當前數據庫的db_name和instance_name:app

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:tcp

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
[oracle@dg1 ~]$ sed -i s/"ORACLE_SID=scp"/"ORACLE_SID=etdb"/g  ~/.bash_profile 
[oracle@dg1 ~]$ source ~/.bash_profile 
[oracle@dg1 ~]$ env | grep ORACLE_SID
ORACLE_SID=etdb
[oracle@dg1 ~]$ mv $ORACLE_HOME/dbs/spfilescp.ora $ORACLE_HOME/dbs/spfileetdb.ora
[oracle@dg1 ~]$ 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.this

SQL> host lsnrctl reload;spa

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

 最後修改一下密碼文件:

[oracle@dg1 ~]$ orapwd file=$ORACLE_HOME/dbs/orapwetdb password='aba123!@#' entries=3

 若是listener.ora、 tnsnames.ora文件中含有原來的 SERVICE_NAME 名稱的話,用編輯器作相應的修改。

 針對數據庫自啓動文件: /etc/oratab , /etc/rc.local 文件也須要作相應的修改。

相關文章
相關標籤/搜索