赞
踩
修改oracle数据库的名称需要同时在控制文件和参数文件中进行修改。修改控制文件中数据库的名称使用操作系统命令nid,修改参数文件中数据库的名称使用alter system命令。
所有的数据文件、临时文件和表空间状态必须是online或offline。查看数据库是否处于归档模式,如果不是,修改为归档模式。
SQL> select name,status from v$datafile;
NAME STATUS
---------------------------------------- -------
/usr/local/oradata/orcl/system01.dbf SYSTEM
/usr/local/oradata/orcl/sysaux01.dbf ONLINE
/usr/local/oradata/orcl/undotbs01.dbf ONLINE
/usr/local/oradata/orcl/users01.dbf ONLINE
/usr/local/oradata/orcl/data01.dbf ONLINE
/usr/local/oradata/orcl/data02.dbf ONLINE
6 rows selected.
SQL> select name,status from v$tempfile;
NAME STATUS
---------------------------------------- -------
/usr/local/oradata/orcl/temp01.dbf ONLINE
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
DATA01 ONLINE
DATA02 ONLINE
7 rows selected.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archive_logs
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2220200 bytes
Variable Size 482348888 bytes
Database Buffers 578813952 bytes
Redo Buffers 5554176 bytes
Database mounted.
nid命令修改控制文件中的数据库名称和DBID,命令如下:
[oracle@wgx ~]$ nid target=sys/sys dbname=BOOK DBNEWID: Release 11.2.0.1.0 - Production on Sat Apr 11 03:20:49 2020 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to database MYDB (DBID=2952401142) Connected to server version 11.2.0 Control Files in database: /usr/local/oradata/orcl/control01.ctl /usr/local/oracle/flash_recovery_area/orcl/control02.ctl Change database ID and database name MYDB to BOOK? (Y/[N]) => Y Proceeding with operation Changing database ID from 2952401142 to 1478168914 Changing database name from MYDB to BOOK Control File /usr/local/oradata/orcl/control01.ctl - modified Control File /usr/local/oracle/flash_recovery_area/orcl/control02.ctl - modified Datafile /usr/local/oradata/orcl/system01.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/sysaux01.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/undotbs01.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/users01.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/data01.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/data02.db - dbid changed, wrote new name Datafile /usr/local/oradata/orcl/temp01.db - dbid changed, wrote new name Control File /usr/local/oradata/orcl/control01.ctl - dbid changed, wrote new name Control File /usr/local/oracle/flash_recovery_area/orcl/control02.ctl - dbid changed, wrote new name Instance shut down Database name changed to BOOK. Modify parameter file and generate a new password file before restarting. Database ID for database BOOK changed to 1478168914. 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> startup force nomount
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2220200 bytes
Variable Size 482348888 bytes
Database Buffers 578813952 bytes
Redo Buffers 5554176 bytes
SQL> alter system set db_name=BOOK scope=spfile;
System altered.
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2220200 bytes
Variable Size 482348888 bytes
Database Buffers 578813952 bytes
Redo Buffers 5554176 bytes
Database mounted.
必须以resetlogs方式打开数据库。
SQL> alter database open resetlogs;
Database altered.
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string BOOK
db_unique_name string BOOK
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
service_names string BOOK
可以看到数据库的名称已经更改,但实例名没有更改。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。