Oracle 中的表压缩要求

发布于 2024-08-22 09:45:09 字数 476 浏览 5 评论 0原文

我有一个总大小为 600 MB 的表空间(这是我的测试机),可用空间为 110 MB。我试图压缩一个大小为 120 MB 的表。执行命令时:

alter table DOWNLOADSESSIONLOG move compress;

我收到错误消息:

(错误):ORA-01659:无法在表空间 WAP 中分配超过 16 的 MINEXTENTS。

我正在搜索,所有人都在说增加表空间,但我想知道我需要提供多少空间,因为我不想提供一些 200 /300 MB 的额外空间。我想在我的测试机中对此进行测试,并希望在具有 60 GB 表空间和一个 47 GB 表的实时系统上实现。我想在实时系统上压缩 47 GB 表,在此之前我想在测试环境中测试它。有没有计算过我们需要给多少空间?否则,在实时系统上,我需要提供大量不必要的空间,这很困难。

感谢有人可以提供一些想法。

I have a Tablespace with total Size 600 MB(this is my test machine), and free space of 110 MB. I was trying to compress a table that's size is 120 MB. When execute the commands:

alter table DOWNLOADSESSIONLOG move compress;

I'm getting error saying:

(Error): ORA-01659: unable to allocate MINEXTENTS beyond 16 in tablespace WAP.

I was searching and all are saying to increase the Tablespace, but I wanted to know how much space I need to give, because I don't want to gave some 200 /300 MB extra space. I wanted to test this in my Test Machine and wanted to implement on Live system that have 60 GB tablespace with one 47 GB table. I wanted to compress 47 GB table on live system, before that I wanted to test it in test environment. Is there any calculation how much space we need to give; otherwise on live system I need to give Lots of space unnecessarily and its difficult.

Appreciate somebody can give some ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

内心激荡 2024-08-29 09:45:09

我将在测试环境中创建一个新的一次性表空间,该表空间与生产环境中的目标表空间具有相同的特征,然后将表移动/压缩到其中。这将为您提供需要多少额外空间的最佳估计。获得此编号后,您可以将表移回原始表空间并删除新表空间。

请记住,在移动期间,表空间中至少需要(原始大小)+(压缩大小)可用。

I would create a new throw-away tablespace in your test environment that has the same characteristics as your target tablespace in the production environment and then move/compress your table into that. This will give you the best estimate of how much additional space will be necessary. You can move the table back to the original tablespace and drop the new tablespace once you have this number.

Remember that you'll need at least (original size) + (compressed size) available in the tablespace for the duration of the move.

っ左 2024-08-29 09:45:09

压缩的关键在于它的工作原理是删除每个块中的重复值。因此,您的测试表需要具有代表性的数据分布。

两个极端的表...

SQL> create table totally_similar
  2      ( txt varchar2(1000) )
  3  /

Table created.

SQL> insert into totally_similar
  2  select rpad('a', 1000, 'a')
  3  from dual connect by level <= 1000
  4  /

1000 rows created.

SQL> create table totally_different
  2      ( txt varchar2(1000) )
  3  /

Table created.

SQL>

在压缩之前,让我们检查表大小...

SQL> insert into totally_different
  2  select dbms_random.string('A',1000)
  3  from dual connect by level <= 1000
  4  /

1000 rows created.

SQL> select segment_name
  2         , sum(bytes)
  3         , sum(blocks)
  4  from user_segments
  5  where segment_name in ('TOTALLY_SIMILAR', 'TOTALLY_DIFFERENT')
  6  group by segment_name
  7  /

SEGMENT_NAME         SUM(BYTES) SUM(BLOCKS)
-------------------- ---------- -----------
TOTALLY_SIMILAR         2097152         256
TOTALLY_DIFFERENT       2097152         256

SQL>

如果我们压缩它们,我们会得到两个完全不同的结果...

SQL> alter table totally_similar move compress
  2  /

Table altered.

SQL> alter table totally_different move compress
  2  /

Table altered.

SQL> select segment_name
  2         , sum(bytes)
  3         , sum(blocks)
  4  from user_segments
  5  where segment_name in ('TOTALLY_SIMILAR', 'TOTALLY_DIFFERENT')
  6  group by segment_name
  7  /

