catcon.pl cheat sheet Mustafa, 2022-08-262023-04-24 Hello, Oracle uses a container database architecture permanently anymore, you should be familiar with “catcon.pl” perl file. Let’s say you have container database with 10 different PDBs and you need to run a script file on all of those pdbs (maybe even in root and seed too) so what you need is catcon.pl. catcon.pl will automatically execute your script file and run it on all or specified containers. Since it is a perl file it must be called with perl binary (perl in linux, perl.exe in windows) and you can find it under $ORACLE_HOME/perl/bin directory and catcon.pl itself is under $ORACLE_HOME/rdbms/admin . so, you have a sql file to run under the /home/oracle/scripts directory called myfile.sql. let’s see how we can execute it in all pdbs: Shell $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -d /home/oracle/scripts -b MyScript myfile.sql 1 $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -d /home/oracle/scripts -b MyScript myfile.sql that is it. myfile.sql file will be run in all containers (including root and seed) with the command above. Let’s dissect the command: $ORACLE_HOME/perl/bin/perl => PERL binary to run catcon.pl $ORACLE_HOME/rdbms/admin/catcon.pl => catcon.pl path -d /home/oracle/scripts => directory where script is located. -b MyScript => Prefix for the log files so you can separate them from other scripts logs. myfile.sql => actual script name actual script file must be the last parameter. It is that easy. in this example ORACLE_HOME and ORACLE_SID should be set before you run the command otherwise you cannot connect to the database. This is a local connection and by default it is a SYSDBA connection. So whatever you run will be run under SYS user. To add some more functionality: -c : list of containers that you want to execute the script: ….catcon.pl -c ‘SALES PDB1 TEST’ => execute the script only at SALES, PDB1 and TEST pdbs. -C : list of containers that you don’t want to execute the script. -l : log directory -s : spool the output of script files. -S : (capital S) don’t execute the script in root and seed. (Edit: this option also don’t set “_oracle_scripts” parameter as true, so if you are creating a user it won’t be Oracle Maintained user) -u : specify username/password. -z : ez-connect string -n : number of workers. if you want to execute a script for 100 pdbs then you can increase the number of workers to execute script simultaneously on different pdbs. default is 1 -e : set echo on -r : run script in Reverse order, first in pdbs then cdb. useful while removing an Oracle component like multimedia (it is desupported). Can we use catcon.pl to run a script on a remote server? Yes with a combination of -u and -z Oracle PL/SQL $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl \ -d /home/oracle/scripts \ -b MyScript \ -l /home/oracle/logs \ -u mustafa/mustafa \ -z mydbserver.mydomain:1521/CDBX \ -n 2 \ -c 'PDB1 PDB2 PDB3 PDB4 PDB5 PDB6 PDB7 PDB8' myfile.sql 123456789 $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl \-d /home/oracle/scripts \-b MyScript \-l /home/oracle/logs \-u mustafa/mustafa \-z mydbserver.mydomain:1521/CDBX \-n 2 \-c 'PDB1 PDB2 PDB3 PDB4 PDB5 PDB6 PDB7 PDB8'myfile.sql run myfile.sql script under /home/oracle/scripts directory on CDBX database and only specified pdbs (PDB1…PDB8) which is on mydbserver.mydomain server using mustafa user and create 2 worker process so script will be run on 2 pdbs at a time and write log files under /home/oracle/logs. catcon has more parameters but I just write about the ones I used most. thanks for reading. edit: I add -r and -e options. 12c 18c 19c 21c Administration Development Multi-tenant all containersall pdbscatconcatcon.plexecute scriptmulti-tenant