export ORACLE_SID=cdb1
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
cd $ORACLE_HOME/rdbms/admin
sql / as sysdba -s <<EOF
SHOW PDBS
EXIT;
EOF
SQLcl: Release 19.1 Production on Fri Jul 31 10:20:51 2020
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.7.0.0.0
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 READ WRITE NO
5 PDB3 READ WRITE NO
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.7.0.0.0
$
# Make an output directory.
rm -Rf /tmp/utlrp_output
mkdir /tmp/utlrp_output
# Compile invalid objects in all containers.
perl catcon.pl \
-d $ORACLE_HOME/rdbms/admin \
-l /tmp/utlrp_output \
-b utlrp_output \
utlrp.sql
$ # Show output files.
$ ls -l /tmp/utlrp_output/*
-rw-------. 1 oracle oinstall 9911 Jul 31 10:29 /tmp/utlrp_output/utlrp_output0.log
-rw-------. 1 oracle oinstall 5265 Jul 31 10:29 /tmp/utlrp_output/utlrp_output1.log
-rw-------. 1 oracle oinstall 5264 Jul 31 10:29 /tmp/utlrp_output/utlrp_output2.log
-rw-------. 1 oracle oinstall 5263 Jul 31 10:29 /tmp/utlrp_output/utlrp_output3.log
-rw-------. 1 oracle oinstall 434 Jul 31 10:28 /tmp/utlrp_output/utlrp_output_catcon_7581.lst
$
$ # Check contents.
$ fgrep "Current Container =" /tmp/utlrp_output/*.log
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = CDB$ROOT Id = 1 ====
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = CDB$ROOT Id = 1 ====
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB$SEED Id = 2 ====
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB$SEED Id = 2 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB1 Id = 3 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB1 Id = 3 ====
/tmp/utlrp_output/utlrp_output2.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output2.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output3.log:==== Current Container = PDB3 Id = 5 ====
/tmp/utlrp_output/utlrp_output3.log:==== Current Container = PDB3 Id = 5 ====
$
# Make an output directory.
rm -Rf /tmp/utlrp_output
mkdir /tmp/utlrp_output
# Exclude the root and seed containers (-C, --excl_con).
perl catcon.pl \
-d $ORACLE_HOME/rdbms/admin \
-C 'CDB$ROOT PDB$SEED'
\
-l /tmp/utlrp_output \
-b utlrp_output \
utlrp.sql
$ # Show output files.
$ ls -l /tmp/utlrp_output/*
-rw-------. 1 oracle oinstall 5225 Jul 31 10:31 /tmp/utlrp_output/utlrp_output0.log
-rw-------. 1 oracle oinstall 5225 Jul 31 10:31 /tmp/utlrp_output/utlrp_output1.log
-rw-------. 1 oracle oinstall 5225 Jul 31 10:31 /tmp/utlrp_output/utlrp_output2.log
-rw-------. 1 oracle oinstall 434 Jul 31 10:30 /tmp/utlrp_output/utlrp_output_catcon_7809.lst
$
$ # Check contents.
$ fgrep "Current Container =" /tmp/utlrp_output/*.log
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output2.log:==== Current Container = PDB3 Id = 5 ====
/tmp/utlrp_output/utlrp_output2.log:==== Current Container = PDB3 Id = 5 ====
$
# Make an output directory.
rm -Rf /tmp/utlrp_output
mkdir /tmp/utlrp_output
# Include only PDB2 and PDB3 containers (-c, --incl_con).
perl catcon.pl \
-d $ORACLE_HOME/rdbms/admin \
-c 'PDB2 PDB3'
\
-l /tmp/utlrp_output \
-b utlrp_output \
utlrp.sql
$ # Show output files.
$ ls -l /tmp/utlrp_output/*
-rw-------. 1 oracle oinstall 5225 Jul 31 10:34 /tmp/utlrp_output/utlrp_output0.log
-rw-------. 1 oracle oinstall 5225 Jul 31 10:34 /tmp/utlrp_output/utlrp_output1.log
-rw-------. 1 oracle oinstall 434 Jul 31 10:33 /tmp/utlrp_output/utlrp_output_catcon_7949.lst
$
$ # Check contents.
$ fgrep "Current Container =" /tmp/utlrp_output/*.log
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output0.log:==== Current Container = PDB2 Id = 4 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB3 Id = 5 ====
/tmp/utlrp_output/utlrp_output1.log:==== Current Container = PDB3 Id = 5 ====
$
# Make an output directory.
rm -Rf /tmp/select_output
mkdir /tmp/select_output
# Run query. Exclude the root and seed containers (-C, --excl_con).
perl catcon.pl \
-C 'CDB$ROOT PDB$SEED' \
-l /tmp/select_output \
-b select_output \
-- --x"SELECT SYS_CONTEXT('USERENV', 'CON_NAME') FROM dual"
$ # Show output files.
$ ls -l /tmp/select_output/*
-rw-------. 1 oracle oinstall 2243 Jul 31 10:36 /tmp/select_output/select_output0.log
-rw-------. 1 oracle oinstall 2243 Jul 31 10:36 /tmp/select_output/select_output1.log
-rw-------. 1 oracle oinstall 2244 Jul 31 10:36 /tmp/select_output/select_output2.log
-rw-------. 1 oracle oinstall 438 Jul 31 10:36 /tmp/select_output/select_output_catcon_8069.lst
$
$ # Check contents.
$ fgrep "Current Container =" /tmp/select_output/*.log
/tmp/select_output/select_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output2.log:==== Current Container = PDB3 Id = 5 ====
/tmp/select_output/select_output2.log:==== Current Container = PDB3 Id = 5 ====
$
# Make an output directory.
rm -Rf /tmp/select_output
mkdir /tmp/select_output
# Run query. Exclude the root and seed containers (-C, --excl_con).
perl catcon.pl \
-C 'CDB$ROOT PDB$SEED' \
-l /tmp/select_output \
-b select_output \
-- --x"SELECT SYS_CONTEXT('USERENV', 'CON_NAME') FROM dual" \
--x"SELECT USER FROM dual"
$ # Show output files.
$ ls -l /tmp/select_output/*
-rw-------. 1 oracle oinstall 2243 Jul 31 10:46 /tmp/select_output/select_output0.log
-rw-------. 1 oracle oinstall 3739 Jul 31 10:46 /tmp/select_output/select_output1.log
-rw-------. 1 oracle oinstall 2244 Jul 31 10:46 /tmp/select_output/select_output2.log
-rw-------. 1 oracle oinstall 3582 Jul 31 10:46 /tmp/select_output/select_output3.log
-rw-------. 1 oracle oinstall 438 Jul 31 10:46 /tmp/select_output/select_output_catcon_8220.lst
$
$ # Check contents.
$ fgrep "Current Container =" /tmp/select_output/*.log
/tmp/select_output/select_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output0.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB1 Id = 3 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB3 Id = 5 ====
/tmp/select_output/select_output1.log:==== Current Container = PDB3 Id = 5 ====
/tmp/select_output/select_output2.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output2.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output3.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output3.log:==== Current Container = PDB2 Id = 4 ====
/tmp/select_output/select_output3.log:==== Current Container = PDB3 Id = 5 ====
/tmp/select_output/select_output3.log:==== Current Container = PDB3 Id = 5 ====
$
$ perl catcon.pl
Usage: catcon [-h, --help]
[-u, --usr username
[{/password | -w, --usr_pwd_env_var env-var-name}]]
[-U, --int_usr username
[{/password | -W, --int_usr_pwd_env_var env-var-name]]
[-d, --script_dir directory]
[-l, --log_dir directory]
[{-c, --incl_con | -C, --excl_con} container]
[-p, --catcon_instances degree-of-parallelism]
[-z, --ez_conn EZConnect-strings]
[-e, --echo]
[-s, --spool]
[-E, --error_logging
{ ON | errorlogging-table-other-than-SPERRORLOG } ]
[-F, --app_con Application-Root]
[-V, --ignore_errors errors-to-ignore ]
[-I, --no_set_errlog_ident]
[-g, --diag]
[-v, --verbose]
[-f, --ignore_unavailable_pdbs]
[--fail_on_unopenable_pdbs]
[-r, --reverse]
[-R, --recover]
[-m, --pdb_seed_mode pdb-mode]
[--force_pdb_mode pdb-mode]
[--all_instances]
[--upgrade]
[--ezconn_to_pdb pdb-name]
[--sqlplus_dir directory]
[--dflt_app_module app-module]
-b, --log_file_base log-file-name-base
--
{ sqlplus-script [arguments] | --x
} ...
Optional:
-h, --help
print usage info and exit
-u, --usr
username (optional /password; otherwise prompts for password)
used to connect to the database to run user-supplied scripts or
SQL statements
defaults to "/ as sysdba"
-w, --usr_pwd_env_var
name of environment variable which contains a password for a user
whose name was specified with --usr;
NOTE: should NOT be used if --usr specified a password
-U, --int_usr
username (optional /password; otherwise prompts for password)
used to connect to the database to perform internal tasks
defaults to "/ as sysdba"
-W, --int_usr_pwd_env_var
name of environment variable which contains a password for a user
whose name was specified with --int_usr;
NOTE: should NOT be used if --int_usr specified a password
-d, --script_dir
directory containing the file to be run
-l, --log_dir
directory to use for spool log files
-c, --incl_con
container(s) in which to run sqlplus scripts, i.e. skip all
Containers not named here; for example,
--incl_con 'PDB1 PDB2',
-C, --excl_con
container(s) in which NOT to run sqlplus scripts, i.e. skip all
Containers named here; for example,
--excl_con 'CDB PDB3'
NOTE: --incl_con and --excl_con are mutually exclusive
-p, --catcon_instances
expected number of concurrent invocations of this script on a given
host
NOTE: this parameter rarely needs to be specified
-z, --ez_conn
blank-separated EZConnect strings corresponding to RAC instances
which can be used to run scripts
-e, --echo
sets echo on while running sqlplus scripts
-s, --spool
output of running every script will be spooled into a file whose name
will be
_
_[
].
-E, --error_logging
sets errorlogging on; if ON is specified, default error logging table
will be used, otherwise, specified error logging table (which must
have been created in every Container) will be used
-F, --app_con
causes scripts to run in a Application Root and all Application PDBs
belonging to it;
***CANNOT*** be specified concurrently with -{cC} flags
-V, --ignore_errors
causes catcon to ignore errors encountered during specified operations.
The following options are supported:
script_path == ignore errors while validating script path
-S, --user_scripts
running user scripts, meaning that _oracle_script will not be set and
all entities created by scripts will not be marked as Oracle-maintained
-I, --no_set_errlog_ident
do not issue set Errorlogging Identifier (ostensibly because the
caller already did it and does not want us to override it)
-g, --diag
turns on production of diagnostic info while running this script
-v, --verbose
turns on verbose output which is less verbose than debugging output
-f, --ignore_unavailable_pdbs
instructs catcon to ignore PDBs which are closed or, if --incl_con or
--excl_con was used, do not exist and process existing PDBs which
were specified (explicitly or implicitly) and are open
NOTE: if this flag is not specified and some specified PDBs do not
exist or are not open, an error will be returned and none of
the Containers will be processed.
--fail_on_unopenable_pdbs
by default, if the caller instructs catcon to open PDBs against which
scripts will be run in a certain mode (using --pdb_seed_mode or
--force_pdb_mode), and some of them could not be opened in that mode,
catcon will issue a warning and proceed to execute scripts, skipping
such PDBs.
This option should be specified if the caller prefers that
in such cases catcon report an error and not execute supplied scripts
against any PDBs.
-r, --reverse
causes scripts to be run in all PDBs and then in the Root (reverse
of the default order); required for running catdwgrd.sql in a CDB
-m, --pdb_seed_mode
mode in which PDB should be opened; one of the following values
may be specified:
- UNCHANGED - leave PDB in whatever mode it is already open
- READ WRITE (default)
- READ ONLY
- UPGRADE
- DOWNGRADE
NOTE: if the desired mode is different from the mode in which
PDB is open, it is will be closed and reopened in the
desired mode before running any scripts; after all scripts were
run, it will be restored to the original mode
--pdb_seed_mode should not be specified if --force_pdb_mode
is specified because mode supplied with the latter will apply
to PDB
--force_pdb_mode
mode in which ALL PDBs against which scripts will be run must be
opened; one of the following values may be specified:
- UNCHANGED - leave PDBs in whatever mode they are already
open (default)
- READ WRITE
- READ ONLY
- UPGRADE
- DOWNGRADE
NOTE: if the desired mode is different from the mode in which
some of the PDBs specified by the caller are open, they will be
closed and reopened in the desired mode before running any
scripts; after all scripts were run, they will be restored to
the original mode
--force_pdb_mode should not be specified if --pdb_seed_mode
is specified because mode supplied with the latter will apply
to PDB
-R, --recover
causes catcon to recover from unexpected death of a SQL*Plus process
that it spawned; if not specified, such event will cause catcon to die
-D, --disable_lockdown
causes catcon to disable lockdown profile before running script(s) in
a PDB and reenable them before existing
--all_instances
if used to run scripts against a CDB and if --force_pdb_mode was
specified, catcon will attempt to run scripts on PDBs using all
instances on which a CDB is open
--upgrade
catcon is being invoked in the course of upgrading a database
--ezconn_to_pdb
caller is expected to provide catcon with one or more EZConnect strings
leading to the specified PDB; all specified scripts will be run ONLY
against that PDB; neither --incl_con nor --excl_con may be specified
concurrentrly with this flag
--sqlplus_dir
directory where sqlplus binary which catcon should use can be found
(e.g. if does not include it or if the caller wants
catcon to use a particular version of sqlplus binary)
--dflt_app_module
if specified, value to which catcon should set APPLICATION MODULE
Mandatory:
-b, --log_file_base
base name (e.g. catcon_test) for log and spool file names
sqlplus-script - sqlplus script to run OR
SQL-statement - a statement to execute
NOTES:
- if --x
is the first non-option string, it needs to be
preceeded with -- to avoid confusing module parsing options into
assuming that '-' is an option which that module is not expecting and
about which it will complain
- command line parameters to SQL scripts can be introduced using --p
- interactive (or secret) parameters to SQL scripts can be introduced
using --P
- occupying middle ground between --p and --P, parameters whose values
are stored in environment variables can be specified using --e
(as in --e"env_var_holding_password")
For example,
perl catcon.pl ... x.sql --p"John" --P"Enter Password for John:" ...
or store John's password in environment variable JOHNS_PASSWORD and
then issue
perl catcon.pl ... x.sql --p"John" --e"JOHNS_PASSWORD" ...
$