If you are initiating a remote connection through the network, then you need to first set up a listener on the target database server and create a password file (see Chapter 2 for details). Once the listener and password files are established, you can connect remotely over the network, as shown here:
$ sqlplus user/password@connection_string SQL> show user con_id con_name user
USER is “user” CON_ID———–3
CON_NAME—————MMPDB
USER is “user”
For details on implementing a listener for pluggables, see Chapter 2; we also review it later in this chapter.
Displaying Currently Connected Container Information
There are a couple of easy techniques for displaying the name of the CDB that you are currently connected to. This example uses the SHOW command to display the container ID, the name, and the user:
SQL> show con_id con_name user
You can also display the same information via an SQL query:
SQL> SELECT SYS_CONTEXT(‘USERENV’, ‘CON_ID’) AS con_id, SYS_CONTEXT(‘USERENV’, ‘CON_NAME’) AS cur_container, SYS_CONTEXT(‘USERENV’, ‘SESSION_USER’) AS cur_user
FROM DUAL;
Here is some sample output:
CON_ID CUR_CONTAINER CUR_USER
1 CDB$ROOT USER
Starting/Stopping the Root Container
You can start/stop the CDB only while connected as a privileged user to the root container. To start a CDB, first connect as SYS or a user with SYSOPER privileges, and issue the startup command:
$ sqlplus / as sysdba SQL> startup;
Starting the CDB database does not open any associated PDBs unless you have saved the state of the PDB to open automatically. It is recommended to make sure you set the PDBs to start automatically. You can open all PDBs with this command:
SQL> alter pluggable database all open;
To shut down a CDB database, issue the following command:
SQL> shutdown immediate;
The prior line shuts down the CDB instance and disconnects any users connected to the database. If any pluggable databases are open, they are closed, and users are disconnected.
For Oracle Restart, the SRVCTL command can be used to start, modify, and stop instances. SRVCTL can be used for CDBs and PDBs, and services need to be created for the PDBs.
$ srvctl start database
The environment variables are part of the Oracle Restart configuration, and there are several parameters that can be passed in for starting up with different spfiles and parameter files using start options such as mount, restrict, open, and recover.
$ srvctl stop database – db mmdb23c
The default option is immediate, but you can specify stop options of normal and abort.
To create a service for a PDB, use the following:
$ srvctl add service -db mmdb23c -service mmpdbsrv -pdb mmpdb
Now you can use the service to perform commands in a RAC environment or configurations for the PDB. You can modify, stop, and start services, as well as relocate, remove, and get the status of services.