创建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:
- 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.
- 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.
- 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:
- 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.
- 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;
- 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
- 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');
- PARAMETER SERVICE_NAMES
PDB是无法更改SERVICE_NAMES参数的,即此方法配置服务只能用于CDB$ROOT.
CDB$ROOT中使用ALTER SYSTEM SET SERVICE_NAMES会隐式在数据字典创建service,并自动开始此服务,可以使用dbms_service或srvctl来start/stop/modify/disconnect更改此服务,但不能删除它
本文详细介绍了如何在Oracle数据库中管理PDB(Pluggable Database)的服务,包括创建、修改和移除服务。强调了默认服务仅用于管理,不应用于应用程序连接,并且每个服务名称必须在CDB内唯一。还提供了使用SRVCTL和DBMS_SERVICE包进行操作的示例。
2085

被折叠的 条评论
为什么被折叠?



