如何从 Oracle 表中删除表分区?

发布于 2024-08-13 01:32:31 字数 237 浏览 1 评论 0原文

我发现特定表上使用的分区会损害查询性能,并且希望从表中删除这些分区。有没有简单的方法可以做到这一点?该表有 64 个分区。根据一些初步调查,我提出了以下选项。有更好的办法吗?

  1. 将数据复制到另一个表,删除所有分区,然后将数据复制回原始表
  2. 将数据复制到另一个表,删除原始表,然后重命名新表并重建索引
  3. 使用 MERGE PARTITION 将所有分区合并为一个分区

想法?

I've discovered that the partitions used on a particular table are hurting query performance and would like to remove the partitions from the table. Is there an easy way to do this? The table in question has 64 partitions. Based on some initial investigation, I've come up with the following options. Is there a better way?

  1. Copy data into another table, drop all partitions, then copy the data back into the original table
  2. Copy data into another table, drop the original table, then rename the new table and rebuild the indexes
  3. Use MERGE PARTITION to merge all partitions into a single partition

Thoughts?

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

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

发布评论

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

评论(2

森末i 2024-08-20 01:32:31

我个人认为选项 2 的变体听起来是最好的方法。

  1. 创建新表作为 select * from
    旧表
  2. 在新表上构建索引 (*)
  3. 将旧表重命名为某个名称
    不同
  4. 将新表重命名为旧表名称
  5. 切换任何外键约束
    旧表到新表。还要传输任何授权、同义词等。
  6. 在缓慢的时间内删除旧表

(*)非分区表可能需要与分区表不同的索引。如果您特别重视索引名称,则可以在步骤 6 之后使用 ALTER INDEX ... RENAME TO ... 语法。

这种方法的优点是可以最大限度地减少停机时间(基本上是步骤 3、 4 和 5)。

Personally I think a variant on option 2 sounds like the best approach.

  1. Create new table as select * from
    old table
  2. Build indexes on new table (*)
  3. Rename old table to something
    different
  4. Rename new table to old table name
  5. Switch any foreign key constraints from
    old table to new table. Also transfer any grants, synonyms, etc.
  6. Drop old table in slow time

(*) A non-partitioned table will probably require different indexes from the partitioned one. If you are particularly attached to the index names you can use ALTER INDEX ... RENAME TO ... syntax after step 6.

The advantage of this approach is that it minimises your downtime (basically steps 3, 4 and 5).

等待我真够勒 2024-08-20 01:32:31

对表进行分区可能会损害查询性能,但也可以提高性能......
这取决于您的技术解决方案的设计,使用正确的索引、提示等...

如果您想在不停机的情况下从表中删除分区并使正在使用您的表的其他对象失效,您可以使用dbms_redefinition 它将在您配置/计划重新定义过程时分析和移动索引,您可以配置表的结构。

--1. Verify object for Redefinition
--2. Create Partitioned Interim Table
--3. Start the Redefinition Process
--4. Copy Dependent Objects
--5. Synchronize the Interim Table
--6. Complete the Redefinition Process

--Step 1: Verification
BEGIN
  DBMS_REDEFINITION.CAN_REDEF_TABLE('SCHEMA', 'YOUR_CURRENT_TABLE');
END;

--Step 2: Create Partitioned Interim Table
--sql....
create table SCHEMA.YOUR_FUTURE_TABLE
(
  id                        NUMBER(10),
  some_col                  VARCHAR2(100)
);

--Step 3: Redefinition
BEGIN
  DBMS_REDEFINITION.START_REDEF_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

--Step 4: Copy Keys
DECLARE
  num_errors PLS_INTEGER;
BEGIN
  DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
    uname            => 'SCHEMA',
    orig_table       => 'YOUR_CURRENT_TABLE',
    int_table        => 'YOUR_FUTURE_TABLE',
    num_errors       => num_errors, 
    copy_indexes     => DBMS_REDEFINITION.CONS_ORIG_PARAMS,
    copy_triggers    => TRUE,
    copy_constraints => TRUE,
    copy_privileges  => TRUE,
    ignore_errors    => FALSE, 
    copy_statistics  => TRUE,  
    copy_mvlog       => FALSE  
  );
  IF num_errors > 0 THEN
    DBMS_OUTPUT.PUT_LINE('There are errors: ' || num_errors);
  END IF;
END;

--Step 5: Synchronize Archive
BEGIN
  DBMS_REDEFINITION.SYNC_INTERIM_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

--Step 6: Complete Redefinition 
BEGIN
  DBMS_REDEFINITION.FINISH_REDEF_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

这将从表中移动数据,而不会使其他对象失效,并且不需要任何停机时间。

Partitioning the table, can hurt query performance, but also it can improve performance...
It depends on design of your technical solution, using correct indexes, hints and etc...

If you want to remove partitions from your table without downtime and invalidating other objects which are using your table, you can use dbms_redefinition which will analyse and move indexes as you configure/plan your redefinition process, you can configure your table's structure.

--1. Verify object for Redefinition
--2. Create Partitioned Interim Table
--3. Start the Redefinition Process
--4. Copy Dependent Objects
--5. Synchronize the Interim Table
--6. Complete the Redefinition Process

--Step 1: Verification
BEGIN
  DBMS_REDEFINITION.CAN_REDEF_TABLE('SCHEMA', 'YOUR_CURRENT_TABLE');
END;

--Step 2: Create Partitioned Interim Table
--sql....
create table SCHEMA.YOUR_FUTURE_TABLE
(
  id                        NUMBER(10),
  some_col                  VARCHAR2(100)
);

--Step 3: Redefinition
BEGIN
  DBMS_REDEFINITION.START_REDEF_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

--Step 4: Copy Keys
DECLARE
  num_errors PLS_INTEGER;
BEGIN
  DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
    uname            => 'SCHEMA',
    orig_table       => 'YOUR_CURRENT_TABLE',
    int_table        => 'YOUR_FUTURE_TABLE',
    num_errors       => num_errors, 
    copy_indexes     => DBMS_REDEFINITION.CONS_ORIG_PARAMS,
    copy_triggers    => TRUE,
    copy_constraints => TRUE,
    copy_privileges  => TRUE,
    ignore_errors    => FALSE, 
    copy_statistics  => TRUE,  
    copy_mvlog       => FALSE  
  );
  IF num_errors > 0 THEN
    DBMS_OUTPUT.PUT_LINE('There are errors: ' || num_errors);
  END IF;
END;

--Step 5: Synchronize Archive
BEGIN
  DBMS_REDEFINITION.SYNC_INTERIM_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

--Step 6: Complete Redefinition 
BEGIN
  DBMS_REDEFINITION.FINISH_REDEF_TABLE(
    uname      => 'SCHEMA',
    orig_table => 'YOUR_CURRENT_TABLE',
    int_table  => 'YOUR_FUTURE_TABLE'
  );
END;

This will move your data from tables without invalidating other objects and there is no need for any downtime.

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