收缩段空间

查看oracle给 对象分配的空间
SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST03          TABLE              TEST                                   28       3584

查看该对象实际占用的空间
SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
   2070296           7 13.8207169
   
 
根据每行的长度 以及 行数 大致获得 该表的空间  
SQL> select count(*)*6/1024/1024 from test;

COUNT(*)*6/1024/1024
--------------------
                  12
                  
查看表空间的使用量
SQL> select tablespace_name,used_space,tablespace_size,used_percent  from dba_tablespace_usage_metrics;

TABLESPACE_NAME                USED_SPACE TABLESPACE_SIZE USED_PERCENT
------------------------------ ---------- --------------- ------------
ADMIN_TBS                               8           15872   .050403226
ADMIN_TBS2                              8            6400         .125
EXAMPLE                              8728         4194302   .208091835
SYSAUX                              29720         4194302   .708580355
SYSTEM                              60680         4194302   1.44672463
TEMP                                    0         4194302            0
TEST                                29184         4194302   .695801113
UNDOTBS1                              176         4194302   .004196169
USERS                                 400         4194302   .009536748

第2次操作

SQL> delete from test03;

2097152 rows deleted.

SQL> insert into test03 select * from test03;

2097152 rows created.

SQL> commit;

Commit complete.

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST03‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST03          TABLE              TEST                                   56       7168

SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST03‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
   2070296           7 13.8207169

SQL> select count(*)*6/1024/1024 from test03;

COUNT(*)*6/1024/1024
--------------------
                  24

收缩表空间
shrink space
SQL> alter table test03 enable row movement;

Table altered.

SQL> alter table test03 shrink space;

Table altered.

SQL> analyze table test03 compute statistics;

Table analyzed.

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST03‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST03          TABLE              TEST                              55.1875       7064
仅仅收缩了 104个数据块!!!

move
SQL> alter table test03 move tablespace admin_tbs;

Table altered.

SQL> alter table test03 disable row movement;

Table altered.

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST03‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST03          TABLE              ADMIN_TBS                              56       7168

第3次

SQL> insert into test values(‘oracle‘);

1 row created.

SQL> /

1 row created.

SQL> insert into test select * from test;

2 rows created.

SQL> /

4 rows created.

SQL> /

8 rows created.

SQL> /

16 rows created.

SQL> /

32 rows created.

SQL> /

64 rows created.

SQL> /

128 rows created.

SQL> /

256 rows created.

SQL> /

512 rows created.

SQL> /

1024 rows created.

SQL> /

2048 rows created.

SQL> /

4096 rows created.

SQL> /

8192 rows created.

SQL> /

16384 rows created.

SQL> /

32768 rows created.

SQL> /

65536 rows created.

SQL> /

131072 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

COUNT(*)
----------
    262144

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST            TABLE              TEST                                    4        512

SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
         0           0          0

SQL> analyze table test compute statistics;

Table analyzed.

SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
    262144          10        2.5

SQL> select count(*)*6/1024/1024 from test;

COUNT(*)*6/1024/1024
--------------------
                 1.5

SQL> delete from test;

262144 rows deleted.

SQL> commit;

Commit complete.

SQL> analyze table test compute statistics;

Table analyzed.

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST            TABLE              TEST                                    4        512

SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
         0           0          0

SQL> select tablespace_name,used_space,tablespace_size,used_percent  from dba_tablespace_usage_metrics;

TABLESPACE_NAME                USED_SPACE TABLESPACE_SIZE USED_PERCENT
------------------------------ ---------- --------------- ------------
ADMIN_TBS                               8           15872   .050403226
ADMIN_TBS2                              8            6400         .125
EXAMPLE                              8728         4194302   .208091835
SYSAUX                              29984         4194302   .714874608
SYSTEM                              60680         4194302   1.44672463
TEMP                                  128         4194302   .003051759
TEST                                  512         4194302   .012207037
UNDOTBS1                            81656         4194302   1.94683168
USERS                                 400         4194302   .009536748

SQL> alter table test move compress;

Table altered.

SQL> analyze table test compute statistics;

Table analyzed.

SQL> select segment_name,segment_type,tablespace_name,bytes/1024/1024 "MB" ,blocks from user_segments where segment_name=‘TEST‘;

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE_NAME                        MB     BLOCKS
--------------- ------------------ ------------------------------ ---------- ----------
TEST            TABLE              TEST                                .0625          8

SQL> select num_rows,avg_row_len,num_rows*avg_row_len/1024/1024 "MB" from user_tables where table_name=‘TEST‘;

NUM_ROWS AVG_ROW_LEN         MB
---------- ----------- ----------
         0           0          0

SQL> select tablespace_name,used_space,tablespace_size,used_percent  from dba_tablespace_usage_metrics;

