oracle大表怎么检测 oracle 大表

如何检测Oracle的可用性和表空间容量

除了Oracle的激活和可用性之外,我们还需要进行检测以确保它可以用,这样我们还可以检测表空间的容量 。

为代县等地区用户提供了全套网页设计制作服务,及代县网站建设行业解决方案。主营业务为成都网站设计、做网站、成都外贸网站建设公司、代县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

检测的脚本:

◆假设所有的Oracle环境都已经搭建起来了

◆假设所有的扩展都已经达到了最大的限度

◆假设左右的表空间都缺乏运行的空闲空间

下面的脚本可以在你想要的任何时候通过crontab 来中断 。另外,如果上面的例外情况出现了的话,您还可以就这个脚本写信或者电子邮件给支持人员获得帮助 。

如果您有什么其他的测试,这个脚本可以让您轻松地进行修改以加以利用 。我使用这个Monitororcl 脚本作为模板并且在末尾添加了功能 。

按crontab来调用query_oracle_instances.sh 脚本:

#!/bin/ksh

. /u01/home/oracle/.profile

/u01/app/oracle/admin/monitororcl

cat /u01/app/oracle/admin/Get_Oracle_Instance_Listexit

Get_Oracle_Instance_List 脚本如下:

instance_name1 tnsname1 sys_password_for_this_instanceinstance_name2 tnsname2 sys_password_for_this_instanceinstance_name3 tnsname3 sys_password_for_this_instance下面是MONITORORCL脚本:

#!/bin/ksh

#script : Rick Stehno

# script will monitor to see if Oracle is upwhile [ "$1" != "" ]

do

ORACLE_INSTANCE=$1

ORACLE_TNS=$2

USR_ID=sys

USR_PASS=$3

# echo "Instance: [$ORACLE_INSTANCE]"

# echo "TNS [$ORACLE_TNS]"

# echo "PASS: [$USR_PASS]"

LOGFIL=/u01/app/oracle/admin/monitordev1.outNOTIFY_LIST=userid1@mobilephone.com,userid2,userid3@pagercompany.com#

# 检测关键的段没有达到最大限度

sqlplus -s $LOGFIL 2/dev/null

$USR_ID/$USR_PASS@$ORACLE_TNS

set pages 0

select distinct YES from dba_segments

where extents = (max_extents-5) and segment_name not like 1.%;EOF1

grep -i ^ORA- $LOGFIL /dev/null

if [ $? -eq 0 ]

then

echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LISTexit 1

fi

MAXEXTENTS_REACHED=`awk { print $1 } $LOGFIL`if [ "$MAXEXTENTS_REACHED" = "YES" ]

then

echo "$0 failed: $ORACLE_INSTANCE max extents reached" | /bin/mailx -s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LISTexit 1

fi

#

# 检测是否能分配下一个段

sqlplus -s $LOGFIL 2/dev/null

$USR_ID/$USR_PASS@$ORACLE_TNS

set pages 0

select distinct YES from dba_segments ds

where next_extent

(select max(bytes) from dba_free_space

where tablespace_name = ds.tablespace_name);EOF2

grep -i ^ORA- $LOGFIL /dev/null

if [ $? -eq 0 ]

then

echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LISTexit 1

fi

POSSIBLE_NEXTEXT_FAIL=`awk {print $1 } $LOGFIL`if [ "$POSSIBLE_NEXTEXT_FAIL" = "YES" ]

then

echo "$0 failed: $ORACLE_INSTANCE cannot extend segment" | /bin/mailx -s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LISTexit 1

fi

shift 3

# echo "shift done"

done

echo "Successful completion of $0" `date`exit 0

Oracle怎么查看表的大小?

有两种含义的表大小。一种是分配给一个表的物理空间数量,而不管空间是否被使用。可以这样查询获得字节数:

select segment_name, bytes 

from user_segments 

where segment_type = 'TABLE'; 

或者

Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name

另一种表实际使用的空间。这样查询:

analyze table emp compute statistics; 

select num_rows * avg_row_len 

from user_tables 

where table_name = 'EMP';

查看每个表空间的大小

Select Tablespace_Name,Sum(bytes)/1024/1024 From Dba_Segments Group By Tablespace_Name

怎么查看oracle数据库表的大小

1. 查看所有表空间大小 SQL select tablespace_name,sum(bytes)/1024/1024 from dba_data_files 2 group by tablespace_name; 2. 已经使用的表空间大小 SQL select tablespace_name,sum(bytes)/1024/1024 from dba_free_space 2 group by tablespace_name; 3. 所以使用空间可以这样计算 select a.tablespace_name,total,free,total-free used from ( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files group by tablespace_name) a, ( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name; 4. 下面这条语句查看所有segment的大小。 Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name 5. 还有在命令行情况下如何将结果放到一个文件里。 SQL spool out.txt SQL select * from v$database; SQL spool off

Oracle 怎么查看表大小

可用如下语句查看:

select round(BYTES/1024/1024,2)||'M' from user_segments where segment_name='表名';

注意:表名需要用英文大写。

如要查询数据库中emp表的大小,用如下语句:

select round(BYTES/1024/1024,2)||'M' from user_segments where segment_name='EMP';

查询结果:

查询结果代表EMP表所占空间大小为0.06M。


本文标题:oracle大表怎么检测 oracle 大表
URL标题:http://pwwzsj.com/article/hjgohh.html