update list-tablespaces

This commit is contained in:
garnier-quentin 2019-11-08 11:47:45 +01:00
parent 370614f827
commit 6c0b9c6939
1 changed files with 29 additions and 5 deletions

View File

@ -49,10 +49,30 @@ sub manage_selection {
my ($self, %options) = @_;
$options{sql}->connect();
# request from check_oracle_health.
my $query;
if ($options{sql}->is_version_minimum(version => '9')) {
if ($options{sql}->is_version_minimum(version => '11')) {
$query = sprintf(
q{
SELECT
tum.tablespace_name "Tablespace",
t.status "Status",
t.contents "Type",
t.extent_management "Extent Mgmt",
tum.used_space*t.block_size bytes,
tum.tablespace_size*t.block_size bytes_max
FROM
DBA_TABLESPACE_USAGE_METRICS tum
INNER JOIN
dba_tablespaces t on tum.tablespace_name=t.tablespace_name
%s
},
defined($self->{option_results}->{notemp}) ?
"WHERE (t.contents != 'TEMPORARY' AND t.contents != 'UNDO')" :
''
);
} elsif ($options{sql}->is_version_minimum(version => '9')) {
my $tbs_sql_undo = q{
SELECT
tablespace_name, bytes_expired
@ -269,10 +289,8 @@ sub manage_selection {
}
$options{sql}->query(query => $query);
my $result = $options{sql}->fetchall_arrayref();
$options{sql}->disconnect();
my $tablespaces = {};
foreach my $row (@$result) {
my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row;
@ -296,7 +314,12 @@ sub manage_selection {
}
my ($percent_used, $percent_free, $used, $free, $size);
if ((!defined($bytes_max)) || ($bytes_max eq '')) {
if ($options{sql}->is_version_minimum(version => '11')) {
$percent_used = $bytes / $bytes_max * 100;
$size = $bytes_max;
$free = $bytes_max - $bytes;
$used = $bytes;
} elsif ((!defined($bytes_max)) || ($bytes_max eq '')) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1);
next;
} elsif ($bytes_max > $bytes) {
@ -322,6 +345,7 @@ sub manage_selection {
};
}
$options{sql}->disconnect();
return $tablespaces;
}