修改dbname和sid



说明:

数据库版本:单机oracle10.2.0.5
操作系统版本是linux 5.8
将sid从orcl改为exam
将dbname由orcl改为test,不改变dbid,不用resetlogs打开数据库(一般客户可能要求该sid和dbname对于dbid应该不需要更改,而且一旦改了dbid之前的备份都无效了)
一、修改sid
1.关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
sORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
2.修改pfile中的sid为exam
[oracle@ttee ~]$ vi .bash_profile
# .bash_profile


# Get the aliases and functions
        . ~/.bashrc
fi


# User specific environment and startup programs
# Oracle Settings
 export ORACLE_SID=orcl
 export ORACLE_BASE=/u01/app/oracle
 export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
 export PATH=$ORACLE_HOME/bin:$PATH:$HOME/BIN


#将ORACLE_SID=orcl改为exam
~
".bash_profile" 13L, 319C written                                                          
3.修改/etc/oratab文件,将最后一行orcl改为exam,但我最后一个字符是N不生效。
     
[oracle@ttee ~]$ vi /etc/oratab 
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.


# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#


#
#orcl:/u01/app/oracle/product/10.2.0/db_1:N
exam:/u01/app/oracle/product/10.2.0/db_1:N
"/etc/oratab" 23L, 721C written    
4.修改dbs目录下的相关文件   (密码文件可以重建,我这里直接重命名了)                                                    
[oracle@ttee ~]$ cd $ORACLE_HOME/dbs
[oracle@ttee dbs]$ ls
alert_orcl.log  hc_orcl.dat  initdw.ora  init.ora  lkORCL  orapworcl  spfileorcl.ora
[oracle@ttee dbs]$ cat lkORCL 
DO NOT DELETE THIS FILE![oracle@ttee dbs]$ ll
total 48
-rw-r----- 1 oracle oinstall   168 May 24 05:31 alert_orcl.log
-rw-rw---- 1 oracle oinstall  1552 May 24 05:30 hc_orcl.dat
-rw-r--r-- 1 oracle oinstall 12920 May  3  2001 initdw.ora
-rw-r----- 1 oracle oinstall  8385 Sep 11  1998 init.ora
-rw-r----- 1 oracle oinstall    24 May  8 02:01 lkORCL
-rw-r----- 1 oracle oinstall  1536 May 20 06:15 orapworcl
-rw-r----- 1 oracle oinstall  2560 May 24 04:42 spfileorcl.ora
[oracle@ttee dbs]$ mv spfileorcl.ora spfileexam.ora
[oracle@ttee dbs]$ mv orapworcl orapwexam
[oracle@ttee dbs]$ mv lkORCL lkEXAM
[oracle@ttee dbs]$ mv hc_orcl.dat hc_exam.dat
查看环境变量是否生效
[oracle@ttee dbs]$ exit
logout
[root@ttee ~]# su - oracle
[oracle@ttee ~]$ cd $ORACLE_HOME/dbs
[oracle@ttee dbs]$ echo $ORACLE_SID
exam
5.打开数据库
[oracle@ttee dbs]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 05:39:36 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to an idle instance.


SQL> startup
ORACLE instance started.


Total System Global Area 1048576000 bytes
Fixed Size                  2101544 bytes
Variable Size             255856344 bytes
Database Buffers          784334848 bytes
Redo Buffers                6283264 bytes
Database mounted.
Database opened.
SQL> select instance from v$thread;


INSTANCE
--------------------------------------------------------------------------------
exam


SQL> conn scott/tiger@orcl
ERROR:
ORA-12541: TNS:no listener




Warning: You are no longer connected to ORACLE.




SQL> conn / as sysdba
Connected.
SQL> select username,account_status from dba_users where username='SCOTT';


USERNAME                       ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT                          OPEN


SQL> EXIT
Disconnected from 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@ttee dbs]$ lsnrctl status


LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 24-MAY-2016 05:41:16


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


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ttee)(PORT=1521)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 2: No such file or directory
[oracle@ttee dbs]$ lsnrctl start


LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 24-MAY-2016 05:41:21


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


Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...


TNSLSNR for Linux: Version 10.2.0.5.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ttee)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ttee)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                24-MAY-2016 05:41:21
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ttee)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@ttee dbs]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 05:41:34 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> alter system register
  2  ;


System altered.


SQL> conn scott/tiger
Connected.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
二、使用nid修改dbname
1.生成pfile,关闭数据库,开启到mount阶段
[oracle@ttee dbs]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 05:41:59 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options




SQL> conn / as sysdba
Connected.
SQL> create pfile='/tmp/pfile.ora' from spfile;


File created.


SQL> shutdown immediate;
Database closed.
Database dismounted.
sORACLE instance shut down.
SQL> startup mount;
SP2-0734: unknown command beginning "sstartup m..." - rest of line ignored.
SQL> startup mount;
ORACLE instance started.


