Oracle 12c中多宿主容器数据库(CDBs)和可插拔数据库(2)

Oracle12c中的调度器已被增强,以便可以包含基于脚本的任务,这样,你就可以定义行内脚本,或在文件系统上调用脚本。这些是外部任务的一个变种,但SQL_SCRIPT和BACKUP_SCRIPT任务类型使得处理认证和多宿主环境变得 更加容易。

catcon.pl

当在多宿主环境运行脚本时,DBA遇到的另一个问题是在多个PDBS中运行同样的脚本。这可以通过前面的方法实现,但Oracle提供的叫"catcon.pl"的PERL模块也许更加方便。

在多宿主环境中,有些Oracle提供的脚本必须按照特定顺序执行,先在CDB$ROOT容器中执行。"catcon.pl" 模块可以完成它,并且提供确定容器的日志,这样,你可以很容易的检查任务完成情况。

该模块的完整语法如下,不带参数运行该模块会显示所有的用法。

$ perl catcon.pl

Usage: catcon  [-uusername[/password]] [-U username[/password]]

[-d directory] [-l directory]

[{-c|-C} container] [-pdegree-of-parallelism]

[-e] [-s]

[-E { ON |errorlogging-table-other-than-SPERRORLOG } ]

[-g]

-b log-file-name-base

--

{ sqlplus-script [arguments] |--x } ...

Optional:

-uusername (optional /password; otherwise prompts for password)

used to connect to the database to run user-supplied scripts or

SQL statements

defaults to "/ as sysdba"

-Uusername (optional /password; otherwise prompts for password)

used to connect to the database to perform internal tasks

defaults to "/ as sysdba"

-ddirectory containing the file to be run

-ldirectory to use for spool log files

-ccontainer(s) in which to run sqlplus scripts, i.e. skip all

Containers not named here; for example,

-c 'PDB1 PDB2',

-Ccontainer(s) in which NOT to run sqlplus scripts, i.e. skip all

Containers named here; for example,

-C 'CDB PDB3'

NOTE: -c and -C are mutually exclusive

-pexpected number of concurrent invocations of this script on a given

host

NOTE: this parameter rarely needs to be specified

-esets echo on while running sqlplus scripts

-soutput of running every script will be spooled into a file whose name

will be

__[].

-Esets 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

-gturns on production of debugging info while running this script

Mandatory:

-bbase name (e.g. catcon_test) for log and spool file names

sqlplus-script - sqlplus script to run OR

SQL-statement  - a statement toexecute

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

For example,

perl catcon.pl ... x.sql '--pJohn' '--PEnter Password for John:' ...

$

关于运行Oracle提供的脚本,手册中使用了在所有容器中运行"catblock.sql"脚本的例子。

$ . oraenv

ORACLE_SID = [cdb1] ?

The Oracle base remains unchanged with value/u01/app/oracle

$ cd $ORACLE_HOME/rdbms/admin/

$ perl catcon.pl -d $ORACLE_HOME/rdbms/admin-b /tmp/catblock_output catblock.sql

$ ls /tmp/catblock_output*

catblock_output0.log  catblock_output1.log  catblock_output2.log  catblock_output3.log

$

第一个输出文件包含了来自"cdb$root" and "pdb$seed"容器的输出。最后一个文件包含了该任务的整体状态输出信息。中间的其他文件包含了所有用户自己创建的PDBS的输出。

"catcon.pl"模块也能用来在CDB中所有容器中运行查询。下面的命令在所有容器中运行一个查询,针对每个容器,其信息将会输出到名为"/tmp/tbs_files_outputN.log"的文件中。

$ cd $ORACLE_HOME/rdbms/admin/

$ perl catcon.pl -e -b /tmp/tbs_files_output-- --x"SELECT tablespace_name,file_name FROM dba_data_files"

$ ls /tmp/tbs_files_output*

/tmp/tbs_files_output0.log  /tmp/tbs_files_output1.log  /tmp/tbs_files_output2.log  /tmp/tbs_files_output3.log

$

通过"-c"选项和"-C"选项,你可以包含和排除特定的PDBS。下例通过漏掉root 和seed容器来在所有用户定义的容器中运行一个查询。

$ rm -f /tmp/tbs_files_output*

$ cd $ORACLE_HOME/rdbms/admin/

$ perl catcon.pl -e -C 'CDB$ROOT PDB$SEED' -b/tmp/tbs_files_output -- --x"SELECT tablespace_name,file_name FROM dba_data_files"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/78c351390a5eb7d9c13d8b92bb67f769.html