LINUX环境下ORACLE数库改名

Nid是Oracle从9iR2开始提供的工具,可以用来更改数据库名称或者生成新的dbid,而无需通过之前重建控制文件等繁琐方式


1.查看当前实例名和数据库名
SQL> select instance_name from v$instance; 

INSTANCE_NAME
----------------
test

SQL> select name from v$database; 

NAME
---------
TEST



2.关闭数据库

SQL> shutdown immediate 


Database closed.
Database dismounted.
ORACLE instance shut down.



3.启动数据库到mount状态 
SQL> startup mount; 
ORACLE instance started.

Total System Global Area 205520896 bytes
Fixed Size 1218532 bytes
Variable Size 67110940 bytes
Database Buffers 134217728 bytes
Redo Buffers 2973696 bytes
Database mounted.


4.使用NID更改数据库名
SQL> host nid target=sys/test123 dbname=test2; 

DBNEWID: Release 10.2.0.1.0 - Production on Wed Jul 21 16:31:20 2010

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

Connected to database TESTORA (DBID=547002923)

Connected to server version 10.2.0

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

Change database ID and database name TESTORA to TEST? (Y/[N]) => y 

Proceeding with operation
Changing database ID from 547002923 to 2023088600
Changing database name from TESTORA to TEST2
Control File /u01/oradata/oratest/control01.ctl - modified
Control File /u01/oradata/oratest/control02.ctl - modified
Control File /u01/oradata/oratest/control03.ctl - modified
Datafile /u01/oradata/oratest/system01.dbf - dbid changed, wrote new name
Datafile /u01/oradata/oratest/undotbs01.dbf - dbid changed, wrote new name
Datafile /u01/oradata/oratest/sysaux01.dbf - dbid changed, wrote new name
Datafile /u01/oradata/oratest/users01.dbf - dbid changed, wrote new name
Datafile /u01/oradata/oratest/test.dbf - dbid changed, wrote new name
Datafile /u01/oradata/oratest/temp02.dbf - dbid changed, wrote new name
Control File /u01/oradata/oratest/control01.ctl - dbid changed, wrote new name
Control File /u01/oradata/oratest/control02.ctl - dbid changed, wrote new name
Control File /u01/oradata/oratest/control03.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to TEST2.
Modify parameter file and generate a new password file before restarting.
Database ID for database TEST changed to 2023088600.
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.



5.关闭数据库
SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.



6.修改初始化参数文件inittest.ora

*.instance_name=test2
*.db_name=test2



7.重建spfile文件
SQL> startup nomount pfile='/opt/oracle/product/10.2.0/dbs/inittest2.ora'

SQL> CREATE SPFILE FROM PFILE;

File created. 



8.重建口令文件
[oracle@local~]$ orapwd file='/opt/oracle/product/10.2.0/db_1/dbs/orapwtest2' password=test123 entries=10

***注意windows与linux下密码文件格式的区别***

On UNIX, the file name MUST be orapw<SID>,  <SID> being the name of the instance.密码文件目录 $ORACLE_HOME/dbs 
On  Windows, the file name MUST be pwd<SID>.ORA.密码文件目录%ORACLE_HOME%\database


9.关闭数据库
SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.


10.mount数据库,使用resetlogs打开
SQL> startup mount; 
ORACLE instance started.

Total System Global Area 205520896 bytes
Fixed Size 1218532 bytes
Variable Size 67110940 bytes
Database Buffers 134217728 bytes
Redo Buffers 2973696 bytes
Database mounted.


SQL> alter database open resetlogs;  

Database altered.


11.验证数据库名和实例名
SQL> select dbid,name from v$database;   

      DBID NAME
---------- ---------
 808938177 TEST2

SQL> select instance_name from v$instance;  

INSTANCE_NAME
----------------
test2


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值