Total System Global Area 1048576000 bytes
Fixed Size                  2101544 bytes
Variable Size             255856344 bytes
Database Buffers          784334848 bytes
Redo Buffers                6283264 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
使用nid修改dbname(这里只修改dbname。都修改的话nid target=sys/oracle dbname=test,只修改dbid的话nid target=sys/oracle)
[oracle@ttee dbs]$ nid target=sys/oracle dbname=test setname=yes


DBNEWID: Release 10.2.0.5.0 - Production on Tue May 24 06:00:22 2016


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


Connected to database ORCL (DBID=1439048815)


Connected to server version 10.2.0


Control Files in database:
    /oradata/orcl/control01.ctl
    /oradata/orcl/control02.ctl
    /oradata/orcl/control03.ctl


Change database name of database ORCL to TEST? (Y/[N]) => y


Proceeding with operation
Changing database name from ORCL to TEST
    Control File /oradata/orcl/control01.ctl - modified
    Control File /oradata/orcl/control02.ctl - modified
    Control File /oradata/orcl/control03.ctl - modified
    Datafile /oradata/orcl/system01.dbf - wrote new name
    Datafile /oradata/orcl/undotbs01.dbf - wrote new name
    Datafile /oradata/orcl/sysaux01.dbf - wrote new name
    Datafile /oradata/orcl/users01.dbf - wrote new name
    Datafile /oradata/orcl/temp01.dbf - wrote new name
    Control File /oradata/orcl/control01.ctl - wrote new name
    Control File /oradata/orcl/control02.ctl - wrote new name
    Control File /oradata/orcl/control03.ctl - wrote new name
    Instance shut down


Database name changed to TEST.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.
修改完成,使用pfile打开数据库,这里只改dbname不用使用resetlogs打开数据库。pfile注意修改dbname=test
[oracle@ttee dbs]$ vi /tmp/pfile.ora 
orcl.__db_cache_size=763363328
exam.__db_cache_size=784334848
orcl.__java_pool_size=33554432
exam.__java_pool_size=4194304
orcl.__large_pool_size=4194304
exam.__large_pool_size=4194304
orcl.__shared_pool_size=239075328
exam.__shared_pool_size=247463936
orcl.__streams_pool_size=0
exam.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/oradata/orcl/control01.ctl','/oradata/orcl/control02.ctl','/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)'
*.db_name='orcl'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
"/tmp/pfile.ora" 31L, 1077C written                                                        
[oracle@ttee dbs]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 06:01:36 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to an idle instance.
打开数据库
SQL> startup pfile='/tmp/pfile.ora'
ORACLE instance started.


Total System Global Area 1048576000 bytes
Fixed Size                  2101544 bytes
Variable Size             255856344 bytes
Database Buffers          784334848 bytes
Redo Buffers                6283264 bytes
Database mounted.
Database opened.
SQL> conn sys/oracle  as sysdba
Connected.
由于service_names 由orcl变为test,查看监听状态。
SQL> show parameter name


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      test
db_unique_name                       string      test
global_names                         boolean     FALSE
instance_name                        string      exam
lock_name_space                      string
log_file_name_convert                string
service_names                        string      test
SQL> exit
Disconnected from 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@ttee dbs]$ lsnrctl status


LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 24-MAY-2016 06:04:10


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


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ttee)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                24-MAY-2016 05:41:21
Uptime                    0 days 0 hr. 22 min. 48 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ttee)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "exam", status READY, has 1 handler(s) for this service...
Service "test" has 1 instance(s).
  Instance "exam", status READY, has 1 handler(s) for this service...
Service "test_XPT" has 1 instance(s).
  Instance "exam", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@ttee dbs]$ sqlplus /nolog


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 06:04:20 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> conn system/oracle@orcl
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor




SQL> exit

服务已经更改为test如lisnrctl status里和show parameter name里的service,

需要改一下tnsnames.ora配置文件

[oracle@ttee dbs]$ cd /u01/app/oracle/product/10.2.0/db_1/network/
[oracle@ttee network]$ ls
admin  doc  install  jlib  lib  lib32  log  mesg  tools  trace
[oracle@ttee network]$ cd admin
[oracle@ttee admin]$ ls
listener.ora  samples  shrept.lst  tnsnames.ora
[oracle@ttee admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ttee)(PORT = 1521))
      (SERVICE_NAME = orcl)
    )
  )
#将(SERVICE_NAME = orcl)改为(SERVICE_NAME = test)
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
      (PRESENTATION = RO)
"tnsnames.ora" 23L, 521C written   
测试使用字符串连接                                                        
[oracle@ttee admin]$ sqlplus /nolog


SQL*Plus: Release 10.2.0.5.0 - Production on Tue May 24 06:05:26 2016


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> conn scott/tiger
Connected.
SQL> conn scott/tiger@orcl
Connected.
SQL> exit
其实到这步已经成功。但是官方文档中要求改密码文件,可密码文件是对应sid的,我sid在这一步没有变,为何修改密码文件
,而且文档中明确说只改dbname不需要resetlogs。
http://blog.youkuaiyun.com/huoshuyinhua/article/details/51490186
官方文档是否是完全正确的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值