TABLESPACE_NAME                USED_SPACE TABLESPACE_SIZE USED_PERCENT
------------------------------ ---------- --------------- ------------
ADMIN_TBS                               8           15872   .050403226
ADMIN_TBS2                              8            6400         .125
EXAMPLE                              8728         4194302   .208091835
SYSAUX                              29984         4194302   .714874608
SYSTEM                              60680         4194302   1.44672463
TEMP                                  128         4194302   .003051759
TEST                                    8         4194302   .000190735
UNDOTBS1                             8232         4194302   .196266268
USERS                                 400         4194302   .009536748

SQL> alter table test nocompress;

Table altered.

时间: 2024-10-11 03:57:56

收缩段空间的相关文章

SQLServer数据库如何收缩日志空间?

SQLServer数据库如何收缩日志空间 说明:  SQLServer数据库日志会越来越大,尤其是服务器空间紧张时,你不得不收缩日志来放出部分空间,下面说方法. 版本:  SQLserver 2008 R2 方法: 新建查询,执行脚本.脚本如下 注意 红色部分需要修改成相应的数据库名. 绿色部分需要修改成相应数据库日志名称 USE [USRINF]GOALTER DATABASE USRINF SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE US

本地管理表空间(LMT)与自动段空间管理(ASSM)概念

创建表空间时,extent management local 定义本地管理表空间(LMT),segment space management auto 定义自动段空间管理(ASSM). extent management local(本地管理表空间)是在表空间的头部用位图区记录extent(区)的使用情况(是否为free).与之相对的是字典管理表空间,用数据字典记录extent使用信息. segment space management auto(段空间自动管理)是在段的头部使用位图管理块(BM

如何收缩表空间大小

转摘: oracle数据库表空间文件收缩实例 1.查看数据文件的使用情况 包括内容:数据文件大小,已经used空间,free空间,hwm信息 1 select /*+ ordered use_hash(a,b,c) */ 2 a.file_id,a.file_name,a.filesize, b.freesize, 3 (a.filesize-b.freesize) usedsize, 4 c.hwmsize, 5 c.hwmsize - (a.filesize-b.freesize) unse

dedecms列表页如何让文章列表里面的文章每隔五篇就隔开一段空间

dedecms列表页如何让文章列表里面的文章每隔五篇就隔开一段空间,运用js控制列表样式的方法. 代码如下: <script type="text/javascript">$(function(){         var liList=document.getElementById("uls").getElementsByTagName("li");        for(i=0;i<liList.length;i++)  

脏页flush和收缩表空间

mysql脏页 由于WAL机制,InnoDB在更新语句的时候,制作了写日志这一个磁盘操作,就是redo log,在内存写完redo log后,就返回给客户端, 即更新成功. 把内存里的数据写入磁盘的过程,术语就是flush,在flush之前,实际数据和数据库中的数据是不一致的,因为在redo log基础上更新了还未写入,数据库是老的,当内存数据页跟磁盘数据页内容不一致的时候,称这个内存页为脏页,内存写入后就一致了,称为干净页, 如果mysql偶尔运行速度很慢,很可能是在刷脏页.引发数据库flus

SYBASE扩充日志段空间

有时候日志段空间满了使用下列语句也无济于事,又不能直接重启库,就加空间应急,dump tran QAS with truncate_only dump tran QAS with no_log sp_helpdevicegosp_helpdb QASgo sp_helpsegment logsegment go 声明设备 use master DISK INIT name = 'QAS_data_004',physname = 'E:\sybase\QAS\sapdata_1\QAS_data_

进程间通信 - 动态链接库中共享内存(利用DLL的2~3G的地址段空间)

前言 进程是装入内存并准备执行的程序,每个进程都有私有的虚拟地址空间,由代码.数据,以及其他的一些资源组成.32位系统的进程分配4G的虚拟地址空间.内存地址范围是0x00000000-0xFFFFFFFF.这个内存地址空间是每个进程独立的,也就是说,在一个进程中是不能访问其他进程的地址空间的. 举个例子,进程A的内存里保存了一个数据,假设这个数据的地址是0x33333333.这个是时候,即使把进程B的内存地址是0x33333333的数据读出来.这个数据也和进程A里同地址的数据是不一样的.甚至进程

ORACLE 11G收缩表空间报错 ORA-03297: file contains used data beyondrequested RESIZE value

测试环境磁盘空间不足,所以drop一些无用的大表,但是发现空间没有变化,df -h还是没有释放出磁盘空间来. SQL> set line 200 SQL> set pagesize 200 SQL> col name format A150 1,查看表空间使用情况 SQL> SELECTUPPER(F.TABLESPACE_NAME) "表空间名", 2 D.TOT_GROOTTE_MB "表空间大小(M)", 3 D.TOT_GROOTTE

段空间

段(segment)空间管理模式:段所拥有的数据块中空闲块如何管理 表在表空间所拥有的若干个块叫做段 查看段的管理模式:select tablespace_name, sement_space_management from dba_tablespaces; 段内空闲空闲空间的手工管理:使用空闲列表管理段内的空闲块空闲列表记录在段头,空闲列表指向段内空闲块的地址 查看表所占有的段:select file_id,block_id,blocks from dba_extents where segm