SEGMENT_NAME         SUM(BYTES) SUM(BLOCKS)
-------------------- ---------- -----------
TOTALLY_SIMILAR           65536           8
TOTALLY_DIFFERENT       2097152         256

SQL>

请注意,TOTALLY_SIMILAR 有八个块大,即使每一行都是相同的。因此,您需要先了解数据的分布,然后才能计算压缩率。 Oracle 文档 是这样说的:

压缩系数可以是
实现取决于基数
特定的列或列对
(代表列的可能性
值重复)和平均值
这些列的行长度。甲骨文
表压缩不仅仅压缩
单列的重复值
但尝试使用多列值
尽可能配对。

在估计回报时,它的建议是目标表的 1000 个块的样本表应该为您提供足够好的预测(尽管更多块可以提供更准确的预测)。在不知道你的块大小的情况下很难判断,但你的 TEST 表似乎比它需要的大得多。重要的是测试表中的数据是否能代表您的目标表。那么,您是使用导出还是目标表中的样本来创建它,例如,

create table test_table as select * from big_table sample block (1)
/

您将需要调整 SAMPLE() 子句中的百分比以确保获得至少 1000 个块。

编辑

在大多数情况下,压缩实际上应该加快数据检索速度,但 YMMV 除外。插入或更新数据时会产生压缩成本。税费是多少以及您是否可以采取任何措施来避免税费取决于您的餐桌的情况。

The key thing about compression is that it works by removing duplicate values in each block. So your test table needs to have a representative spread of data.

Two extreme tables ...

SQL> create table totally_similar
  2      ( txt varchar2(1000) )
  3  /

Table created.

SQL> insert into totally_similar
  2  select rpad('a', 1000, 'a')
  3  from dual connect by level <= 1000
  4  /

1000 rows created.

SQL> create table totally_different
  2      ( txt varchar2(1000) )
  3  /

Table created.

SQL>

Before we compress let's just check the table sizes...

SQL> insert into totally_different
  2  select dbms_random.string('A',1000)
  3  from dual connect by level <= 1000
  4  /

1000 rows created.

SQL> select segment_name
  2         , sum(bytes)
  3         , sum(blocks)
  4  from user_segments
  5  where segment_name in ('TOTALLY_SIMILAR', 'TOTALLY_DIFFERENT')
  6  group by segment_name
  7  /

SEGMENT_NAME         SUM(BYTES) SUM(BLOCKS)
-------------------- ---------- -----------
TOTALLY_SIMILAR         2097152         256
TOTALLY_DIFFERENT       2097152         256

SQL>

If we compress them we get two radically different results ...

SQL> alter table totally_similar move compress
  2  /

Table altered.

SQL> alter table totally_different move compress
  2  /

Table altered.

SQL> select segment_name
  2         , sum(bytes)
  3         , sum(blocks)
  4  from user_segments
  5  where segment_name in ('TOTALLY_SIMILAR', 'TOTALLY_DIFFERENT')
  6  group by segment_name
  7  /

SEGMENT_NAME         SUM(BYTES) SUM(BLOCKS)
-------------------- ---------- -----------
TOTALLY_SIMILAR           65536           8
TOTALLY_DIFFERENT       2097152         256

SQL>

Note that TOTALLY_SIMILAR is eight blocks big, even though every single row was the same. So you need to understand the distribution of your data before you can calculate the compression ratio. The Oracle documentation has this to say:

The compression factor that can be
achieved depends on the cardinality of
a specific column or column pairs
(representing the likelihood of column
value repetitions) and on the average
row length of those columns. Oracle
table compression not only compresses
duplicate values of a single column
but tries to use multi-column value
pairs whenever possible.

Its advice when it comes to estimation of the return is that a sample table of 1000 blocks of the target table should give you a good enough prediction (although more blocks give a more accurate forecast). It is hard to tell without knowing your blocksize, but it seems likely that your TEST table is much bigger than it needs to be. The important thing is whether the data in the test table is representative of your target table. So, did you create it using an export or a sample from the target table, e.g.

create table test_table as select * from big_table sample block (1)
/

You will need to adjust the percentage in the SAMPLE() clause to ensure you get at least 1000 blocks.

edit

In most cases compression should actually speed up data retrieval but YMMV. The cost of compression is paid when inserting or updating the data. How much that tax is and whether you can do anything to avoid it rather depends on the profile of your table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文