Oracle修改(db_name,db_unique_name, servie_names,db_domain)方法
原网址:http://blog.itpub.net/26442936/viewspace-758305
分类: Oracle
Oracle修改数据库名db_name 方法及(db_unique_name, servie_names,db_domain修改方法)
前提:
备份参数文件、控制文件、用户口令文件、参数文件、tnsnames.ora(个人习惯:什么工作都会备份为先)
实际操作方法:
1、 备份文本控制文件,并修改、编写新的生成控制文件SQL
2、 vi pfile,修改db_name,dispatchers成你需要的数据库名
3、 关闭数据库(shutdown immedaite)
4、 开启数据库nomount(startup nomount pfile=’xxx’;)
5、 使用编写好的控制文件SQL生成新的控制文件
6、 添加临时文件
7、 修改用户口令文件、tnsnames.ora、并使用远程登陆数据库验证
操作方法记录如下:
1、
备份文本控制文件
sys@TEST> alter database backup controlfile to trace as '/home/ora/control.ctl';
Database altered.
编写建立新控制文件SQL
-- Set #2. RESETLOGS case
把CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS ARCHIVELOG
修改成CREATE CONTROLFILE SET DATABASE "DOUDOU" RESETLOGS ARCHIVELOG
删除下面一行
#RECOVER DATABASE USING BACKUP CONTROLFILE
因为我们是shutdown immediate关闭数据库,没有必要恢复SCN了!shutdown immediate会checkpoint ,所有的数据文件SCN都会一致
生成新的控制文件SQL如下:
CREATE CONTROLFILE SET DATABASE "DOUDOU" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/opt/oracle/oradata/test/redo01.log' SIZE 50M,
GROUP 2 '/opt/oracle/oradata/test/redo02.log' SIZE 50M,
GROUP 3 '/opt/oracle/oradata/test/redo03.log' SIZE 50M
DATAFILE
'/opt/oracle/oradata/test/system01.dbf',
'/opt/oracle/oradata/test/undotbs1.dbf',
'/opt/oracle/oradata/test/sysaux01.dbf',
'/opt/oracle/oradata/test/users01.dbf',
'/opt/oracle/oradata/test/perfstat.dbf',
'/opt/oracle/oradata/test/doudou.dbf',
'/opt/oracle/oradata/test/doudou_index.dbf',
'/opt/oracle/oradata/test/maclean.dbf',
'/opt/oracle/oradata/test/test.dbf',
'/opt/oracle/oradata/test/gaokao.dbf'
CHARACTER SET AL32UTF8
;
2、
修改参数文件
sys@TEST> alter system set db_name='doudou' scope=spfile;
alter system set db_name='doudou' scope=spfile
*
ERROR at line 1:
ORA-32017: failure in updating SPFILE
ORA-32016: parameter "db_name" cannot be updated in SPFILE
注:db_name不允许直接使用spfile文件修改,所以选择建立pfile,并修改
sys@TEST> create pfile from spfile;
File created.
修改以下2项参数
*.db_name='doudou'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=doudouXDB)'
3、
关闭数据库
sys@TEST> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
4、
Startup nomount开启数据库
SQL> startup nomount pfile='/opt/oracle/product/10.2.0/db_1/dbs/initdoudou.ora';
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string test
lock_name_space string
log_file_name_convert string
service_names string doudou
为什么我们修改了db_name而实例名没有变化呢,因为我们没有设置实例名,这里默认了oracle_sid(这也说明了oracle_sid和实例的关系,实例的唯一标识)
[ora@dg-pp dbs]$ ORACLE_SID=doudou
SQL> startup nomount pfile='/opt/oracle/product/10.2.0/db_1/dbs/initdoudou.ora';
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou
Resetlogs开启数据库
Alter database open resetlogs
5、
使用新的控制文件SQL创建新的控制文件
CREATE CONTROLFILE SET DATABASE "DOUDOU" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/opt/oracle/oradata/test/redo01.log' SIZE 50M,
GROUP 2 '/opt/oracle/oradata/test/redo02.log' SIZE 50M,
GROUP 3 '/opt/oracle/oradata/test/redo03.log' SIZE 50M
DATAFILE
'/opt/oracle/oradata/test/system01.dbf',
'/opt/oracle/oradata/test/undotbs1.dbf',
'/opt/oracle/oradata/test/sysaux01.dbf',
'/opt/oracle/oradata/test/users01.dbf',
'/opt/oracle/oradata/test/perfstat.dbf',
'/opt/oracle/oradata/test/doudou.dbf',
'/opt/oracle/oradata/test/doudou_index.dbf',
'/opt/oracle/oradata/test/maclean.dbf',
'/opt/oracle/oradata/test/test.dbf',
'/opt/oracle/oradata/test/gaokao.dbf'
CHARACTER SET AL32UTF8
;
执行成功后,数据库为mount状态
6、
添加临时文件
col tablespace_name for a30
SQL> select TABLESPACE_NAME,SEGMENT_SPACE_MANAGEMENT,CONTENTS from dba_tablespaces where contents='TEMPORARY';
TABLESPACE_NAME SEGMENT_SPAC CONTENTS
------------------------------ ------------ ------------------
TEMP MANUAL TEMPORARY
TEMP01 MANUAL TEMPORARY
DOUDOU_TEMP MANUAL TEMPORARY
alter tablespace temp add tempfile '/opt/oracle/oradata/test/temp.dbf' reuse;
alter tablespace temp01 add tempfile '/opt/oracle/oradata/test/temp01.dbf' reuse;
alter tablespace doudou_temp add tempfile '/opt/oracle/oradata/test/doudou_temp.dbf' reuse;
7、
修改用户口令文件,tnsnames.ora
[ora@dg-pp dbs]$ cp orapwtest orapwdoudou
vi tnsnames.ora
doudou =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg-pp)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = doudou)
)
)
使用sqlplus 登陆数据库验证
[ora@dg-pp admin]$ sqlplus sys/oracle@doudou as sysdba (登陆成功)
SQL> col name for a30
SQL> col type for a10
SQL> col value for a20
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou
附表:
Db_name ----(只能pfile修改,并重启生效)
Db_domain ----(pfile,spfile都可修改,并重启生效)
Db_unique_name ----(只能pfile修改,并重启生效)
Service_names ----(pfile,spfile都可修改,立刻生效,无需重启)
1、db_domain
修改db_domain (spfile启动)
alter system set db_domain='com' scope=spfile;
重启数据库生效
shutdown immediate
startup
2、db_unique_name
修改db_unique_name(spfile启动)
create pfile from spfile; (创建pfile文件修改db_unique_name)
vi pfile
startup pfile='/opt/oracle/product/10.2.0/db_1/dbs/initdoudou.ora';
3、service_names(spfile启动)
alter system set service_names='www.xiaoyu.com' ;
总结:service_names未设置情况下,service_names=db_unique_name.db_domain;若是设置了service_names时,已service_names为准
操作方法记录
1、db_domain 操作方法记录
col name for a30
col type for a10
col value for a20
show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string
show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou
alter system set db_domain='com' scope=spfile;
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou
虽然我们修改成功了,但是没有立刻生效,我们重启数据库
shutdown immediate
startup
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string com
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou.com
修改db_domain重启数据库后生效!还有一点需注意service_names自动变为doudou.com也就是说当你设置db_domain时,在不设置service_names的情况下,service_names =db_unique.db_domain (为什么会有这个公式,下面会讲)
2、db_unique_name 操作方法记录
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string doudou
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string doudou.com
SQL> create pfile from spfile;
vi pfile
添加
db_unique_name=’xiaoyu’
开启数据库
SQL> startup pfile='/opt/oracle/product/10.2.0/db_1/dbs/initdoudou.ora';
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string com
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string xiaoyu
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string xiaoyu.com
在不设置service_names的情况下,service_names=db_unique_name.db_domain公式了
3、service_names操作方法记录
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string com
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string xiaoyu
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string xiaoyu.com
SQL> alter system set service_names='www.xiaoyu.com' ;
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_domain string com
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ---------- ------------------------------
db_file_name_convert string
db_name string doudou
db_unique_name string xiaoyu
global_names boolean FALSE
instance_name string doudou
lock_name_space string
log_file_name_convert string
service_names string www.xiaoyu.com