oracle 中的 DB_NAME、DB_DOMAIN、DB_UNIQUE_NAME--转

  • 💡这篇文章主要讲的这几个参数:
    DB相关的:DBID,SID_NAME,db_domain,instance_name,
    PFILE中的参数::DB_NAME,DB_DOMAIN, INSTANCE_NAME,DB_UNIQUE_NAME,SERVICE_NAMES,GLOBAL_NAME,GLOBAL_NAMES
    Listener.ora 中参数:SID_NAME,GLOBAL_DBNAME
    Tnsnames.ora 中参数:SERVICE_NAME,SID
  • 💭 与DB相关的两个参数
    DB_ID\SID
    • 1.1 DBID(DataBase IDentifier)
      • Oracle 官网对 DBID 的解释如下:An internal, uniquely generated number that differentiates databases. Oracle creates this number automatically when you create the database.
      • 查看DBID:
        • SQL>select dbid from nv$database;
        • DBID----------1262006473
      • 我们可以用命令来修改 DBID, 这个官网有说明:
        • 修改的步骤:
          • 将数据库启动到mount状态下;
          • 用nid命令修改:nid TARGET=/DBNAME=tainlesoftware;
          • 修改之后,在启动到mount状态下:startup mount;
          • resetlogs 打开数据库:alter database openresetlogs;
          • 要注意一点:在修改DBID之后,之前备份的和归档都将无效,具体参考官网内容;
            • Ramifications of Changing the DBID and DBNAMEChanging the DBID of a database is a serious procedure. When the DBID of a database is changed, all previous backups and archived logs of the database become unusable. This is similar to creating a database except that the data is already in the datafiles. After you change the DBID, backups and archive logs that were created prior to the change can no longer be used because they still have the original DBID, which does not match the current DBID. You must open the database with the RESETLOGS option, which re-creates the online redo logs and resets their sequence to 1 (see the Oracle Database Administrator's Guide). Consequently, you should make a backup of the whole database immediately after changing the DBID.Changing the DBNAME without changing the DBID does not require you to open with the RESETLOGS option, so database backups and archived logs are not invalidated. However, changing the DBNAME does have consequences. You must change the DB_NAME initialization parameter after a database name change to reflect the new name. Also, you may have to re-create the Oracle password file. If you restore an old backup of the control file (before the name change), then you should use the initialization parameter file and password file from before the database name change. from:Ramifications of Changing the DBID and DBNAME
    • 1.2 SID
      • 官网的说明如下:The system identifier (SID) is a unique name for an Oracle database instance on a specific host. On UNIX and Linux, Oracle Database uses the SID and Oracle homevalues to create a key to shared memory. Also, the SID is used by default to locate the parameter file, which is used to locate relevant files such as the database control files.On most platforms, the ORACLE_SID environment variable sets the SID, whereas the ORACLE_HOME variable sets the Oracle home. When connecting to an instance, clients can specify the SID in an Oracle Net connection or use a net service name. Oracle Database converts a service name into an ORACLE_HOME and ORACLE_SID.系统标识符(SID)是特定主机上Oracle数据库实例的唯一名称。在UNIX和Linux上,Oracle数据库使用SID和Oracle HOME来创建共享内存的密钥。此外,默认情况下,SID用于定位参数文件,参数文件用于定位相关文件,如数据库控制文件。在大多数平台上,Oracle_SID环境变量设置SID,而Oracle_HOME变量设置Oracle HOME。当连接到实例时,客户端可以在Oracle网络连接中指定SID或使用网络服务名称。Oracle数据库将服务名称转换为Oracle_HOME和Oracle_SID。
      • 查看SID:
        • SQL> select instance_name from v$instance;
          • INSTANCE_NAME----------------orcl
        • 尽管 v$instance 中字段 instance_name 看起来是实例名,但是实际上存储的是 sid。在 win 下, 不管 oracle_home 是否相同,sid 不能重复。在 unix/linux 下只要不同版本的 oracle 安装在不同的 oracle_home 下就可以创建相同 sid 的实例,但是 win 下不可以,主要是受到 windows 服务的限制,在服务中不能存在服务名相同的 oracle 服务,服务名是由如下格式组成的:OracleServiceSID,因为服务名中包括了 sid,所以 sid 如果相同了,服务名就相同了,这是 windows 所不允许的。因此在 win 下无法创建相同 sid 的不同实例。
  • 🏃‍♂️ Pfile 中的参数
    DB_NAME、DB_DOMAIN、DB_UNIQUE_NAME
    • 1、DB_NAME
      • 官网的说明如下: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 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.From:http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/initparams062.htm#REFRN10041
        • DB_NAME 是数据库名,它的长度不能超过八个字节,超过八个字节会被截断。对于RAC环境,各个节点之间的DB_NAME都是相同的,instance_name不同。对于DG环境,DB-NAME 不同。
        • DB_NAME记录在datafile,redo log 和control file 中。这个记录fang'shi'tong'guo DBID 就是db_name的算法来生成的。
        • 还是借用身份证的比喻:DB_NAME就是姓名,DBID 就是身份证。所以如果要修改 DB_NAME,只能用 nid 命令来修改 DBID,然后修改相关pfile 参数。
        • 查看 DB_NAMESQL> show parameter db_name
        • NAME TYPE VALUE
        • ------------------------------------ ----------- ------------------------------db_name string orcl
        • SQL> select dbid,name from v$database;
        • DBID NAME---------- ---------1262006473 ORCL
        • db_name 还有一个非常重要的作用就是动态注册监听. 关于动态注册和静态注册,参考 Blog:
          • Oracle Listener动态注册与静态注册:
            • 1、什么是注册?、
              • 注册就是将数据库作为一个服务注册到监听程序。客户端不需要知道数据库名和实例名,只需要知道该数据库对外提供的服务名就可以申请连接到数据库。这个服务名可能与实例名一样,也有可能不一样。
              • 在数据库服务器启动过程中,数据库服务器会向监听程序注册相应的服务(无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。)
              • 相当于是这样:在数据库服务器和客户端之间有一监听程序(Listener),在监听程序中,会记录相应数据库对应的服务名(一个数据库可能对应有多个服务名),当客户端需要连接数据库时,只需要提供服务名,就可以建立客户端和服务器之间的连接。
            • 2、什么是动态注册?
              • 动态注册是在instance启动的时候PMON进程根据init.ora中的instance_name,service_names两个参数将实例和服务动态注册到listener中。
              • 首先要在init.ora中指定instance_name,service_names两个参数的值。在sqlplus下通过show parameter service_names 和show parameter instance_name可以查看这两个参数的值。
              • 注册到监听器中的实例值从init.ora文件中的instance_name参数取得。如果该参数没有设定值,那么它将取init.ora文件中的db_name的值。如果在RAC中配置,您必须将集群中每个实例的instance_name参数设置为一个唯一的值。
              • 册到监听器中的服务值从init.ora文件中的参数service_names取得。如果该参数没有设定值,数据库将拼接init.ora文件中的 db_name和db_domain的值来注册自己。如果选择提供service_names值,您可以使用完全限定的名称(比如 orcl.oracle.com)或缩写的名称(比如orcl)。如果选择缩写的名称并设置了db_domain参数,注册到监听器中的服务将是 service_name值和db_domain值的拼接。例如下面的设置将导致服务orcl.oracle.com被注册到监听器中:db_domain=oracle.comservice_names=orcl ;
                • 采取动态注册方法时,listener.ora中的内容如下:
                  • 可选择的是,您可以在service_names参数中指定多个服务值,值之间用逗号格开,这对于共享服务器配置是很有用的。
                  • 动态注册默认只注册到默认的监听器上(名称是LISTENER、端口是1521、协议是TCP),因为pmon只会动态注册port等于1521的监听,否则pmon不能动态注册listener,如果需要向非默认监听注册,则需要配置local_listener参数!
                  • 将监听的信息添加到tnsnames.ora 文件中。 注意,是tnsnames.ora 文件, 因为pmon在动态注册监听时要从tnsnames.ora中读取相关信息。
                  • 如果没有显式设置service_names和instance_name的值,那么仅当数据库在监听器运行之后启动时,动态注册才会发生;在这种情况下,如果监听器后来发生了重启,动态注册信息将会丢失。显然,最好在所有的数据库启动之前先启动监听器,这样就会避免没有显式设置 service_names和instance_name的值时,若重启监听器带来的动态注册信息丢失的情况。
                  • 为初始化参数service_names和instance_name设置显式的值是个很好的实践,尽管如果您没有设置它们,Oracle也会为动态注册而生成默认值(基于db_name和db_main)。这样做的原因是,如果监听器在数据库启动之后重新启动,其动态注册行为将会有一些微妙的区别.如果监听器在数据库运行之后重新启动,你们仅当您在init.ora文件中显式地设置了service_names和instance_name的值时,每个数据库的PMON进程才会在很短的时间之后自动注册数据库。
                  • 如果需要执行连接时故障转移或负载均衡,或者想要在RAC中配置在实例之间透明地分布连接,那么使用service_names参数将是必要的。为启用这些功能,您只需要将每个实例的数据库参数文件中的service_names设置为同一个值,并在客户端连接请求的service_name设置中引用该值。
                  • 如果没有显式设置service_names和instance_name的值,那么仅当数据库在监听器运行之后启动时,动态注册才会发生;在这种情况下,如果监听器后来发生了重启,动态注册信息将会丢失。显然,最后在启动任何数据库之前启动服务器上的监听器,并完全避免监听器的重启。
                  • 另外,您还可以在SQL*PLUS中使用命令:
                  • SQL>ALTER SYSTEM REGISTER;
                  • 在数据库打开时的任何时候,手工地在监听器中注册服务值。这个命令对于替换因监听器重启而丢失地服务值很有用,并且它所注册地值与在数据库启动时由动态注册所设置的值完全一样。
                  • 动态监听:
                    • oracle监听器运行后,oracle实例在open时,会动态向监听程序注册其service_names和instance_name。
                    •   其中instance_name默认是:db_name
                    •   而service_names默认是:db_name.db_domain
                  •  
            • 3、静态注册
              • 静态注册就是实例启动时读取listener.ora文件的配置,将实例和服务注册到监听程序。无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。
              • 静态注册时,listener.ora中的GLOBAL_DBNAME向外提供服务名,listener.ora中的SID_NAME提供注册的实例名。
              • 采取静态注册方法时,listener.ora中的内容如下:
              • 该文件表明数据库是单实例的,实例名为orcl,向外提供了两个服务:orcl和orcl1
                • 静态监听:
                •  oracle实例运行后,监听程序启动时,根据listener.ora的配置注册相应的服务。
                •   其中global_dbname对应的是oracle对外的服务名,即初始化参数里的service_names
                • 而sid_name对应的是oralce实例的名称,即初始化参数里的instance_name
                • 既然有动态监听为什么还要静态监听呢?原因如下:
                  • 1.监听器不是最早启动,oracle实例先启动
                  • 2.监听器重启
                  • 3.oracle实例没有open
                •  
            • 4、查询某服务是静态注册还是动态注册?
              • 可以使用命令lsnrctl status来查看某服务是静态注册还是动态注册。
              • 实例状态为UNKNOWN值时表明此服务是静态注册的设置。这时监听器用来表明它不知道关于该实例的任何信息,只有当客户发出连接请求时,它才检查该实例是否存在。
              • 动态注册的数据库通过状态信息中的状态READY或状态BLOCKED(对于一个备用数据库)来指明。不管关闭何时数据库,动态注册的数据库都会动态地从 监听器注销,而与之相关的信息将从状态列表中消失。这样,不管数据库是在运行还是已经关闭,监听器总是知道它的状态。该信息将被用于连接请求的回退(fallback)和负载平衡。
          • 不管是否指定了 service_name,或者说 service_name 的值是什么,pmon 都会使用 db_name 动态注册监听的。
          • 注册到监听器中的服务值从 init.ora 文件中的参数 service_names 取得。如果该参数没有设定值,数据库将拼接 init.ora 文件中的 db_name 和 db_domain 的值来注册自己。如果选择提供 service_names 值,您可以使用完全限定的名称(比如 orcl.oracle.com)或缩写的名称(比如 orcl)。如果选择缩写的名称并设置了db_domain 参数,注册到监听器中的服务将是 service_name 值和 db_domain 值的拼接。
    • 2、DB_DOMA
    • IN
      • 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 (#).
    • 3、DB_UNIQUE_NAME
    •  

      • DB_UNIQUE_NAME specifies a globally unique name for the database. Databases with the same DB_NAME within the same DB_DOMAIN (for example, copies of a database created for reporting or a physical standby) must have a unique DB_UNIQUE_NAME. Every database's DB_UNIQUE_NAME must be unique within the enterprise.-- 对于 DB_NAME 系统的的数据库必须要有不同的 DB_UNIQUE_NAME。Data Guard 就是这么回事。The value of DB_UNIQUE_NAME can be up to 30 characters and is case insensitive. The following characters are valid in a database name: alphanumeric characters, underscore (_), number sign (#), and dollar sign ($)
      • DB_UNQUIE_NAME 的会影响到 Service_names,也会影响到动态监听的时候的 service_name。 如在 Data Guard 环境下,如果采用动态注册,那么注册的Service 就是 DB_UNIQUE_NAME。 但 instance 还是 instance_name,即 SID.
      • 如:Service " orcl_st " has 1 instance(s).Instance "orcl", status BLOCKED, has 1 handler(s) for this service...Service " orcl_st _XPT" has 1 instance(s).Instance "orcl", status BLOCKED, has 1 handler(s) for this service...The command completed successfully
    •  
    • 4、INSTANCE_NAME
    •  

      • 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.
      • INSTANCE_NAME 的默认值就是 SID。 一般跟数据库库名称相同,也可以不相同。
  •  

转至墨天轮

https://www.modb.pro/db/391624

 

posted @ 2022-12-07 16:37  心愿666  阅读(1000)  评论(0编辑  收藏  举报