在Oracle中有关数据库和数据库实例的几个重要概念,有时候如果理解不是很深或者对其疏忽、混淆了,还真容易搞错或弄不清其概念,下面就数据库实例名、数据库名、数据库域名、数据库服务名、全局数据库名几个概念,我们来梳理一下概念,总结归纳一下这些知识,首先,我们来看看官方文档对这几者的概念介绍:
INSTANCE_NAME(数据库实例名)

PropertyDescription
Parameter typeString
SyntaxINSTANCE\_NAME =instance\_id
Default valueThe instance's SIDNote: The SID identifies the instance's shared memory on a host, but may not uniquely distinguish this instance from other instances.
ModifiableNo
Range of valuesAny alphanumeric characters
BasicNo

In a Real Application Clusters environment, multiple instances can be associated with a single database service. Clients can override Oracle's connection load balancing by specifying a particular instance by which to connect to the database. INSTANCE\_NAME specifies the unique name of this instance.
In a single-instance database system, the instance name is usually the same as the database name.
Oracle Instance是指一组后台进程(在Windows上是一组线程)和一块共享内存区域。实例名(instance\_name)就是用来标识这个instance的一个名称而已。
DB_NAME(数据库名)

PropertyDescription
Parameter typeString
SyntaxDB\_NAME =database\_name
Default valueThere is no default value.
ModifiableNo
BasicYes
Real Application ClustersYou must set this parameter for every instance. Multiple instances must have the same value, or the same value must be specified in the STARTUP OPEN SQL*Plus command or the ALTER DATABASE MOUNT SQL statement.

