Managing Services Associated with PDBs

本文详细介绍了如何在Oracle数据库中管理PDB(Pluggable Database)的服务,包括创建、修改和移除服务。强调了默认服务仅用于管理,不应用于应用程序连接,并且每个服务名称必须在CDB内唯一。还提供了使用SRVCTL和DBMS_SERVICE包进行操作的示例。

创建PDB时会自动创建它的默认service,名字与pdb名相同,此servcie是用于DBA管理的,尽量不要用于应用连接,因为没有SERIVE属性,用也无所谓

PDB数据库是以动态监听连接的,PDB无法使用静态服务( 因为PDB不是一个实例,无法使用SID作实例名)

When a PDB is created, a new default service for the PDB is created automatically, and this service has the same name as the PDB. You cannot manage this service, and it should only be used for administrative tasks. Do not use this default PDB service for applications. Always use user-defined services for applications because you can customize user-defined services to fit the requirements of your applications.

Note:

  1. Each database service name must be unique in a CDB, and each database service name must be unique within the scope of all the CDBs whose instances are reached through a specific listener.

When two or more CDBs on the same computer system use the same listener and two or more PDBs have the same service name in these CDBs, a connection that specifies this service name connects randomly to one of the PDBs with the service name. To avoid incorrect connections, ensure that all service names for PDBs are unique on the computer system, or configure a separate listener for each CDB on the computer system.

  1. When you unplug or drop a PDB, the services of the unplugged or dropped PDB are not removed automatically. You can remove these services manually.
  2. Do not associate a service with a proxy PDB.

Creating, Modifying, or Removing a Service for a PDB

You can create, modify, or remove a service with a PDB property.

You can do so in the following ways:

  1. If your single-instance database is being managed by Oracle Restart or your Oracle RAC database is being managed by Oracle Clusterware, then use the Server Control (SRVCTL) utility to create, modify, or remove the service.

To create a service for a PDB using the SRVCTL utility, use the add service command and specify the PDB in the -pdb parameter. If you do not specify a PDB in the -pdb parameter when you create a service, then the service is associated with the root.

You can use other SRVCTL commands to manage the service, such as the start service and stop service commands, even if they do not include the -pdb parameter.

  1. If your database is not being managed by Oracle Restart or Oracle Clusterware, then use the DBMS_SERVICE package to create or remove a database service.

To create a service with a PDB property set to a specific PDB using the DBMS_SERVICE package, run the CREATE_SERVICE procedure when the current container is that PDB. If you create a service using the CREATE_SERVICE procedure when the current container is the root, then the service is associated with the root.

Note: If your database is being managed by Oracle Restart or Oracle Clusterware, then use the SRVCTL utility to manage services. Do not use the DBMS_SERVICE package.

查看SERVICE:

col name format a20

col pdb format a20

select con_id,name, PDB from cdb_services;

COL NAME FORMAT A30

COL CON_NAME FORMAT A20

SELECT NAME,CON_NAME, CON_ID FROM V$ACTIVE_SERVICES;

  1. USING SRVCTL Utility

This example adds the salesrep service for the PDB salespdb in the CDB with DB_UNIQUE_NAME mycdb:

srvctl add service -db mycdb -service salesrep -pdb salespdb

Modifying the PDB Property of a Service Using the SRVCTL Utility

This example modifies the salesrep service in the CDB with DB_UNIQUE_NAME mycdb to associate the service with the hrpdb PDB:

$ srvctl modify service -db mycdb -service salesrep -pdb hrpdb

Removing a Service Using the SRVCTL Utility

$ srvctl remove service -db mycdb -service salesrep

  1. USING DBMS_SERVICE

SQL> Alter session set container=pdb1;

SQL> EXEC DBMS_SERVICE.CREATE_SERVICE(service_name => 'hr', network_name => 'hr');

SQL> EXEC DBMS_SERVICE.START_SERVICE(service_name => 'hr');

SQL> ALTER SYSTEM REGISTER;

连接PDB1:

$ lsnrctl status

$ sqlplus scott/tiger@127.0.0.1/hr

$ sqlplus scott/tiger@127.0.0.1/pdb1

SQL> EXEC DBMS_SERVICE.DISCONNECT_SESSION(

service_name => 'hr', disconnect_option=>DBMS_SERVICE.NOREPLAY);

SQL> EXEC DBMS_SERVICE.STOP_SESSION(service_name => 'hr');

SQL> Exec DBMS_SERVICE.DELETE_SERVICE('hr');

  1. PARAMETER SERVICE_NAMES

PDB是无法更改SERVICE_NAMES参数的,即此方法配置服务只能用于CDB$ROOT.

CDB$ROOT中使用ALTER SYSTEM SET SERVICE_NAMES会隐式在数据字典创建service,并自动开始此服务,可以使用dbms_service或srvctl来start/stop/modify/disconnect更改此服务,但不能删除它

GNU Make 是一个广泛使用的项目管理工具,它可以帮助我们自动化构建和管理项目。它的核心思想是基于规则来定义项目的构建过程。 首先,我们需要在项目的根目录中创建一个名为“Makefile”的文件,用于定义项目的规则和依赖关系。Makefile 是用来告诉 GNU Make 如何构建和更新项目的文件,它由一系列规则组成。 每个规则由一个目标(target)和相应的依赖列表组成。目标是指我们希望生成的文件或执行的操作,而依赖列表则表示生成目标所需要的文件或操作。当某个目标的依赖发生变化时,GNU Make 将会自动检测并更新相应的目标。 在 Makefile 中,我们可以使用一些预定义的变量来简化配置,如 CC 表示编译器,CFLAGS 表示编译选项等。我们还可以定义自己的变量,以便在规则中使用。 通过定义规则和依赖关系,我们可以利用 GNU Make 来自动构建项目。当我们运行 make 命令时,GNU Make 将会读取 Makefile,并根据规则和依赖关系来判断哪些目标需要重新构建,然后执行相应的命令。 GNU Make 还支持一些高级特性,如条件判断、循环、递归等,这使得我们可以根据不同的情况来定义不同的规则和行为。 总之,GNU Make 是一个强大而灵活的项目管理工具,它允许我们根据项目的需求来定义规则和依赖关系,并自动化构建过程,提高项目的开发效率和可维护性。无论是小型项目还是大型项目,GNU Make 都是一个极为有用的工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值