在Oracle中有關數據庫和數據庫實例的幾個重要概念,有時候如果理解不是很深或者對其疏忽、混淆了,還真容易搞錯或弄不清其概念,下面就數據庫實例名、數據庫名、數據庫域名、數據庫服務名、全局數據庫名幾個概念,我們來梳理一下概念,總結歸納一下這些知識,首先,我們來看看官方文檔對這幾者的概念介紹:
INSTANCE_NAME(數據庫實例名)
| Property |
Description |
| Parameter type |
String |
| Syntax |
INSTANCE_NAME = instance_id |
| Default value |
The instance's SID Note: The SID identifies the instance's shared memory on a host, but may not uniquely distinguish this instance from other instances. |
| Modifiable |
No |
| Range of values |
Any alphanumeric characters |
| Basic |
No |
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(數據庫名)
| Property |
Description |
| Parameter type |
String |
| Syntax |
DB_NAME = database_name |
| Default value |
There is no default value. |
| Modifiable |
No |
| Basic |
Yes |
| Real Application Clusters |
You 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(數據庫域名)
| Property |
Description |
| Parameter type |
String |
| Syntax |
DB_DOMAIN = domain_name |
| Default value |
There is no default value. |
| Modifiable |
No |
| Range of values |
Any legal string of name components, separated by periods and up to 128 characters long (including the periods). This value cannot be NULL. |
| Basic |
Yes |
| Real Application Clusters |
You 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
| Property |
Description |
| Parameter type |
Boolean |
| Default value |
false |
| Modifiable |
ALTER SESSION, ALTER SYSTEM |
| Range of values |
true | false |
| Basic |
No |
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:
| Component |
Parameter |
Requirements |
Example |
| Database name |
DB_NAME |
Must be eight characters or less. |
sales |
| Domain containing the database |
DB_DOMAIN |
Must 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
| Property |
Description |
| Parameter type |
String |
| Syntax |
SERVICE_NAMES = db_service_name [, db_service_name [ ... ] ] |
| Default value |
DB_UNIQUE_NAME.DB_DOMAIN if defined |
| Modifiable |
ALTER SYSTEM |
| Range of values |
Any ASCII string or comma-separated list of string names |
| Basic |
No |
| Real Application Clusters |
Do 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
