oracle数据库实例名如何修改
1. 准备
原数据库的实例名为linuxdb,控制文件、数据文件、联机日志文件存放在/home/oracle/ora9/oradata/linuxdb目录,将所有的文件拷贝到另外一个目录/home/oracle/ora9/oradata/dbtest。
再将linuxdb 的初始化文件也复制一份出来,执行如下的sql:
Create pfile='/home/oracle/ora9/oracle/dbs/pfiledbtest.ora' from spfile='/home/oracle/ora9/oracle/dbs/spfilelinuxdb.ora';
我们将修改实例名为dbtest。
下面我们开始一步一步地进行处理。
2. 加载初始化文件
打开pfiledbtest.ora文件,修改对应的dump属性的路径名,实例名字,控制文件路径等。
然后执行如下命令:
[oracle@localhost oracle]$ export ORACLE_SID=dbtest
[oracle@localhost oracle]$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Mon Aug 17 16:57:36 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to an idle instance.
SQL> startup pfile='/home/oracle/ora9/oracle/dbs/pfiledbtest.ora' nomount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL>
这样加载初始化文件就成功了。
下面接着进行,加载控制文件。
3. 加载控制文件
先执行如下命令。
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying controlfile, check alert log for more info
好像是控制文件的路径不对,修改初始文件再次加载。
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01103: database name 'LINUXDB' in controlfile is not 'DBTEST'
根据错误信息提示,是实例名字不一致,但是控制文件是二进制的,用vi打开之后没法编辑,只能通过用重建控制文件可以解决。
在/home/oracle/ora9/oradata/dbtest目录下删除老的三个控制文件。然后开始重建控制文件。
SQL> CREATE CONTROLFILE SET DATABASE "DBTEST" RESETLOGS FORCE LOGGING NOARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 '/home/oracle/ora9/oradata/dbtest/redo01.log' SIZE 50M,
9 GROUP 2 '/home/oracle/ora9/oradata/dbtest/redo02.log' SIZE 50M,
10 GROUP 3 '/home/oracle/ora9/oradata/dbtest/redo03.log' SIZE 50M
11 DATAFILE
12 '/home/oracle/ora9/oradata/dbtest/cwmlite01.dbf',
13 '/home/oracle/ora9/oradata/dbtest/devbase_20090408.dbf',
14 '/home/oracle/ora9/oradata/dbtest/drsys01.dbf',
15 '/home/oracle/ora9/oradata/dbtest/example01.dbf',
16 '/home/oracle/ora9/oradata/dbtest/indx01.dbf',
17 '/home/oracle/ora9/oradata/dbtest/odm01.dbf',
18 '/home/oracle/ora9/oradata/dbtest/system01.dbf',
19 '/home/oracle/ora9/oradata/dbtest/tools01.dbf',
20 '/home/oracle/ora9/oradata/dbtest/undotbs01.dbf',
21 '/home/oracle/ora9/oradata/dbtest/users01.dbf',
22 '/home/oracle/ora9/oradata/dbtest/xdb01.dbf'
23 CHARACTER SET ZHS16GBK;
CREATE CONTROLFILE SET DATABASE "DBTEST" RESETLOGS FORCE LOGGING NOARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-01990: error opening password file '/home/oracle/ora9/oracle/dbs/orapw'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
根据错误提示,是缺少密码验证文件,用下面的命令创建密码文件。
$cd $ORACLE_HOME/dbs
orapwd password=chenli file=orapwdbtest
SQL> CREATE CONTROLFILE SET DATABASE 'dbtest' RESETLOGS FORCE LOGGING NOARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 '/home/oracle/ora9/oradata/dbtest/redo01.log' SIZE 50M,
9 GROUP 2 '/home/oracle/ora9/oradata/dbtest/redo02.log' SIZE 50M,
10 GROUP 3 '/home/oracle/ora9/oradata/dbtest/redo03.log' SIZE 50M
11 DATAFILE
12 '/home/oracle/ora9/oradata/dbtest/cwmlite01.dbf',
13 '/home/oracle/ora9/oradata/dbtest/devbase_20090408.dbf',
14 '/home/oracle/ora9/oradata/dbtest/drsys01.dbf',
15 '/home/oracle/ora9/oradata/dbtest/example01.dbf',
16 '/home/oracle/ora9/oradata/dbtest/indx01.dbf',
17 '/home/oracle/ora9/oradata/dbtest/odm01.dbf',
18 '/home/oracle/ora9/oradata/dbtest/system01.dbf',
19 '/home/oracle/ora9/oradata/dbtest/tools01.dbf',
20 '/home/oracle/ora9/oradata/dbtest/undotbs01.dbf',
21 '/home/oracle/ora9/oradata/dbtest/users01.dbf',
22 '/home/oracle/ora9/oradata/dbtest/xdb01.dbf'
23 CHARACTER SET ZHS16GBK;
Control file created.
现在创建成功了。
创建控制文件成功了,下面重新启动数据库。
SQL> startup nomount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount;
Database altered.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open RESETLOGS;
Database altered.
查看表中的记录,正确的。
修改实例名成功。
4. 总结
由上面的操作可以看到,在数据库维护中,最重要的是数据文件,初始化文件可以从别的实例拷贝过来,然后修改。控制文件可以重新创建,只要数据文件正确,就可以重建初始化文件和控制文件之后,恢复数据库。
遇到的错误:
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-00200: controlfile could not be created
ORA-00202: controlfile: '/home/ora/ora9/oradata/dbtest/control01.ctl'
ORA-27040: skgfrcre: create error, unable to create file
Linux Error: 2: No such file or directory
请查看初始化文件中,控制文件的路径是正确,控制文件的路径上的目录是否有权限创建文件,如果这些问题都解决了,那么应该能成功创建控制文件。
2024-08-23 广告
推荐于2018-02-27 · 知道合伙人数码行家
1、先查询oracle当前的db_name和sid;
SYS@test > select instance_name from v$instance;
INSTANCE_NAME
----------------
test
SYS@test > select name from v$database;
NAME
---------
TEST
关闭数据库;
SYS@test > shutdown immediate;
启动到mount状态;
SYS@test > startup mount;
修改数据文件中,控制文件中的数据库名称;
SYS@test > !nid target=sys/oracle dbname=mai logfile=/tmp/change_name.log
关闭数据库;
SYS@test > shutdown immediate;
2、启动到mount状态,这个时候会提示数据库名称不一致(ORA-01103: database name 'MAI' in control file is not 'TEST'),木有关系;
SYS@test > startup mount;
修改数据库名称,到spfile文件中
SYS@test > alter system set db_name=mai scope=spfile;
关闭数据库,并重新启动到mount状态,可以看到这次的启动没有错误提示
SYS@test > shutdown immediate;
SYS@test > startup mount;
SYS@test > alter database open resetlogs;
数据库的名称已经修改过了,接下来修改一下实例名,即instance_name,(其实经过上面的步骤数据库已经能够正常运行了,不过习惯上将db_name和instance_name设置为相同的值)
SYS@test > create pfile='initmai.ora' from spfile;
SYS@test > shutdown immediate;
SHELL > export ORACLE_SID=mai
SYS@mai > startup mount pfile='initmai.ora';
SYS@mai > create spfile from pfile;
SYS@mai > shutdown immediate;
SYS@mai > startup;
SYS@mai > select instance_name from v$instance;
INSTANCE_NAME
----------------
mai
SYS@mai > select name from v$database;
NAME
---------
MAI
修改完成