[Oracle] oracle-DB_NAME、DB_UNIQUE_NAME、GLOBAL_NAME、INSTANCE_NAME、SERVICE_NAME详解


本文总阅读量

1、DB_NAME

DB_NAME:指定最多8个字符的数据库连接标识符。rac环境每个实例都要配置该值,且每个实例的值必须相同。如果存在从库,主库和从库的db_name要相同。

2、DB_UNIQUE_NAME

db_unique_name:数据库全局唯一名称。如果没有修改,默认情况下,数据库实例对应的名称为db_name。
oracle asm实例对应的名称为:+ASM。
rac各实例的对应的该值必须相同。
对于adg环境,主从具有相同的db_name,db_domain,但是必须保证db_unique_name不同,主从库有自己唯一的db_unique_name。最多设置30个字符。

3、GLOBAL_NAME

global_names:指定dblink是否需要和所要连接的远程库服务名称(service_names)一样,如果为false则不检查。
如果计划使用分布式处理,建议将该参数设为true,在一个网络环境下来确定数据库和连接的一致性命名规范。
该值为fasle|true影响的只是本机,远程库的global_names值为true|false对本机使用dblink的查询没有任何影响。
如果该值设置为true,dblink名称与service_name名称不一致则会报错ora-02085,实验如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SYS@ boston> alter system set global_names=true;
SYS@ boston> create database link oibs1 connect to test identified by oracle using 'oibs1';
Database link created.
SYS@ boston> select * from t1@oibs1;
ID
----------
1
2
SYS@ boston> create database link oibs connect to test identified by oracle using 'oibs1';
Database link created.
Elapsed: 00:00:00.03
SYS@ boston> select * from t1@oibs;
select * from t1@oibs
*
ERROR at line 1:
ORA-02085: database link OIBS connects to OIBS1

4、INSTANCE_NAME

instance_name:实例名,rac环境下,多个实例可以关联一个单独的数据服务。客户端可以通过指定一个特殊的实例来做负载均衡。
一个单实例的数据系统,实例名与数据库名相同。
tnsname.ora下的连接如果使用SID时要与该值相同。

5、SERVICE_NAMES

service_names:默认值为db_unique_name.db_domain。
在rac环境下不要通过sqlplus设置service_names参数,如果需要设置该参数,通过oracle EM和srvctl配置。
tnsname.ora下的连接如果使用SERVICE_NAME时要与该值相同。

5.1、默认db_domain值为空的情况下,测试修改service_names

因此service_names=db_unique_name,单实例手动设置service_names,检查service_names

1
2
3
4
18:50:14 SYS@ boston> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string boston

修改service_names

1
2
3
19:56:42 SYS@ boston> alter system set service_names='chicago.us.oracle';
System altered.
Elapsed: 00:00:00.23

查看service_names已修改

1
2
3
4
19:56:56 SYS@ boston> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string chicago.us.oracle

此时查看监听,新增了chicago.us.oracle的服务,原来boston的服务名并没有被覆盖掉:

1
2
3
4
5
6
7
8
9
10
11
[oracle@dax-mysql-slave admin]$ lsnrctl status
......
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dax-mysql-slave)(PORT=1521)))
Services Summary...
Service "boston" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "bostonXDB" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "chicago.us.oracle" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
The command completed successfully

再次修改service_names

1
2
3
19:56:59 SYS@ boston> alter system set service_names='chicago.us.oracle.com';
System altered.
Elapsed: 00:00:00.12

查看监听

1
2
3
4
5
6
7
8
9
10
11
[oracle@dax-mysql-slave admin]$ lsnrctl status
......
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dax-mysql-slave)(PORT=1521)))
Services Summary...
Service "boston" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "bostonXDB" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "chicago.us.oracle.com" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
The command completed successfully

chicago.us.oracle的服务名被替代为chicago.us.oracle.com

5.2、在db_domain存在的情况下(如果没有,可以自己修改,修改该值需要重启库)

先修改db_domain值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22:18:05 SYS@ boston> alter system set db_domain='us.oracle.cn' scope=spfile;
System altered.
22:18:22 SYS@ boston> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
22:18:38 SYS@ boston> startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 503319712 bytes
Database Buffers 1090519040 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.
22:19:36 SYS@ boston> show parameter db_domain
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_domain string us.oracle.cn

修改service_names,在不指定后缀的情况下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
22:45:57 SYS@ boston> alter system set service_names='chicago';
System altered.
Elapsed: 00:00:00.11
22:46:45 SYS@ boston> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string chicago

[oracle@dax-mysql-slave admin]$ lsnrctl status
......
Services Summary...
Service "boston.us.oracle.cn" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "bostonXDB.us.oracle.cn" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "chicago.us.oracle.cn" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
The command completed successfully

监听的服务名自动添加了db_domain,服务名变为了chicago.us.oracle.cn
当修改的service_names自己添加了其他的domian,那么系统自带的db_domain就不会覆盖了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
22:46:49 SYS@ boston> alter system set service_names='chicago.cn.oracle.com';
System altered.
Elapsed: 00:00:00.15
22:48:40 SYS@ boston> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string chicago.cn.oracle.com
[oracle@dax-mysql-slave admin]$ lsnrctl status
.....
Services Summary...
Service "boston.us.oracle.cn" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "bostonXDB.us.oracle.cn" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
Service "chicago.cn.oracle.com" has 1 instance(s).
Instance "boston", status READY, has 1 handler(s) for this service...
The command completed successfully

监听的service_names为chicago.cn.oracle.com,而不是chicago.us.oracle.com

目录
  1. 1. 1、DB_NAME
  2. 2. 2、DB_UNIQUE_NAME
  3. 3. 3、GLOBAL_NAME
  4. 4. 4、INSTANCE_NAME
  5. 5. 5、SERVICE_NAMES
    1. 5.1. 5.1、默认db_domain值为空的情况下,测试修改service_names
    2. 5.2. 5.2、在db_domain存在的情况下(如果没有,可以自己修改,修改该值需要重启库)

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog