Friday, December 8, 2023

Script sniplet to differentiate between cdb and pdb environment settings in a shell script

This little sniplet could be used if you find yourself in a situation where you need to differentiate between the cdb environment and the pdb environment on a server using multitenant setup.

I am setting a commonly used alias for the usage of sqlplus called "sql" depending on the ORACLE_SID being set to the cdb or the pdb.

It differs slightly since I you can only do a bequath session when connecting to the former, and not the latter:

  • When connecting to the pdb as sysdba, you need to go through the listener, and therefore supply the password.
  • When connecting to the cdb you can do a so called bequeath session and connect directly to the oracle instance through IPC.
    read -p 'Will you be administrating the cdb or the PDB? ' container
    case $container in
            CDB|cdb)
            . $ORACLE_HOME/cdb_settings.env;
            alias sql='sqlplus / as sysdba';;
            PDB1|pdb1)
            . $ORACLE_HOME/pdb1.env;
            alias sql='sqlplus sys@pdb1 as sysdba';;
            *) echo "You must select cdb or pdb1";
             exit 1;;
    esac
    
  • No comments:

    Post a Comment