签到成功

知道了

CNDBA社区CNDBA社区

Oracle rac 为pdb添加service

2022-01-14 13:49 1305 0 翻译 oracle
作者: sanynkc

默认情况下,容器数据库(CDB)只为每个连接的可插拔数据库(PDB)提供一个服务,但我们可以为各种应用程序条目创建自己的服务。

有两种方法可以将服务添加到PDB:

DBMS_服务为PDB创建服务

它是一个用于管理数据库服务的管理包。https://www.cndba.cn/sanynkc/article/106565

SRVCTL向PDB添加服务

对于RAC数据库或Oracle重启,我们可以使用它来管理服务。https://www.cndba.cn/sanynkc/article/106565

A.DBMS_服务为PDB创建服务https://www.cndba.cn/sanynkc/article/106565

对于单个实例,我们只能使用DBMS_服务向PDB添加服务。

1.检查侦听器

让我们看看侦听器的当前状态。

[oracle@test ~]$ lsnrctl status

Services Summary…
Service “ORCLCDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “ORCLCDBXDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “aa736f65d66215cce053992aa8c08959” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “orclpdb” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
The command completed successfully
As you can see, the default service ORCLPDB of the PDB now registers with listener.

2.切换容器

让我们看看我们有什么PDB。

SQL> show pdbs

CON_ID CON_NAME                       OPEN MODE  RESTRICTED

     2 PDB$SEED                       READ ONLY  NO
     3 ORCLPDB                        READ WRITE NO

Let’s switch container to the PDB.

SQL> alter session set container=ORCLPDB;

Session altered.
Make sure that we are in the right container.

SQL> show con_namehttps://www.cndba.cn/sanynkc/article/106565

CON_NAME

ORCLPDB
Let’s see current services of the container before adding a service to it.

https://www.cndba.cn/sanynkc/article/106565

SQL> column con_id format 99
SQL> column pdb format a15
SQL> column network_name format a30
SQL> select con_id, pdb, network_name from cdb_services where pdb is not null and con_id > 2 order by pdb;

CON_ID PDB NETWORK_NAME


 3 ORCLPDB         ORCLPDB 

3.向PDB添加服务

创建服务

SQL> exec dbms_service.create_service(‘ERP’, ‘ERP’);

PL/SQL procedure successfully completed.

无论是单个实例还是RAC数据库,该服务都会添加到当前PDB中

启动服务
SQL> exec dbms_service.start_service(‘ERP’);

PL/SQL procedure successfully completed.

对于RAC数据库,应在群集中的所有实例上启动服务:

SQL> exec dbms_service.start_service(‘ERP’, DBMS_SERVICE.ALL_INSTANCES);

PL/SQL procedure successfully completed.
保存此容器的当前状态。
SQL> alter pluggable database orclpdb save state;

Pluggable database altered.
对于RAC数据库,您应该在群集中的所有实例上保存PDB的状态:

SQL> alter pluggable database orclpdb save state instances=all;

Pluggable database altered.

在PDB或所有PDB的保存状态上有更多的变化。

https://www.cndba.cn/sanynkc/article/106565

检查rac集群的服务。
在向容器添加服务后,让我们看看容器的当前服务。

SQL> select con_id, pdb, network_name from cdb_services where pdb is not null and con_id > 2 order by pdb;https://www.cndba.cn/sanynkc/article/106565

CON_ID PDB NETWORK_NAME


 3 ORCLPDB         ERP
 3 ORCLPDB         ORCLPDB

Let’s check online services of current PDB.

SQL> column name format a30;
SQL> column network_name format a30;
SQL> select name, network_name from v$active_services;

NAME NETWORK_NAME


orclpdb orclpdb
ERP ERP
For RAC databases, you may see the information like this:

SQL> select inst_id, name, network_name from gv$active_services;

INST_ID NAME NETWORK_NAME


     1 orclpdb                        orclpdb
     1 ERP                            ERP
     2 orclpdb                        orclpdb
     2 ERP                            ERP
  1. 再次检查监听
    查看监听状态

[oracle@test ~]$ lsnrctl status

Services Summary…
Service “ERP” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “ORCLCDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “ORCLCDBXDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “aa736f65d66215cce053992aa8c08959” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “orclpdb” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
The command completed successfully
We have a new service which registers with the new listener.

  1. 连接测试
    使用sqlplus 连接测试

C:/Users/edchen>sqlplus hr/hr@192.168.0.11:1521/erp

SQL> select count(*) from employees;

COUNT(*)

   107

已经连接到pdb

  1. 删除服务
    如果删除服务,先停止服务

SQL> show con_name

CON_NAME

ORCLPDB
SQL> exec dbms_service.stop_service(‘ERP’, DBMS_SERVICE.ALL_INSTANCES);

PL/SQL procedure successfully completed.
Then delete it.

SQL> exec dbms_service.delete_service(‘ERP’);https://www.cndba.cn/sanynkc/article/106565

PL/SQL procedure successfully completed.

B. SRVCTL 添加服务到pdb

  1. 添加服务
    在rac环境中,使用如下命令添加服务

[oracle@primary01 ~]$ srvctl add service -d orclcdb -s CRM -pdb ORCLPDB -preferred ORCLCDB1,ORCLCDB2

  1. 启动服务
    [oracle@primary01 ~]$ srvctl start service -d orclcdb -s crm

  2. 检查服务
    [oracle@primary01 ~]$ srvctl status service -d orclcdb -s crm
    Service CRM is running on instance(s) ORCLCDB1,ORCLCDB2
    Now we should check the statuses of both listeners.

    https://www.cndba.cn/sanynkc/article/106565
    https://www.cndba.cn/sanynkc/article/106565

Node 1
[oracle@primary01 ~]$ lsnrctl status

Service “CRM” has 1 instance(s).
Instance “ORCLCDB1”, status READY, has 1 handler(s) for this service…
Node 2
[oracle@primary02 ~]$ lsnrctl status

Service “CRM” has 1 instance(s).
Instance “ORCLCDB2”, status READY, has 1 handler(s) for this service…
The service is ready to accept connections.

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
sanynkc

sanynkc

关注
  • 0
    原创
  • 1
    翻译
  • 0
    转载
  • 0
    评论
  • 访问:1306次
  • 积分:41
  • 等级:注册会员
  • 排名:第51名
精华文章
    最新问题
    查看更多+
    热门文章
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