DB\_NAME specifies a database identifier of up to 8 characters. This parameter must be specified and must correspond to the name specified in the CREATE DATABASE statement.
If you have multiple databases, the value of this parameter should match the Oracle instance identifier of each one to avoid confusion with other databases running on the system. The value of DB\_NAME should be the same in both the standby and production initialization parameter files.
The database name specified in either the STARTUP command or the ALTER DATABASE ... MOUNT statement for each instance of the cluster database must correspond to the DB\_NAME initialization parameter setting.
The following characters are valid in a database name: alphanumeric characters, underscore (_), number sign (#), and dollar sign ($). No other characters are valid. Oracle removes double quotation marks before processing the database name. Therefore you cannot use double quotation marks to embed other characters in the name. The database name is case insensitive.
DB\_NAME Initialization Parameter
DB_NAME must be set to a text string of no more than eight characters. During database creation, the name provided for DB_NAME is recorded in the datafiles, redo log files, and control file of the database. If during database instance startup the value of the DB_NAME parameter (in the parameter file) and the database name in the control file are not the same, the database does not start.
简单来说,数据库名是数据库的名称标识,它是在创建数据库的时候确定的,一旦确定,不能更改。该信息存在于初始化文件,控制文件、redo log文件以及数据文件等地方。
DB_DOMAIN(数据库域名)

PropertyDescription
Parameter typeString
SyntaxDB\_DOMAIN =domain\_name
Default valueThere is no default value.
ModifiableNo
Range of valuesAny legal string of name components, separated by periods and up to 128 characters long (including the periods). This value cannot be NULL.
BasicYes
Real Application ClustersYou must set this parameter for every instance, and multiple instances must have the same value.

In a distributed database system, DB\_DOMAIN specifies the logical location of the database within the network structure. You should set this parameter if this database is or ever will be part of a distributed system. The value consists of the extension components of a global database name, consisting of valid identifiers (any alphanumeric ASCII characters), separated by periods. Oracle recommends that you specify DB\_DOMAIN as a unique string for all databases in a domain.
This parameter allows one department to create a database without worrying that it might have the same name as a database created by another department. If one sales department's DB\_DOMAIN is JAPAN.ACME.COM, then their SALES database (SALES.JAPAN.ACME.COM) is uniquely distinguished from another database with DB\_NAME = SALES but with DB\_DOMAIN = US.ACME.COM.
If you omit the domains from the name of a database link, Oracle expands the name by qualifying the database with the domain of your local database as it currently exists in the data dictionary, and then stores the link name in the data dictionary. The characters valid in a database domain name are: alphanumeric characters, underscore (_), and number sign (#).
在分布式数据库系统中,定义一个数据库所在的域,该域的命名同互联网的’域’没有任何关系,只是数据库管理员为了更好的管理分布式数据库而根据实际情况决定的。当然为了管理方便,可以将其等于互联网的域。本来db\_name用来对一个数据库的唯一标识,这种表示对于单个数据库是足够的,但是随着由多个数据库构成的分布式数据库的普及,这种命名数据库的方法给数据库的管理造成一定的负担,因为各个数据库的名字可能一样,造成管理上的混乱。为了解决这种情况,引入了db\_domain参数,这样在数据库的标识是由 db\_name和db\_domain两个参数共同决定的,避免了因为数据库重名而造成管理上的混乱。这类似于互连网上的机器名的管理.
GLOBAL_NAMES

PropertyDescription
Parameter typeBoolean
Default valuefalse
ModifiableALTER SESSION, ALTER SYSTEM
Range of valuestrue \false
BasicNo

GLOBAL\_NAMES specifies whether a database link is required to have the same name as the database to which it connects.
If the value of GLOBAL\_NAMES is false, then no check is performed. If you use or plan to use distributed processing, then Oracle recommends that you set this parameter to true to ensure the use of consistent naming conventions for databases and links in a networked environment.
global database name(全局数据库名)

  1. What is a global database name?

The global database name is the unique name of the database. In a distributed
database system (a set of databases stored on multiple computers that typically
appears to applications as a single database) the global database name ensures
that each database is distinct from all other databases in the system. Oracle
forms a database's global database name by prefixing the database's network
domain with the individual database's name. For example: sales.us.oracle.com
and sales.uk.oracle.com.
The global database name defaults to DB\_NAME.DB\_DOMAIN and this value is marked
at database creation time. If you change the DB\_NAME or DB\_DOMAIN after the
database has been created, the value for the global database name (GLOBAL\_NAME)
will not change.
Understanding How Global Database Names Are Formed
A global database name is formed from two components: a database name and a domain. The database name and the domain name are determined by the following initialization parameters at database creation:

ComponentParameterRequirementsExample
Database nameDB\_NAMEMust be eight characters or less.sales
Domain containing the databaseDB\_DOMAINMust follow standard Internet conventions. Levels in domain names must be separated by dots and the order of domain names is from leaf to root, left to right.

说简单一点,global database name就是用来唯一标识数据库的概念。Oracle的GLOBAL\_NAME由两个部分组成:DB\_NAME和DB\_DOMAIN。如果在建立数据库的时候不指定DB\_DOMAIN的值,则GLOBAL\_NAME和DB\_NAME的值一样。
注意:不管是设置通过DB\_DOMAIN的方式,还是通过ALTER DATABASE RENAME GLOBAL\_NAME TO的方式。一旦GLOBAL\_NAME包含了DB\_DOMAIN部分。就再也无法去掉了(可以更新SYS.PROPS$解决,不推荐)
SERVICE_NAMES

PropertyDescription
Parameter typeString
SyntaxSERVICE\_NAMES =db\_service\_name[,db\_service\_name[ ... ] ]
Default valueDB\_UNIQUE\_NAME.DB\_DOMAIN if defined
ModifiableALTER SYSTEM
Range of valuesAny ASCII string or comma-separated list of string names
BasicNo
Real Application ClustersDo not set the SERVER\_NAMES parameter for Real Application Clusters (RAC). Instead, define services using Database Configuration Assistant (DBCA) and manage services using Server Control (SRVCTL) utility.

SERVICE\_NAMES specifies one or more names by which clients can connect to the instance. The instance registers its service names with the listener. When a client requests a service, the listener determines which instances offer the requested service and routes the client to the appropriate instance.
You can specify multiple service names in order to distinguish among different uses of the same database. For example:
SERVICE\_NAMES = sales.acme.com, widgetsales.acme.com
You can also use service names to identify a single service that is available from two different databases through the use of replication.
If you do not qualify the names in this parameter with a domain, Oracle qualifies them with the value of the DB\_DOMAIN parameter. If DB\_DOMAIN is not specified, then no domain will be applied to the non-qualified SERVICE\_NAMES values.
该参数是Oracle 8i新引进的。在8i以前,我们用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐。为了方便并行环境中的设置,引进了SERVICE\_NAME参数,该参数对应一个数据库,而不是一个实例,而且该参数有许多其它的好处。该参数的缺省值为db\_name.db\_domain,即等于GLOBAL\_NAME。一个数据库可以对应多个service\_name,以便实现更灵活的配置。该参数与SID没有直接关系,即不必service name必须与SID一样。
服务名(service\_names):指listener提供的对外的服务名,客户端可以通过配置tnsnmaes.ora连进行连接,tnsnmaes.ora文件中的service\_name要等于服务器端listener所注册的服务名,服务名可以通过输入lsnrctl后,在输入service查看,一般的service\_name在listener.ora文件中配置(静态注册),或者当没有listener.ora文件时,在初始化文件中配置instance\_name和service\_names这2个参数进行动态注册。但是无论采用那种注册方式,都可以通过lsnrctl-sevice来检查。
查看当前数据库名
方法1:
SQL> show parameter db\_name;
方法2:查询数据库视图
SQL> select name from v$database;
方法3:查看参数文件
查看数据库实例名
方法1:
SQL> show parameter instance\_name;
方法2:查询数据库视图
SQL> select instance\_name from v$instance;
查看数据库域名
方法1:
SQL> show parameter db\_domain;
方法2:
select value from v$parameter where name='db\_domain';
查看数据库服务名
方法1:
SQL> show parameter service\_name;
查看全局数据库名
SQL> SELECT * FROM GLOBAL\_NAME;
SID与SERVICE\_NAME的区别
instance\_name是Oracle数据库参数。而ORACLE\_SID是操作系统的环境变量。数据库实例启动后select instance\_name from v$instance;这个时候我们可以看到instance\_name和在环境变量里面配置的ORACLE\_SID是同样的名称。(注:正是由于这个原因,我们一般说的SID就是instance\_name,但是需要注意的是,实际上instance\_name不等于ORACLE\_SID。前者是数据库层面的概念,后者是操作系统中环境变量的设置。)
ORACLE\_SID is used to distinguish this instance from other Oracle Database instances that you may create later and run concurrently on the same host computer. The maximum number of characters for ORACLE\_SID is 12, and only letters and numeric digits are permitted. On some platforms, the SID is case-sensitive.
参考资料:
https://gerardnico.com/db/oracle/global_name
https://docs.oracle.com/cd/B28359_01/server.111/b28320/initparams059.htm#REFRN10041 https://blog.csdn.net/tanwen1234/article/details/11991743 https://yq.aliyun.com/articles/248995 https://docs.oracle.com/cd/B28359_01/server.111/b28310/ds_admin001.htm#BEGIN`

最后修改:2022 年 02 月 08 日
如果觉得我的文章对你有用,请随意赞赏