PHP OCI8查询ORACLE自动扩展表空间占用和状态

<?php

$conn = oci_connect('system', ' password', '127.0.0.1/orcl');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

// Prepare the statement
$stid = oci_parse($conn, "select tablespace_name,
       max_gb,
       used_gb,
       round(100 * used_gb / max_gb) pct_used,
       status,LOGGING,FORCE_LOGGING,EXTENT_MANAGEMENT,ALLOCATION_TYPE
  from (
select t.status status,t.LOGGING LOGGING,t.FORCE_LOGGING FORCE_LOGGING,t.EXTENT_MANAGEMENT EXTENT_MANAGEMENT,t.ALLOCATION_TYPE ALLOCATION_TYPE,a.tablespace_name tablespace_name,
               round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 30),
                     2) used_gb,
               round(a.maxbytes / power(2, 30), 2) max_gb
          from dba_tablespaces t,(select f.tablespace_name,
                       sum(f.bytes) bytes_alloc,
                       sum(decode(f.autoextensible,
                                  'YES',
                                  f.maxbytes,
                                  'NO',
                                  f.bytes)) maxbytes
                  from dba_data_files f
                 group by tablespace_name) a,
               (select f.tablespace_name, sum(f.bytes) bytes_free
                  from dba_free_space f
                 group by tablespace_name) b
         where a.tablespace_name = b.tablespace_name(+) and a.tablespace_name = t.tablespace_name
union all
select t.status status,t.LOGGING LOGGING,t.FORCE_LOGGING FORCE_LOGGING,t.EXTENT_MANAGEMENT EXTENT_MANAGEMENT,t.ALLOCATION_TYPE ALLOCATION_TYPE,h.tablespace_name tablespace_name,
               round(sum(nvl(p.bytes_used, 0)) / power(2, 30), 2) used_gb,
               round(sum(decode(f.autoextensible,
                                'YES',
                                f.maxbytes,
                                'NO',
                                f.bytes)) / power(2, 30),
                     2) max_gb
          from dba_tablespaces t,v\$temp_space_header h, v\$temp_extent_pool p, dba_temp_files f
         where p.file_id(+) = h.file_id
           and p.tablespace_name(+) = h.tablespace_name
           and f.file_id = h.file_id
           and f.tablespace_name = h.tablespace_name
           and t.tablespace_name = h.tablespace_name
         group by h.tablespace_name,t.status,t.LOGGING,t.FORCE_LOGGING,t.EXTENT_MANAGEMENT,t.ALLOCATION_TYPE
)                  
order by 4");
if (!$stid) {
    $e = oci_error($conn);
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

// Fetch the results of the query
print "<table border='1'>\n";
        echo "<tr>";
$ncols = oci_num_fields($stid);

    for ($i = 1; $i <= $ncols; $i++) {
        $column_name  = oci_field_name($stid, $i);
        echo "<td>$column_name</td>";
    }
        echo "</tr>";

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    print "<tr>\n";
    foreach ($row as $item) {
        print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";

oci_free_statement($stid);
oci_close($conn);

?>

 

TABLESPACE_NAMEMAX_GBUSED_GBPCT_USEDSTATUSLOGGINGFORCE_LOGGINGEXTENT_MANAGEMENTALLOCATION_TYPE
USERS3200ONLINELOGGINGNOLOCALSYSTEM
TESTTBS6400ONLINELOGGINGNOLOCALSYSTEM
UNDOTBS132.020ONLINELOGGINGNOLOCALSYSTEM
TEMP3200ONLINENOLOGGINGNOLOCALUNIFORM
SYSTEM32.732ONLINELOGGINGNOLOCALSYSTEM
SYSAUX32.512ONLINELOGGINGNOLOCALSYSTEM
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值