安装 oracle 的时候会制定 db_domain,制定 db_domain 后 service_name 和 global_name 都会加上这个domain,此时在配置 tns file 以及 easy connect 的时候都要 service_name 很复杂。尝试修改 global_name,因为 service_name 默认是 global_name,而global_name=db_name.db_domain。
db_domain常用于分布式数据库系统标识
global_name和service_name常用于监听和tnsnames
unique_name是数据库的唯一名,常用于数据库DG搭建。
1.查看状态
show parameter name
show parameter db_domain
show parameter service_name;
show parameter db_unique_name;
show parameter global_name;
2.修改db_domain
alter system set db_domain='coco' scope=spfile;
startup force //重启数据库(生产环需要正常关库)
show parameter db_domain; //检验结果
修改db_domain会顺带改变service_name
3.开启并修改global_name
alter system set global_names=true scope=both;
update global_name set global_name = 'coco'
commit;
修改 global_name 并不会默认改掉 service_name,也不会默认修改 db_domain
4.修改service_names:
alter system set service_names = 'coco' scope=spfile;
startup force //重启数据库(生产环需要正常关库)
show parameter service_names;
修改global_name和service_name后数据库的监听配置和tnsnames也需要修改
5.修改unique_name
alter system set db_unique_name = 'coco' scope=spfile;
startup force //重启数据库(生产环需要正常关库)
show parameter db_unique_name;
过程如下:
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string orcl
SQL> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_domain string
SQL> show parameter service_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string orcl
SQL> show parameter db_unique_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orcl
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
ORCL
SQL> alter system set db_domain='coco' scope=spfile;
System altered.
SQL> startup force
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
Database opened.
SQL> show parameter db_domain;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_domain string coco
SQL> show parameter global_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean FALSE
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
ORCL
修改db_domain,service_name会更着修改。
SQL> alter system set global_names=true scope=both;
System altered.
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean TRUE
instance_name string orcl
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string orcl.coco
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
ORCL
SQL> update global_name set global_name = 'coco';
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
coco
SQL> startup force
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
Database opened.
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
coco
SQL> alter system set db_unique_name = 'coco' scope=spfile;
System altered.
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean TRUE
instance_name string orcl
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string orcl.coco
SQL> startup force
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
Database opened.
SQL> show parameter db_unique_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string coco
SQL> alter system set service_names = 'coco' scope=spfile;
System altered.
SQL> startup force
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
Database opened.
SQL> show parameter service_names;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string coco