2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 # Check_MK agent plugin for monitoring ORACLE databases
27 # This plugin is a result of the common work of Thorsten Bruhns
28 # and Mathias Kettner. Thorsten is responsible for the ORACLE
29 # stuff, Mathias for the shell hacking...
31 # This plugin works for Linux, Solaris and AIX.
32 # See http://mathias-kettner.de/cms_monitoring_oracle.html
33 # for more details regarding configuration.
42 echo " mk_oracle [OPTIONS]"
45 echo " Check_MK agent plugin for monitoring ORACLE databases."
46 echo " This plugin works for Linux, Solaris and AIX."
47 echo " See http://mathias-kettner.de/cms_monitoring_oracle.html"
48 echo " for more details regarding configuration."
51 echo " -h, --help Shows this help message and exit"
52 echo " -d Enable full bash debugging"
53 echo " -t Just check the connection"
54 echo " -l, --log Logs certain steps while execution"
55 echo " ('flock' needs to be installed)"
56 echo " -s, --sections S1,S2,.. Only execute stated sections"
57 echo " Note: asynchronous sections are execute"
58 echo " as synchronous sections"
63 while test -n "$1"; do
77 MK_ORA_DEBUG_CONNECT
=1
82 if type flock
> /dev
/null
2>&1; then
91 MK_ORA_SECTIONS
=($
(echo "$1" |
tr ',' '\n'))
102 if [ ! "$MK_CONFDIR" ]; then
103 echo "MK_CONFDIR not set!" >&2
108 if [ ! "$MK_VARDIR" ]; then
109 #TODO Which default? (run_cached/ mk_oracle.found, log file)
110 export MK_VARDIR
=$MK_CONFDIR
114 if [ ! -d "$MK_VARDIR/log" ]; then
115 mkdir
"$MK_VARDIR/log"
119 #TODO ma: Logging texte + stellen pruefen
120 #TODO si: fehlerhandling raus => check plugins
121 #TODO si: log file size ??
122 #TODO mk_ora_db_connect: aufraeumen und def local vars
125 # .--OS env--------------------------------------------------------------.
127 # | / _ \/ ___| ___ _ ____ __ |
128 # | | | | \___ \ / _ \ '_ \ \ / / |
129 # | | |_| |___) | | __/ | | \ V / |
130 # | \___/|____/ \___|_| |_|\_/ |
132 # '----------------------------------------------------------------------'
135 /usr
/bin
/perl
-e 'if (! -f $ARGV[0]){die "0000000"};$mtime=(stat($ARGV[0]))[9];print ($mtime);' "$1"
140 if [ "$OS_TYPE" = 'Linux' ]; then
146 elif [ "$OS_TYPE" = 'SunOS' ]; then
147 # expand the PATH for inetd. Otherwise some stuff in /opt/sfw/bin is not found!
148 export PATH
=$PATH:/usr
/ucb
:/usr
/proc
/bin
:opt
/sfw
/bin
:/opt
/sfw
/sbin
:/usr
/sfw
/bin
:/usr
/sfw
/sbin
:/opt
/csw
/bin
149 GREP
="/usr/xpg4/bin/grep"
150 if [ ! -x "$GREP" ]; then
151 logging
-c "[set_os_env]" "Please make sure that ${GREP} is existing on Solaris. Aborting mk_oracle plugin."
152 echo "Please make sure that $GREP is existing on Solaris!" >&2
153 echo "Aborting mk_oracle plugin." >&2
161 elif [ "$OS_TYPE" = 'AIX' ]; then
167 elif [ "$OS_TYPE" = 'HP-UX' ]; then
170 STATCX
="perl -le 'print((stat shift)[8])'"
171 STATCY
="perl -le 'print((stat shift)[9])'"
174 logging
-c "[set_os_env]" "Unsupported OS: ${OS_TYPE}"
175 echo "Unsupported OS: $OS_TYPE" >&2
180 export GREP AWK STATCX STATCY
184 # .--config--------------------------------------------------------------.
186 # | ___ ___ _ __ / _(_) __ _ |
187 # | / __/ _ \| '_ \| |_| |/ _` | |
188 # | | (_| (_) | | | | _| | (_| | |
189 # | \___\___/|_| |_|_| |_|\__, | |
191 # '----------------------------------------------------------------------'
194 # Sections that run fast and do no caching
195 SYNC_SECTIONS
="instance sessions logswitches undostat recovery_area processes recovery_status longactivesessions dataguard_stats performance locks"
197 # Sections that are run in the background and at a larger interval.
198 # Note: sections not listed in SYNC_SECTIONS or ASYNC_SECTIONS will not be
200 ASYNC_SECTIONS
="tablespaces rman jobs ts_quotas resumable"
202 # Sections that are run in the background and at a larger interval.
203 # Note: _ASM_ sections are only executed when SID starts with '+'
204 # sections listed in SYNC_SECTIONS or ASYNC_SECTIONS are not
206 SYNC_ASM_SECTIONS
="instance processes"
207 ASYNC_ASM_SECTIONS
="asm_diskgroup"
209 # Interval for running async checks (in seconds)
212 # set OLRLOC=/dev/null in mk_oracle.cfg to disable the discovery from GI/Restart.
213 # A fully configured oratab is mandatory, when this has been disabled.
214 # Be aware! Please disable OLRLOC for failover cluster with custom
215 # clusterware resources.
216 OLRLOC
=/etc
/oracle
/olr.loc
218 # You can specify a list of SIDs to monitor. Those databases will
219 # only be handled, if they are found running, though!
221 # ONLY_SIDS="XE ORCL FOO BAR"
223 # You can specify a list of SIDs to be skipped.
225 # SKIP_SIDS="FOO BAR"
227 # It is possible to filter SIDS negatively. Just add the following to
228 # the mk_oracle.cfg file:
230 # EXCLUDE_<sid>="ALL"
232 # Another option is to filter single checks for SIDS. Just add
233 # lines as follows to the mk_oracle.cfg file. One service per
236 # EXCLUDE_<sid>="<service>"
238 # For example skip oracle_sessions and oracle_logswitches checks
239 # for the instance "mysid".
241 # EXCLUDE_mysid="sessions logswitches"
243 # NOTE: SKIP_SIDS same as 'EXCLUDE_<SID>=ALL' but
244 # also +ASM instances are possible to be excluded:
245 # SKIP_SIDS="+ASM1 +ASM2"
248 # => No valid variable indirection
251 # Source the optional configuration file for this agent plugin
252 if [ -e "$MK_CONFDIR/mk_oracle.cfg" ]; then
253 # shellcheck disable=SC1090
254 .
"$MK_CONFDIR/mk_oracle.cfg"
259 # .--logging-------------------------------------------------------------.
261 # | | | ___ __ _ __ _(_)_ __ __ _ |
262 # | | |/ _ \ / _` |/ _` | | '_ \ / _` | |
263 # | | | (_) | (_| | (_| | | | | | (_| | |
264 # | |_|\___/ \__, |\__, |_|_| |_|\__, | |
265 # | |___/ |___/ |___/ |
266 # '----------------------------------------------------------------------'
268 # How to use logging function:
270 # logging "[WHEREIAM]"
272 # Logging without ID ELSEWHERE:
273 # logging "[ELSEWHERE]"
278 # Logging with ID in function:
279 # logging "[ID] [FUNC-NAME]"
281 # Logging with ID elsewhere:
282 # logging "[ID] [ELSEWHERE]"
284 # Add some useful messages:
285 # logging "" "Set ORACLE_HOME=${ORACLE_HOME}"
287 # There are some optional flags for prefix in log lines:
288 # Flag Criticality Meaning
289 # --------------------------------------------------------------
291 # '-w' 1 (WARNING) error but plugin goes on
292 # '-c' 2 (CRITICAL) error and plugin exits
295 # Add some useful messages:
296 # logging "" "Set OS environment" "OS: ${OS_TYPE}" "GREP: ${GREP}"
299 # logging "[${SID}] [set_ora_env]" "Found local ORACLE_HOME: ${ORACLE_HOME}"
300 # >>> 2018-05-15 16:27:43 [0] [352] [this-sid] [set_ora_env] Found local ORACLE_HOME: /path/to/ora/home
302 # logging "[preliminaries]" "Set OS environment" "OS: ${OS_TYPE}" "GREP: ${GREP}" "AWK: ${AWK}"
303 # >>> 2018-05-15 16:27:43 [0] [1748] [preliminaries] Set OS environment
304 # >>> 2018-05-15 16:27:44 [0] [1748] [preliminaries] OS: Linux
305 # >>> 2018-05-15 16:27:45 [0] [1748] [preliminaries] GREP: /bin/grep
306 # >>> 2018-05-15 16:27:46 [0] [1748] [preliminaries] AWK: /usr/bin/awk
308 # logging -c "[${SID}] [set_ora_env]" "ORA-99999 oratab not found in local mode"
309 # >>> 2018-05-15 16:27:43 [2] [362] [this-sid] [set_ora_env] ORA-99999 oratab not found in local mode
311 # If you need to declare some headers:
312 # logging "" "-- Set OS environment --" "OS: ${OS_TYPE}" "GREP: ${GREP}"
313 # >>> 2018-05-15 16:27:43 [0] [1748] [preliminaries] -- Set OS environment --
314 # >>> 2018-05-15 16:27:44 [0] [1748] [preliminaries] OS: Linux
315 # >>> 2018-05-15 16:27:45 [0] [1748] [preliminaries] GREP: /bin/grep
319 if [ "$MK_ORA_LOGGING" == "1" ]; then
323 local log_file
="$MK_VARDIR/log/mk_oracle.log"
329 while test -n "$1"; do
332 criticality
="0" # OK, default
337 criticality
="1" # WARNING
342 criticality
="2" # CRITICAL
347 criticality
="3" # UNKNOWN
359 if [ -z "${criticality}" ]; then
363 header
="$(perl -MPOSIX -le 'print strftime "%F
%T
", localtime $^T') [${criticality}] ${args[0]}"
365 if [ "${#args[@]}" -le 1 ]; then
366 echo "$header" >> "$log_file"
368 for arg
in "${args[@]:1}"; do
369 echo "${header} $arg" >> "$log_file"
373 ) 200>|
/tmp
/mk_oracle.lock
379 # .--ORA env-------------------------------------------------------------.
381 # | / _ \| _ \ / \ ___ _ ____ __ |
382 # | | | | | |_) | / _ \ / _ \ '_ \ \ / / |
383 # | | |_| | _ < / ___ \ | __/ | | \ V / |
384 # | \___/|_| \_\/_/ \_\ \___|_| |_|\_/ |
386 # '----------------------------------------------------------------------'
391 unset ORA_HOME_SOURCE
393 if [[ "$sid" =~ ^REMOTE_INSTANCE_.
* ]]; then
394 # we get the ORACLE_HOME from mk_oracle.cfg for REMOTE execution
395 ORACLE_HOME
=${ORACLE_HOME:-${REMOTE_ORACLE_HOME}}
396 export ORA_HOME_SOURCE
="(remote):"
399 # we work in local mode
400 # GI/Restart installed?
401 if [ -f ${OLRLOC} ]; then
402 # oratab is not supported in Grid-Infrastructure 12.2+
403 # => fetch ORACLE_HOME from cluster repository for all GI/Restart Environments!
404 # OLRLOC holds CRS_HOME
406 export ORA_HOME_SOURCE
="(GI): "
408 # set ORACLE_HOME = crs_home for ASM
409 if [ "${ORACLE_SID:0:1}" = '+' ]; then
410 ORACLE_HOME
=${crs_home}
412 # get ORACLE_HOME with crsctl from Oracle Grid Infrastructure / Restart
413 ORACLE_HOME
=$
(${crs_home}/bin
/crsctl stat res
-p -w "((TYPE = ora.database.type) and (GEN_USR_ORA_INST_NAME = ${ORACLE_SID}))" |
grep "^ORACLE_HOME=" | cut
-d"=" -f2)
416 # Single Instance with oratab
417 test -f /etc
/oratab
&& ORATAB
=/etc
/oratab
418 # /var/opt/oracle/oratab is needed for Oracle Solaris
419 test -f /var
/opt
/oracle
/oratab
&& ORATAB
=/var
/opt
/oracle
/oratab
420 if ! test -f ${ORATAB:-""}; then
421 logging
-c "[${sid}] [set_ora_env]" "ORA-99999 oratab not found in local mode"
422 echo "ORA-99999 oratab not found" >&2
425 ORACLE_HOME
=$
("${GREP}" "^${ORACLE_SID}:" <"${ORATAB}" | cut
-d":" -f2)
426 export ORA_HOME_SOURCE
="(oratab):"
429 if [ -z "${ORACLE_HOME}" ]; then
430 # cut last number from SID for Oracle RAC to find entry in oratab
431 ORACLE_HOME
=$
("${GREP}" "^${ORACLE_SID/%[0-9]/}:" <"${ORATAB}" | cut
-d":" -f2)
435 LD_LIBRARY_PATH
=$ORACLE_HOME/lib
436 if [ ! -d "${ORACLE_HOME:-'not_found'}" ]; then
437 logging
-c "[${sid}] [set_ora_env]" "ORA-99999 ORACLE_HOME for ORACLE_SID=${ORACLE_SID} not found or not existing!"
438 echo "ORA-99999 ORACLE_HOME for ORACLE_SID=${ORACLE_SID} not found or not existing!" >&2
442 TNS_ADMIN
=${TNS_ADMIN:-$MK_CONFDIR}
443 if ! test -f "${TNS_ADMIN}/sqlnet.ora"; then
444 logging
-c "[${sid}] [set_ora_env]" "TNS_ADMIN/sqlnet.ora: ${TNS_ADMIN}/sqlnet.ora"
445 echo "ORA-99998 Couldn't find ${TNS_ADMIN}/sqlnet.ora" >&2
448 export ORACLE_HOME TNS_ADMIN ORACLE_SID LD_LIBRARY_PATH
454 NUMERIC_ORACLE_VERSION
=${ORACLE_VERSION//./}
455 export NUMERIC_ORACLE_VERSION
460 # .--SQL Queries---------------------------------------------------------.
461 # | ____ ___ _ ___ _ |
462 # | / ___| / _ \| | / _ \ _ _ ___ _ __(_) ___ ___ |
463 # | \___ \| | | | | | | | | | | |/ _ \ '__| |/ _ \/ __| |
464 # | ___) | |_| | |___ | |_| | |_| | __/ | | | __/\__ \ |
465 # | |____/ \__\_\_____| \__\_\\__,_|\___|_| |_|\___||___/ |
467 # +----------------------------------------------------------------------+
468 # | The following functions create SQL queries for ORACLE and output |
469 # | them to stdout. All queries output the database name or the instane |
470 # | name as first column. |
471 # '----------------------------------------------------------------------'
473 #TODO Create subsections in query and parse them in related check plugin.
477 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
478 echo 'PROMPT <<<oracle_performance:sep(124)>>>'
479 echo "select upper(i.INSTANCE_NAME)
480 ||'|'|| 'sys_time_model'
482 ||'|'|| Round(s.value/1000000)
485 where s.stat_name in('DB time', 'DB CPU')
486 order by s.stat_name;
487 select upper(i.INSTANCE_NAME ||'.'||vd.name)
488 ||'|'|| 'sys_time_model'
490 ||'|'|| Round(s.value/1000000)
492 join v\$con_sys_time_model s on s.stat_name in('DB time', 'DB CPU')
493 join v\$containers vd on vd.con_id = s.con_id
494 join v\$database d on d.cdb = 'YES'
496 order by s.stat_name;
497 select upper(i.INSTANCE_NAME)
498 ||'|'|| 'buffer_pool_statistics'
500 ||'|'|| b.db_block_gets
501 ||'|'|| b.db_block_change
502 ||'|'|| b.consistent_gets
503 ||'|'|| b.physical_reads
504 ||'|'|| b.physical_writes
505 ||'|'|| b.FREE_BUFFER_WAIT
506 ||'|'|| b.BUFFER_BUSY_WAIT
507 from v\$instance i, V\$BUFFER_POOL_STATISTICS b;
508 select upper(i.INSTANCE_NAME)
512 from v\$sgainfo s, v\$instance i;
513 select upper(i.INSTANCE_NAME)
514 ||'|'|| 'librarycache'
521 ||'|'|| b.invalidations
522 from v\$instance i, V\$librarycache b;"
524 elif [ "$NUMERIC_ORACLE_VERSION" -ge 101 ]; then
525 echo "PROMPT <<<oracle_performance:sep(124)>>>"
526 echo "select upper(i.INSTANCE_NAME)
527 ||'|'|| 'sys_time_model'
529 ||'|'|| Round(s.value/1000000)
532 where s.stat_name in('DB time', 'DB CPU')
533 order by s.stat_name;
534 select upper(i.INSTANCE_NAME)
535 ||'|'|| 'buffer_pool_statistics'
537 ||'|'|| b.db_block_gets
538 ||'|'|| b.db_block_change
539 ||'|'|| b.consistent_gets
540 ||'|'|| b.physical_reads
541 ||'|'|| b.physical_writes
542 ||'|'|| b.FREE_BUFFER_WAIT
543 ||'|'|| b.BUFFER_BUSY_WAIT
544 from v\$instance i, V\$BUFFER_POOL_STATISTICS b;
545 select upper(i.INSTANCE_NAME)
549 from v\$sgainfo s, v\$instance i;
550 select upper(i.INSTANCE_NAME)
551 ||'|'|| 'librarycache'
558 ||'|'|| b.invalidations
559 from v\$instance i, V\$librarycache b;"
565 echo "PROMPT <<<oracle_tablespaces:sep(124)>>>"
566 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
568 echo "select upper(decode(${IGNORE_DB_NAME:-0}
569 , 0, decode(vp.con_id, null, d.NAME
570 ,d.NAME||'.'||vp.name)
572 || '|' || dbf.file_name
573 || '|' || dbf.tablespace_name
574 || '|' || dbf.fstatus
575 || '|' || dbf.AUTOEXTENSIBLE
577 || '|' || dbf.maxblocks
578 || '|' || dbf.USER_BLOCKS
579 || '|' || dbf.INCREMENT_BY
580 || '|' || dbf.ONLINE_STATUS
581 || '|' || dbf.BLOCK_SIZE
582 || '|' || decode(tstatus,'READ ONLY', 'READONLY', tstatus)
583 || '|' || dbf.free_blocks
584 || '|' || dbf.contents
587 join v\$instance i on 1=1
589 select f.con_id, f.file_name, f.tablespace_name, f.status fstatus, f.AUTOEXTENSIBLE,
590 f.blocks, f.maxblocks, f.USER_BLOCKS, f.INCREMENT_BY,
591 f.ONLINE_STATUS, t.BLOCK_SIZE, t.status tstatus, nvl(sum(fs.blocks),0) free_blocks, t.contents
592 from cdb_data_files f
593 join cdb_tablespaces t on f.tablespace_name = t.tablespace_name
594 and f.con_id = t.con_id
595 left outer join cdb_free_space fs on f.file_id = fs.file_id
596 and f.con_id = fs.con_id
597 group by f.con_id, f.file_name, f.tablespace_name, f.status, f.autoextensible,
598 f.blocks, f.maxblocks, f.user_blocks, f.increment_by, f.online_status,
599 t.block_size, t.status, t.contents
601 left outer join v\$pdbs vp on dbf.con_id = vp.con_id
602 where d.database_role = 'PRIMARY';
604 select upper(decode(${IGNORE_DB_NAME:-0}
605 , 0, decode(dbf.con_id, null, d.NAME
608 || '|' || dbf.file_name
609 || '|' || dbf.tablespace_name
610 || '|' || dbf.fstatus
611 || '|' || dbf.AUTOEXTENSIBLE
613 || '|' || dbf.maxblocks
614 || '|' || dbf.USER_BLOCKS
615 || '|' || dbf.INCREMENT_BY
616 || '|' || dbf.ONLINE_STATUS
617 || '|' || dbf.BLOCK_SIZE
618 || '|' || decode(tstatus,'READ ONLY', 'READONLY', tstatus)
619 || '|' || dbf.free_blocks
620 || '|' || 'TEMPORARY'
623 JOIN v\$instance i ON 1 = 1
635 'ONLINE' online_status,
638 f.blocks - nvl(SUM(tu.blocks),0) free_blocks,
640 FROM cdb_tablespaces t
643 ,d.name || '.'|| vp.name name
644 FROM v\$containers vp
645 JOIN v\$database d ON 1 = 1
652 ) vp ON t.con_id = vp.con_id
653 LEFT OUTER JOIN cdb_temp_files f ON t.con_id = f.con_id
654 AND t.tablespace_name = f.tablespace_name
655 LEFT OUTER JOIN gv\$tempseg_usage tu ON f.con_id = tu.con_id
656 AND f.tablespace_name = tu.tablespace
657 AND f.RELATIVE_FNO = tu.SEGRFNO#
658 WHERE t.contents = 'TEMPORARY'
673 where d.database_role = 'PRIMARY';"
675 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
676 echo "select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
677 || '|' || file_name ||'|'|| tablespace_name ||'|'|| fstatus ||'|'|| AUTOEXTENSIBLE
678 ||'|'|| blocks ||'|'|| maxblocks ||'|'|| USER_BLOCKS ||'|'|| INCREMENT_BY
679 ||'|'|| ONLINE_STATUS ||'|'|| BLOCK_SIZE
680 ||'|'|| decode(tstatus,'READ ONLY', 'READONLY', tstatus) || '|' || free_blocks
683 from v\$database d , v\$instance i, (
684 select f.file_name, f.tablespace_name, f.status fstatus, f.AUTOEXTENSIBLE,
685 f.blocks, f.maxblocks, f.USER_BLOCKS, f.INCREMENT_BY,
686 f.ONLINE_STATUS, t.BLOCK_SIZE, t.status tstatus, nvl(sum(fs.blocks),0) free_blocks, t.contents,
687 (select version from v\$instance) iversion
688 from dba_data_files f, dba_tablespaces t, dba_free_space fs
689 where f.tablespace_name = t.tablespace_name
690 and f.file_id = fs.file_id(+)
691 group by f.file_name, f.tablespace_name, f.status, f.autoextensible,
692 f.blocks, f.maxblocks, f.user_blocks, f.increment_by, f.online_status,
693 t.block_size, t.status, t.contents)
694 where d.database_role = 'PRIMARY';
696 select upper(decode(${IGNORE_DB_NAME:-0}
699 || '|' || dbf.file_name
700 || '|' || dbf.tablespace_name
701 || '|' || dbf.fstatus
702 || '|' || dbf.AUTOEXTENSIBLE
704 || '|' || dbf.maxblocks
705 || '|' || dbf.USER_BLOCKS
706 || '|' || dbf.INCREMENT_BY
707 || '|' || dbf.ONLINE_STATUS
708 || '|' || dbf.BLOCK_SIZE
709 || '|' || decode(tstatus,'READ ONLY', 'READONLY', tstatus)
710 || '|' || dbf.free_blocks
711 || '|' || 'TEMPORARY'
714 JOIN v\$instance i ON 1 = 1
725 'ONLINE' online_status,
728 f.blocks - nvl(SUM(tu.blocks),0) free_blocks,
730 FROM dba_tablespaces t
735 LEFT OUTER JOIN dba_temp_files f ON t.tablespace_name = f.tablespace_name
736 LEFT OUTER JOIN gv\$tempseg_usage tu ON f.tablespace_name = tu.tablespace
737 AND f.RELATIVE_FNO = tu.SEGRFNO#
738 WHERE t.contents = 'TEMPORARY'
753 elif [ "$NUMERIC_ORACLE_VERSION" -ge 92 ]; then
754 echo "select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
755 || '|' || file_name ||'|'|| tablespace_name ||'|'|| fstatus ||'|'|| AUTOEXTENSIBLE
756 ||'|'|| blocks ||'|'|| maxblocks ||'|'|| USER_BLOCKS ||'|'|| INCREMENT_BY
757 ||'|'|| ONLINE_STATUS ||'|'|| BLOCK_SIZE
758 ||'|'|| decode(tstatus,'READ ONLY', 'READONLY', tstatus) || '|' || free_blocks
760 from v\$database d , v\$instance i, (
761 select f.file_name, f.tablespace_name, f.status fstatus, f.AUTOEXTENSIBLE,
762 f.blocks, f.maxblocks, f.USER_BLOCKS, f.INCREMENT_BY,
763 'ONLINE' ONLINE_STATUS, t.BLOCK_SIZE, t.status tstatus, nvl(sum(fs.blocks),0) free_blocks, t.contents
764 from dba_data_files f, dba_tablespaces t, dba_free_space fs
765 where f.tablespace_name = t.tablespace_name
766 and f.file_id = fs.file_id(+)
767 group by f.file_name, f.tablespace_name, f.status, f.autoextensible,
768 f.blocks, f.maxblocks, f.user_blocks, f.increment_by, 'ONLINE',
769 t.block_size, t.status, t.contents
771 select f.file_name, f.tablespace_name, 'ONLINE' status, f.AUTOEXTENSIBLE,
772 f.blocks, f.maxblocks, f.USER_BLOCKS, f.INCREMENT_BY, 'TEMP',
773 t.BLOCK_SIZE, 'TEMP' status, sum(sh.blocks_free) free_blocks, 'TEMPORARY'
774 from v\$thread th, dba_temp_files f, dba_tablespaces t, v\$temp_space_header sh
775 WHERE f.tablespace_name = t.tablespace_name and f.file_id = sh.file_id
776 GROUP BY th.instance, f.file_name, f.tablespace_name, 'ONLINE',
777 f.autoextensible, f.blocks, f.maxblocks, f.user_blocks, f.increment_by,
778 'TEMP', t.block_size, t.status);"
783 sql_dataguard_stats
() {
784 if [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
785 echo 'PROMPT <<<oracle_dataguard_stats:sep(124)>>>'
786 echo "SELECT upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
787 ||'|'|| upper(d.DB_UNIQUE_NAME)
788 ||'|'|| d.DATABASE_ROLE
791 ||'|'|| d.SWITCHOVER_STATUS
793 JOIN v\$parameter vp on 1=1
794 JOIN v\$instance i on 1=1
795 left outer join V\$dataguard_stats ds on 1=1
796 WHERE vp.name = 'log_archive_config'
797 AND vp.value is not null
803 sql_recovery_status
() {
804 echo 'PROMPT <<<oracle_recovery_status:sep(124)>>>'
805 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
806 echo "SELECT upper(decode(${IGNORE_DB_NAME:-0}
807 , 0, decode(vp.con_id, null, d.NAME
808 ,d.NAME||'.'||vp.name)
810 ||'|'|| d.DB_UNIQUE_NAME
811 ||'|'|| d.DATABASE_ROLE
814 ||'|'|| round((dh.CHECKPOINT_TIME-to_date('01.01.1970','dd.mm.yyyy'))*24*60*60)
815 ||'|'|| round((sysdate-dh.CHECKPOINT_TIME)*24*60*60)
819 ||'|'|| dh.CHECKPOINT_CHANGE#
821 ||'|'|| round((sysdate-vb.TIME)*24*60*60)
822 FROM V\$datafile_header dh
823 JOIN v\$database d on 1=1
824 JOIN v\$instance i on 1=1
825 JOIN v\$backup vb on 1=1
826 LEFT OUTER JOIN V\$PDBS vp on dh.con_id = vp.con_id
827 WHERE vb.file# = dh.file#
829 elif [ "$NUMERIC_ORACLE_VERSION" -ge 101 ]; then
830 echo "SELECT upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
831 ||'|'|| d.DB_UNIQUE_NAME
832 ||'|'|| d.DATABASE_ROLE
835 ||'|'|| round((dh.CHECKPOINT_TIME-to_date('01.01.1970','dd.mm.yyyy'))*24*60*60)
836 ||'|'|| round((sysdate-dh.CHECKPOINT_TIME)*24*60*60)
840 ||'|'|| dh.CHECKPOINT_CHANGE#
841 FROM V\$datafile_header dh, v\$database d, v\$instance i
844 elif [ "$NUMERIC_ORACLE_VERSION" -ge 92 ]; then
845 echo "SELECT upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
846 ||'|'|| upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
847 ||'|'|| d.DATABASE_ROLE
850 ||'|'|| round((dh.CHECKPOINT_TIME-to_date('01.01.1970','dd.mm.yyyy'))*24*60*60)
851 ||'|'|| round((sysdate-dh.CHECKPOINT_TIME)*24*60*60)
855 ||'|'|| dh.CHECKPOINT_CHANGE#
856 FROM V\$datafile_header dh, v\$database d, v\$instance i
864 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
866 echo 'PROMPT <<<oracle_rman:sep(124)>>>'
867 echo "select /*"$HINT_RMAN" check_mk rman1 */ upper(name)
869 || '|'|| to_char(COMPLETION_TIME, 'YYYY-mm-dd_HH24:MI:SS')
870 || '|'|| to_char(COMPLETION_TIME, 'YYYY-mm-dd_HH24:MI:SS')
871 || '|'|| case when INCREMENTAL_LEVEL IS NULL
875 || '|'|| INCREMENTAL_LEVEL
876 || '|'|| round(((sysdate-COMPLETION_TIME) * 24 * 60), 0)
877 || '|'|| INCREMENTAL_CHANGE#
878 from (select upper(decode(${IGNORE_DB_NAME:-0}, 0, vd.NAME, i.instance_name)) name
879 , bd2.INCREMENTAL_LEVEL, bd2.INCREMENTAL_CHANGE#, min(bd2.COMPLETION_TIME) COMPLETION_TIME
880 from (select bd.file#, bd.INCREMENTAL_LEVEL, max(bd.COMPLETION_TIME) COMPLETION_TIME
881 from v\$backup_datafile bd
882 join v\$datafile_header dh on dh.file# = bd.file#
883 where dh.status = 'ONLINE'
885 group by bd.file#, bd.INCREMENTAL_LEVEL
887 join v\$backup_datafile bd2 on bd2.file# = bd.file#
888 and bd2.COMPLETION_TIME = bd.COMPLETION_TIME
889 join v\$database vd on vd.RESETLOGS_CHANGE# = bd2.RESETLOGS_CHANGE#
890 join v\$instance i on 1=1
891 group by upper(decode(${IGNORE_DB_NAME:-0}, 0, vd.NAME, i.instance_name))
892 , bd2.INCREMENTAL_LEVEL
893 , bd2.INCREMENTAL_CHANGE#
894 order by name, bd2.INCREMENTAL_LEVEL);
896 select /*"$HINT_RMAN" check_mk rman2 */ name
897 || '|' || 'COMPLETED'
899 || '|' || to_char(CHECKPOINT_TIME, 'yyyy-mm-dd_hh24:mi:ss')
900 || '|' || 'CONTROLFILE'
902 || '|' || round((sysdate - CHECKPOINT_TIME) * 24 * 60)
904 from (select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name)) name
905 ,max(bcd.CHECKPOINT_TIME) CHECKPOINT_TIME
907 join V\$BACKUP_CONTROLFILE_DETAILS bcd on d.RESETLOGS_CHANGE# = bcd.RESETLOGS_CHANGE#
908 join v\$instance i on 1=1
909 group by upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
912 select /*"$HINT_RMAN" check_mk rman3 */ name
914 || '|'|| to_char(sysdate, 'YYYY-mm-dd_HH24:MI:SS')
915 || '|'|| to_char(completed, 'YYYY-mm-dd_HH24:MI:SS')
917 || round((sysdate - completed)*24*60,0)
920 select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name)) name
921 , max(a.completion_time) completed
922 , case when a.backup_count > 0 then 1 else 0 end
923 from v\$archived_log a, v\$database d, v\$instance i
924 where a.backup_count > 0
927 from v\$archive_dest b
928 where b.target = 'PRIMARY'
929 and b.SCHEDULE = 'ACTIVE'
931 group by d.NAME, i.instance_name
932 , case when a.backup_count > 0 then 1 else 0 end);"
934 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
935 echo 'PROMPT <<<oracle_rman:sep(124)>>>'
936 echo "select /*${HINT_RMAN} check_mk rman1 */ upper(name)
938 || '|'|| to_char(COMPLETION_TIME, 'YYYY-mm-dd_HH24:MI:SS')
939 || '|'|| to_char(COMPLETION_TIME, 'YYYY-mm-dd_HH24:MI:SS')
940 || '|'|| case when INCREMENTAL_LEVEL IS NULL
944 || '|'|| INCREMENTAL_LEVEL
945 || '|'|| round(((sysdate-COMPLETION_TIME) * 24 * 60), 0)
946 || '|'|| INCREMENTAL_CHANGE#
947 from (select upper(decode(${IGNORE_DB_NAME:-0}, 0, vd.NAME, i.instance_name)) name
948 , bd2.INCREMENTAL_LEVEL, bd2.INCREMENTAL_CHANGE#, min(bd2.COMPLETION_TIME) COMPLETION_TIME
949 from (select bd.file#, bd.INCREMENTAL_LEVEL, max(bd.COMPLETION_TIME) COMPLETION_TIME
950 from v\$backup_datafile bd
951 join v\$datafile_header dh on dh.file# = bd.file#
952 where dh.status = 'ONLINE'
953 group by bd.file#, bd.INCREMENTAL_LEVEL
955 join v\$backup_datafile bd2 on bd2.file# = bd.file#
956 and bd2.COMPLETION_TIME = bd.COMPLETION_TIME
957 join v\$database vd on vd.RESETLOGS_CHANGE# = bd2.RESETLOGS_CHANGE#
958 join v\$instance i on 1=1
959 group by upper(decode(${IGNORE_DB_NAME:-0}, 0, vd.NAME, i.instance_name))
960 , bd2.INCREMENTAL_LEVEL
961 , bd2.INCREMENTAL_CHANGE#
962 order by name, bd2.INCREMENTAL_LEVEL);
964 select /*${HINT_RMAN} check_mk rman2 */ name
965 || '|' || 'COMPLETED'
967 || '|' || to_char(CHECKPOINT_TIME, 'yyyy-mm-dd_hh24:mi:ss')
968 || '|' || 'CONTROLFILE'
970 || '|' || round((sysdate - CHECKPOINT_TIME) * 24 * 60)
972 from (select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name)) name
973 ,max(bcd.CHECKPOINT_TIME) CHECKPOINT_TIME
975 join V\$BACKUP_CONTROLFILE_DETAILS bcd on d.RESETLOGS_CHANGE# = bcd.RESETLOGS_CHANGE#
976 join v\$instance i on 1=1
977 group by upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
980 select /*${HINT_RMAN} check_mk rman3 */ name
982 || '|'|| to_char(sysdate, 'YYYY-mm-dd_HH24:MI:SS')
983 || '|'|| to_char(completed, 'YYYY-mm-dd_HH24:MI:SS')
985 || round((sysdate - completed)*24*60,0)
988 select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name)) name
989 , max(a.completion_time) completed
990 , case when a.backup_count > 0 then 1 else 0 end
991 from v\$archived_log a, v\$database d, v\$instance i
992 where a.backup_count > 0
995 from v\$archive_dest b
996 where b.target = 'PRIMARY'
997 and b.SCHEDULE = 'ACTIVE'
999 group by d.NAME, i.instance_name
1000 , case when a.backup_count > 0 then 1 else 0 end);"
1005 sql_recovery_area
() {
1006 if [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
1007 echo 'PROMPT <<<oracle_recovery_area:sep(124)>>>'
1008 echo "select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
1009 ||'|'|| round((SPACE_USED-SPACE_RECLAIMABLE)/
1010 (CASE NVL(SPACE_LIMIT,1) WHEN 0 THEN 1 ELSE SPACE_LIMIT END)*100)
1011 ||'|'|| round(SPACE_LIMIT/1024/1024)
1012 ||'|'|| round(SPACE_USED/1024/1024)
1013 ||'|'|| round(SPACE_RECLAIMABLE/1024/1024)
1014 ||'|'|| d.FLASHBACK_ON
1015 from V\$RECOVERY_FILE_DEST, v\$database d, v\$instance i;"
1021 echo 'PROMPT <<<oracle_undostat:sep(124)>>>'
1022 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1023 echo "select decode(vp.con_id, null, upper(i.INSTANCE_NAME)
1024 ,upper(i.INSTANCE_NAME || '.' || vp.name))
1026 ||'|'|| MAXCONCURRENCY
1027 ||'|'|| TUNED_UNDORETENTION
1029 ||'|'|| NOSPACEERRCNT
1032 (select * from v\$undostat
1033 where TUNED_UNDORETENTION > 0
1034 order by end_time desc
1035 fetch next 1 rows only
1037 left outer join v\$pdbs vp on vp.con_id = u.con_id;
1040 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
1041 echo "select upper(i.INSTANCE_NAME)
1043 ||'|'|| MAXCONCURRENCY
1044 ||'|'|| TUNED_UNDORETENTION
1046 ||'|'|| NOSPACEERRCNT
1048 (select * from (select *
1049 from v\$undostat order by end_time desc
1052 and TUNED_UNDORETENTION > 0
1055 elif [ "$NUMERIC_ORACLE_VERSION" -ge 92 ]; then
1056 # TUNED_UNDORETENTION and ACTIVEBLKS are not availibe in Oracle <=9.2!
1057 # we sent a -1 for filtering in check_undostat
1058 echo "select upper(i.INSTANCE_NAME)
1060 ||'|'|| MAXCONCURRENCY
1063 ||'|'|| NOSPACEERRCNT
1065 (select * from (select *
1066 from v\$undostat order by end_time desc
1075 echo 'PROMPT <<<oracle_resumable:sep(124)>>>'
1076 echo "select upper(i.INSTANCE_NAME)
1078 ||'|'|| a.SESSION_ID
1081 ||'|'|| round((sysdate-to_date(a.SUSPEND_TIME,'mm/dd/yy hh24:mi:ss'))*24*60*60)
1082 ||'|'|| a.ERROR_NUMBER
1083 ||'|'|| to_char(to_date(a.SUSPEND_TIME, 'mm/dd/yy hh24:mi:ss'),'mm/dd/yy_hh24:mi:ss')
1084 ||'|'|| a.RESUME_TIME
1086 from dba_resumable a, v\$instance i, dba_users u
1087 where a.INSTANCE_ID = i.INSTANCE_NUMBER
1088 and u.user_id = a.user_id
1089 and a.SUSPEND_TIME is not null
1091 select upper(i.INSTANCE_NAME)
1093 from v\$instance i;"
1098 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1100 echo 'PROMPT <<<oracle_jobs:sep(124)>>>'
1101 echo "SELECT upper(vp.name)
1105 ||'|'|| ROUND((TRUNC(sysdate) + j.LAST_RUN_DURATION - TRUNC(sysdate)) * 86400)
1108 ||'|'|| NVL(j.NEXT_RUN_DATE, to_date('1970-01-01', 'YYYY-mm-dd'))
1109 ||'|'|| NVL(j.SCHEDULE_NAME, '-')
1111 FROM cdb_scheduler_jobs j
1112 JOIN ( SELECT vp.con_id
1113 ,d.name || '|' || vp.name name
1114 FROM v\$containers vp
1115 JOIN v\$database d on 1=1
1116 WHERE d.cdb = 'YES' and vp.con_id <> 2
1120 ) vp on j.con_id = vp.con_id
1121 left outer join (SELECT con_id, owner, job_name, max(LOG_ID) log_id
1122 FROM cdb_scheduler_job_run_details dd
1123 group by con_id, owner, job_name
1124 ) jm on jm.JOB_NAME = j.JOB_NAME
1125 and jm.owner=j.OWNER
1126 and jm.con_id = j.con_id
1127 left outer join cdb_scheduler_job_run_details jd
1128 on jd.con_id = jm.con_id
1129 AND jd.owner = jm.OWNER
1130 AND jd.JOB_NAME = jm.JOB_NAME
1131 AND jd.LOG_ID = jm.LOG_ID;
1134 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
1135 echo 'PROMPT <<<oracle_jobs:sep(124)>>>'
1136 echo "SELECT upper(decode(${IGNORE_DB_NAME:-0}, 0, vd.NAME, i.instance_name))
1140 ||'|'|| ROUND((TRUNC(sysdate) + j.LAST_RUN_DURATION - TRUNC(sysdate)) * 86400)
1143 ||'|'|| NVL(j.NEXT_RUN_DATE, to_date('1970-01-01', 'YYYY-mm-dd'))
1144 ||'|'|| NVL(j.SCHEDULE_NAME, '-')
1146 FROM dba_scheduler_jobs j
1147 join v\$database vd on 1 = 1
1148 join v\$instance i on 1 = 1
1149 left outer join (SELECT owner, job_name, max(LOG_ID) log_id
1150 FROM dba_scheduler_job_run_details dd
1151 group by owner, job_name
1152 ) jm on jm.JOB_NAME = j.JOB_NAME
1153 and jm.owner=j.OWNER
1154 left outer join dba_scheduler_job_run_details jd
1155 on jd.owner = jm.OWNER
1156 AND jd.JOB_NAME = jm.JOB_NAME
1157 AND jd.LOG_ID = jm.LOG_ID
1158 WHERE j.auto_drop = 'FALSE';"
1164 echo 'PROMPT <<<oracle_ts_quotas:sep(124)>>>'
1165 echo "select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
1167 ||'|'|| Q.TABLESPACE_NAME
1170 from dba_ts_quotas Q, v\$database d, v\$instance i
1173 select upper(decode(${IGNORE_DB_NAME:-0}, 0, d.NAME, i.instance_name))
1175 from v\$database d, v\$instance i
1181 echo 'PROMPT <<<oracle_version>>>'
1182 echo "select upper(i.INSTANCE_NAME)
1184 from v\$version, v\$instance i
1185 where banner like 'Oracle%';"
1190 echo 'prompt <<<oracle_instance:sep(124)>>>'
1191 if [ "${ORACLE_SID:0:1}" = '+' ]; then
1193 echo "select upper(i.instance_name)
1197 || '|' || i.ARCHIVER
1198 || '|' || round((sysdate - i.startup_time) * 24*60*60)
1203 || '|' || i.instance_name
1204 from v\$instance i;"
1206 elif [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1207 echo "select upper(instance_name)
1212 || '|' || round((sysdate - startup_time) * 24*60*60)
1215 || '|' || database_role
1216 || '|' || force_logging
1218 || '|' || to_char(created, 'ddmmyyyyhh24mi')
1219 || '|' || upper(value)
1223 || '|' || popen_mode
1224 || '|' || prestricted
1225 || '|' || ptotal_time
1226 || '|' || precovery_status
1227 || '|' || round(nvl(popen_time, -1))
1228 || '|' || pblock_size
1230 select i.instance_name, i.version, i.status, i.logins, i.archiver
1231 ,i.startup_time, d.dbid, d.log_mode, d.database_role, d.force_logging
1232 ,d.name, d.created, p.value, vp.con_id, vp.name pname
1233 ,vp.dbid pdbid, vp.open_mode popen_mode, vp.restricted prestricted, vp.total_size ptotal_time
1234 ,vp.block_size pblock_size, vp.recovery_status precovery_status
1235 ,(cast(systimestamp as date) - cast(open_time as date)) * 24*60*60 popen_time
1237 join v\$database d on 1=1
1238 join v\$parameter p on 1=1
1239 join v\$pdbs vp on 1=1
1240 where p.name = 'enable_pluggable_database'
1243 i.instance_name, i.version, i.status, i.logins, i.archiver
1244 ,i.startup_time, d.dbid, d.log_mode, d.database_role, d.force_logging
1245 ,d.name, d.created, p.value, 0 con_id, null pname
1246 ,0 pdbis, null popen_mode, null prestricted, null ptotal_time
1247 ,0 pblock_size, null precovery_status, null popen_time
1249 join v\$database d on 1=1
1250 join v\$parameter p on 1=1
1251 where p.name = 'enable_pluggable_database'
1257 echo "select upper(i.instance_name)
1261 || '|' || i.ARCHIVER
1262 || '|' || round((sysdate - i.startup_time) * 24*60*60)
1265 || '|' || DATABASE_ROLE
1266 || '|' || FORCE_LOGGING
1268 || '|' || to_char(d.created, 'ddmmyyyyhh24mi')
1269 from v\$instance i, v\$database d;"
1275 echo 'prompt <<<oracle_sessions:sep(124)>>>'
1277 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1278 echo "SELECT upper(vp.name)
1279 || '|' || ltrim(COUNT(1))
1281 , 0, '|'||ltrim(rtrim(LIMIT_VALUE))||'|-1')
1282 FROM ( SELECT vp.con_id
1283 ,i.instance_name || '.' || vp.name name
1284 FROM v\$containers vp
1285 JOIN v\$instance i ON 1 = 1
1286 JOIN v\$database d on 1=1
1287 WHERE d.cdb = 'YES' and vp.con_id <> 2
1289 SELECT 0, instance_name
1292 JOIN v\$resource_limit rl on RESOURCE_NAME = 'sessions'
1293 LEFT OUTER JOIN v\$session vs ON vp.con_id = vs.con_id
1294 GROUP BY vp.name, vp.con_id, rl.LIMIT_VALUE
1298 echo "select upper(i.instance_name)
1299 || '|' || CURRENT_UTILIZATION
1300 || '|' || ltrim(LIMIT_VALUE)
1301 || '|' || MAX_UTILIZATION
1302 from v\$resource_limit, v\$instance i
1303 where RESOURCE_NAME = 'sessions';"
1309 echo 'prompt <<<oracle_processes:sep(124)>>>'
1310 echo "select upper(i.instance_name)
1311 || '|' || CURRENT_UTILIZATION
1312 || '|' || ltrim(rtrim(LIMIT_VALUE))
1313 from v\$resource_limit, v\$instance i
1314 where RESOURCE_NAME = 'processes';"
1318 sql_logswitches
() {
1319 echo 'prompt <<<oracle_logswitches:sep(124)>>>'
1320 echo "select upper(i.instance_name)
1321 || '|' || logswitches
1322 from v\$instance i ,
1323 (select count(1) logswitches
1324 from v\$loghist h , v\$instance i
1325 where h.first_time > sysdate - 1/24
1326 and h.thread# = i.instance_number
1332 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1333 echo 'prompt <<<oracle_locks:sep(124)>>>'
1334 echo "select upper(vp.name)
1341 || '|' || b.username
1342 || '|' || b.SECONDS_IN_WAIT
1343 || '|' || b.BLOCKING_SESSION_STATUS
1344 || '|' || bs.inst_id
1346 || '|' || bs.serial#
1347 || '|' || bs.machine
1348 || '|' || bs.program
1349 || '|' || bs.process
1351 || '|' || bs.username
1353 join gv\$session bs on bs.inst_id = b.BLOCKING_INSTANCE
1354 and bs.sid = b.BLOCKING_SESSION
1355 and bs.con_id = b.con_id
1356 join ( SELECT vp.con_id
1357 ,i.instance_name || '.' || vp.name name
1358 FROM v\$containers vp
1359 JOIN v\$instance i ON 1 = 1
1360 JOIN v\$database d on 1=1
1361 WHERE d.cdb = 'YES' and vp.con_id <> 2
1363 SELECT 0, instance_name
1365 ) vp on b.con_id = vp.con_id
1366 where b.BLOCKING_SESSION is not null;
1368 SELECT upper(i.instance_name || '.' || vp.name)
1369 || '|||||||||||||||||'
1370 FROM v\$containers vp
1371 JOIN v\$instance i ON 1 = 1
1372 JOIN v\$database d on 1=1
1373 WHERE d.cdb = 'YES' and vp.con_id <> 2
1375 SELECT upper(i.instance_name)
1376 || '|||||||||||||||||'
1380 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
1381 echo 'prompt <<<oracle_locks:sep(124)>>>'
1382 echo "select upper(i.instance_name)
1389 || '|' || b.username
1390 || '|' || b.SECONDS_IN_WAIT
1391 || '|' || b.BLOCKING_SESSION_STATUS
1392 || '|' || bs.inst_id
1394 || '|' || bs.serial#
1395 || '|' || bs.machine
1396 || '|' || bs.program
1397 || '|' || bs.process
1399 || '|' || bs.username
1401 join v\$instance i on 1=1
1402 join gv\$session bs on bs.inst_id = b.BLOCKING_INSTANCE
1403 and bs.sid = b.BLOCKING_SESSION
1404 where b.BLOCKING_SESSION is not null;
1405 select upper(i.instance_name)
1406 || '|||||||||||||||||'
1407 from v\$instance i;"
1413 if [ "$NUMERIC_ORACLE_VERSION" -ge 101 ]; then
1414 echo 'prompt <<<oracle_locks:sep(124)>>>'
1415 echo "SET SERVEROUTPUT ON feedback off
1417 type x is table of varchar2(20000) index by pls_integer;
1421 execute immediate 'select upper(i.instance_name)
1423 || ''|'' || b.serial#
1424 || ''|'' || b.machine
1425 || ''|'' || b.program
1426 || ''|'' || b.process
1427 || ''|'' || b.osuser
1429 || ''|'' || decode(c.owner,NULL,''NULL'',c.owner)
1430 || ''|'' || decode(c.object_name,NULL,''NULL'',c.object_name)
1431 from V\$LOCK a, v\$session b, dba_objects c, v\$instance i
1432 where (a.id1, a.id2, a.type)
1433 IN (SELECT id1, id2, type
1439 and a.id1 = c.object_id (+)
1441 select upper(i.instance_name) || ''|||||||||''
1443 bulk collect into xx;
1444 if xx.count >= 1 then
1445 for i in 1 .. xx.count loop
1446 dbms_output.put_line(xx(i));
1451 for cur1 in (select upper(i.instance_name) instance_name from v\$instance i) loop
1452 dbms_output.put_line(cur1.instance_name || '|||||||||'||sqlerrm);
1462 sql_longactivesessions
() {
1463 if [ "$NUMERIC_ORACLE_VERSION" -ge 121 ]; then
1465 echo 'prompt <<<oracle_longactivesessions:sep(124)>>>'
1466 echo "select upper(vp.name)
1473 || '|' || s.last_call_et
1476 join ( SELECT vp.con_id
1477 ,i.instance_name || '.' || vp.name name
1478 FROM v\$containers vp
1479 JOIN v\$instance i ON 1 = 1
1480 JOIN v\$database d on 1=1
1481 WHERE d.cdb = 'YES' and vp.con_id <> 2
1483 SELECT 0, instance_name
1486 where s.status = 'ACTIVE'
1487 and s.type != 'BACKGROUND'
1488 and s.username is not null
1489 and s.username not in('PUBLIC')
1490 and s.last_call_et > 60*60;
1492 SELECT upper(i.instance_name || '.' || vp.name)
1494 FROM v\$containers vp
1495 JOIN v\$instance i ON 1 = 1
1496 JOIN v\$database d on 1=1
1497 WHERE d.cdb = 'YES' and vp.con_id <> 2
1499 SELECT upper(i.instance_name)
1504 elif [ "$NUMERIC_ORACLE_VERSION" -ge 101 ]; then
1505 echo 'prompt <<<oracle_longactivesessions:sep(124)>>>'
1506 echo "select upper(i.instance_name)
1513 || '|' || s.last_call_et
1515 from v\$session s, v\$instance i
1516 where s.status = 'ACTIVE'
1517 and type != 'BACKGROUND'
1518 and s.username is not null
1519 and s.username not in('PUBLIC')
1520 and s.last_call_et > 60*60
1522 select upper(i.instance_name)
1524 from v\$instance i;"
1529 sql_asm_diskgroup
() {
1530 echo 'prompt <<<oracle_asm_diskgroup:sep(124)>>>'
1531 if [ "$NUMERIC_ORACLE_VERSION" -ge 112 ]; then
1533 echo "SELECT g.state
1536 || '|' || g.BLOCK_SIZE
1537 || '|' || g.ALLOCATION_UNIT_SIZE
1538 || '|' || g.REQUIRED_MIRROR_FREE_MB
1539 || '|' || sum(d.total_mb)
1540 || '|' || sum(d.free_mb)
1541 || '|' || d.failgroup
1542 || '|' || d.VOTING_FILE
1543 || '|' || d.FAILGROUP_TYPE
1544 || '|' || g.offline_disks
1545 || '|' || min(decode(d.REPAIR_TIMER, 0, 8640000, d.REPAIR_TIMER))
1547 FROM v\$asm_diskgroup g
1548 LEFT OUTER JOIN v\$asm_disk d on d.group_number = g.group_number
1549 and d.group_number = g.group_number
1550 and d.group_number <> 0
1557 , g.ALLOCATION_UNIT_SIZE
1558 , g.REQUIRED_MIRROR_FREE_MB
1562 ORDER BY g.name, d.failgroup;"
1564 elif [ "$NUMERIC_ORACLE_VERSION" -ge 102 ]; then
1568 || '|' || sector_size
1569 || '|' || block_size
1570 || '|' || allocation_unit_size
1573 || '|' || required_mirror_free_mb
1574 || '|' || usable_file_mb
1575 || '|' || offline_disks
1577 || '|' || name || '/'
1578 from v\$asm_diskgroup;"
1583 # .--helper--------------------------------------------------------------.
1585 # | | |__ ___| |_ __ ___ _ __ |
1586 # | | '_ \ / _ \ | '_ \ / _ \ '__| |
1587 # | | | | | __/ | |_) | __/ | |
1588 # | |_| |_|\___|_| .__/ \___|_| |
1590 # '----------------------------------------------------------------------'
1592 do_dummy_sections
() {
1593 if [ "$MK_ORA_LOGGING" != "1" ]; then
1594 for section
in $SYNC_SECTIONS $ASYNC_SECTIONS $SYNC_ASM_SECTIONS $ASYNC_ASM_SECTIONS; do
1595 echo "<<<oracle_${section}>>>"
1603 if [ -n "${MK_ORA_SECTIONS[*]}" ]; then
1604 for mk_ora_section
in "${MK_ORA_SECTIONS[@]}"; do
1605 if [ "$mk_ora_section" = "${section}" ]; then
1619 if [ "$ONLY_SIDS" ]; then
1620 if echo "$ONLY_SIDS" |
"${GREP}" -q "$sid"; then
1628 if [ "$SKIP_SIDS" ]; then
1629 if echo "$SKIP_SIDS" |
"${GREP}" -q "$sid"; then
1637 EXCLUDE
=EXCLUDE_
$sid
1638 # Handle explicit exclusion of instances but not for +ASM
1639 if [[ "$EXCLUDE" =~ ^
[a-zA-Z
][a-zA-Z0-9_
]*$
]]; then
1641 if [ "$EXCLUDE" = "ALL" ]; then
1652 remove_excluded_sections
() {
1653 # We exclude instance section because we have already executed
1654 # the sql_instance section at the beginning for every SID.
1659 for section
in $sections; do
1661 for exclude
in $excluded; do
1662 if [ "$exclude" = "$section" ]; then
1667 if [ "$skip" != yes ]; then
1668 result
=${result:+"$result "}"${section}"
1675 ora_session_environment
() {
1676 echo 'set pages 0 trimspool on feedback off lines 8000'
1677 if [ "$NUMERIC_ORACLE_VERSION" -ge 102 ] && [ ! "$DISABLE_ORA_SESSION_SETTINGS" ]; then
1679 echo 'alter session set "_optimizer_mjc_enabled"=false;'
1681 # cursor_sharing is not valid for ASM instances
1682 if [ ! "${ORACLE_SID:0:1}" = '+' ]; then
1683 echo 'alter session set cursor_sharing=exact;'
1688 #TODO Do not exit after first error otherwise
1689 # section specific errors won't be seen any more.
1690 #echo 'whenever sqlerror exit 1'
1695 # .--run cached----------------------------------------------------------.
1697 # | _ __ _ _ _ __ ___ __ _ ___| |__ ___ __| | |
1698 # | | '__| | | | '_ \ / __/ _` |/ __| '_ \ / _ \/ _` | |
1699 # | | | | |_| | | | | | (_| (_| | (__| | | | __/ (_| | |
1700 # | |_| \__,_|_| |_| \___\__,_|\___|_| |_|\___|\__,_| |
1702 # '----------------------------------------------------------------------'
1705 if [ -n "${MK_ORA_SECTIONS[*]}" ]; then
1712 local cache_file
="$MK_VARDIR/cache/oracle_${MK_SID}.cache"
1713 local use_cache_file
=
1718 logging
"[${MK_SID}] [run_cached]" "Cache file: $cache_file"\
1719 "Cache max age: $maxage" "Command name: $cmd_name"
1721 if [ ! -d "$MK_VARDIR/cache" ]; then
1722 mkdir
-p "$MK_VARDIR/cache"
1725 # Check if the creation of the cache takes suspiciously long and return
1726 # nothing if the age (access time) of $cache_file.new is twice the 'maxage'
1727 # perl is needed for Solaris => no date +%s availible
1728 now
=$
(perl
-le "print time()")
1729 if [ -e "${cache_file}.new" ]; then
1730 cf_atime
=$
(eval "$STATCX" "${cache_file}.new")
1731 if [ $
((now
- cf_atime
)) -ge $
((maxage
* 2)) ]; then
1732 # Kill the process still accessing that file in case
1733 # it is still running. This avoids overlapping processes!
1734 fuser
-k -9 "${cache_file}.new" >/dev
/null
2>&1
1735 rm -f "${cache_file}.new"
1736 logging
"[${MK_SID}] [run_cached]" "Creation of the cache takes suspiciously long"
1741 # Check if cache file exists and is recent enough
1742 if [ -s "$cache_file" ]; then
1743 mtime
=$
(eval "$STATCY" "$cache_file")
1744 if [ $
((now
- mtime
)) -le "$maxage" ]; then
1747 # Output the file in any case, even if it is
1748 # outdated. The new file will not yet be available
1749 logging
"[${MK_SID}] [run_cached]" "Cache file exists and is recent enough"
1753 # Cache file outdated and new job not yet running? Start it
1754 if [ -z "$use_cache_file" ] && [ ! -e "${cache_file}.new" ]; then
1755 logging
"[${MK_SID}] [run_cached]" "Cache file outdated, start it."
1756 if [ "$MK_ORA_DEBUG" ]; then
1757 echo "set -o noclobber; exec > \"${cache_file}.new\" || exit 1; ${cmd_name} && mv \"${cache_file}.new\" \"${cache_file}\" || rm -f \"${cache_file}\" \"${cache_file}.new\"" |
/bin
/bash
1759 # When the command fails, the output is throws away ignored
1760 echo "set -o noclobber; exec > \"${cache_file}.new\" || exit 1; ${cmd_name} && mv \"${cache_file}.new\" \"${cache_file}\" || rm -f \"${cache_file}\" \"${cache_file}.new\"" | nohup
/bin
/bash
>/dev
/null
2>&1 &
1766 # .--DB connect----------------------------------------------------------.
1768 # | | _ \| __ ) ___ ___ _ __ _ __ ___ ___| |_ |
1769 # | | | | | _ \ / __/ _ \| '_ \| '_ \ / _ \/ __| __| |
1770 # | | |_| | |_) | | (_| (_) | | | | | | | __/ (__| |_ |
1771 # | |____/|____/ \___\___/|_| |_|_| |_|\___|\___|\__| |
1773 # '----------------------------------------------------------------------'
1775 mk_ora_db_connect
() {
1781 if [[ "$sid" =~ ^REMOTE_INSTANCE_.
* ]]; then
1782 # working on REMOTE_-Mode!
1783 ORACFGLINE
=$
(eval "echo \${$1}")
1784 ORACLE_SID
=$
(echo "${ORACFGLINE}" | cut
-d":" -f7)
1785 TNSALIAS
=$
(echo "${REMOTE_VARNAME}" | cut
-d"_" -f3-)
1788 # working with locally running instances
1789 # mk_oracle_dbusers.conf is for compatibility. Do not use it anymore
1790 ORACLE_USERCONF
=${MK_CONFDIR}/mk_oracle_dbuser.conf
1791 TNSALIAS
=${ORACLE_SID}
1793 # ASM use '+' as 1st character in SID!
1794 if [ "${ORACLE_SID:0:1}" = '+' ]; then
1795 ORACFGLINE
=${ASMUSER}
1798 # use an individuel user or the default DBUSER from mk_oracle.cfg
1799 dummy
="DBUSER_${ORACLE_SID}"
1800 ORACFGLINE
=${!dummy}
1801 if [ "$ORACFGLINE" = '' ]; then
1802 ORACFGLINE
=${DBUSER}
1806 if [ -f "${ORACLE_USERCONF}" ] && [ "${ORACFGLINE}" = '' ]; then
1807 # mk_oracle_dbuser.conf
1808 ORACFGLINE
=$
("${GREP}" "^${ORACLE_SID}:" < "${ORACLE_USERCONF}")
1809 # mk_oracle_dbuser has ORACLE_SID as 1. parameter. we need an offset for all values
1815 ORADBUSER
=$
(echo "${ORACFGLINE}" | cut
-d":" -f$
((1+offset
)))
1816 DBPASSWORD
=$
(echo "${ORACFGLINE}" | cut
-d":" -f$
((2+offset
)))
1817 DBSYSCONNECT
=$
(echo "${ORACFGLINE}" | cut
-d":" -f$
((3+offset
)))
1818 DBHOST
=$
(echo "${ORACFGLINE}" | cut
-d":" -f$
((4+offset
)))
1819 DBPORT
=$
(echo "${ORACFGLINE}" | cut
-d":" -f$
((5+offset
)))
1822 if [ -f "${TNS_ADMIN}/tnsnames.ora" ]; then
1823 if [ "${ORADBUSER:0:2}" = '/@' ]; then
1824 P_TNSALIAS_P
=$
(eval echo "${ORADBUSER:2}")
1826 P_TNSALIAS_P
=$ORACLE_SID
1829 if [ -n "$P_TNSALIAS_P" ]; then
1830 PREFIX_SID
="PREFIX_$sid"
1831 PREFIX_SID
=${!PREFIX_SID}
1832 if [ -n "$PREFIX_SID" ]; then
1833 P_TNSALIAS_P
="$PREFIX_SID$P_TNSALIAS_P"
1834 elif [ -n "$PREFIX" ]; then
1835 P_TNSALIAS_P
="$PREFIX$P_TNSALIAS_P"
1837 P_TNSALIAS_P
="$P_TNSALIAS_P"
1840 POSTFIX_SID
="POSTFIX_$sid"
1841 POSTFIX_SID
=${!POSTFIX_SID}
1842 if [ -n "$POSTFIX_SID" ]; then
1843 P_TNSALIAS_P
="$P_TNSALIAS_P$POSTFIX_SID"
1844 elif [ -n "$POSTFIX" ]; then
1845 P_TNSALIAS_P
="$P_TNSALIAS_P$POSTFIX"
1847 P_TNSALIAS_P
="$P_TNSALIAS_P"
1851 if "${ORACLE_HOME}"/bin
/tnsping
"${P_TNSALIAS_P}" >/dev
/null
2>&1; then
1852 TNSALIAS
="$P_TNSALIAS_P"
1861 logging
"[${sid}] [mk_ora_db_connect]" "ORA DB user: $ORADBUSER"\
1862 "DB sys connect: $DBSYSCONNECT" "DB host: $DBHOST" "DB port: $DBPORT"\
1863 "TNS alias: $TNSALIAS" "TNS PING: ${TNSPINGOK}"
1865 if [ ! "${ORACFGLINE}" ]; then
1866 # no configuration found
1867 # => use the wallet with tnsnames.ora or EZCONNECT
1868 TNSALIAS
=${TNSALIAS:-"localhost:1521/${ORACLE_SID}"}
1870 if [ "${DBSYSCONNECT}" ]; then
1871 assysdbaconnect
=" as "${DBSYSCONNECT}
1874 TNSALIAS
=${TNSALIAS:-"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=${DBHOST:-"localhost"})(PORT=${DBPORT:-1521}))(CONNECT_DATA=(SID=${ORACLE_SID})(SERVER=DEDICATED)(UR=A)))"}
1876 # ORADBUSER = '/'? => ignore DBPASSWORD and use the wallet
1877 if [ "${ORADBUSER:0:1}" = '/' ]; then
1878 # connect with / and wallet
1881 if [ "$TNSPINGOK" = 'no' ]; then
1882 # create an EZCONNECT string when no tnsnames.ora is usable
1883 # defaults to localhost:1521/<ORACLE_SID>
1884 TNSALIAS
="${DBHOST:-"localhost"}:${DBPORT:-1521}/${ORACLE_SID}"
1889 logging
"[${sid}] [mk_ora_db_connect]" "DB connection: ${ORADBUSER}/${DBPASSWORD//?/*}@${TNSALIAS}${assysdbaconnect}"
1890 echo "${ORADBUSER}/${DBPASSWORD}@${TNSALIAS}${assysdbaconnect}"
1895 # .--mk ora sqlplus------------------------------------------------------.
1897 # | _ __ ___ | | __ ___ _ __ __ _ ___ __ _| |_ __ | |_ _ ___ |
1898 # | | '_ ` _ \| |/ / / _ \| '__/ _` | / __|/ _` | | '_ \| | | | / __| |
1899 # | | | | | | | < | (_) | | | (_| | \__ \ (_| | | |_) | | |_| \__ \ |
1900 # | |_| |_| |_|_|\_\ \___/|_| \__,_| |___/\__, |_| .__/|_|\__,_|___/ |
1902 # '----------------------------------------------------------------------'
1905 local from_where
="$1"
1911 logging
"[${MK_SID}] [${from_where}] [mk_ora_sqlplus]" "Piggyback host: $MK_PIGGYBACK_HOST"
1913 start_time
="$(perl -MTime::HiRes=time -wle 'print time')"
1916 SQLPLUS
=${ORACLE_HOME}/bin
/sqlplus
1917 if [ ! -x "${SQLPLUS}" ]; then
1918 logging
-w "[${MK_SID}] [${from_where}] [mk_ora_sqlplus]" "SQLplus '${SQLPLUS}' not found or ORACLE_HOME '${ORACLE_HOME}' wrong."
1919 echo "sqlplus not found or ORACLE_HOME wrong!"
1920 echo "SQLPLUS=${SQLPLUS}"
1924 if [ -n "$MK_PIGGYBACK_HOST" ]; then
1925 echo "<<<<${MK_PIGGYBACK_HOST}>>>>"
1928 if output
=$
(echo "$(ora_session_environment)${loc_stdin}" |
"$SQLPLUS" -L -s "$MK_DB_CONNECT"); then
1932 logging
-w "[${MK_SID}] [${from_where}] [mk_ora_sqlplus]" "OUTPUT '$output'"
1933 output
=$
(echo -e "$output" |
"${GREP}" -v "^ERROR at line" |
tr '\n' ' ' |\
1934 sed "s/^/$(echo "$MK_SID" | tr '[:lower:]' '[:upper:]')|FAILURE|/" ; echo)
1935 if [ "$MK_ORA_DEBUG_CONNECT" ]; then
1936 echo "Logindetails: ${DBCONNECT}" >&2
1939 echo '<<<oracle_instance:sep(124)>>>'
1945 elapsed_time
=$
(bc <<<"$(perl -MTime::HiRes=time -wle 'print time')-$start_time")
1947 if [ -n "$MK_PIGGYBACK_HOST" ]; then
1951 logging
"[${MK_SID}] [${from_where}] [mk_ora_sqlplus]" "Elapsed time: $elapsed_time"
1955 # .--do checks-----------------------------------------------------------.
1957 # | __| | ___ ___| |__ ___ ___| | _____ |
1958 # | / _` |/ _ \ / __| '_ \ / _ \/ __| |/ / __| |
1959 # | | (_| | (_) | | (__| | | | __/ (__| <\__ \ |
1960 # | \__,_|\___/ \___|_| |_|\___|\___|_|\_\___/ |
1962 # '----------------------------------------------------------------------'
1964 # Create one SQL statements for several sections and run
1965 # these with sqlplus. The exitcode is preserved.
1967 logging
"[${MK_SID}] [do_sync_checks]" "Query: $MK_SYNC_SECTIONS_QUERY"
1968 echo "$MK_SYNC_SECTIONS_QUERY" | mk_ora_sqlplus
"do_sync_checks"
1972 do_async_checks
() {
1973 logging
"[${MK_SID}] [do_async_checks]" "Query: $MK_ASYNC_SECTIONS_QUERY"
1974 echo "$MK_ASYNC_SECTIONS_QUERY" | mk_ora_sqlplus
"do_async_checks"
1983 echo "---login----------------------------------------------------------------"
1984 echo " Operating System: ${OS_TYPE}"
1985 echo " ORACLE_HOME ${ORA_HOME_SOURCE} ${ORACLE_HOME}"
1986 echo " Logincheck to Instance: ${MK_SID}"
1987 echo " Version: ${ORACLE_VERSION}"
1988 echo "select ' Login ok User: ' || user || ' on ' || host_name ||' Instance ' || instance_name
1989 from v\$instance;" | mk_ora_sqlplus
"do_testmode"
1990 echo " SYNC_SECTIONS: $sections"
1991 echo " ASYNC_SECTIONS: $asections"
1992 if [ "$IGNORE_DB_NAME" ]; then
1993 echo " IGNORE_DB_NAME found. Ignoring DB_NAME in all SQLs!"
1996 if [ "$DISABLE_ORA_SESSION_SETTINGS" ]; then
1997 echo " Paramter DISABLE_ORA_SESSION_SETTINGS found!"
2000 if [ "$HINT_RMAN" ]; then
2001 echo " Using HINT_RMAN for this Instance!"
2003 echo "------------------------------------------------------------------------"
2013 if [ "${ORACLE_SID:0:1}" = '+' ]; then
2015 local do_async_sections
=${ASYNC_ASM_SECTIONS}
2016 local do_sync_sections
=${SYNC_ASM_SECTIONS}
2018 local do_sync_sections
=${SYNC_SECTIONS}
2019 local do_async_sections
=${ASYNC_SECTIONS}
2022 if [ -n "${MK_ORA_SECTIONS[*]}" ]; then
2024 for section
in $do_sync_sections $do_async_sections; do
2025 if [ "$(do_section "$section")" = "yes" ]; then
2026 sections
=${sections:+"$sections "}"${section}"
2028 done; echo "$sections")
2029 logging
"[${MK_SID}] [do_checks]" "Do single sections: $sections"
2031 MK_SYNC_SECTIONS_QUERY
=$
(for section
in $sections; do eval "sql_$section" ; done)
2032 MK_ASYNC_SECTIONS_QUERY
=
2035 excluded
=$
(eval "echo \$EXCLUDE_$MK_SID")
2036 sections
=$
(remove_excluded_sections
"$do_sync_sections" "$excluded")
2037 asections
=$
(remove_excluded_sections
"$do_async_sections" "$excluded")
2038 logging
"[${MK_SID}] [do_checks]" "Excluded: $excluded"\
2039 "Sections: $sections" "Async sections: $asections"
2041 MK_SYNC_SECTIONS_QUERY
=$
(for section
in $sections; do eval "sql_$section" ; done)
2042 MK_ASYNC_SECTIONS_QUERY
=$
(for section
in $asections; do eval "sql_$section" ; done)
2045 export MK_ASYNC_SECTIONS_QUERY
2047 if [ "$MK_ORA_LOGGING" = "1" ]; then
2048 logging
"[${MK_SID}] [do_checks]" "Testmode: $(echo \
2049 "select user ||
' on ' || host_name ||
' instance ' || instance_name from v\
$instance;" | mk_ora_sqlplus "do_checks
")"
2052 if [ "$MK_ORA_DEBUG_CONNECT" = "1" ]; then
2053 do_testmode
"$sections" "$asections" 2>&1
2056 run_cached
"$CACHE_MAXAGE" do_async_checks
2061 # .--main----------------------------------------------------------------.
2063 # | _ __ ___ __ _(_)_ __ |
2064 # | | '_ ` _ \ / _` | | '_ \ |
2065 # | | | | | | | (_| | | | | | |
2066 # | |_| |_| |_|\__,_|_|_| |_| |
2068 # +----------------------------------------------------------------------+
2069 # | Iterate over all instances and execute sync and async sections. |
2070 # '----------------------------------------------------------------------'
2072 # Make sure that the new shell that is being run by run_cached inherits
2075 export -f mk_ora_sqlplus
2076 export -f ora_session_environment
2077 export -f do_async_checks
2078 export -f set_ora_env
2080 # ---preliminaries--------------------------------------------------------
2082 logging
"--------------------------------------------------------------------"
2083 if [ "$MK_ORA_LOGGING" == "1" ]; then
2084 echo "Start logging to file: $MK_VARDIR/log/mk_oracle.log" >&2
2088 logging
"[preliminaries]" "OS: ${OS_TYPE}"\
2089 "GREP: ${GREP}" "AWK: ${AWK}" "STATCX: ${STATCX}" "STATCY: ${STATCY}"
2092 logging
"[preliminaries]" "SYNC_SECTIONS: ${SYNC_SECTIONS}"\
2093 "ASYNC_SECTIONS: ${ASYNC_SECTIONS}" "SYNC_ASM_SECTIONS: ${SYNC_ASM_SECTIONS}"\
2094 "ASYNC_ASM_SECTIONS: ${ASYNC_ASM_SECTIONS}" "CACHE_MAXAGE: ${CACHE_MAXAGE}"\
2095 "ONLY_SIDS: ${ONLY_SIDS}" "SKIP_SIDS: ${SKIP_SIDS}"
2098 # Get list of all running databases. Do not work on ASM in this plugin.
2099 # => Ignore a running ASM-Instance!
2100 # shellcheck disable=SC2016
2101 SIDS
=$
(UNIX95
=true ps
-ef |
"${AWK}" '{print $NF}' |
"${GREP}" -E '^asm_pmon_|^ora_pmon_|^xe_pmon_XE' | cut
-d"_" -f3-)
2104 # Are there any remote configurations?
2105 for remote_instance
in $
(compgen
-A variable |
"${GREP}" -E "^REMOTE_INSTANCE_.*"); do
2106 REMOTE_INSTANCES
="${REMOTE_INSTANCES} ${remote_instance}"
2107 # shellcheck disable=SC2005
2108 PIGGYBACK_HOSTS
="$(echo "$
(eval "echo \${$remote_instance}")" | cut -d":" -f6) ${PIGGYBACK_HOSTS}"
2112 logging
"[preliminaries]" "SIDs: ${SIDS//\\n/ }"\
2113 "Remote instances: ${REMOTE_INSTANCES}"\
2114 "Piggyback hosts: ${PIGGYBACK_HOSTS}"
2117 if [ "$PIGGYBACK_HOSTS" ]; then
2118 PIGGYBACK_HOSTS
=$
(echo "$PIGGYBACK_HOSTS" |
tr ' ' '\n' |
sort |
uniq)
2119 logging
"[preliminaries]" "Removed duplicate piggyback hosts"\
2120 "Remaining piggyback hosts: ${PIGGYBACK_HOSTS}"
2122 if [ ! -e "$MK_VARDIR/mk_oracle.found" ]; then
2123 touch "$MK_VARDIR/mk_oracle.found"
2128 # If we do not have found any running database instance, then either
2129 # no ORACLE is present on this system or it's just currently not running.
2130 # In the later case we ouput empty agent sections so that Check_MK will be
2131 # happy and execute the actual check functions.
2132 if [ -z "$SIDS" ] && [ ! -e "$MK_VARDIR/mk_oracle.found" ]; then
2133 logging
-c "[preliminaries]" "No SIDs and \$MK_VARDIR/mk_oracle.found not found"
2134 echo "No SIDs and \$MK_VARDIR/mk_oracle.found not found" >&2
2139 # From now on we expect databases on this system (for ever)
2140 touch "$MK_VARDIR/mk_oracle.found"
2143 # Make sure that always all sections are present, even
2144 # in case of an error. Note: the section <<<oracle_instance>>>
2145 # section shows the general state of a database instance. If
2146 # that section fails for an instance then all other sections
2147 # do not contain valid data anyway.
2151 if [ "$PIGGYBACK_HOSTS" ]; then
2152 for piggyback_host
in $PIGGYBACK_HOSTS; do
2153 echo "<<<<${piggyback_host}>>>>"
2159 # ---local----------------------------------------------------------------
2161 for sid
in $SIDS; do
2162 skip
=$
(skip_sid
"$sid")
2163 logging
"[${sid}] [local]" "Skipping: $skip"
2164 if [ "$skip" == "yes" ]; then
2169 if [ $?
-eq 2 ] ; then
2170 # we have to skip this SID due to missing/unknown ORACLE_HOME
2173 set_ora_version
"$("${ORACLE_HOME}"/bin/sqlplus -V | "${GREP}" ^SQL | cut -d" " -f3 | cut -d".
" -f-2)"
2174 logging
"[${sid}] [local]" "ORACLE_HOME: ${ORACLE_HOME}" "TNS_ADMIN: ${TNS_ADMIN}"\
2175 "ORACLE_SID: ${ORACLE_SID}" "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"\
2176 "ORACLE_VERSION: ${ORACLE_VERSION} (${NUMERIC_ORACLE_VERSION})"
2179 db_connect
=$
(mk_ora_db_connect
"$sid")
2181 export MK_DB_CONNECT
=$db_connect
2186 # ---remote---------------------------------------------------------------
2188 for remote_instance
in $REMOTE_INSTANCES; do
2189 remote_instance_line
=$
(eval "echo \${$remote_instance}")
2191 set_ora_env
"$remote_instance"
2192 set_ora_version
"$(echo "$remote_instance_line" | cut -d":" -f8)"
2193 logging
"[${remote_instance}] [remote]" "ORACLE_HOME: ${ORACLE_HOME}" "TNS_ADMIN: ${TNS_ADMIN}"\
2194 "ORACLE_SID: ${ORACLE_SID}" "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"\
2195 "ORACLE_VERSION: ${ORACLE_VERSION} (${NUMERIC_ORACLE_VERSION})"
2197 db_connect
=$
(mk_ora_db_connect
"$remote_instance")
2198 piggyback_host
=$
(echo "${remote_instance_line}" | cut
-d":" -f6)
2199 export MK_SID
=$remote_instance
2200 export MK_DB_CONNECT
=$db_connect
2201 export MK_PIGGYBACK_HOST
=$piggyback_host